karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject git commit: Add features conditional support in install-kar goal
Date Thu, 25 Sep 2014 19:34:06 GMT
Repository: karaf
Updated Branches:
  refs/heads/karaf-3.0.x 74515f50f -> 77fa6967d


Add features conditional support in install-kar goal


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

Branch: refs/heads/karaf-3.0.x
Commit: 77fa6967d2c1bf086ac5b545c8bd90710732330c
Parents: 74515f5
Author: Jean-Baptiste Onofré <jbonofre@apache.org>
Authored: Thu Sep 25 21:33:07 2014 +0200
Committer: Jean-Baptiste Onofré <jbonofre@apache.org>
Committed: Thu Sep 25 21:33:53 2014 +0200

----------------------------------------------------------------------
 .../karaf/tooling/features/InstallKarsMojo.java | 174 ++++++++++++-------
 1 file changed, 107 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/77fa6967/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java
----------------------------------------------------------------------
diff --git a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java
b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java
index df3653d..b1ea605 100644
--- a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java
+++ b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java
@@ -384,86 +384,99 @@ public class InstallKarsMojo extends MojoSupport {
         // installing feature bundles
         getLog().info("= Installing bundles from " + feature.getName() + " feature");
         for (Bundle bundle : feature.getBundle()) {
-            if (!ignoreDependencyFlag && bundle.isDependency()) {
-                getLog().warn("== Bundle " + bundle.getLocation() + " is defined as dependency,
so it's not installed");
-            } else {
-                getLog().info("== Installing bundle " + bundle.getLocation());
-                String bundleLocation = bundle.getLocation();
-                // cleanup prefixes
-                if (bundleLocation.startsWith("wrap:")) {
-                    bundleLocation = bundleLocation.substring("wrap:".length());
-                    int index = bundleLocation.indexOf("$");
-                    if (index != -1) {
-                        bundleLocation = bundleLocation.substring(0, index);
+            installBundle(bundle);
+        }
+
+        // installing feature config files
+        getLog().info("= Installing configuration files from " + feature.getName() + " feature");
+        for (ConfigFile configFile : feature.getConfigfile()) {
+            installConfigFile(configFile);
+        }
+
+        // installing condition features
+        for (Conditional conditional : feature.getConditional()) {
+            boolean found = true;
+            for (String condition : conditional.getCondition()) {
+                if (!condition.startsWith("req:")) {
+                    if (!installedFeatures.contains(condition) && !bootFeatures.contains(condition))
{
+                        found = false;
+                        break;
                     }
                 }
-                if (bundleLocation.startsWith("blueprint:")) {
-                    bundleLocation = bundleLocation.substring("blueprint:".length());
-                }
-                if (bundleLocation.startsWith("webbundle:")) {
-                    bundleLocation = bundleLocation.substring("webbundle:".length());
-                }
-                if (bundleLocation.startsWith("war:")) {
-                    bundleLocation = bundleLocation.substring("war:".length());
-                }
-                File bundleFile;
-                if (bundleLocation.startsWith("mvn:")) {
-                    if (bundleLocation.endsWith("/")) {
-                        // for bad formed URL (like in Camel for mustache-compiler), we remove
the trailing /
-                        bundleLocation = bundleLocation.substring(0, bundleLocation.length()
- 1);
-                    }
-                    if (bundleLocation.startsWith("mvn:http")) {
-                        // cleanup the URL containing the repository location directly in
the URL
-                        int index = bundleLocation.indexOf("!");
-                        if (index != -1) {
-                            bundleLocation = bundleLocation.substring(index + 1);
-                            bundleLocation = "mvn:" + bundleLocation;
+            }
+            if (found) {
+                getLog().info("= Installing conditional " + conditional.getCondition().toString());
+                getLog().debug("== Conditional features ...");
+                for (Dependency dependency : conditional.getFeature()) {
+                    for (Feature f : features.keySet()) {
+                        if (f.getName().equals(dependency.getName())) {
+                            resolveFeature(f, features);
                         }
                     }
-                    bundleFile = dependencyHelper.resolveById(bundleLocation, getLog());
-                    bundleLocation = dependencyHelper.pathFromMaven(bundleLocation);
-                } else {
-                    bundleFile = new File(new URI(bundleLocation));
                 }
-                File bundleSystemFile = new File(system.resolve(bundleLocation));
-                copy(bundleFile, bundleSystemFile);
-                // add metadata for snapshot
-                if (bundleLocation.startsWith("mvn")) {
-                    Artifact bundleArtifact = dependencyHelper.mvnToArtifact(bundleLocation);
-                    if (bundleArtifact.isSnapshot()) {
-                        File metadataTarget = new File(bundleSystemFile.getParentFile(),
"maven-metadata-local.xml");
-                        try {
-                            MavenUtil.generateMavenMetadata(bundleArtifact, metadataTarget);
-                        } catch (Exception e) {
-                            getLog().warn("Could not create maven-metadata-local.xml", e);
-                            getLog().warn("It means that this SNAPSHOT could be overwritten
by an older one present on remote repositories");
-                        }
-                    }
+                getLog().debug("== Conditional bundles");
+                for (Bundle bundle : conditional.getBundle()) {
+                    installBundle(bundle);
+                }
+                getLog().debug("== Conditional configuration files");
+                for (ConfigFile configFile : conditional.getConfigfile()) {
+                    installConfigFile(configFile);
                 }
             }
         }
+    }
 
-        // installing feature config files
-        getLog().info("= Installing configuration files from " + feature.getName() + " feature");
-        for (ConfigFile configFile : feature.getConfigfile()) {
-            getLog().warn("== Installing configuration file " + configFile.getLocation());
-            String configFileLocation = configFile.getLocation();
-            File configFileFile;
-            if (configFileLocation.startsWith("mvn:")) {
-                configFileFile = dependencyHelper.resolveById(configFileLocation, getLog());
-                configFileLocation = dependencyHelper.pathFromMaven(configFileLocation);
+    private void installBundle(Bundle bundle) throws Exception {
+        if (!ignoreDependencyFlag && bundle.isDependency()) {
+            getLog().warn("== Bundle " + bundle.getLocation() + " is defined as dependency,
so it's not installed");
+        } else {
+            getLog().info("== Installing bundle " + bundle.getLocation());
+            String bundleLocation = bundle.getLocation();
+            // cleanup prefixes
+            if (bundleLocation.startsWith("wrap:")) {
+                bundleLocation = bundleLocation.substring("wrap:".length());
+                int index = bundleLocation.indexOf("$");
+                if (index != -1) {
+                    bundleLocation = bundleLocation.substring(0, index);
+                }
+            }
+            if (bundleLocation.startsWith("blueprint:")) {
+                bundleLocation = bundleLocation.substring("blueprint:".length());
+            }
+            if (bundleLocation.startsWith("webbundle:")) {
+                bundleLocation = bundleLocation.substring("webbundle:".length());
+            }
+            if (bundleLocation.startsWith("war:")) {
+                bundleLocation = bundleLocation.substring("war:".length());
+            }
+            File bundleFile;
+            if (bundleLocation.startsWith("mvn:")) {
+                if (bundleLocation.endsWith("/")) {
+                    // for bad formed URL (like in Camel for mustache-compiler), we remove
the trailing /
+                    bundleLocation = bundleLocation.substring(0, bundleLocation.length()
- 1);
+                }
+                if (bundleLocation.startsWith("mvn:http")) {
+                    // cleanup the URL containing the repository location directly in the
URL
+                    int index = bundleLocation.indexOf("!");
+                    if (index != -1) {
+                        bundleLocation = bundleLocation.substring(index + 1);
+                        bundleLocation = "mvn:" + bundleLocation;
+                    }
+                }
+                bundleFile = dependencyHelper.resolveById(bundleLocation, getLog());
+                bundleLocation = dependencyHelper.pathFromMaven(bundleLocation);
             } else {
-                configFileFile = new File(new URI(configFileLocation));
+                bundleFile = new File(new URI(bundleLocation));
             }
-            File configFileSystemFile = new File(system.resolve(configFileLocation));
-            copy(configFileFile, configFileSystemFile);
+            File bundleSystemFile = new File(system.resolve(bundleLocation));
+            copy(bundleFile, bundleSystemFile);
             // add metadata for snapshot
-            if (configFileLocation.startsWith("mvn")) {
-                Artifact configFileArtifact = dependencyHelper.mvnToArtifact(configFileLocation);
-                if (configFileArtifact.isSnapshot()) {
-                    File metadataTarget = new File(configFileSystemFile.getParentFile(),
"maven-metadata-local.xml");
+            if (bundleLocation.startsWith("mvn")) {
+                Artifact bundleArtifact = dependencyHelper.mvnToArtifact(bundleLocation);
+                if (bundleArtifact.isSnapshot()) {
+                    File metadataTarget = new File(bundleSystemFile.getParentFile(), "maven-metadata-local.xml");
                     try {
-                        MavenUtil.generateMavenMetadata(configFileArtifact, metadataTarget);
+                        MavenUtil.generateMavenMetadata(bundleArtifact, metadataTarget);
                     } catch (Exception e) {
                         getLog().warn("Could not create maven-metadata-local.xml", e);
                         getLog().warn("It means that this SNAPSHOT could be overwritten by
an older one present on remote repositories");
@@ -473,4 +486,31 @@ public class InstallKarsMojo extends MojoSupport {
         }
     }
 
+    private void installConfigFile(ConfigFile configFile) throws Exception {
+        getLog().warn("== Installing configuration file " + configFile.getLocation());
+        String configFileLocation = configFile.getLocation();
+        File configFileFile;
+        if (configFileLocation.startsWith("mvn:")) {
+            configFileFile = dependencyHelper.resolveById(configFileLocation, getLog());
+            configFileLocation = dependencyHelper.pathFromMaven(configFileLocation);
+        } else {
+            configFileFile = new File(new URI(configFileLocation));
+        }
+        File configFileSystemFile = new File(system.resolve(configFileLocation));
+        copy(configFileFile, configFileSystemFile);
+        // add metadata for snapshot
+        if (configFileLocation.startsWith("mvn")) {
+            Artifact configFileArtifact = dependencyHelper.mvnToArtifact(configFileLocation);
+            if (configFileArtifact.isSnapshot()) {
+                File metadataTarget = new File(configFileSystemFile.getParentFile(), "maven-metadata-local.xml");
+                try {
+                    MavenUtil.generateMavenMetadata(configFileArtifact, metadataTarget);
+                } catch (Exception e) {
+                    getLog().warn("Could not create maven-metadata-local.xml", e);
+                    getLog().warn("It means that this SNAPSHOT could be overwritten by an
older one present on remote repositories");
+                }
+            }
+        }
+    }
+
 }


Mime
View raw message