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:41 UTC

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

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
      */