karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pie...@apache.org
Subject svn commit: r1442066 - /karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java
Date Mon, 04 Feb 2013 10:15:11 GMT
Author: pieber
Date: Mon Feb  4 10:15:10 2013
New Revision: 1442066

URL: http://svn.apache.org/viewvc?rev=1442066&view=rev
Log:
[KARAF-2159] Add option to resolve transitive feature-dependencies in InstallKarsMojo (thanks
to Christoph Gritschenberger for this patch)

Signed-off-by: Andreas Pieber <anpieber@gmail.com>

Modified:
    karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java

Modified: karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java?rev=1442066&r1=1442065&r2=1442066&view=diff
==============================================================================
--- karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java
(original)
+++ karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java
Mon Feb  4 10:15:10 2013
@@ -34,7 +34,9 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.EnumSet;
+import java.util.HashSet;
 import java.util.List;
+import java.util.ListIterator;
 import java.util.Map;
 import java.util.Set;
 
@@ -43,6 +45,7 @@ import javax.xml.stream.XMLStreamExcepti
 
 import org.apache.felix.utils.properties.Properties;
 import org.apache.karaf.features.BundleInfo;
+import org.apache.karaf.features.Dependency;
 import org.apache.karaf.features.FeaturesService;
 import org.apache.karaf.features.Repository;
 import org.apache.karaf.features.internal.model.Bundle;
@@ -164,8 +167,18 @@ public class InstallKarsMojo extends Moj
      */
     private List<RemoteRepository> remoteRepos;
 
+    /**
+     * When a feature depends on another feature, try to find it in another referenced feature-file
and install that one
+     * too.
+     *
+     * @parameter
+     */
+    private boolean addTransitiveFeatures = true;
+
     private URI system;
     private CommentProperties startupProperties = new CommentProperties();
+    private Set<Feature> featureSet = new HashSet<Feature>();
+    private List<Dependency> missingDependencies = new ArrayList<Dependency>();
 
     /**
      * list of features to  install into local repo.
@@ -399,10 +412,12 @@ public class InstallKarsMojo extends Moj
                     }
                     Features repo = readFeatures(uri);
                     for (Feature feature : repo.getFeature()) {
+                        featureSet.add(feature);
                         if (startupFeatures != null && startupFeatures.contains(feature.getName()))
{
                             installFeature(feature, null);
                         } else if (bootFeatures != null && bootFeatures.contains(feature.getName()))
{
                             localRepoFeatures.add(feature);
+                            missingDependencies.addAll(feature.getDependencies());
                             String existingBootFeatures = retrieveProperty(properties, FEATURES_BOOT);
                             if (!existingBootFeatures.contains(feature.getName())) {
                                 existingBootFeatures = existingBootFeatures + feature.getName();
@@ -410,8 +425,12 @@ public class InstallKarsMojo extends Moj
                             }
                         } else if (installedFeatures != null && installedFeatures.contains(feature.getName()))
{
                             localRepoFeatures.add(feature);
+                            missingDependencies.addAll(feature.getDependencies());
                         }
                     }
+                    if (addTransitiveFeatures) {
+                        addMissingDependenciesToRepo();
+                    }
                     FileOutputStream out = new FileOutputStream(featuresCfgFile);
                     try {
                         properties.save(out);
@@ -428,6 +447,27 @@ public class InstallKarsMojo extends Moj
             }
         }
 
+        private void addMissingDependenciesToRepo() {
+            for (ListIterator<Dependency> iterator = missingDependencies.listIterator();
iterator.hasNext(); ) {
+                Dependency dependency = iterator.next();
+                Feature depFeature = lookupFeature(dependency);
+                if (depFeature == null) {
+                    continue;
+                }
+                localRepoFeatures.add(depFeature);
+                iterator.remove();
+                addAllMissingDependencies(iterator, depFeature);
+            }
+        }
+
+        private void addAllMissingDependencies(ListIterator<Dependency> iterator, Feature
depFeature) {
+            for (Dependency dependency : depFeature.getDependencies()) {
+                if (!missingDependencies.contains(dependency)) {
+                    iterator.add(dependency);
+                }
+            }
+        }
+
         @Override
         public void addRepository(URI uri, boolean install) throws Exception {
         }
@@ -509,6 +549,22 @@ public class InstallKarsMojo extends Moj
             }
         }
 
+        private Feature lookupFeature(Dependency dependency) {
+            for (Feature feature : featureSet) {
+                if (featureSatisfiesDependency(feature, dependency)) {
+                    return feature;
+                }
+            }
+            return null;
+        }
+
+        private boolean featureSatisfiesDependency(Feature feature, Dependency dependency)
{
+            if (!feature.getName().equals(dependency.getName())) {
+                return false;
+            }
+            return true;
+        }
+
         @Override
         public void installFeatures(Set<org.apache.karaf.features.Feature> features,
EnumSet<Option> options)
             throws Exception {



Mime
View raw message