karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject karaf git commit: [KARAF-3802] Provide a way do disable service requirements for old features (replace the disableServiceReqs flag), the default being to only verify requirements for new (schema >= 1.3.0) features
Date Tue, 23 Jun 2015 09:01:34 GMT
Repository: karaf
Updated Branches:
  refs/heads/master 5d106f79a -> fd086d3ae


[KARAF-3802] Provide a way do disable service requirements for old features (replace the disableServiceReqs
flag), the default being to only verify requirements for new (schema >= 1.3.0) features

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

Branch: refs/heads/master
Commit: fd086d3ae52462bafe2676ebc91d48976a3a3818
Parents: 5d106f7
Author: Guillaume Nodet <gnodet@Guillaumes-MacBook-Pro.local>
Authored: Tue Jun 23 11:01:28 2015 +0200
Committer: Guillaume Nodet <gnodet@Guillaumes-MacBook-Pro.local>
Committed: Tue Jun 23 11:01:28 2015 +0200

----------------------------------------------------------------------
 .../resources/etc/org.apache.karaf.features.cfg | 16 +++++++-----
 .../java/org/apache/karaf/features/Feature.java |  3 +++
 .../apache/karaf/features/FeaturesService.java  |  4 +++
 .../karaf/features/internal/model/Feature.java  | 11 ++++++++
 .../karaf/features/internal/model/Features.java | 12 +++++++++
 .../karaf/features/internal/model/JaxbUtil.java | 20 ++++++++++++---
 .../karaf/features/internal/osgi/Activator.java |  4 +--
 .../features/internal/region/Subsystem.java     | 24 +++++++++++------
 .../region/SubsystemResolveContext.java         | 12 ++++-----
 .../internal/region/SubsystemResolver.java      |  5 ++--
 .../internal/resolver/ResourceBuilder.java      | 27 +++++++++++++++++---
 .../features/internal/service/Deployer.java     |  3 +++
 .../internal/service/FeaturesServiceImpl.java   |  7 +++++
 .../karaf/features/FeaturesServiceTest.java     |  8 +++---
 .../apache/karaf/features/RepositoryTest.java   |  1 +
 .../features/internal/region/SubsystemTest.java | 18 ++++++-------
 .../service/FeaturesServiceImplTest.java        |  8 +++---
 17 files changed, 134 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/fd086d3a/assemblies/features/base/src/main/filtered-resources/resources/etc/org.apache.karaf.features.cfg
----------------------------------------------------------------------
diff --git a/assemblies/features/base/src/main/filtered-resources/resources/etc/org.apache.karaf.features.cfg
b/assemblies/features/base/src/main/filtered-resources/resources/etc/org.apache.karaf.features.cfg
index d0b1dde..f0c82c5 100644
--- a/assemblies/features/base/src/main/filtered-resources/resources/etc/org.apache.karaf.features.cfg
+++ b/assemblies/features/base/src/main/filtered-resources/resources/etc/org.apache.karaf.features.cfg
@@ -49,10 +49,14 @@ featuresBoot=
 featuresBootAsynchronous=false
 
 #
-# By default, the feature resolver checks the requirements/capabilities of the bundle
-# in order to automatically installs the required bundles.
-# It especially checks the service capabilities/requirements, that may cause feature installation
-# issue if the capabilities are missing.
-# The following flag (if true) will ignore the service requirements and install the features
anyway.
+# Service requirements enforcement
 #
-#ignoreServiceReq=false
+# By default, the feature resolver checks the service requirements/capabilities of
+# bundles for new features (xml schema >= 1.3.0) in order to automatically installs
+# the required bundles.
+# The following flag can have those values:
+#   - disable: service requirements are completely ignored
+#   - default: service requirements are ignored for old features
+#   - enforce: service requirements are always verified
+#
+#serviceRequirements=default

http://git-wip-us.apache.org/repos/asf/karaf/blob/fd086d3a/features/core/src/main/java/org/apache/karaf/features/Feature.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/Feature.java b/features/core/src/main/java/org/apache/karaf/features/Feature.java
index d2c9415..3bf61a4 100644
--- a/features/core/src/main/java/org/apache/karaf/features/Feature.java
+++ b/features/core/src/main/java/org/apache/karaf/features/Feature.java
@@ -63,4 +63,7 @@ public interface Feature {
     Scoping getScoping();
 
     List<? extends Library> getLibraries();
+
+    String getNamespace();
+
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/fd086d3a/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java b/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java
index 57e7014..87e2f4a 100644
--- a/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java
+++ b/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java
@@ -38,6 +38,10 @@ public interface FeaturesService {
 
     String UPDATEABLE_URIS = "mvn:.*SNAPSHOT|(?!mvn:).*";
 
+    String SERVICE_REQUIREMENTS_DISABLE = "disable";
+    String SERVICE_REQUIREMENTS_DEFAULT = "default";
+    String SERVICE_REQUIREMENTS_ENFORCE = "enforce";
+
     int DEFAULT_DOWNLOAD_THREADS = 8;
     long DEFAULT_SCHEDULE_DELAY = 250;
     int DEFAULT_SCHEDULE_MAX_RUN = 9;

http://git-wip-us.apache.org/repos/asf/karaf/blob/fd086d3a/features/core/src/main/java/org/apache/karaf/features/internal/model/Feature.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/model/Feature.java
b/features/core/src/main/java/org/apache/karaf/features/internal/model/Feature.java
index 90c9530..0de5905 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/model/Feature.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/model/Feature.java
@@ -102,6 +102,8 @@ public class Feature extends Content implements org.apache.karaf.features.Featur
     protected List<Requirement> requirement;
     protected Scoping scoping;
     protected List<Library> library;
+    @XmlTransient
+    protected String namespace;
 
     public Feature() {
     }
@@ -386,4 +388,13 @@ public class Feature extends Content implements org.apache.karaf.features.Featur
             }
         }
     }
+
+    @Override
+    public String getNamespace() {
+        return namespace;
+    }
+
+    public void setNamespace(String namespace) {
+        this.namespace = namespace;
+    }
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/fd086d3a/features/core/src/main/java/org/apache/karaf/features/internal/model/Features.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/model/Features.java
b/features/core/src/main/java/org/apache/karaf/features/internal/model/Features.java
index 66d8d2f..48582d4 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/model/Features.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/model/Features.java
@@ -24,6 +24,7 @@ import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlSchemaType;
+import javax.xml.bind.annotation.XmlTransient;
 import javax.xml.bind.annotation.XmlType;
 
 
@@ -61,6 +62,8 @@ public class Features {
     protected List<Feature> feature;
     @XmlAttribute
     protected String name;
+    @XmlTransient
+    private String namespace;
 
     /**
      * Gets the value of the repository property.
@@ -139,8 +142,17 @@ public class Features {
     public void postUnmarshall() {
         if (feature != null) {
             for (Feature f : feature) {
+                f.setNamespace(namespace);
                 f.postUnmarshall();
             }
         }
     }
+
+    public void setNamespace(String namespace) {
+        this.namespace = namespace;
+    }
+
+    public String getNamespace() {
+        return namespace;
+    }
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/fd086d3a/features/core/src/main/java/org/apache/karaf/features/internal/model/JaxbUtil.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/model/JaxbUtil.java
b/features/core/src/main/java/org/apache/karaf/features/internal/model/JaxbUtil.java
index a42c734..051b476 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/model/JaxbUtil.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/model/JaxbUtil.java
@@ -130,8 +130,9 @@ public final class JaxbUtil {
 
             fixDom(doc, doc.getDocumentElement());
             Unmarshaller unmarshaller = FEATURES_CONTEXT.createUnmarshaller();
-            return (Features) unmarshaller.unmarshal(new DOMSource(doc));
-
+            Features features = (Features) unmarshaller.unmarshal(new DOMSource(doc));
+            features.setNamespace(nsuri);
+            return features;
 
         } catch (RuntimeException e) {
             throw e;
@@ -192,7 +193,7 @@ public final class JaxbUtil {
     private static Features unmarshalNoValidate(String uri, InputStream stream) {
         try {
             Unmarshaller unmarshaller = FEATURES_CONTEXT.createUnmarshaller();
-            XMLFilter xmlFilter = new NoSourceAndNamespaceFilter(XmlUtils.xmlReader());
+            NoSourceAndNamespaceFilter xmlFilter = new NoSourceAndNamespaceFilter(XmlUtils.xmlReader());
             xmlFilter.setContentHandler(unmarshaller.getUnmarshallerHandler());
 
             InputSource is = new InputSource(uri);
@@ -200,7 +201,9 @@ public final class JaxbUtil {
                 is.setByteStream(stream);
             }
             SAXSource source = new SAXSource(xmlFilter, is);
-            return (Features) unmarshaller.unmarshal(source);
+            Features features = (Features) unmarshaller.unmarshal(source);
+            features.setNamespace(xmlFilter.getNamespace());
+            return features;
 
         } catch (RuntimeException e) {
             throw e;
@@ -217,6 +220,8 @@ public final class JaxbUtil {
     public static class NoSourceAndNamespaceFilter extends XMLFilterImpl {
         private static final InputSource EMPTY_INPUT_SOURCE = new InputSource(new ByteArrayInputStream(new
byte[0]));
 
+        private String namespace;
+
         public NoSourceAndNamespaceFilter(XMLReader xmlReader) {
             super(xmlReader);
         }
@@ -228,6 +233,9 @@ public final class JaxbUtil {
 
         @Override
         public void startElement(String uri, String localName, String qName, Attributes atts)
throws SAXException {
+            if ("features".equals(localName)) {
+                namespace = uri;
+            }
             super.startElement(FeaturesNamespaces.URI_CURRENT, localName, qName, atts);
         }
 
@@ -235,6 +243,10 @@ public final class JaxbUtil {
         public void endElement(String uri, String localName, String qName) throws SAXException
{
             super.endElement(FeaturesNamespaces.URI_CURRENT, localName, qName);
         }
+
+        public String getNamespace() {
+            return namespace;
+        }
     }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/fd086d3a/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
b/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
index b4f088d..b38c33f 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
@@ -179,8 +179,7 @@ public class Activator extends BaseActivator {
         long scheduleDelay = getLong("scheduleDelay", FeaturesService.DEFAULT_SCHEDULE_DELAY);
         int scheduleMaxRun = getInt("scheduleMaxRun", FeaturesService.DEFAULT_SCHEDULE_MAX_RUN);
         String blacklisted = getString("blacklisted", new File(System.getProperty("karaf.etc"),
"blacklisted.properties").toURI().toString());
-        boolean ignoreServiceReqs = getBoolean("ignoreServiceReqs", false);
-        SubsystemResolveContext.setIgnoreServiceReqs(ignoreServiceReqs);
+        String serviceRequirements = getString("serviceRequirements", FeaturesService.SERVICE_REQUIREMENTS_DEFAULT);
         StateStorage stateStorage = new StateStorage() {
             @Override
             protected InputStream getInputStream() throws IOException {
@@ -217,6 +216,7 @@ public class Activator extends BaseActivator {
                 featureResolutionRange,
                 bundleUpdateRange,
                 updateSnapshots,
+                serviceRequirements,
                 globalRepository,
                 downloadThreads,
                 scheduleDelay,

http://git-wip-us.apache.org/repos/asf/karaf/blob/fd086d3a/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 75e497a..a449e16 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
@@ -41,6 +41,8 @@ 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.FeaturesNamespaces;
+import org.apache.karaf.features.FeaturesService;
 import org.apache.karaf.features.Library;
 import org.apache.karaf.features.ScopeFilter;
 import org.apache.karaf.features.internal.download.DownloadCallback;
@@ -347,9 +349,10 @@ public class Subsystem extends ResourceImpl {
     @SuppressWarnings("InfiniteLoopStatement")
     public void downloadBundles(DownloadManager manager,
                                 Set<String> overrides,
-                                String featureResolutionRange) throws Exception {
+                                String featureResolutionRange,
+                                final String serviceRequirements) throws Exception {
         for (Subsystem child : children) {
-            child.downloadBundles(manager, overrides, featureResolutionRange);
+            child.downloadBundles(manager, overrides, featureResolutionRange, serviceRequirements);
         }
         final Map<String, ResourceImpl> bundles = new ConcurrentHashMap<>();
         final Downloader downloader = manager.createDownloader();
@@ -370,7 +373,7 @@ public class Subsystem extends ResourceImpl {
             downloader.download(loc, new DownloadCallback() {
                 @Override
                 public void downloaded(StreamProvider provider) throws Exception {
-                    ResourceImpl res = createResource(loc, getMetadata(provider));
+                    ResourceImpl res = createResource(loc, getMetadata(provider), serviceRequirements);
                     bundles.put(loc, res);
                 }
             });
@@ -380,7 +383,7 @@ public class Subsystem extends ResourceImpl {
             downloader.download(loc, new DownloadCallback() {
                 @Override
                 public void downloaded(StreamProvider provider) throws Exception {
-                    ResourceImpl res = createResource(loc, getMetadata(provider));
+                    ResourceImpl res = createResource(loc, getMetadata(provider), serviceRequirements);
                     bundles.put(loc, res);
                 }
             });
@@ -390,7 +393,7 @@ public class Subsystem extends ResourceImpl {
             downloader.download(loc, new DownloadCallback() {
                 @Override
                 public void downloaded(StreamProvider provider) throws Exception {
-                    ResourceImpl res = createResource(loc, getMetadata(provider));
+                    ResourceImpl res = createResource(loc, getMetadata(provider), serviceRequirements);
                     bundles.put(loc, res);
                 }
             });
@@ -402,7 +405,7 @@ public class Subsystem extends ResourceImpl {
                     downloader.download(loc, new DownloadCallback() {
                         @Override
                         public void downloaded(StreamProvider provider) throws Exception
{
-                            ResourceImpl res = createResource(loc, getMetadata(provider));
+                            ResourceImpl res = createResource(loc, getMetadata(provider),
serviceRequirements);
                             bundles.put(loc, res);
                         }
                     });
@@ -552,9 +555,14 @@ public class Subsystem extends ResourceImpl {
         return policy;
     }
 
-    ResourceImpl createResource(String uri, Map<String, String> headers) throws Exception
{
+    ResourceImpl createResource(String uri, Map<String, String> headers, String serviceRequirements)
throws Exception {
+        boolean removeServiceRequirements = false;
+        if (feature != null && FeaturesService.SERVICE_REQUIREMENTS_DEFAULT.equals(serviceRequirements)
+                && !FeaturesNamespaces.URI_1_3_0.equals(uri)) {
+            removeServiceRequirements = true;
+        }
         try {
-            return ResourceBuilder.build(uri, headers);
+            return ResourceBuilder.build(uri, headers, removeServiceRequirements);
         } catch (BundleException e) {
             throw new Exception("Unable to create resource for bundle " + uri, e);
         }

http://git-wip-us.apache.org/repos/asf/karaf/blob/fd086d3a/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolveContext.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolveContext.java
b/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolveContext.java
index 1ed9ef5..704db13 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolveContext.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolveContext.java
@@ -27,6 +27,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.karaf.features.FeaturesService;
 import org.apache.karaf.features.internal.download.Downloader;
 import org.apache.karaf.features.internal.repository.BaseRepository;
 import org.apache.karaf.features.internal.resolver.CapabilityImpl;
@@ -69,12 +70,13 @@ public class SubsystemResolveContext extends ResolveContext {
     private final Repository repository;
     private final Repository globalRepository;
     private final Downloader downloader;
-    private static boolean ignoreServiceReqs = true; 
+    private final String serviceRequirements;
 
-    public SubsystemResolveContext(Subsystem root, RegionDigraph digraph, Repository globalRepository,
Downloader downloader) throws BundleException {
+    public SubsystemResolveContext(Subsystem root, RegionDigraph digraph, Repository globalRepository,
Downloader downloader, String serviceRequirements) throws BundleException {
         this.root = root;
         this.globalRepository = globalRepository != null ? new SubsystemRepository(globalRepository)
: null;
         this.downloader = downloader;
+        this.serviceRequirements = serviceRequirements;
 
         prepare(root);
         repository = new BaseRepository(resToSub.keySet());
@@ -89,10 +91,6 @@ public class SubsystemResolveContext extends ResolveContext {
         findMandatory();
     }
     
-    public static void setIgnoreServiceReqs(boolean ignoreServiceReqs) {
-        SubsystemResolveContext.ignoreServiceReqs = ignoreServiceReqs;
-    }
-
     public Repository getRepository() {
         return repository;
     }
@@ -279,7 +277,7 @@ public class SubsystemResolveContext extends ResolveContext {
     @Override
     public boolean isEffective(Requirement requirement) {
         boolean isServiceReq = ServiceNamespace.SERVICE_NAMESPACE.equals(requirement.getNamespace());
-        return !ignoreServiceReqs || !isServiceReq;
+        return !(isServiceReq && FeaturesService.SERVICE_REQUIREMENTS_DISABLE.equals(serviceRequirements));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/karaf/blob/fd086d3a/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolver.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolver.java
b/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolver.java
index d3701c7..c9013ec 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolver.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolver.java
@@ -179,6 +179,7 @@ public class SubsystemResolver {
     public Map<Resource, List<Wire>> resolve(
             Set<String> overrides,
             String featureResolutionRange,
+            String serviceRequirements,
             final Repository globalRepository,
             String outputFile) throws Exception {
 
@@ -187,14 +188,14 @@ public class SubsystemResolver {
         }
 
         // Download bundles
-        root.downloadBundles(manager, overrides, featureResolutionRange);
+        root.downloadBundles(manager, overrides, featureResolutionRange, serviceRequirements);
 
         // Populate digraph and resolve
         digraph = new StandardRegionDigraph(null, null);
         populateDigraph(digraph, root);
 
         Downloader downloader = manager.createDownloader();
-        SubsystemResolveContext context = new SubsystemResolveContext(root, digraph, globalRepository,
downloader);
+        SubsystemResolveContext context = new SubsystemResolveContext(root, digraph, globalRepository,
downloader, serviceRequirements);
         if (outputFile != null) {
             Map<String, Object> json = new HashMap<>();
             if (globalRepository != null) {

http://git-wip-us.apache.org/repos/asf/karaf/blob/fd086d3a/features/core/src/main/java/org/apache/karaf/features/internal/resolver/ResourceBuilder.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/resolver/ResourceBuilder.java
b/features/core/src/main/java/org/apache/karaf/features/internal/resolver/ResourceBuilder.java
index ec3b0e3..e5b2405 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/resolver/ResourceBuilder.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/resolver/ResourceBuilder.java
@@ -20,6 +20,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -59,12 +60,20 @@ public final class ResourceBuilder {
 
     private ResourceBuilder() {
     }
-    
+
     public static ResourceImpl build(String uri, Map<String, String> headerMap) throws
BundleException {
-        return build(new ResourceImpl(), uri, headerMap);
+        return build(new ResourceImpl(), uri, headerMap, false);
+    }
+
+    public static ResourceImpl build(String uri, Map<String, String> headerMap, boolean
removeServiceRequirements) throws BundleException {
+        return build(new ResourceImpl(), uri, headerMap, removeServiceRequirements);
     }
 
     public static ResourceImpl build(ResourceImpl resource, String uri, Map<String, String>
headerMap) throws BundleException {
+        return build(resource, uri, headerMap, false);
+    }
+
+    public static ResourceImpl build(ResourceImpl resource, String uri, Map<String, String>
headerMap, boolean removeServiceRequirements) throws BundleException {
         // Verify that only manifest version 2 is specified.
         String manifestVersion = getManifestVersion(headerMap);
         if (manifestVersion == null || !manifestVersion.equals("2")) {
@@ -213,7 +222,19 @@ public final class ResourceBuilder {
         if (!hasServiceReferenceRequirement) {
             List<ParsedHeaderClause> importServices = parseStandardHeader(headerMap.get(Constants.IMPORT_SERVICE));
             List<Requirement> reqs = convertImportService(importServices, resource);
-            requireReqs.addAll(reqs);
+            if (!reqs.isEmpty()) {
+                requireReqs.addAll(reqs);
+                hasServiceReferenceRequirement = true;
+            }
+        }
+
+        if (hasServiceReferenceRequirement && removeServiceRequirements) {
+            for (Iterator<Requirement> iterator = requireReqs.iterator(); iterator.hasNext();)
{
+                Requirement req = iterator.next();
+                if (ServiceNamespace.SERVICE_NAMESPACE.equals(req.getNamespace())) {
+                    iterator.remove();
+                }
+            }
         }
         
         // Combine all capabilities.

http://git-wip-us.apache.org/repos/asf/karaf/blob/fd086d3a/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
b/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
index f3f767b..574bac7 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
@@ -156,6 +156,7 @@ public class Deployer {
     public static class DeploymentRequest {
         public Set<String> overrides;
         public String featureResolutionRange;
+        public String serviceRequirements;
         public String bundleUpdateRange;
         public String updateSnaphots;
         public Repository globalRepository;
@@ -246,6 +247,7 @@ public class Deployer {
             DeploymentRequest newRequest = new DeploymentRequest();
             newRequest.bundleUpdateRange = request.bundleUpdateRange;
             newRequest.featureResolutionRange = request.featureResolutionRange;
+            newRequest.serviceRequirements = request.serviceRequirements;
             newRequest.globalRepository = request.globalRepository;
             newRequest.options = request.options;
             newRequest.overrides = request.overrides;
@@ -262,6 +264,7 @@ public class Deployer {
         resolver.resolve(
                 request.overrides,
                 request.featureResolutionRange,
+                request.serviceRequirements,
                 request.globalRepository,
                 request.outputFile);
 

http://git-wip-us.apache.org/repos/asf/karaf/blob/fd086d3a/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 4dcd267..db80c33 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
@@ -151,6 +151,10 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
      * - crc : use CRC to detect changes
      */
     private final String updateSnaphots;
+    /**
+     * Service requirements enforcement
+     */
+    private final String serviceRequirements;
 
     private final int downloadThreads;
 
@@ -188,6 +192,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
                                String featureResolutionRange,
                                String bundleUpdateRange,
                                String updateSnaphots,
+                               String serviceRequirements,
                                org.osgi.service.repository.Repository globalRepository,
                                int downloadThreads,
                                long scheduleDelay,
@@ -206,6 +211,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
         this.featureResolutionRange = featureResolutionRange;
         this.bundleUpdateRange = bundleUpdateRange;
         this.updateSnaphots = updateSnaphots;
+        this.serviceRequirements = serviceRequirements;
         this.globalRepository = globalRepository;
         this.downloadThreads = downloadThreads > 0 ? downloadThreads : 1;
         this.scheduleDelay = scheduleDelay;
@@ -1039,6 +1045,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
         Deployer.DeploymentRequest request = new Deployer.DeploymentRequest();
         request.bundleUpdateRange = bundleUpdateRange;
         request.featureResolutionRange = featureResolutionRange;
+        request.serviceRequirements = serviceRequirements;
         request.updateSnaphots = updateSnaphots;
         request.globalRepository = globalRepository;
         request.overrides = Overrides.loadOverrides(overrides);

http://git-wip-us.apache.org/repos/asf/karaf/blob/fd086d3a/features/core/src/test/java/org/apache/karaf/features/FeaturesServiceTest.java
----------------------------------------------------------------------
diff --git a/features/core/src/test/java/org/apache/karaf/features/FeaturesServiceTest.java
b/features/core/src/test/java/org/apache/karaf/features/FeaturesServiceTest.java
index aa59614..0571bae 100644
--- a/features/core/src/test/java/org/apache/karaf/features/FeaturesServiceTest.java
+++ b/features/core/src/test/java/org/apache/karaf/features/FeaturesServiceTest.java
@@ -348,7 +348,7 @@ public class FeaturesServiceTest extends TestBase {
                 + "  <feature name='f2' version='0.2'><bundle>bundle2</bundle></feature>"
                 + "</features>");
 
-        FeaturesServiceImpl svc = new FeaturesServiceImpl(null, null, new Storage(), null,
null, null, resolver, null, null, null, null, null, null, 0, 0, 0, null);
+        FeaturesServiceImpl svc = new FeaturesServiceImpl(null, null, new Storage(), null,
null, null, resolver, null, null, null, null, null, null, null, 0, 0, 0, null);
         svc.addRepository(uri);
 
         assertEquals(feature("f2", "0.2"), svc.getFeatures("f2", "[0.1,0.3)")[0]);
@@ -374,7 +374,7 @@ public class FeaturesServiceTest extends TestBase {
         expect(fsl.getStartLevel()).andReturn(100);
         replay(bundleContext, bundle, fsl);
 
-        FeaturesServiceImpl svc = new FeaturesServiceImpl(null, bundleContext, new Storage(),
null, null, null, resolver, null, null, null, null, null, null, 0, 0, 0, null);
+        FeaturesServiceImpl svc = new FeaturesServiceImpl(null, bundleContext, new Storage(),
null, null, null, resolver, null, null, null, null, null, null, null, 0, 0, 0, null);
         svc.addRepository(uri);
         try {
             List<String> features = new ArrayList<String>();
@@ -399,7 +399,7 @@ public class FeaturesServiceTest extends TestBase {
         URI uri = createTempRepo("<features name='test' xmlns='http://karaf.apache.org/xmlns/features/v1.0.0'>"
                 + "  <featur><bundle>somebundle</bundle></featur></features>");
 
-        FeaturesServiceImpl svc = new FeaturesServiceImpl(null, null, new Storage(), null,
null, null, resolver, null, null, null, null, null, null, 0, 0, 0, null);
+        FeaturesServiceImpl svc = new FeaturesServiceImpl(null, null, new Storage(), null,
null, null, resolver, null, null, null, null, null, null, null, 0, 0, 0, null);
         try {
             svc.addRepository(uri);
             fail("exception expected");
@@ -417,7 +417,7 @@ public class FeaturesServiceTest extends TestBase {
                 + "  <feature name='f1'><bundle>file:bundle1</bundle><bundle>file:bundle2</bundle></feature>"
                 + "</features>");
 
-        FeaturesServiceImpl svc = new FeaturesServiceImpl(null, null, new Storage(), null,
null, null, resolver, null, null, null, null, null, null, 0, 0, 0, null);
+        FeaturesServiceImpl svc = new FeaturesServiceImpl(null, null, new Storage(), null,
null, null, resolver, null, null, null, null, null, null, null, 0, 0, 0, null);
         svc.addRepository(uri);
         Feature[] features = svc.getFeatures("f1");
         Assert.assertEquals(1, features.length);

http://git-wip-us.apache.org/repos/asf/karaf/blob/fd086d3a/features/core/src/test/java/org/apache/karaf/features/RepositoryTest.java
----------------------------------------------------------------------
diff --git a/features/core/src/test/java/org/apache/karaf/features/RepositoryTest.java b/features/core/src/test/java/org/apache/karaf/features/RepositoryTest.java
index 819be28..de543cd 100644
--- a/features/core/src/test/java/org/apache/karaf/features/RepositoryTest.java
+++ b/features/core/src/test/java/org/apache/karaf/features/RepositoryTest.java
@@ -38,6 +38,7 @@ public class RepositoryTest extends TestCase {
         assertNotNull(features);
         assertEquals(3, features.length);
         assertNotNull(features[0]);
+        assertEquals("http://karaf.apache.org/xmlns/features/v1.1.0", features[0].getNamespace());
         assertEquals("f1", features[0].getName());
         assertNotNull(features[0].getConfigurations());
         assertEquals(1, features[0].getConfigurations().size());

http://git-wip-us.apache.org/repos/asf/karaf/blob/fd086d3a/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 d957ae6..f0af9d4 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
@@ -67,7 +67,7 @@ public class SubsystemTest {
                          Collections.<String, Set<BundleRevision>>emptyMap());
         resolver.resolve(Collections.<String>emptySet(),
                          FeaturesService.DEFAULT_FEATURE_RESOLUTION_RANGE,
-                         null, null);
+                         null, null, null);
 
         verify(resolver, expected);
     }
@@ -98,7 +98,7 @@ public class SubsystemTest {
                          Collections.<String, Set<BundleRevision>>emptyMap());
         resolver.resolve(Collections.<String>emptySet(),
                          FeaturesService.DEFAULT_FEATURE_RESOLUTION_RANGE,
-                         null, null);
+                         null, null, null);
 
         verify(resolver, expected);
     }
@@ -119,7 +119,7 @@ public class SubsystemTest {
                          Collections.<String, Set<BundleRevision>>emptyMap());
         resolver.resolve(Collections.singleton("b"),
                          FeaturesService.DEFAULT_FEATURE_RESOLUTION_RANGE,
-                         null, null);
+                         null, null, null);
 
         verify(resolver, expected);
     }
@@ -139,7 +139,7 @@ public class SubsystemTest {
                          Collections.<String, Set<BundleRevision>>emptyMap());
         resolver.resolve(Collections.<String>emptySet(),
                          FeaturesService.DEFAULT_FEATURE_RESOLUTION_RANGE,
-                         null, null);
+                         null, null, null);
 
         verify(resolver, expected);
     }
@@ -161,7 +161,7 @@ public class SubsystemTest {
                          Collections.<String, Set<BundleRevision>>emptyMap());
         resolver.resolve(Collections.<String>emptySet(),
                          FeaturesService.DEFAULT_FEATURE_RESOLUTION_RANGE,
-                         null, null);
+                         null, null, null);
 
         verify(resolver, expected);
     }
@@ -183,7 +183,7 @@ public class SubsystemTest {
                 Collections.<String, Set<BundleRevision>>emptyMap());
         resolver.resolve(Collections.<String>emptySet(),
                 FeaturesService.DEFAULT_FEATURE_RESOLUTION_RANGE,
-                null, null);
+                null, null, null);
 
         verify(resolver, expected);
     }
@@ -204,7 +204,7 @@ public class SubsystemTest {
                 Collections.<String, Set<BundleRevision>>emptyMap());
         resolver.resolve(Collections.<String>emptySet(),
                 FeaturesService.DEFAULT_FEATURE_RESOLUTION_RANGE,
-                null, null);
+                null, null, null);
 
         verify(resolver, expected);
     }
@@ -226,7 +226,7 @@ public class SubsystemTest {
                 Collections.<String, Set<BundleRevision>>emptyMap());
         resolver.resolve(Collections.<String>emptySet(),
                 FeaturesService.DEFAULT_FEATURE_RESOLUTION_RANGE,
-                null, null);
+                null, null, null);
 
         verify(resolver, expected);
     }
@@ -248,7 +248,7 @@ public class SubsystemTest {
                 Collections.<String, Set<BundleRevision>>emptyMap());
         resolver.resolve(Collections.<String>emptySet(),
                 FeaturesService.DEFAULT_FEATURE_RESOLUTION_RANGE,
-                null, null);
+                null, null, null);
 
         verify(resolver, expected);
     }

http://git-wip-us.apache.org/repos/asf/karaf/blob/fd086d3a/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesServiceImplTest.java
----------------------------------------------------------------------
diff --git a/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesServiceImplTest.java
b/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesServiceImplTest.java
index 264cdc0..cc51375 100644
--- a/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesServiceImplTest.java
+++ b/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesServiceImplTest.java
@@ -54,7 +54,7 @@ public class FeaturesServiceImplTest extends TestBase {
     public void testGetFeature() throws Exception {
         Feature transactionFeature = feature("transaction", "1.0.0");
         final Map<String, Map<String, Feature>> features = features(transactionFeature);
-        final FeaturesServiceImpl impl = new FeaturesServiceImpl(null, null, new Storage(),
null, null, null, this.resolver, null, "", null, null, null, null, 0, 0, 0, null) {
+        final FeaturesServiceImpl impl = new FeaturesServiceImpl(null, null, new Storage(),
null, null, null, this.resolver, null, "", null, null, null, null, null, 0, 0, 0, null) {
             protected Map<String,Map<String,Feature>> getFeatures() throws Exception
{
                 return features;
             }
@@ -65,7 +65,7 @@ public class FeaturesServiceImplTest extends TestBase {
     
     @Test
     public void testGetFeatureStripVersion() throws Exception {
-        final FeaturesServiceImpl impl = new FeaturesServiceImpl(null, null, new Storage(),
null, null, null, this.resolver, null, "", null, null, null, null, 0, 0, 0, null) {
+        final FeaturesServiceImpl impl = new FeaturesServiceImpl(null, null, new Storage(),
null, null, null, this.resolver, null, "", null, null, null, null, null, 0, 0, 0, null) {
             protected Map<String,Map<String,Feature>> getFeatures() throws Exception
{
                 return features(feature("transaction", "1.0.0"));
             }
@@ -79,7 +79,7 @@ public class FeaturesServiceImplTest extends TestBase {
     
     @Test
     public void testGetFeatureNotAvailable() throws Exception {
-        final FeaturesServiceImpl impl = new FeaturesServiceImpl(null, null, new Storage(),
null, null, null, this.resolver, null, "", null, null, null, null, 0, 0, 0, null) {
+        final FeaturesServiceImpl impl = new FeaturesServiceImpl(null, null, new Storage(),
null, null, null, this.resolver, null, "", null, null, null, null, null, 0, 0, 0, null) {
             protected Map<String,Map<String,Feature>> getFeatures() throws Exception
{
                 return features(feature("transaction", "1.0.0"));
             }
@@ -93,7 +93,7 @@ public class FeaturesServiceImplTest extends TestBase {
                 feature("transaction", "1.0.0"),
                 feature("transaction", "2.0.0")
         );
-        final FeaturesServiceImpl impl = new FeaturesServiceImpl(null, null, new Storage(),
null, null, null, this.resolver, null, "", null, null, null, null, 0, 0, 0, null) {
+        final FeaturesServiceImpl impl = new FeaturesServiceImpl(null, null, new Storage(),
null, null, null, this.resolver, null, "", null, null, null, null, null, 0, 0, 0, null) {
             protected Map<String,Map<String,Feature>> getFeatures() throws Exception
{
                 return features;
             }


Mime
View raw message