You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/03/16 11:00:40 UTC

[1/2] camel git commit: CAMEL-10799: camel-connector maven plugin should update version to actual version of JAR in use

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 <da...@apache.org>
Authored: Thu Mar 16 12:00:24 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
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<String> 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"


[2/2] camel git commit: CAMEL-10799: camel-connector maven plugin should update baseVersion to actual version of JAR in use

Posted by da...@apache.org.
CAMEL-10799: camel-connector maven plugin should update baseVersion 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/a13bed88
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a13bed88
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a13bed88

Branch: refs/heads/master
Commit: a13bed8878368bda36cb608716a8102d61962ed7
Parents: 5889715
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Mar 16 11:29:43 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Mar 16 12:00:33 2017 +0100

----------------------------------------------------------------------
 .../camel/maven/connector/ConnectorMojo.java    | 39 +++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a13bed88/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 59c91d8..c430860 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
@@ -401,6 +401,7 @@ public class ConnectorMojo extends AbstractJarMojo {
             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
@@ -410,11 +411,13 @@ public class ConnectorMojo extends AbstractJarMojo {
                     Artifact artifact = (Artifact) obj;
                     if ("jar".equals(artifact.getType())) {
                         // use baseVersion so we can support SNAPSHOT versions that are based on a base version
-                        if (groupId.equals(artifact.getGroupId()) && artifactId.equals(artifact.getArtifactId()) && version.equals(artifact.getBaseVersion())) {
+                        if (groupId.equals(artifact.getGroupId()) && artifactId.equals(artifact.getArtifactId())) {
                             // load the component file inside the file
                             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<String> lines = FileHelper.loadFile(is);
@@ -441,6 +444,9 @@ 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);
+
                                     return out;
                                 }
                             }
@@ -456,6 +462,37 @@ public class ConnectorMojo extends AbstractJarMojo {
         return null;
     }
 
+    private void updateBaseVersionInCamelConnectorJSon(String baseVersion) 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);
+                        // update file
+                        mapper.writerWithDefaultPrettyPrinter().writeValue(file, dto);
+                        // project root folder
+                        File root = classesDirectory.getParentFile().getParentFile();
+                        // 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);
+                            mapper.writerWithDefaultPrettyPrinter().writeValue(file, dto);
+                        }
+                    }
+                }
+            } catch (Exception e) {
+                throw new MojoExecutionException("Error in camel-connector-maven-plugin", e);
+            }
+        }
+    }
+
     /**
      * Builds a JSon line of the given row
      */