Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6CF10200C3A for ; Thu, 16 Mar 2017 12:00:42 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 6BAEB160B7A; Thu, 16 Mar 2017 11:00:42 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 6A302160B78 for ; Thu, 16 Mar 2017 12:00:41 +0100 (CET) Received: (qmail 57257 invoked by uid 500); 16 Mar 2017 11:00:40 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 57238 invoked by uid 99); 16 Mar 2017 11:00:40 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Mar 2017 11:00:40 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 4B638DFC15; Thu, 16 Mar 2017 11:00:40 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Thu, 16 Mar 2017 11:00:40 -0000 Message-Id: <1bc034773986439aa62ec250bde26584@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] camel git commit: CAMEL-10799: camel-connector maven plugin should update version to actual version of JAR in use archived-at: Thu, 16 Mar 2017 11:00:42 -0000 Repository: camel Updated Branches: refs/heads/master 5889715e4 -> 861548aec CAMEL-10799: camel-connector maven plugin should update version to actual version of JAR in use Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/861548ae Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/861548ae Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/861548ae Branch: refs/heads/master Commit: 861548aec0c53a509f9748996f8d8315b1e9a7fa Parents: a13bed8 Author: Claus Ibsen Authored: Thu Mar 16 12:00:24 2017 +0100 Committer: Claus Ibsen Committed: Thu Mar 16 12:00:33 2017 +0100 ---------------------------------------------------------------------- .../camel/maven/connector/ConnectorMojo.java | 83 +++++++++++--------- .../src/main/resources/camel-connector.json | 42 +++++----- .../src/main/resources/camel-connector.json | 32 ++++---- 3 files changed, 82 insertions(+), 75 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/861548ae/connectors/camel-connector-maven-plugin/src/main/java/org/apache/camel/maven/connector/ConnectorMojo.java ---------------------------------------------------------------------- diff --git a/connectors/camel-connector-maven-plugin/src/main/java/org/apache/camel/maven/connector/ConnectorMojo.java b/connectors/camel-connector-maven-plugin/src/main/java/org/apache/camel/maven/connector/ConnectorMojo.java index c430860..3894b4f 100644 --- a/connectors/camel-connector-maven-plugin/src/main/java/org/apache/camel/maven/connector/ConnectorMojo.java +++ b/connectors/camel-connector-maven-plugin/src/main/java/org/apache/camel/maven/connector/ConnectorMojo.java @@ -95,37 +95,16 @@ public class ConnectorMojo extends AbstractJarMojo { File file = new File(classesDirectory, "camel-connector.json"); if (file.exists()) { - if (includeGitUrl) { - // we want to include the git url of the project - File gitFolder = GitHelper.findGitFolder(); - try { - gitUrl = GitHelper.extractGitUrl(gitFolder); - } catch (IOException e) { - throw new MojoExecutionException("Cannot extract gitUrl due " + e.getMessage(), e); - } - if (gitUrl == null) { - getLog().warn("No .git directory found for connector"); - } - } + // updating to use correct project version in camel-connector.json + String version = getProject().getVersion(); + updateVersionInCamelConnectorJSon("version", version); try { ObjectMapper mapper = new ObjectMapper(); Map dto = mapper.readValue(file, Map.class); - // embed girUrl in camel-connector.json file - if (gitUrl != null) { - String existingGitUrl = (String) dto.get("gitUrl"); - if (existingGitUrl == null || !existingGitUrl.equals(gitUrl)) { - dto.put("gitUrl", gitUrl); - // update file - mapper.writerWithDefaultPrettyPrinter().writeValue(file, dto); - // update source file also - file = new File(root, "src/main/resources/camel-connector.json"); - if (file.exists()) { - getLog().info("Updating gitUrl to " + file); - mapper.writerWithDefaultPrettyPrinter().writeValue(file, dto); - } - } + if (includeGitUrl) { + gitUrl = embedGitUrlInCamelConnectorJSon(mapper, dto); } File schema = embedCamelComponentSchema(file); @@ -193,6 +172,37 @@ public class ConnectorMojo extends AbstractJarMojo { return super.createArchive(); } + private String embedGitUrlInCamelConnectorJSon(ObjectMapper mapper, Map dto) throws MojoExecutionException { + // we want to include the git url of the project + File gitFolder = GitHelper.findGitFolder(); + try { + String gitUrl = GitHelper.extractGitUrl(gitFolder); + if (gitUrl == null) { + return null; + } + + // embed girUrl in camel-connector.json file + String existingGitUrl = (String) dto.get("gitUrl"); + if (existingGitUrl == null || !existingGitUrl.equals(gitUrl)) { + dto.put("gitUrl", gitUrl); + // update file + File file = new File(classesDirectory, "camel-connector.json"); + mapper.writerWithDefaultPrettyPrinter().writeValue(file, dto); + // update source file also + File root = classesDirectory.getParentFile().getParentFile(); + File sourceFile = new File(root, "src/main/resources/camel-connector.json"); + if (sourceFile.exists()) { + getLog().info("Updating gitUrl to " + gitUrl + " in " + sourceFile); + mapper.writerWithDefaultPrettyPrinter().writeValue(sourceFile, dto); + } + } + return gitUrl; + + } catch (IOException e) { + throw new MojoExecutionException("Error in camel-connector-maven-plugin", e); + } + } + private String extractJavaType(String scheme) throws Exception { File file = new File(classesDirectory, "META-INF/services/org/apache/camel/component/" + scheme); if (file.exists()) { @@ -400,8 +410,6 @@ public class ConnectorMojo extends AbstractJarMojo { String scheme = extractScheme(dto); String groupId = extractGroupId(dto); String artifactId = extractArtifactId(dto); - String version = extractVersion(dto); - String baseVersion = null; // find the artifact on the classpath that has the Camel component this connector is using // then we want to grab its json schema file to embed in this JAR so we have all files together @@ -416,8 +424,6 @@ public class ConnectorMojo extends AbstractJarMojo { URL url = new URL("file:" + artifact.getFile()); URLClassLoader child = new URLClassLoader(new URL[]{url}, this.getClass().getClassLoader()); - baseVersion = artifact.getVersion(); - InputStream is = child.getResourceAsStream("META-INF/services/org/apache/camel/component/" + scheme); if (is != null) { List lines = FileHelper.loadFile(is); @@ -445,7 +451,8 @@ public class ConnectorMojo extends AbstractJarMojo { getLog().info("Embedded camel-component-schema.json file for Camel component " + scheme); // updating to use correct base version in camel-connector.json - updateBaseVersionInCamelConnectorJSon(baseVersion); + String baseVersion = artifact.getVersion(); + updateVersionInCamelConnectorJSon("baseVersion", baseVersion); return out; } @@ -462,19 +469,17 @@ public class ConnectorMojo extends AbstractJarMojo { return null; } - private void updateBaseVersionInCamelConnectorJSon(String baseVersion) throws MojoExecutionException { + private void updateVersionInCamelConnectorJSon(String qualifier, String version) throws MojoExecutionException { File file = new File(classesDirectory, "camel-connector.json"); if (file.exists()) { try { ObjectMapper mapper = new ObjectMapper(); Map dto = mapper.readValue(file, Map.class); - // find the component dependency and get its .json file - file = new File(classesDirectory, "camel-connector.json"); - if (baseVersion != null) { - String existingBaseVersion = (String) dto.get("baseVersion"); - if (existingBaseVersion == null || !existingBaseVersion.equals(baseVersion)) { - dto.put("baseVersion", baseVersion); + if (version != null) { + String existingVersion = (String) dto.get(qualifier); + if (existingVersion == null || !existingVersion.equals(version)) { + dto.put(qualifier, version); // update file mapper.writerWithDefaultPrettyPrinter().writeValue(file, dto); // project root folder @@ -482,7 +487,7 @@ public class ConnectorMojo extends AbstractJarMojo { // update source file also file = new File(root, "src/main/resources/camel-connector.json"); if (file.exists()) { - getLog().info("Updating baseVersion to " + baseVersion + " in " + file); + getLog().info("Updating " + qualifier + " to " + version + " in " + file); mapper.writerWithDefaultPrettyPrinter().writeValue(file, dto); } } http://git-wip-us.apache.org/repos/asf/camel/blob/861548ae/connectors/examples/salesforce-upsert-contact-connector/src/main/resources/camel-connector.json ---------------------------------------------------------------------- diff --git a/connectors/examples/salesforce-upsert-contact-connector/src/main/resources/camel-connector.json b/connectors/examples/salesforce-upsert-contact-connector/src/main/resources/camel-connector.json index 1e009ab..79f2c10 100644 --- a/connectors/examples/salesforce-upsert-contact-connector/src/main/resources/camel-connector.json +++ b/connectors/examples/salesforce-upsert-contact-connector/src/main/resources/camel-connector.json @@ -1,26 +1,28 @@ { - "baseScheme": "salesforce", - "baseGroupId": "org.apache.camel", - "baseArtifactId": "camel-salesforce", - "baseVersion": "2.19.0-SNAPSHOT", - "baseJavaType": "org.apache.camel.component.salesforce.SalesforceComponent", - "name": "SalesforceUpsertContact", - "scheme": "salesforce-upsert-contact", - "javaType": "org.foo.salesforce.contact.SalesforceUpsertContactComponent", - "groupId": "org.foo", - "artifactId": "salesforce-upsert-contact-connector", - "version": "1.0", - "description": "Create or update Salesforce Contact SObject", - "labels": [ "salesforce" ], - "pattern": "To", - "inputDataType": "java:org.foo.salesforce.upsert.contact.Contact", - "outputDataType": "none", + "baseScheme" : "salesforce", + "baseGroupId" : "org.apache.camel", + "baseArtifactId" : "camel-salesforce", + "baseVersion" : "2.19.0-SNAPSHOT", + "baseJavaType" : "org.apache.camel.component.salesforce.SalesforceComponent", + "name" : "SalesforceUpsertContact", + "scheme" : "salesforce-upsert-contact", + "javaType" : "org.foo.salesforce.contact.SalesforceUpsertContactComponent", + "groupId" : "org.foo", + "artifactId" : "salesforce-upsert-contact-connector", + "version" : "2.19.0-SNAPSHOT", + "description" : "Create or update Salesforce Contact SObject", + "labels" : [ "salesforce" ], + "pattern" : "To", + "inputDataType" : "java:org.foo.salesforce.upsert.contact.Contact", + "outputDataType" : "none", "componentOptions" : [ "loginUrl", "clientId", "clientSecret", "refreshToken" ], "endpointValues" : { - "operationName": "upsertSObject" + "operationName" : "upsertSObject" }, - "endpointOverrides": { - "sObjectIdName": { "required": true } + "endpointOverrides" : { + "sObjectIdName" : { + "required" : true + } }, - "endpointOptions": [ "sObjectIdName", "sObjectIdValue" ] + "endpointOptions" : [ "sObjectIdName", "sObjectIdValue" ] } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/861548ae/connectors/examples/twitter-mention-connector/src/main/resources/camel-connector.json ---------------------------------------------------------------------- diff --git a/connectors/examples/twitter-mention-connector/src/main/resources/camel-connector.json b/connectors/examples/twitter-mention-connector/src/main/resources/camel-connector.json index 7bc0095..357a830 100644 --- a/connectors/examples/twitter-mention-connector/src/main/resources/camel-connector.json +++ b/connectors/examples/twitter-mention-connector/src/main/resources/camel-connector.json @@ -1,20 +1,20 @@ { - "baseScheme": "twitter", - "baseGroupId": "org.apache.camel", - "baseArtifactId": "camel-twitter", - "baseVersion": "2.19.0-SNAPSHOT", - "baseJavaType": "org.apache.camel.component.twitter.TwitterComponent", - "name": "TwitterMention", - "scheme": "twitter-mention", - "javaType": "org.foo.mention.TwitterMentionComponent", - "groupId": "org.foo", - "artifactId": "twitter-mention-connector", - "version": "1.0", - "description": "Connection from twitter when anyone mention you", - "labels": [ "twitter" ], - "pattern": "From", - "inputDataType": "none", - "outputDataType": "java:twitter4j.Status", + "baseScheme" : "twitter", + "baseGroupId" : "org.apache.camel", + "baseArtifactId" : "camel-twitter", + "baseVersion" : "2.19.0-SNAPSHOT", + "baseJavaType" : "org.apache.camel.component.twitter.TwitterComponent", + "name" : "TwitterMention", + "scheme" : "twitter-mention", + "javaType" : "org.foo.mention.TwitterMentionComponent", + "groupId" : "org.foo", + "artifactId" : "twitter-mention-connector", + "version" : "2.19.0-SNAPSHOT", + "description" : "Connection from twitter when anyone mention you", + "labels" : [ "twitter" ], + "pattern" : "From", + "inputDataType" : "none", + "outputDataType" : "java:twitter4j.Status", "componentOptions" : [ "accessToken", "accessTokenSecret", "consumerKey", "consumerSecret" ], "endpointValues" : { "kind" : "timeline/mentions"