karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject [11/33] git commit: [KARAF-2900] Allow generic requirements as condition to features
Date Fri, 11 Apr 2014 17:20:33 GMT
[KARAF-2900] Allow generic requirements as condition to features


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

Branch: refs/heads/master
Commit: f2669e1d709da292b679307f523a771769129e8b
Parents: fc37f55
Author: Guillaume Nodet <gnodet@gmail.com>
Authored: Fri Apr 11 17:04:09 2014 +0200
Committer: Guillaume Nodet <gnodet@gmail.com>
Committed: Fri Apr 11 19:20:03 2014 +0200

----------------------------------------------------------------------
 .../standard/src/main/feature/feature.xml       |  5 +++-
 .../org/apache/karaf/features/Conditional.java  |  2 +-
 .../features/command/InfoFeatureCommand.java    | 10 +++----
 .../internal/deployment/DeploymentBuilder.java  | 30 ++++++++++++++++----
 .../features/internal/model/Conditional.java    | 14 ++++-----
 .../internal/resolver/FeatureResource.java      | 16 +++++++++--
 .../internal/service/FeaturesServiceImpl.java   |  2 +-
 .../apache/karaf/features/ConditionalTest.java  | 13 +++++++--
 .../karaf/features/internal/service/f06.xml     |  4 +++
 9 files changed, 69 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/f2669e1d/assemblies/features/standard/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/assemblies/features/standard/src/main/feature/feature.xml b/assemblies/features/standard/src/main/feature/feature.xml
index 4d06455..86f8270 100644
--- a/assemblies/features/standard/src/main/feature/feature.xml
+++ b/assemblies/features/standard/src/main/feature/feature.xml
@@ -222,7 +222,10 @@
         </config>
         <feature>shell</feature>
         <feature>jaas</feature>
-        <bundle start="true" start-level="30">mvn:org.apache.mina/mina-core/${mina.version}</bundle>
+        <conditional>
+            <condition>req:osgi.ee;filter:="(&amp;(osgi.ee=JavaSE)(!(version>=1.7)))"</condition>
+            <bundle start="true" start-level="30">mvn:org.apache.mina/mina-core/${mina.version}</bundle>
+        </conditional>
         <bundle start="true" start-level="30">mvn:org.apache.sshd/sshd-core/${sshd.version}</bundle>
         <bundle start="true" start-level="30">mvn:org.apache.karaf.shell/org.apache.karaf.shell.ssh/${project.version}</bundle>
     </feature>

http://git-wip-us.apache.org/repos/asf/karaf/blob/f2669e1d/features/src/main/java/org/apache/karaf/features/Conditional.java
----------------------------------------------------------------------
diff --git a/features/src/main/java/org/apache/karaf/features/Conditional.java b/features/src/main/java/org/apache/karaf/features/Conditional.java
index c0e4d59..fdc9261 100644
--- a/features/src/main/java/org/apache/karaf/features/Conditional.java
+++ b/features/src/main/java/org/apache/karaf/features/Conditional.java
@@ -21,7 +21,7 @@ import java.util.Map;
 
 public interface Conditional {
 
-    List<? extends Dependency> getCondition();
+    List<String> getCondition();
 
     List<Dependency> getDependencies();
 

http://git-wip-us.apache.org/repos/asf/karaf/blob/f2669e1d/features/src/main/java/org/apache/karaf/features/command/InfoFeatureCommand.java
----------------------------------------------------------------------
diff --git a/features/src/main/java/org/apache/karaf/features/command/InfoFeatureCommand.java
b/features/src/main/java/org/apache/karaf/features/command/InfoFeatureCommand.java
index 7084a6e..5ad855c 100644
--- a/features/src/main/java/org/apache/karaf/features/command/InfoFeatureCommand.java
+++ b/features/src/main/java/org/apache/karaf/features/command/InfoFeatureCommand.java
@@ -219,7 +219,7 @@ public class InfoFeatureCommand extends FeaturesCommandSupport {
 
                 if (conditional) {
                     for (Conditional cond : resolved.getConditional()) {
-                        List<? extends Dependency> condition = cond.getCondition();
+                        List<String> condition = cond.getCondition();
                         List<BundleInfo> conditionalBundles = cond.getBundles();
                         for (BundleInfo bundleInfo : conditionalBundles) {
                             bundleLocation.add(bundleInfo.getLocation() + "(condition:"+condition+")");
@@ -278,13 +278,11 @@ public class InfoFeatureCommand extends FeaturesCommandSupport {
 
     private String getConditionDescription(Conditional cond) {
         StringBuffer sb = new StringBuffer();
-        Iterator<? extends Dependency> di = cond.getCondition().iterator();
-        while (di.hasNext()) {
-            Dependency dep = di.next();
-            sb.append(dep.getName()).append("/").append(dep.getVersion());
-            if (di.hasNext()) {
+        for (String dep : cond.getCondition()) {
+            if (sb.length() > 0) {
                 sb.append(" ");
             }
+            sb.append(dep);
         }
         return sb.toString();
     }

http://git-wip-us.apache.org/repos/asf/karaf/blob/f2669e1d/features/src/main/java/org/apache/karaf/features/internal/deployment/DeploymentBuilder.java
----------------------------------------------------------------------
diff --git a/features/src/main/java/org/apache/karaf/features/internal/deployment/DeploymentBuilder.java
b/features/src/main/java/org/apache/karaf/features/internal/deployment/DeploymentBuilder.java
index 00a91c4..c3ac2b7 100644
--- a/features/src/main/java/org/apache/karaf/features/internal/deployment/DeploymentBuilder.java
+++ b/features/src/main/java/org/apache/karaf/features/internal/deployment/DeploymentBuilder.java
@@ -158,8 +158,7 @@ public class DeploymentBuilder {
         return resources;
     }
 
-    public Map<Resource, List<Wire>> resolve(List<Resource> systemBundles,
-                                        boolean resolveOptionalImports) throws ResolutionException
{
+    public Map<Resource, List<Wire>> resolve(List<Resource> systemBundles)
throws ResolutionException {
         // Resolve
         for (int i = 0; i < systemBundles.size(); i++) {
             resources.put("system-bundle-" + i, systemBundles.get(i));
@@ -172,11 +171,32 @@ public class DeploymentBuilder {
         ResolverImpl resolver = new ResolverImpl(new Slf4jResolverLog(LOGGER));
         ResolveContext context = new ResolveContextImpl(
                 Collections.<Resource>singleton(requirements),
-                this.optionals,
+                Collections.<Resource>emptySet(),
                 new AggregateRepository(repos),
-                resolveOptionalImports);
+                false);
+        Map<Resource, List<Wire>> best = resolver.resolve(context);
 
-        return resolver.resolve(context);
+        // TODO: we actually need to use multiple passes for conditionals
+        // TODO: but it may be optimized by passing the old wiring instead
+        // TODO: of computing everything again
+        Set<Resource> resources = new HashSet<Resource>();
+        resources.add(requirements);
+        for (Resource optional : optionals) {
+            try {
+                Set<Resource> newSet = new HashSet<Resource>(resources);
+                newSet.add(optional);
+                context = new ResolveContextImpl(
+                        newSet,
+                        Collections.<Resource>emptySet(),
+                        new AggregateRepository(repos),
+                        false);
+                best = resolver.resolve(context);
+                resources = newSet;
+            } catch (ResolutionException e) {
+                // Ignore this resource
+            }
+        }
+        return best;
     }
 
     public void requireFeature(String feature) throws IOException {

http://git-wip-us.apache.org/repos/asf/karaf/blob/f2669e1d/features/src/main/java/org/apache/karaf/features/internal/model/Conditional.java
----------------------------------------------------------------------
diff --git a/features/src/main/java/org/apache/karaf/features/internal/model/Conditional.java
b/features/src/main/java/org/apache/karaf/features/internal/model/Conditional.java
index 5bc0b95..ed0e8ff 100644
--- a/features/src/main/java/org/apache/karaf/features/internal/model/Conditional.java
+++ b/features/src/main/java/org/apache/karaf/features/internal/model/Conditional.java
@@ -36,11 +36,11 @@ import org.apache.karaf.features.Feature;
 public class Conditional extends Content implements org.apache.karaf.features.Conditional
{
 
     @XmlElement(name = "condition")
-    protected List<Dependency> condition;
+    protected List<String> condition;
 
-    public List<Dependency> getCondition() {
+    public List<String> getCondition() {
         if (condition == null) {
-            this.condition = new ArrayList<Dependency>();
+            this.condition = new ArrayList<String>();
         }
         return condition;
     }
@@ -58,13 +58,11 @@ public class Conditional extends Content implements org.apache.karaf.features.Co
 
     private String getConditionId() {
         StringBuffer sb = new StringBuffer();
-        Iterator<Dependency> di = getCondition().iterator();
-        while (di.hasNext()) {
-            Dependency dependency = di.next();
-            sb.append(dependency.getName() + "_" + dependency.getVersion());
-            if (di.hasNext()) {
+        for (String cond : getCondition()) {
+            if (sb.length() > 0) {
                 sb.append("_");
             }
+            sb.append(cond);
         }
         return sb.toString();
     }

http://git-wip-us.apache.org/repos/asf/karaf/blob/f2669e1d/features/src/main/java/org/apache/karaf/features/internal/resolver/FeatureResource.java
----------------------------------------------------------------------
diff --git a/features/src/main/java/org/apache/karaf/features/internal/resolver/FeatureResource.java
b/features/src/main/java/org/apache/karaf/features/internal/resolver/FeatureResource.java
index 88f08ae..e3b0101 100644
--- a/features/src/main/java/org/apache/karaf/features/internal/resolver/FeatureResource.java
+++ b/features/src/main/java/org/apache/karaf/features/internal/resolver/FeatureResource.java
@@ -44,8 +44,20 @@ public class FeatureResource extends ResourceImpl {
     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);
+        for (String cond : conditional.getCondition()) {
+            if (cond.startsWith("req:")) {
+                cond = cond.substring("req:".length());
+                List<Requirement> reqs = ResourceBuilder.parseRequirement(resource,
cond);
+                resource.addRequirements(reqs);
+            } else {
+                org.apache.karaf.features.internal.model.Dependency dep = new org.apache.karaf.features.internal.model.Dependency();
+                String[] p = cond.split("/");
+                dep.setName(p[0]);
+                if (p.length > 1) {
+                    dep.setVersion(p[1]);
+                }
+                addDependency(resource, dep, featureRange);
+            }
         }
         org.apache.karaf.features.internal.model.Dependency dep = new org.apache.karaf.features.internal.model.Dependency();
         dep.setName(feature.getName());

http://git-wip-us.apache.org/repos/asf/karaf/blob/f2669e1d/features/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
----------------------------------------------------------------------
diff --git a/features/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
b/features/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
index 7008ef6..0243dc0 100644
--- a/features/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
+++ b/features/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
@@ -790,7 +790,7 @@ public class FeaturesServiceImpl implements FeaturesService {
                          Collections.<String>emptySet(),
                          overrides,
                          Collections.<String>emptySet());
-        Map<Resource, List<Wire>> resolution = builder.resolve(systemBundles,
true);
+        Map<Resource, List<Wire>> resolution = builder.resolve(systemBundles);
         Collection<Resource> allResources = resolution.keySet();
         Map<String, StreamProvider> providers = builder.getProviders();
 

http://git-wip-us.apache.org/repos/asf/karaf/blob/f2669e1d/features/src/test/java/org/apache/karaf/features/ConditionalTest.java
----------------------------------------------------------------------
diff --git a/features/src/test/java/org/apache/karaf/features/ConditionalTest.java b/features/src/test/java/org/apache/karaf/features/ConditionalTest.java
index d5e7e46..b103683 100644
--- a/features/src/test/java/org/apache/karaf/features/ConditionalTest.java
+++ b/features/src/test/java/org/apache/karaf/features/ConditionalTest.java
@@ -31,17 +31,24 @@ public class ConditionalTest extends TestCase {
         Feature feature = features[0];
 
         assertNotNull(feature.getConditional());
-        assertEquals(1,feature.getConditional().size());
+        assertEquals(2,feature.getConditional().size());
 
         Conditional conditional = feature.getConditional().get(0);
         assertNotNull(conditional.getCondition());
         assertEquals(1,conditional.getCondition().size());
-        Dependency dependency = conditional.getCondition().get(0);
+        String dependency = conditional.getCondition().get(0);
         assertNotNull(dependency);
-        assertEquals(dependency.getName(),"http");
+        assertEquals("http", dependency);
         assertNotNull(conditional.getBundles());
         assertEquals(1, feature.getConditional().get(0).getBundles().size());
 
+        conditional = feature.getConditional().get(1);
+        assertNotNull(conditional.getCondition());
+        assertEquals(1,conditional.getCondition().size());
+        dependency = conditional.getCondition().get(0);
+        assertNotNull(dependency);
+        assertEquals("req:osgi.ee;filter:=\"(&(osgi.ee=JavaSE)(!(version>=1.7)))\"",
dependency);
+
         String wrapperName = "my6/1.5.3-beta-3".replaceAll("[^A-Za-z0-9 ]", "_");
     }
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/f2669e1d/features/src/test/resources/org/apache/karaf/features/internal/service/f06.xml
----------------------------------------------------------------------
diff --git a/features/src/test/resources/org/apache/karaf/features/internal/service/f06.xml
b/features/src/test/resources/org/apache/karaf/features/internal/service/f06.xml
index 496cbdb..51e78f1 100644
--- a/features/src/test/resources/org/apache/karaf/features/internal/service/f06.xml
+++ b/features/src/test/resources/org/apache/karaf/features/internal/service/f06.xml
@@ -27,6 +27,10 @@
             <condition>http</condition>
             <bundle>mvn:org.springframework/spring-web/2.5.6.SEC02</bundle>
         </conditional>
+        <conditional>
+            <condition>req:osgi.ee;filter:="(&amp;(osgi.ee=JavaSE)(!(version>=1.7)))"</condition>
+            <bundle start="true" start-level="30">mvn:org.apache.mina/mina-core/${mina.version}</bundle>
+        </conditional>
     </feature>
 </features>
 


Mime
View raw message