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 2014/04/25 14:41:01 UTC
[4/6] git commit: [KARAF-2923] Make sure bundles part of a
conditional are only used to solve optional dependencies if the conditional
itself is satisfied
[KARAF-2923] Make sure bundles part of a conditional are only used to solve optional dependencies if the conditional itself is satisfied
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/09a5e995
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/09a5e995
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/09a5e995
Branch: refs/heads/master
Commit: 09a5e995d9951260060742ef938d7fa6f62dccd8
Parents: bbaa966
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Fri Apr 25 13:15:45 2014 +0200
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Fri Apr 25 13:15:45 2014 +0200
----------------------------------------------------------------------
.../features/internal/region/Subsystem.java | 45 +++++++++++---------
.../features/internal/region/SubsystemTest.java | 42 ++++++++++++++++++
.../karaf/features/internal/region/data4/a.mf | 6 +++
.../karaf/features/internal/region/data4/b.mf | 6 +++
.../features/internal/region/data4/features.xml | 32 ++++++++++++++
5 files changed, 112 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/09a5e995/features/core/src/main/java/org/apache/karaf/features/internal/region/Subsystem.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/region/Subsystem.java b/features/core/src/main/java/org/apache/karaf/features/internal/region/Subsystem.java
index 651c388..8d6277a 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/region/Subsystem.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/region/Subsystem.java
@@ -254,16 +254,16 @@ public class Subsystem extends ResourceImpl {
if (feature != null) {
final Map<String, ResourceImpl> bundles = new ConcurrentHashMap<String, ResourceImpl>();
final Downloader downloader = manager.createDownloader();
- final Map<BundleInfo, Boolean> infos = new HashMap<BundleInfo, Boolean>();
+ final Map<BundleInfo, Conditional> infos = new HashMap<BundleInfo, Conditional>();
for (Conditional cond : feature.getConditional()) {
for (final BundleInfo bi : cond.getBundles()) {
- infos.put(bi, false);
+ infos.put(bi, cond);
}
}
for (BundleInfo bi : feature.getBundles()) {
- infos.put(bi, true);
+ infos.put(bi, null);
}
- for (Map.Entry<BundleInfo, Boolean> entry : infos.entrySet()) {
+ for (Map.Entry<BundleInfo, Conditional> entry : infos.entrySet()) {
final BundleInfo bi = entry.getKey();
final String loc = bi.getLocation();
downloader.download(loc, new DownloadCallback() {
@@ -286,17 +286,6 @@ public class Subsystem extends ResourceImpl {
}
downloader.await();
Overrides.override(bundles, overrides);
- for (Map.Entry<BundleInfo, Boolean> entry : infos.entrySet()) {
- final BundleInfo bi = entry.getKey();
- final String loc = bi.getLocation();
- final boolean mandatory = entry.getValue();
- ResourceImpl res = bundles.get(loc);
- if (bi.isDependency()) {
- addDependency(res, false, bi.isStart(), bi.getStartLevel());
- } else {
- doAddDependency(res, mandatory, bi.isStart(), bi.getStartLevel());
- }
- }
for (Dependency dep : feature.getDependencies()) {
Subsystem ss = this;
while (!ss.isAcceptDependencies()) {
@@ -304,15 +293,33 @@ public class Subsystem extends ResourceImpl {
}
ss.requireFeature(dep.getName(), dep.getVersion());
}
+ // Add conditionals
+ Map<Conditional, Resource> resConds = new HashMap<Conditional, Resource>();
for (Conditional cond : feature.getConditional()) {
FeatureResource resCond = FeatureResource.build(feature, cond, featureResolutionRange, bundles);
addIdentityRequirement(this, resCond, false);
installable.add(resCond);
+ resConds.put(cond, resCond);
+ }
+ // Add features
+ FeatureResource resFeature = FeatureResource.build(feature, featureResolutionRange, bundles);
+ addIdentityRequirement(resFeature, this);
+ installable.add(resFeature);
+ // Add dependencies
+ for (Map.Entry<BundleInfo, Conditional> entry : infos.entrySet()) {
+ final BundleInfo bi = entry.getKey();
+ final String loc = bi.getLocation();
+ final Conditional cond = entry.getValue();
+ ResourceImpl res = bundles.get(loc);
+ if (bi.isDependency()) {
+ addDependency(res, false, bi.isStart(), bi.getStartLevel());
+ } else {
+ doAddDependency(res, cond == null, bi.isStart(), bi.getStartLevel());
+ }
+ if (cond != null) {
+ addIdentityRequirement(res, resConds.get(cond), true);
+ }
}
-
- FeatureResource res = FeatureResource.build(feature, featureResolutionRange, bundles);
- addIdentityRequirement(res, this);
- installable.add(res);
}
// Compute dependencies
for (DependencyInfo info : dependencies.values()) {
http://git-wip-us.apache.org/repos/asf/karaf/blob/09a5e995/features/core/src/test/java/org/apache/karaf/features/internal/region/SubsystemTest.java
----------------------------------------------------------------------
diff --git a/features/core/src/test/java/org/apache/karaf/features/internal/region/SubsystemTest.java b/features/core/src/test/java/org/apache/karaf/features/internal/region/SubsystemTest.java
index 5e8edd5..5aabcb7 100644
--- a/features/core/src/test/java/org/apache/karaf/features/internal/region/SubsystemTest.java
+++ b/features/core/src/test/java/org/apache/karaf/features/internal/region/SubsystemTest.java
@@ -125,6 +125,48 @@ public class SubsystemTest {
verify(resolver, expected);
}
+ @Test
+ public void testConditionalUnsatisfiedWithOptional() throws Exception {
+ RepositoryImpl repo = new RepositoryImpl(getClass().getResource("data4/features.xml").toURI());
+
+ Map<String, Set<String>> features = new HashMap<String, Set<String>>();
+ addToMapSet(features, "root/apps1", "f1");
+ Map<String, Set<String>> expected = new HashMap<String, Set<String>>();
+ addToMapSet(expected, "root/apps1", "a/1.0.0");
+
+ SubsystemResolver resolver = new SubsystemResolver(new TestDownloadManager("data4"));
+ resolver.resolve(Arrays.asList(repo.getFeatures()),
+ features,
+ Collections.<String, Set<BundleRevision>>emptyMap(),
+ Collections.<String>emptySet(),
+ FeaturesServiceImpl.DEFAULT_FEATURE_RESOLUTION_RANGE,
+ null);
+
+ verify(resolver, expected);
+ }
+
+ @Test
+ public void testConditionalSatisfiedWithOptional() throws Exception {
+ RepositoryImpl repo = new RepositoryImpl(getClass().getResource("data4/features.xml").toURI());
+
+ Map<String, Set<String>> features = new HashMap<String, Set<String>>();
+ addToMapSet(features, "root/apps1", "f1");
+ addToMapSet(features, "root/apps1", "f2");
+ Map<String, Set<String>> expected = new HashMap<String, Set<String>>();
+ addToMapSet(expected, "root/apps1", "a/1.0.0");
+ addToMapSet(expected, "root/apps1", "b/1.0.0");
+
+ SubsystemResolver resolver = new SubsystemResolver(new TestDownloadManager("data4"));
+ resolver.resolve(Arrays.asList(repo.getFeatures()),
+ features,
+ Collections.<String, Set<BundleRevision>>emptyMap(),
+ Collections.<String>emptySet(),
+ FeaturesServiceImpl.DEFAULT_FEATURE_RESOLUTION_RANGE,
+ null);
+
+ verify(resolver, expected);
+ }
+
private void verify(SubsystemResolver resolver, Map<String, Set<String>> expected) {
Map<String, Set<String>> mapping = getBundleNamesPerRegions(resolver);
if (!expected.equals(mapping)) {
http://git-wip-us.apache.org/repos/asf/karaf/blob/09a5e995/features/core/src/test/resources/org/apache/karaf/features/internal/region/data4/a.mf
----------------------------------------------------------------------
diff --git a/features/core/src/test/resources/org/apache/karaf/features/internal/region/data4/a.mf b/features/core/src/test/resources/org/apache/karaf/features/internal/region/data4/a.mf
new file mode 100644
index 0000000..34f0569
--- /dev/null
+++ b/features/core/src/test/resources/org/apache/karaf/features/internal/region/data4/a.mf
@@ -0,0 +1,6 @@
+Manifest-Version: 1
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: a
+Bundle-Version: 1.0.0
+Require-Capability: ns;filter:="(ns=b)";resolution:=optional
+
http://git-wip-us.apache.org/repos/asf/karaf/blob/09a5e995/features/core/src/test/resources/org/apache/karaf/features/internal/region/data4/b.mf
----------------------------------------------------------------------
diff --git a/features/core/src/test/resources/org/apache/karaf/features/internal/region/data4/b.mf b/features/core/src/test/resources/org/apache/karaf/features/internal/region/data4/b.mf
new file mode 100644
index 0000000..0cc2cef
--- /dev/null
+++ b/features/core/src/test/resources/org/apache/karaf/features/internal/region/data4/b.mf
@@ -0,0 +1,6 @@
+Manifest-Version: 1
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: b
+Bundle-Version: 1.0.0
+Provide-Capability: ns;ns=b
+
http://git-wip-us.apache.org/repos/asf/karaf/blob/09a5e995/features/core/src/test/resources/org/apache/karaf/features/internal/region/data4/features.xml
----------------------------------------------------------------------
diff --git a/features/core/src/test/resources/org/apache/karaf/features/internal/region/data4/features.xml b/features/core/src/test/resources/org/apache/karaf/features/internal/region/data4/features.xml
new file mode 100644
index 0000000..76cddc7
--- /dev/null
+++ b/features/core/src/test/resources/org/apache/karaf/features/internal/region/data4/features.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<features name="test" xmlns="http://karaf.apache.org/xmlns/features/v1.3.0">
+
+ <feature name="f1">
+ <conditional>
+ <condition>f2</condition>
+ <bundle>b</bundle>
+ </conditional>
+ <bundle>a</bundle>
+ </feature>
+
+ <feature name="f2">
+ </feature>
+
+</features>
\ No newline at end of file