karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject [1/3] git commit: [KARAF-2888] Use single resolution to compute feature conditionals, modelled with optional resources
Date Wed, 09 Apr 2014 13:25:34 GMT
Repository: karaf
Updated Branches:
  refs/heads/master 678919692 -> 2b13959ee


[KARAF-2888] Use single resolution to compute feature conditionals, modelled with optional
resources

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

Branch: refs/heads/master
Commit: de72fa9dabfdcaf0df5e4b1715179df42f4ec6c8
Parents: 6789196
Author: Guillaume Nodet <gnodet@gmail.com>
Authored: Wed Apr 9 08:16:59 2014 +0200
Committer: Guillaume Nodet <gnodet@gmail.com>
Committed: Wed Apr 9 12:12:15 2014 +0200

----------------------------------------------------------------------
 .../internal/deployment/DeploymentBuilder.java  | 15 ++++--
 .../internal/resolver/FeatureResource.java      | 48 ++++++++++++++------
 .../internal/service/FeaturesServiceImpl.java   | 42 -----------------
 3 files changed, 44 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/de72fa9d/features/core/src/main/java/org/apache/karaf/features/internal/deployment/DeploymentBuilder.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/deployment/DeploymentBuilder.java
b/features/core/src/main/java/org/apache/karaf/features/internal/deployment/DeploymentBuilder.java
index 022e56f..00a91c4 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/deployment/DeploymentBuilder.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/deployment/DeploymentBuilder.java
@@ -81,6 +81,7 @@ public class DeploymentBuilder {
     Downloader downloader;
     ResourceImpl requirements;
     Map<String, Resource> resources;
+    Set<Resource> optionals;
     Map<String, StreamProvider> providers;
 
     Set<Feature> featuresToRegister = new HashSet<Feature>();
@@ -112,6 +113,7 @@ public class DeploymentBuilder {
                          Set<String> optionals)
                 throws IOException, MultiException, InterruptedException, ResolutionException,
BundleException {
         this.resources = new ConcurrentHashMap<String, Resource>();
+        this.optionals = new HashSet<Resource>();
         this.providers = new ConcurrentHashMap<String, StreamProvider>();
         this.requirements = new ResourceImpl("dummy", "dummy", Version.emptyVersion);
         // First, gather all bundle resources
@@ -139,10 +141,13 @@ public class DeploymentBuilder {
         for (Feature feature : featuresToRegister) {
             Resource resource = FeatureResource.build(feature, featureRange, resources);
             resources.put("feature:" + feature.getName() + "/" + feature.getVersion(), resource);
+            for (Conditional cond : feature.getConditional()) {
+                this.optionals.add(FeatureResource.build(feature, cond, featureRange, resources));
+            }
         }
         // Build requirements
         for (String feature : features) {
-            requireFeature(feature, requirements);
+            requireFeature(feature);
         }
         for (String bundle : bundles) {
             requireResource(bundle);
@@ -167,14 +172,14 @@ public class DeploymentBuilder {
         ResolverImpl resolver = new ResolverImpl(new Slf4jResolverLog(LOGGER));
         ResolveContext context = new ResolveContextImpl(
                 Collections.<Resource>singleton(requirements),
-                Collections.<Resource>emptySet(),
+                this.optionals,
                 new AggregateRepository(repos),
                 resolveOptionalImports);
 
         return resolver.resolve(context);
     }
 
-    public void requireFeature(String feature, ResourceImpl resource) throws IOException
{
+    public void requireFeature(String feature) throws IOException {
         // Find name and version range
         String[] split = feature.split("/");
         String name = split[0].trim();
@@ -188,8 +193,8 @@ public class DeploymentBuilder {
         attrs.put(IdentityNamespace.IDENTITY_NAMESPACE, name);
         attrs.put(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, FeatureNamespace.TYPE_FEATURE);
         attrs.put(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, range);
-        resource.addRequirement(
-                new RequirementImpl(resource, IdentityNamespace.IDENTITY_NAMESPACE,
+        requirements.addRequirement(
+                new RequirementImpl(requirements, IdentityNamespace.IDENTITY_NAMESPACE,
                         Collections.<String, String>emptyMap(), attrs)
         );
     }

http://git-wip-us.apache.org/repos/asf/karaf/blob/de72fa9d/features/core/src/main/java/org/apache/karaf/features/internal/resolver/FeatureResource.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/resolver/FeatureResource.java
b/features/core/src/main/java/org/apache/karaf/features/internal/resolver/FeatureResource.java
index 7d1671c..88f08ae 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/resolver/FeatureResource.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/resolver/FeatureResource.java
@@ -23,6 +23,7 @@ import java.util.Map;
 import org.apache.felix.utils.version.VersionRange;
 import org.apache.felix.utils.version.VersionTable;
 import org.apache.karaf.features.BundleInfo;
+import org.apache.karaf.features.Conditional;
 import org.apache.karaf.features.Dependency;
 import org.apache.karaf.features.Feature;
 import org.apache.karaf.features.internal.util.Macro;
@@ -40,6 +41,19 @@ public class FeatureResource extends ResourceImpl {
 
     private final Feature feature;
 
+    public static Resource build(Feature feature, Conditional conditional, String featureRange,
Map<String, Resource> locToRes) throws BundleException {
+        Feature fcond = conditional.asFeature(feature.getName(), feature.getVersion());
+        FeatureResource resource = (FeatureResource) build(fcond, featureRange, locToRes);
+        for (Dependency dep : conditional.getCondition()) {
+            addDependency(resource, dep, featureRange);
+        }
+        org.apache.karaf.features.internal.model.Dependency dep = new org.apache.karaf.features.internal.model.Dependency();
+        dep.setName(feature.getName());
+        dep.setVersion(feature.getVersion());
+        addDependency(resource, dep, featureRange);
+        return resource;
+    }
+
     public static Resource build(Feature feature, String featureRange, Map<String, Resource>
locToRes) throws BundleException {
         FeatureResource resource = new FeatureResource(feature);
         Map<String, String> dirs = new HashMap<String, String>();
@@ -66,20 +80,7 @@ public class FeatureResource extends ResourceImpl {
             }
         }
         for (Dependency dep : feature.getDependencies()) {
-            String name = dep.getName();
-            String version = dep.getVersion();
-            if (version.equals("0.0.0")) {
-                version = null;
-            } else if (!version.startsWith("[") && !version.startsWith("(")) {
-                version = Macro.transform(featureRange, version);
-            }
-            dirs = new HashMap<String, String>();
-            attrs = new HashMap<String, Object>();
-            attrs.put(FeatureNamespace.FEATURE_NAMESPACE, name);
-            if (version != null) {
-                attrs.put(FeatureNamespace.CAPABILITY_VERSION_ATTRIBUTE, new VersionRange(version));
-            }
-            resource.addRequirement(new RequirementImpl(resource, FeatureNamespace.FEATURE_NAMESPACE,
dirs, attrs));
+            addDependency(resource, dep, featureRange);
         }
         for (org.apache.karaf.features.Capability cap : feature.getCapabilities()) {
             resource.addCapabilities(ResourceBuilder.parseCapability(resource, cap.getValue()));
@@ -90,6 +91,25 @@ public class FeatureResource extends ResourceImpl {
         return resource;
     }
 
+    protected static void addDependency(FeatureResource resource, Dependency dep, String
featureRange) {
+        Map<String, String> dirs;
+        Map<String, Object> attrs;
+        String name = dep.getName();
+        String version = dep.getVersion();
+        if (version.equals("0.0.0")) {
+            version = null;
+        } else if (!version.startsWith("[") && !version.startsWith("(")) {
+            version = Macro.transform(featureRange, version);
+        }
+        dirs = new HashMap<String, String>();
+        attrs = new HashMap<String, Object>();
+        attrs.put(FeatureNamespace.FEATURE_NAMESPACE, name);
+        if (version != null) {
+            attrs.put(FeatureNamespace.CAPABILITY_VERSION_ATTRIBUTE, new VersionRange(version));
+        }
+        resource.addRequirement(new RequirementImpl(resource, FeatureNamespace.FEATURE_NAMESPACE,
dirs, attrs));
+    }
+
     public FeatureResource(Feature feature) {
         super(feature.getName(), FeatureNamespace.TYPE_FEATURE, VersionTable.getVersion(feature.getVersion()));
         this.feature = feature;

http://git-wip-us.apache.org/repos/asf/karaf/blob/de72fa9d/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
index a42e133..8766c91 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
@@ -737,48 +737,6 @@ public class FeaturesServiceImpl implements FeaturesService {
         List<String> installedFeatureIds = getFeatureIds(allResources);
         List<Feature> installedFeatures = getFeatures(repositories, installedFeatureIds);
 
-        // TODO: is there are a way to use fragments or on-demand resources
-        // TODO: in the resolver to use a single resolution ?
-        boolean resolveAgain = false;
-        Set<String> featuresAndConditionals = new TreeSet<String>(features);
-        for (Feature feature : installedFeatures) {
-            for (Conditional cond : feature.getConditional()) {
-                boolean condSatisfied = true;
-                for (Dependency dep : cond.getCondition()) {
-                    boolean depSatisfied = false;
-                    String name = dep.getName();
-                    VersionRange range = new VersionRange(dep.getVersion(), false, true);
-                    for (Feature f : installedFeatures) {
-                        if (f.getName().equals(name)) {
-                            if (range.contains(VersionTable.getVersion(f.getVersion())))
{
-                                depSatisfied = true;
-                                break;
-                            }
-                        }
-                    }
-                    if (!depSatisfied) {
-                        condSatisfied = false;
-                        break;
-                    }
-                }
-                if (condSatisfied) {
-                    featuresAndConditionals.add(cond.asFeature(feature.getName(), feature.getVersion()).getId());
-                    resolveAgain = true;
-                }
-            }
-        }
-        if (resolveAgain) {
-            builder.download(featuresAndConditionals,
-                             Collections.<String>emptySet(),
-                             Collections.<String>emptySet(),
-                             overrides,
-                             Collections.<String>emptySet());
-            resolution = builder.resolve(systemBundles, false);
-            allResources = resolution.keySet();
-            providers = builder.getProviders();
-        }
-
-
         //
         // Compute list of installable resources (those with uris)
         //


Mime
View raw message