You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gg...@apache.org on 2017/12/05 21:58:10 UTC

[karaf] 13/13: [KARAF-5376] Use "versions" PID to resolve placeholders in etc/org.apache.karaf.features.xml

This is an automated email from the ASF dual-hosted git repository.

ggrzybek pushed a commit to branch KARAF-5376-overrides_v2
in repository https://gitbox.apache.org/repos/asf/karaf.git

commit b143eef837490037c87e5d35e2a0511e4c0335e6
Author: Grzegorz Grzybek <gr...@gmail.com>
AuthorDate: Tue Dec 5 22:57:20 2017 +0100

    [KARAF-5376] Use "versions" PID to resolve placeholders in etc/org.apache.karaf.features.xml
---
 features/core/pom.xml                              |  16 ++
 .../model/processing/FeaturesProcessing.java       |   2 +-
 .../service/FeaturesProcessingSerializer.java      | 185 ++++++++++++++++++++-
 .../internal/service/FeaturesProcessorImpl.java    |  20 ++-
 .../internal/service/FeaturesServiceImpl.java      |   2 +-
 .../features/internal/service/BlacklistTest.java   |   4 +-
 .../internal/service/FeaturesProcessorTest.java    |  43 ++++-
 .../karaf/features/internal/service/fpi03.xml      |  30 ++++
 pom.xml                                            |  16 ++
 9 files changed, 297 insertions(+), 21 deletions(-)

diff --git a/features/core/pom.xml b/features/core/pom.xml
index e5eaa85..a2e9729 100644
--- a/features/core/pom.xml
+++ b/features/core/pom.xml
@@ -88,6 +88,19 @@
         </dependency>
 
         <dependency>
+            <groupId>org.ops4j.base</groupId>
+            <artifactId>ops4j-base-util-property</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.base</groupId>
+            <artifactId>ops4j-base-util-collections</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.swissbox</groupId>
+            <artifactId>pax-swissbox-property</artifactId>
+        </dependency>
+
+        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-log4j12</artifactId>
             <scope>test</scope>
@@ -159,6 +172,9 @@
                             org.apache.karaf.util.xml,
                             org.eclipse.equinox.internal.region.*;-split-package:=merge-first,
                             org.apache.felix.resolver.*,
+                            org.ops4j.pax.swissbox.*,
+                            org.ops4j.util.*,
+                            org.ops4j.lang.*
                         </Private-Package>
                         <Embed-Dependency>
                             org.apache.karaf.util;inline="org/apache/karaf/util/XmlUtils*.class"
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/model/processing/FeaturesProcessing.java b/features/core/src/main/java/org/apache/karaf/features/internal/model/processing/FeaturesProcessing.java
index 3f5050b..537057e 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/model/processing/FeaturesProcessing.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/model/processing/FeaturesProcessing.java
@@ -280,7 +280,7 @@ public class FeaturesProcessing {
                     return null;
                 }
                 Version vfloor = new Version(v.getMajor(), v.getMinor(), 0, null);
-                parser.setVersion(new VersionRange(false, vfloor, v, true).toString());
+                parser.setVersion(new VersionRange(false, vfloor, v, v.compareTo(vfloor) > 0).toString());
             }
             return parser.toMvnURI();
         } catch (MalformedURLException e) {
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesProcessingSerializer.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesProcessingSerializer.java
index 4a72fe3..084615b 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesProcessingSerializer.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesProcessingSerializer.java
@@ -24,13 +24,17 @@ import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
+import java.io.StringWriter;
+import java.util.Dictionary;
 import java.util.HashMap;
+import java.util.Hashtable;
 import java.util.Map;
 import java.util.Properties;
 import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.UnmarshallerHandler;
+import javax.xml.parsers.SAXParserFactory;
 import javax.xml.stream.XMLEventFactory;
 import javax.xml.stream.XMLEventReader;
 import javax.xml.stream.XMLEventWriter;
@@ -42,8 +46,24 @@ import javax.xml.transform.stream.StreamResult;
 import org.apache.karaf.features.internal.model.processing.FeaturesProcessing;
 import org.apache.karaf.features.internal.model.processing.ObjectFactory;
 import org.apache.karaf.util.xml.IndentingXMLEventWriter;
+import org.ops4j.pax.swissbox.property.BundleContextPropertyResolver;
+import org.ops4j.util.property.DictionaryPropertyResolver;
+import org.ops4j.util.property.PropertyResolver;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.AttributesImpl;
 
 /**
  * A class to help serialize {@link org.apache.karaf.features.internal.model.processing.FeaturesProcessing} model
@@ -53,12 +73,15 @@ public class FeaturesProcessingSerializer {
 
     public static Logger LOG = LoggerFactory.getLogger(FeaturesProcessingSerializer.class);
 
+    private final BundleContext bundleContext;
     private JAXBContext FEATURES_PROCESSING_CONTEXT;
 
     public FeaturesProcessingSerializer() {
+        Bundle bundle = FrameworkUtil.getBundle(this.getClass());
+        this.bundleContext = bundle == null ? null : bundle.getBundleContext();
         try {
             FEATURES_PROCESSING_CONTEXT = JAXBContext.newInstance(ObjectFactory.class);
-        } catch (JAXBException e) {
+        } catch (Exception e) {
             throw new RuntimeException(e);
         }
     }
@@ -68,9 +91,52 @@ public class FeaturesProcessingSerializer {
      * @param stream
      * @return
      */
-    public FeaturesProcessing read(InputStream stream) throws JAXBException {
+    public FeaturesProcessing read(InputStream stream) throws Exception {
+        return this.read(stream, null);
+    }
+
+    /**
+     * Reads {@link FeaturesProcessing features processing model} from input stream
+     * @param stream
+     * @param configurationAdmin optional reference to {@link ConfigurationAdmin}
+     * @return
+     */
+    public FeaturesProcessing read(InputStream stream, ConfigurationAdmin configurationAdmin) throws Exception {
         Unmarshaller unmarshaller = FEATURES_PROCESSING_CONTEXT.createUnmarshaller();
-        return (FeaturesProcessing) unmarshaller.unmarshal(stream);
+        UnmarshallerHandler handler = unmarshaller.getUnmarshallerHandler();
+
+        Dictionary<String, Object> properties = new Hashtable<>();
+        if (configurationAdmin != null) {
+            String filter = String.format("(%s=%s)", Constants.SERVICE_PID, "versions");
+            Configuration[] pids = configurationAdmin.listConfigurations(filter);
+            if (pids != null && pids.length > 0) {
+                properties = pids[0].getProperties();
+            }
+        }
+
+        // BundleContextPropertyResolver gives access to e.g., ${karaf.base}
+        final PropertyResolver resolver = bundleContext == null ? new DictionaryPropertyResolver(properties)
+                : new DictionaryPropertyResolver(properties, new BundleContextPropertyResolver(bundleContext));
+
+        // indirect unmarshaling with property resolution inside XML attribute values and CDATA
+        SAXParserFactory spf = SAXParserFactory.newInstance();
+        spf.setNamespaceAware(true);
+        XMLReader xmlReader = spf.newSAXParser().getXMLReader();
+        xmlReader.setContentHandler(new ResolvingContentHandler(new Properties() {
+            @Override
+            public String getProperty(String key) {
+                return resolver.get(key);
+            }
+
+            @Override
+            public String getProperty(String key, String defaultValue) {
+                String value = resolver.get(key);
+                return value == null ? defaultValue : value;
+            }
+        }, handler));
+        xmlReader.parse(new InputSource(stream));
+
+        return (FeaturesProcessing) handler.getResult();
     }
 
     /**
@@ -156,4 +222,115 @@ public class FeaturesProcessingSerializer {
         }
     }
 
+    private static class ResolvingContentHandler implements ContentHandler {
+
+        public static Logger LOG = LoggerFactory.getLogger(ResolvingContentHandler.class);
+
+        private Properties properties;
+        private ContentHandler target;
+
+        private boolean inElement = false;
+        private StringWriter sw = new StringWriter();
+
+        public ResolvingContentHandler(Properties properties, ContentHandler target) {
+            this.properties = properties;
+            this.target = target;
+        }
+
+        @Override
+        public void setDocumentLocator(Locator locator) {
+            target.setDocumentLocator(locator);
+        }
+
+        @Override
+        public void startDocument() throws SAXException {
+            target.startDocument();
+        }
+
+        @Override
+        public void endDocument() throws SAXException {
+            target.endDocument();
+        }
+
+        @Override
+        public void startPrefixMapping(String prefix, String uri) throws SAXException {
+            target.startPrefixMapping(prefix, uri);
+        }
+
+        @Override
+        public void endPrefixMapping(String prefix) throws SAXException {
+            target.endPrefixMapping(prefix);
+        }
+
+        @Override
+        public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
+            AttributesImpl resolvedAttributes = new AttributesImpl(atts);
+            for (int i = 0; i < atts.getLength(); i++) {
+                resolvedAttributes.setAttribute(i, atts.getURI(i), atts.getLocalName(i), atts.getQName(i),
+                        atts.getType(i), resolve(atts.getValue(i)));
+            }
+            if (inElement) {
+                flushBuffer(false);
+            }
+            inElement = true;
+            target.startElement(uri, localName, qName, resolvedAttributes);
+        }
+
+        @Override
+        public void endElement(String uri, String localName, String qName) throws SAXException {
+            if (inElement) {
+                flushBuffer(true);
+                inElement = false;
+            }
+            target.endElement(uri, localName, qName);
+        }
+
+        @Override
+        public void characters(char[] ch, int start, int length) throws SAXException {
+            if (inElement) {
+                sw.append(new String(ch, start, length));
+            } else {
+                target.characters(ch, start, length);
+            }
+        }
+
+        @Override
+        public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
+            // only elements without PCDATA in DTD have whitespace passed to this method. so ignore
+            target.ignorableWhitespace(ch, start, length);
+        }
+
+        @Override
+        public void processingInstruction(String target, String data) throws SAXException {
+            this.target.processingInstruction(target, data);
+        }
+
+        @Override
+        public void skippedEntity(String name) throws SAXException {
+            target.skippedEntity(name);
+        }
+
+        /**
+         * Pass collected characters to target {@link ContentHandler}
+         * @param resolve whether to expect placeholders in collected text
+         */
+        private void flushBuffer(boolean resolve) throws SAXException {
+            String value = sw.toString();
+            String resolved = resolve ? resolve(value) : value;
+
+            target.characters(resolved.toCharArray(), 0, resolved.length());
+            sw = new StringWriter();
+        }
+
+        private String resolve(String value) {
+            String resolved = org.ops4j.util.collections.PropertyResolver.resolve(properties, value);
+            if (resolved.contains("${")) {
+                // there are still unresolved properties - just log warning
+                LOG.warn("Value {} has unresolved properties, please check configuration.", value);
+            }
+            return resolved;
+        }
+
+    }
+
 }
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesProcessorImpl.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesProcessorImpl.java
index 4e3fa04..e609dbf 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesProcessorImpl.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesProcessorImpl.java
@@ -33,6 +33,7 @@ import org.apache.karaf.features.internal.model.Feature;
 import org.apache.karaf.features.internal.model.Features;
 import org.apache.karaf.features.internal.model.processing.BundleReplacements;
 import org.apache.karaf.features.internal.model.processing.FeaturesProcessing;
+import org.osgi.service.cm.ConfigurationAdmin;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -49,7 +50,7 @@ public class FeaturesProcessorImpl implements FeaturesProcessor {
 
     public static Logger LOG = LoggerFactory.getLogger(FeaturesProcessorImpl.class);
 
-    private static FeaturesProcessingSerializer serializer = new FeaturesProcessingSerializer();
+    private FeaturesProcessingSerializer serializer = new FeaturesProcessingSerializer();
 
     // empty, but fully functional features processing configuration
     private FeaturesProcessing processing = new FeaturesProcessing();
@@ -60,12 +61,14 @@ public class FeaturesProcessorImpl implements FeaturesProcessor {
      * @param featureModificationsURI
      * @param blacklistDefinitions
      * @param overrides
+     * @param configurationAdmin optional reference to {@link ConfigurationAdmin}
      */
-    public FeaturesProcessorImpl(String featureModificationsURI, Blacklist blacklistDefinitions, Set<String> overrides) {
+    public FeaturesProcessorImpl(String featureModificationsURI, Blacklist blacklistDefinitions, Set<String> overrides,
+                                 ConfigurationAdmin configurationAdmin) {
         if (featureModificationsURI != null) {
             try {
                 try (InputStream stream = new URL(featureModificationsURI).openStream()) {
-                    processing = serializer.read(stream);
+                    processing = serializer.read(stream, configurationAdmin);
                 }
             } catch (FileNotFoundException e) {
                 LOG.debug("Can't find feature processing file (" + featureModificationsURI + "), skipping");
@@ -82,18 +85,21 @@ public class FeaturesProcessorImpl implements FeaturesProcessor {
      * @param featureModificationsURI
      * @param blacklistedURI
      * @param overridesURI
+     * @param configurationAdmin optional reference to {@link ConfigurationAdmin}
      */
-    public FeaturesProcessorImpl(String featureModificationsURI, String blacklistedURI, String overridesURI) {
-        this(featureModificationsURI, new Blacklist(blacklistedURI), Overrides.loadOverrides(overridesURI));
+    public FeaturesProcessorImpl(String featureModificationsURI, String blacklistedURI, String overridesURI,
+                                 ConfigurationAdmin configurationAdmin) {
+        this(featureModificationsURI, new Blacklist(blacklistedURI), Overrides.loadOverrides(overridesURI), configurationAdmin);
     }
 
     /**
      * <p>Creates instance of features processor using {@link FeaturesServiceConfig configuration object} where
      * three files may be specified: overrides.properties, blacklisted.properties and org.apache.karaf.features.xml.</p>
      * @param configuration
+     * @param configurationAdmin optional reference to {@link ConfigurationAdmin}
      */
-    public FeaturesProcessorImpl(FeaturesServiceConfig configuration) {
-        this(configuration.featureModifications, configuration.blacklisted, configuration.overrides);
+    public FeaturesProcessorImpl(FeaturesServiceConfig configuration, ConfigurationAdmin configurationAdmin) {
+        this(configuration.featureModifications, configuration.blacklisted, configuration.overrides, configurationAdmin);
     }
 
     /**
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 0302478..207d76c 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
@@ -150,7 +150,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
         this.resolver = resolver;
         this.installSupport = installSupport;
         this.globalRepository = globalRepository;
-        this.repositories = new RepositoryCacheImpl(new FeaturesProcessorImpl(cfg));
+        this.repositories = new RepositoryCacheImpl(new FeaturesProcessorImpl(cfg, configurationAdmin));
         this.cfg = cfg;
         this.executor = Executors.newSingleThreadExecutor(ThreadUtils.namedThreadFactory("features"));
         loadState();
diff --git a/features/core/src/test/java/org/apache/karaf/features/internal/service/BlacklistTest.java b/features/core/src/test/java/org/apache/karaf/features/internal/service/BlacklistTest.java
index 6c5d7e2..14c52da 100644
--- a/features/core/src/test/java/org/apache/karaf/features/internal/service/BlacklistTest.java
+++ b/features/core/src/test/java/org/apache/karaf/features/internal/service/BlacklistTest.java
@@ -65,7 +65,7 @@ public class BlacklistTest {
         Blacklist blacklist = new Blacklist(getClass().getResource("blacklist.txt").toExternalForm());
         RepositoryImpl repo = new RepositoryImpl(getClass().getResource("f02.xml").toURI(), true);
         Stream<Feature> features = Arrays.stream(repo.getFeatures());
-        FeaturesProcessorImpl processor = new FeaturesProcessorImpl(new FeaturesServiceConfig());
+        FeaturesProcessorImpl processor = new FeaturesProcessorImpl(new FeaturesServiceConfig(), null);
         processor.getInstructions().postUnmarshall(blacklist, new HashSet<>());
         repo.processFeatures(processor);
         assertTrue(features.noneMatch(f -> f.getId().equals("spring/2.5.6.SEC02") && !f.isBlacklisted()));
@@ -84,7 +84,7 @@ public class BlacklistTest {
         }
         RepositoryImpl features = new RepositoryImpl(uri, true);
         FeaturesServiceConfig config = new FeaturesServiceConfig(null, FeaturesService.DEFAULT_FEATURE_RESOLUTION_RANGE, FeaturesService.DEFAULT_BUNDLE_UPDATE_RANGE, null, 1, 0, 0, blacklistedProperties.toURI().toString(), null, null);
-        features.processFeatures(new FeaturesProcessorImpl(config));
+        features.processFeatures(new FeaturesProcessorImpl(config, null));
         return Arrays.stream(features.getFeatures());
     }
 
diff --git a/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesProcessorTest.java b/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesProcessorTest.java
index e73e7d1..36b5059 100644
--- a/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesProcessorTest.java
+++ b/features/core/src/test/java/org/apache/karaf/features/internal/service/FeaturesProcessorTest.java
@@ -19,6 +19,7 @@
 package org.apache.karaf.features.internal.service;
 
 import java.net.URI;
+import java.util.Hashtable;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.Marshaller;
 
@@ -33,10 +34,14 @@ import org.apache.karaf.features.internal.model.processing.FeaturesProcessing;
 import org.apache.karaf.features.internal.model.processing.ObjectFactory;
 import org.apache.karaf.features.internal.model.processing.OverrideBundleDependency;
 import org.apache.karaf.util.maven.Parser;
+import org.easymock.EasyMock;
 import org.junit.Test;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.easymock.EasyMock.*;
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.CoreMatchers.nullValue;
 import static org.junit.Assert.assertFalse;
@@ -89,7 +94,7 @@ public class FeaturesProcessorTest {
     public void readingLegacyOverrides() {
         FeaturesProcessorImpl processor = new FeaturesProcessorImpl(new FeaturesServiceConfig(
                 "file:src/test/resources/org/apache/karaf/features/internal/service/overrides2.properties",
-                null, null));
+                null, null), null);
 
         FeaturesProcessing instructions = processor.getInstructions();
         BundleReplacements bundleReplacements = instructions.getBundleReplacements();
@@ -116,7 +121,7 @@ public class FeaturesProcessorTest {
         FeaturesProcessorImpl processor = new FeaturesProcessorImpl(new FeaturesServiceConfig(
                 null,
                 "file:src/test/resources/org/apache/karaf/features/internal/service/blacklisted2.properties",
-                null));
+                null), null);
 
         FeaturesProcessing instructions = processor.getInstructions();
         Blacklist blacklist = instructions.getBlacklist();
@@ -136,7 +141,7 @@ public class FeaturesProcessorTest {
     public void blacklistingRepositories() {
         FeaturesProcessorImpl processor = new FeaturesProcessorImpl(new FeaturesServiceConfig(
                 null, null,
-                "file:src/test/resources/org/apache/karaf/features/internal/service/fpi01.xml"));
+                "file:src/test/resources/org/apache/karaf/features/internal/service/fpi01.xml"), null);
         URI uri = URI.create("file:src/test/resources/org/apache/karaf/features/internal/service/fp01.xml");
         RepositoryImpl repo = (RepositoryImpl) new RepositoryCacheImpl(processor).create(uri, true);
         assertThat(repo.getRepositories().length, equalTo(3));
@@ -150,7 +155,7 @@ public class FeaturesProcessorTest {
     public void blacklistingFeatures() {
         FeaturesProcessorImpl processor = new FeaturesProcessorImpl(new FeaturesServiceConfig(
                 null, null,
-                "file:src/test/resources/org/apache/karaf/features/internal/service/fpi01.xml"));
+                "file:src/test/resources/org/apache/karaf/features/internal/service/fpi01.xml"), null);
         URI uri = URI.create("file:src/test/resources/org/apache/karaf/features/internal/service/fp02.xml");
         RepositoryImpl repo = (RepositoryImpl) new RepositoryCacheImpl(processor).create(uri, true);
 
@@ -166,7 +171,7 @@ public class FeaturesProcessorTest {
     public void blacklistingBundles() {
         FeaturesProcessorImpl processor = new FeaturesProcessorImpl(new FeaturesServiceConfig(
                 null, null,
-                "file:src/test/resources/org/apache/karaf/features/internal/service/fpi01.xml"));
+                "file:src/test/resources/org/apache/karaf/features/internal/service/fpi01.xml"), null);
         URI uri = URI.create("file:src/test/resources/org/apache/karaf/features/internal/service/fp03.xml");
         RepositoryImpl repo = (RepositoryImpl) new RepositoryCacheImpl(processor).create(uri, true);
 
@@ -182,7 +187,7 @@ public class FeaturesProcessorTest {
     public void overridingBundles() {
         FeaturesProcessorImpl processor = new FeaturesProcessorImpl(new FeaturesServiceConfig(
                 null, null,
-                "file:src/test/resources/org/apache/karaf/features/internal/service/fpi02.xml"));
+                "file:src/test/resources/org/apache/karaf/features/internal/service/fpi02.xml"), null);
         URI uri = URI.create("file:src/test/resources/org/apache/karaf/features/internal/service/fp03.xml");
         RepositoryImpl repo = (RepositoryImpl) new RepositoryCacheImpl(processor).create(uri, true);
 
@@ -202,6 +207,32 @@ public class FeaturesProcessorTest {
     }
 
     @Test
+    public void resolvePlaceholders() throws Exception {
+        Configuration versions = createMock(Configuration.class);
+        ConfigurationAdmin cm = createMock(ConfigurationAdmin.class);
+        expect(cm.listConfigurations("(service.pid=versions)")).andReturn(new Configuration[] {
+                versions
+        });
+        Hashtable<String, Object> props = new Hashtable<>();
+        props.put("version.jclouds", "1.9");
+        props.put("version.commons-io", "2.5");
+        expect(versions.getProperties()).andReturn(props);
+
+        replay(cm, versions);
+
+        FeaturesProcessorImpl processor = new FeaturesProcessorImpl(new FeaturesServiceConfig(
+                null, null,
+                "file:src/test/resources/org/apache/karaf/features/internal/service/fpi03.xml"), cm);
+
+        assertThat(processor.getInstructions().getBlacklistedRepositories().get(0),
+                equalTo("mvn:org.jclouds/jclouds-features/1.9/xml/features"));
+        assertThat(processor.getInstructions().getBundleReplacements().getOverrideBundles().get(0).getReplacement(),
+                equalTo("mvn:commons-io/commons-io/2.5"));
+
+        verify(cm, versions);
+    }
+
+    @Test
     public void serializeWithComments() {
         FeaturesProcessingSerializer serializer = new FeaturesProcessingSerializer();
         FeaturesProcessing featuresProcessing = new FeaturesProcessing();
diff --git a/features/core/src/test/resources/org/apache/karaf/features/internal/service/fpi03.xml b/features/core/src/test/resources/org/apache/karaf/features/internal/service/fpi03.xml
new file mode 100644
index 0000000..4528fbd
--- /dev/null
+++ b/features/core/src/test/resources/org/apache/karaf/features/internal/service/fpi03.xml
@@ -0,0 +1,30 @@
+<?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.
+-->
+<featuresProcessing xmlns="http://karaf.apache.org/xmlns/features-processing/v1.0.0">
+
+    <blacklistedRepositories>
+        <repository>mvn:org.jclouds/jclouds-features/${version.jclouds}/xml/features</repository>
+    </blacklistedRepositories>
+
+    <bundleReplacements>
+        <bundle replacement="mvn:commons-io/commons-io/${version.commons-io}" />
+    </bundleReplacements>
+
+</featuresProcessing>
diff --git a/pom.xml b/pom.xml
index afc72b1..acc0b86 100644
--- a/pom.xml
+++ b/pom.xml
@@ -273,6 +273,7 @@
         <pax.exam.version>4.11.0</pax.exam.version>
         <pax.logging.version>1.10.1</pax.logging.version>
         <pax.base.version>1.5.0</pax.base.version>
+        <pax.swissbox.version>1.8.2</pax.swissbox.version>
         <pax.url.version>2.5.3</pax.url.version>
         <pax.web.version>6.1.0-SNAPSHOT</pax.web.version>
         <pax.tinybundle.version>2.1.1</pax.tinybundle.version>
@@ -1246,6 +1247,16 @@
                 <version>${pax.base.version}</version>
             </dependency>
             <dependency>
+                <groupId>org.ops4j.base</groupId>
+                <artifactId>ops4j-base-util-property</artifactId>
+                <version>${pax.base.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.ops4j.base</groupId>
+                <artifactId>ops4j-base-util-collections</artifactId>
+                <version>${pax.base.version}</version>
+            </dependency>
+            <dependency>
                 <groupId>org.ops4j.pax.url</groupId>
                 <artifactId>pax-url-aether</artifactId>
                 <version>${pax.url.version}</version>
@@ -1305,6 +1316,11 @@
                 </exclusions>
             </dependency>
             <dependency>
+                <groupId>org.ops4j.pax.swissbox</groupId>
+                <artifactId>pax-swissbox-property</artifactId>
+                <version>${pax.swissbox.version}</version>
+            </dependency>
+            <dependency>
                 <groupId>org.ops4j.pax.url</groupId>
                 <artifactId>pax-url-wrap</artifactId>
                 <version>${pax.url.version}</version>

-- 
To stop receiving notification emails like this one, please contact
"commits@karaf.apache.org" <co...@karaf.apache.org>.