You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2016/10/21 13:59:41 UTC

[2/3] karaf git commit: [KARAF-4801] Remove some requirements for the verify goal

[KARAF-4801] Remove some requirements for the verify goal

Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/597a2778
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/597a2778
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/597a2778

Branch: refs/heads/master
Commit: 597a2778e731d68c53d3206ca3e1b834e194a048
Parents: 3065ace
Author: Guillaume Nodet <gn...@apache.org>
Authored: Fri Oct 21 14:09:28 2016 +0200
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Fri Oct 21 14:49:45 2016 +0200

----------------------------------------------------------------------
 tooling/karaf-maven-plugin/pom.xml              |  9 +++
 .../apache/karaf/tooling/versions.properties    |  1 +
 .../org/apache/karaf/tooling/VerifyMojo.java    | 74 +++++++++++++++++---
 3 files changed, 74 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/597a2778/tooling/karaf-maven-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/tooling/karaf-maven-plugin/pom.xml b/tooling/karaf-maven-plugin/pom.xml
index 1f8ed33..e0a0118 100644
--- a/tooling/karaf-maven-plugin/pom.xml
+++ b/tooling/karaf-maven-plugin/pom.xml
@@ -211,6 +211,15 @@
     </dependencies>
 
     <build>
+        <resources>
+            <resource>
+                <directory>${project.basedir}/src/main/resources</directory>
+            </resource>
+            <resource>
+                <directory>${project.basedir}/src/main/filtered-resources</directory>
+                <filtering>true</filtering>
+            </resource>
+        </resources>
         <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>

http://git-wip-us.apache.org/repos/asf/karaf/blob/597a2778/tooling/karaf-maven-plugin/src/main/filtered-resources/org/apache/karaf/tooling/versions.properties
----------------------------------------------------------------------
diff --git a/tooling/karaf-maven-plugin/src/main/filtered-resources/org/apache/karaf/tooling/versions.properties b/tooling/karaf-maven-plugin/src/main/filtered-resources/org/apache/karaf/tooling/versions.properties
new file mode 100644
index 0000000..fbeec5d
--- /dev/null
+++ b/tooling/karaf-maven-plugin/src/main/filtered-resources/org/apache/karaf/tooling/versions.properties
@@ -0,0 +1 @@
+karaf-version=${project.version}

http://git-wip-us.apache.org/repos/asf/karaf/blob/597a2778/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java
----------------------------------------------------------------------
diff --git a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java
index 29f215f..b6b1194 100644
--- a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java
+++ b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java
@@ -132,6 +132,9 @@ public class VerifyMojo extends MojoSupport {
     @Parameter(property = "dist-dir")
     protected String distDir;
 
+    @Parameter(property = "karaf-version")
+    protected String karafVersion;
+
     @Parameter(property = "additional-metadata")
     protected File additionalMetadata;
 
@@ -157,6 +160,17 @@ public class VerifyMojo extends MojoSupport {
         if (skip) {
             return;
         }
+
+        if (karafVersion == null) {
+            Properties versions = new Properties();
+            try (InputStream is = getClass().getResourceAsStream("versions.properties")) {
+                versions.load(is);
+            } catch (IOException e) {
+                throw new IllegalStateException(e);
+            }
+            karafVersion = versions.getProperty("karaf-version");
+        }
+
         Hashtable<String, String> config = new Hashtable<>();
         StringBuilder remote = new StringBuilder();
         for (Object obj : project.getRemoteProjectRepositories()) {
@@ -181,6 +195,22 @@ public class VerifyMojo extends MojoSupport {
         doExecute();
     }
 
+    private String getVersion(String id, String def) {
+        String v = getVersion(id);
+        return v != null ? v : def;
+    }
+
+    private String getVersion(String id) {
+        Artifact artifact = project.getArtifactMap().get(id);
+        if (artifact != null) {
+            return artifact.getBaseVersion();
+        } else if (id.startsWith("org.apache.karaf")) {
+            return karafVersion;
+        } else {
+            return null;
+        }
+    }
+
     private Object invoke(Object object, String getter) throws MojoExecutionException {
         try {
             return object.getClass().getMethod(getter).invoke(object);
@@ -221,6 +251,21 @@ public class VerifyMojo extends MojoSupport {
             }
         }
 
+        if (descriptors == null) {
+            if (framework == null) {
+                framework = Collections.singleton("framework");
+            }
+            descriptors = new LinkedHashSet<>();
+            if (framework.contains("framework")) {
+                descriptors.add("mvn:org.apache.karaf.features/framework/" + getVersion("org.apache.karaf.features:framework") + "/xml/features");
+            }
+            descriptors.add("file:" + project.getBuild().getDirectory() + "/feature/feature.xml");
+        } else {
+            if (framework != null && framework.contains("framework")) {
+                descriptors.add("mvn:org.apache.karaf.features/framework/" + getVersion("org.apache.karaf.features:framework") + "/xml/features");
+            }
+        }
+
         // TODO: allow using external configuration ?
         ScheduledExecutorService executor = Executors.newScheduledThreadPool(8);
         DownloadManager manager = new CustomDownloadManager(resolver, executor);
@@ -455,17 +500,26 @@ public class VerifyMojo extends MojoSupport {
             configPropURL = new URL(configuration);
         } else {
             Artifact karafDistro = project.getArtifactMap().get(distribution);
-            if (karafDistro == null) {
-                throw new MojoFailureException("The karaf distribution " + distribution + " is not a dependency");
-            }
-            if ("kar".equals(karafDistro.getType()) && distDir == null) {
-                distDir = "resources";
-            }
-            String dir = distDir;
-            if (dir == null) {
-                dir = karafDistro.getArtifactId() + "-" + karafDistro.getBaseVersion();
+            if (karafDistro != null) {
+                String dir = distDir;
+                if ("kar".equals(karafDistro.getType()) && dir == null) {
+                    dir = "resources";
+                }
+                if (dir == null) {
+                    dir = karafDistro.getArtifactId() + "-" + karafDistro.getBaseVersion();
+                }
+                configPropURL = new URL("jar:file:" + karafDistro.getFile() + "!/" + dir + "/etc/config.properties");
+            } else {
+                String version = getVersion(distribution, "RELEASE");
+                String[] dist = distribution.split(":");
+                File distFile = resolver.resolve(dist[0], dist[1], null, "zip", version);
+                String resolvedVersion = distFile.getName().substring(dist[1].length() + 1, distFile.getName().length() - 4);
+                String dir = distDir;
+                if (dir == null) {
+                    dir = dist[1] + "-" + resolvedVersion;
+                }
+                configPropURL = new URL("jar:file:" + distFile + "!/" + dir + "/etc/config.properties");
             }
-            configPropURL = new URL("jar:file:" + karafDistro.getFile() + "!/" + dir + "/etc/config.properties");
         }
         org.apache.felix.utils.properties.Properties configProps = PropertiesLoader.loadPropertiesFile(configPropURL, true);
 //        copySystemProperties(configProps);