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 2017/05/15 13:12:01 UTC

[01/11] karaf git commit: Java 8 refactoring

Repository: karaf
Updated Branches:
  refs/heads/master 32f73e2fa -> 9b99ac740


Java 8 refactoring

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

Branch: refs/heads/master
Commit: f8ffd74c3c7e1919aba35388092d92359ca91cca
Parents: 32f73e2
Author: Guillaume Nodet <gn...@apache.org>
Authored: Mon May 15 13:20:59 2017 +0200
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Mon May 15 13:20:59 2017 +0200

----------------------------------------------------------------------
 .../org/apache/karaf/features/internal/service/Blacklist.java | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/f8ffd74c/features/core/src/main/java/org/apache/karaf/features/internal/service/Blacklist.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/Blacklist.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/Blacklist.java
index ba8c8a6..22610b7 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/Blacklist.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/Blacklist.java
@@ -64,12 +64,7 @@ public class Blacklist {
     }
 
     public static void blacklist(Features features, Clause[] clauses) {
-        for (Iterator<Feature> iterator = features.getFeature().iterator(); iterator.hasNext(); ) {
-            Feature feature = iterator.next();
-            if (blacklist(feature, clauses)) {
-                iterator.remove();
-            }
-        }
+        features.getFeature().removeIf(feature -> blacklist(feature, clauses));
     }
 
     public static boolean blacklist(Feature feature, Clause[] clauses) {


[02/11] karaf git commit: Java 8 refactoring

Posted by gn...@apache.org.
Java 8 refactoring

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

Branch: refs/heads/master
Commit: c5f2a0cf9f00a04262b373e6b97e40299d52f28b
Parents: f8ffd74
Author: Guillaume Nodet <gn...@apache.org>
Authored: Mon May 15 14:28:11 2017 +0200
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Mon May 15 14:28:11 2017 +0200

----------------------------------------------------------------------
 .../internal/service/FeaturesServiceImpl.java   | 84 +++++++-------------
 1 file changed, 30 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/c5f2a0cf/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 02be751..f85b75e 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
@@ -43,8 +43,11 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.function.Predicate;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import org.apache.felix.utils.version.VersionCleaner;
 import org.apache.felix.utils.version.VersionRange;
@@ -504,13 +507,12 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
             return;
         }
 
-        Set<String> features = new HashSet<>();
+        Set<String> features;
         synchronized (lock) {
-            for (Feature feature : repo.getFeatures()) {
-                if (isRequired(feature)) {
-                    features.add(feature.getId());
-                }
-            }
+            features = Stream.of(repo.getFeatures())
+                    .filter(this::isRequired)
+                    .map(Feature::getId)
+                    .collect(Collectors.toSet());
         }
         if (!features.isEmpty()) {
             if (uninstall) {
@@ -694,13 +696,8 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
 
     @Override
     public Feature[] listFeatures() throws Exception {
-        Set<Feature> features = new HashSet<>();
-        for (Map<String, Feature> featureWithDifferentVersion : getFeatures().values()) {
-            for (Feature f : featureWithDifferentVersion.values()) {
-                features.add(f);
-            }
-        }
-        return features.toArray(new Feature[features.size()]);
+        Map<String, Map<String, Feature>> allFeatures = getFeatures();
+        return flattenFeatures(allFeatures);
     }
 
     protected Map<String, Map<String, Feature>> getFeatures() throws Exception {
@@ -772,36 +769,31 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
 
     @Override
     public Feature[] listInstalledFeatures() throws Exception {
-        Set<Feature> features = new HashSet<>();
         Map<String, Map<String, Feature>> allFeatures = getFeatures();
         synchronized (lock) {
-            for (Map<String, Feature> featureWithDifferentVersion : allFeatures.values()) {
-                for (Feature f : featureWithDifferentVersion.values()) {
-                    if (isInstalled(f)) {
-                        features.add(f);
-                    }
-                }
-            }
+            return flattenFeatures(allFeatures, this::isInstalled);
         }
-        return features.toArray(new Feature[features.size()]);
     }
 
     @Override
     public Feature[] listRequiredFeatures() throws Exception {
-        Set<Feature> features = new HashSet<>();
         Map<String, Map<String, Feature>> allFeatures = getFeatures();
         synchronized (lock) {
-            for (Map<String, Feature> featureWithDifferentVersion : allFeatures.values()) {
-                for (Feature f : featureWithDifferentVersion.values()) {
-                    if (isRequired(f)) {
-                        features.add(f);
-                    }
-                }
-            }
+            return flattenFeatures(allFeatures, this::isRequired);
         }
-        return features.toArray(new Feature[features.size()]);
     }
 
+    private Feature[] flattenFeatures(Map<String, Map<String, Feature>> features) {
+        return flattenFeatures(features, f -> true /* include all */);
+    }
+
+    private Feature[] flattenFeatures(Map<String, Map<String, Feature>> features, Predicate<Feature> pred) {
+        return features.values().stream()
+                .map(Map::values)
+                .flatMap(Collection::stream)
+                .filter(pred)
+                .toArray(Feature[]::new);
+    }
 
     @Override
     public boolean isInstalled(Feature f) {
@@ -916,11 +908,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
         if (region == null || region.isEmpty()) {
             region = ROOT_REGION;
         }
-        Set<String> fl = required.get(region);
-        if (fl == null) {
-            fl = new HashSet<>();
-            required.put(region, fl);
-        }
+        Set<String> fl = required.computeIfAbsent(region, k -> new HashSet<>());
         List<String> featuresToAdd = new ArrayList<>();
         List<String> featuresToRemove = new ArrayList<>();
         for (String feature : features) {
@@ -983,11 +971,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
         if (region == null || region.isEmpty()) {
             region = ROOT_REGION;
         }
-        Set<String> fl = required.get(region);
-        if (fl == null) {
-            fl = new HashSet<>();
-            required.put(region, fl);
-        }
+        Set<String> fl = required.computeIfAbsent(region, k -> new HashSet<>());
         List<String> featuresToRemove = new ArrayList<>();
         for (String feature : new HashSet<>(features)) {
             List<String> toRemove = new ArrayList<>();
@@ -1247,14 +1231,11 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
     public void refreshPackages(Collection<Bundle> bundles) throws InterruptedException {
         final CountDownLatch latch = new CountDownLatch(1);
         FrameworkWiring fw = systemBundleContext.getBundle().adapt(FrameworkWiring.class);
-        fw.refreshBundles(bundles, new FrameworkListener() {
-            @Override
-            public void frameworkEvent(FrameworkEvent event) {
-                if (event.getType() == FrameworkEvent.ERROR) {
-                    LOGGER.error("Framework error", event.getThrowable());
-                }
-                latch.countDown();
+        fw.refreshBundles(bundles, (FrameworkListener) event -> {
+            if (event.getType() == FrameworkEvent.ERROR) {
+                LOGGER.error("Framework error", event.getThrowable());
             }
+            latch.countDown();
         });
         latch.await();
     }
@@ -1382,12 +1363,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
             public void end() {
             }
         };
-        ResolverHookFactory factory = new ResolverHookFactory() {
-            @Override
-            public ResolverHook begin(Collection<BundleRevision> triggers) {
-                return hook;
-            }
-        };
+        ResolverHookFactory factory = triggers -> hook;
         ServiceRegistration<ResolverHookFactory> registration = systemBundleContext.registerService(ResolverHookFactory.class, factory, null);
         try {
             FrameworkWiring frameworkWiring = systemBundleContext.getBundle().adapt(FrameworkWiring.class);


[07/11] karaf git commit: Fix some internal methods visibility

Posted by gn...@apache.org.
Fix some internal methods visibility

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

Branch: refs/heads/master
Commit: 6abc7dac1565c31622f84eb08b50c073fefa2f12
Parents: 6abe137
Author: Guillaume Nodet <gn...@apache.org>
Authored: Mon May 15 14:33:20 2017 +0200
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Mon May 15 14:33:20 2017 +0200

----------------------------------------------------------------------
 .../features/internal/service/FeaturesServiceImpl.java    | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/6abc7dac/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 b22ae3c..d3640f9 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
@@ -671,7 +671,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
         return features.toArray(new Feature[features.size()]);
     }
 
-    protected Feature getFeatureMatching(Map<String, Feature> versions, String version) {
+    private Feature getFeatureMatching(Map<String, Feature> versions, String version) {
         if (version != null) {
             version = version.trim();
             if (version.equals(org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION)) {
@@ -1068,7 +1068,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
         }
     }
 
-    protected String normalize(String feature) {
+    private String normalize(String feature) {
         if (!feature.contains(VERSION_SEPARATOR)) {
             feature += "/0.0.0";
         }
@@ -1090,7 +1090,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
      * @param options the provisioning options.
      * @throws Exception in case of provisioning failure.
      */
-    public void doProvisionInThread(final Map<String, Set<String>> requirements,
+    private void doProvisionInThread(final Map<String, Set<String>> requirements,
                                     final Map<String, Map<String, FeatureState>> stateChanges,
                                     final State state,
                                     final EnumSet<Option> options) throws Exception {
@@ -1115,7 +1115,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
         }
     }
 
-    protected Deployer.DeploymentState getDeploymentState(State state) throws Exception {
+    private Deployer.DeploymentState getDeploymentState(State state) throws Exception {
         Deployer.DeploymentState dstate = new Deployer.DeploymentState();
         // State
         dstate.state = state;
@@ -1181,7 +1181,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
 
 
 
-    public void doProvision(Map<String, Set<String>> requirements,                // all requirements
+    private void doProvision(Map<String, Set<String>> requirements,                // all requirements
                             Map<String, Map<String, FeatureState>> stateChanges,  // features state changes
                             State state,                                          // current state
                             EnumSet<Option> options,                              // installation options


[08/11] karaf git commit: Only parse blacklisting clauses once when loading repositories

Posted by gn...@apache.org.
Only parse blacklisting clauses once when loading repositories

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

Branch: refs/heads/master
Commit: efa6dc7ab9b138fa23e2d41698bf1690ed28ccac
Parents: 6abc7da
Author: Guillaume Nodet <gn...@apache.org>
Authored: Mon May 15 14:34:25 2017 +0200
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Mon May 15 14:34:25 2017 +0200

----------------------------------------------------------------------
 .../karaf/features/internal/service/Blacklist.java   |  6 ++----
 .../internal/service/FeaturesServiceImpl.java        |  7 ++++++-
 .../features/internal/service/RepositoryImpl.java    | 15 ++++++++++++---
 3 files changed, 20 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/efa6dc7a/features/core/src/main/java/org/apache/karaf/features/internal/service/Blacklist.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/Blacklist.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/Blacklist.java
index 22610b7..0d804a7 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/Blacklist.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/Blacklist.java
@@ -57,10 +57,8 @@ public class Blacklist {
     }
 
     public static void blacklist(Features features, Collection<String> blacklist) {
-        if (!blacklist.isEmpty()) {
-            Clause[] clauses = Parser.parseClauses(blacklist.toArray(new String[blacklist.size()]));
-            blacklist(features, clauses);
-        }
+        Clause[] clauses = Parser.parseClauses(blacklist.toArray(new String[blacklist.size()]));
+        blacklist(features, clauses);
     }
 
     public static void blacklist(Features features, Clause[] clauses) {

http://git-wip-us.apache.org/repos/asf/karaf/blob/efa6dc7a/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 d3640f9..6991e17 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
@@ -49,6 +49,8 @@ import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
+import org.apache.felix.utils.manifest.Clause;
+import org.apache.felix.utils.manifest.Parser;
 import org.apache.felix.utils.version.VersionCleaner;
 import org.apache.felix.utils.version.VersionRange;
 import org.apache.felix.utils.version.VersionTable;
@@ -721,6 +723,9 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
         }
         //the outer map's key is feature name, the inner map's key is feature version
         Map<String, Map<String, Feature>> map = new HashMap<>();
+        // Load blacklist
+        Set<String> blacklistStrings = Blacklist.loadBlacklist(blacklisted);
+        Clause[] blacklist = Parser.parseClauses(blacklistStrings.toArray(new String[blacklistStrings.size()]));
         // Two phase load:
         // * first load dependent repositories
         Set<String> loaded = new HashSet<>();
@@ -733,7 +738,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
             }
             try {
                 if (repo == null) {
-                    RepositoryImpl rep = new RepositoryImpl(URI.create(uri), blacklisted);
+                    RepositoryImpl rep = new RepositoryImpl(URI.create(uri), blacklist);
                     rep.load();
                     repo = rep;
                     synchronized (lock) {

http://git-wip-us.apache.org/repos/asf/karaf/blob/efa6dc7a/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java
index 9b176bb..0cd0407 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java
@@ -21,7 +21,10 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InterruptedIOException;
 import java.net.URI;
+import java.util.Set;
 
+import org.apache.felix.utils.manifest.Clause;
+import org.apache.felix.utils.manifest.Parser;
 import org.apache.karaf.features.Repository;
 import org.apache.karaf.features.internal.model.Features;
 import org.apache.karaf.features.internal.model.JaxbUtil;
@@ -32,16 +35,22 @@ import org.apache.karaf.features.internal.model.JaxbUtil;
 public class RepositoryImpl implements Repository {
 
     private final URI uri;
-    private final String blacklisted;
+    private final Clause[] blacklisted;
     private Features features;
 
     public RepositoryImpl(URI uri) {
-        this(uri, null);
+        this(uri, (Clause[]) null);
     }
 
     public RepositoryImpl(URI uri, String blacklisted) {
         this.uri = uri;
-        this.blacklisted = blacklisted;
+        Set<String> blacklistStrings = Blacklist.loadBlacklist(blacklisted);
+        this.blacklisted = Parser.parseClauses(blacklistStrings.toArray(new String[blacklistStrings.size()]));
+    }
+
+    public RepositoryImpl(URI uri, Clause[] blacklisted) {
+        this.uri = uri;
+        this.blacklisted = blacklisted != null ? blacklisted : new Clause[0];
     }
 
     public URI getURI() {


[04/11] karaf git commit: Clean a bit version handling

Posted by gn...@apache.org.
Clean a bit version handling

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

Branch: refs/heads/master
Commit: cba50b49f435420910b9dc6a5e3f3be13e9ac0fa
Parents: c20c3f3
Author: Guillaume Nodet <gn...@apache.org>
Authored: Mon May 15 14:31:02 2017 +0200
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Mon May 15 14:31:02 2017 +0200

----------------------------------------------------------------------
 .../internal/service/FeaturesServiceImpl.java   | 49 +++++++++++++-------
 1 file changed, 31 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/cba50b49/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 989ab74..2b18c21 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
@@ -112,6 +112,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
 
     private static final Logger LOGGER = LoggerFactory.getLogger(FeaturesServiceImpl.class);
     private static final String FEATURE_OSGI_REQUIREMENT_PREFIX = "feature:";
+    private static final String VERSION_SEPARATOR = "/";
 
     /**
      * Our bundle and corresponding bundle context.
@@ -486,7 +487,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
         if (install) {
             HashSet<String> features = new HashSet<>();
             for (Feature feature : repository.getFeatures()) {
-                features.add(feature.getName() + "/" + feature.getVersion());
+                features.add(feature.getId());
             }
             installFeatures(features, EnumSet.noneOf(FeaturesService.Option.class));
         }
@@ -637,7 +638,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
 
     @Override
     public Feature[] getFeatures(String nameOrId) throws Exception {
-        String[] parts = nameOrId.split("/");
+        String[] parts = nameOrId.split(VERSION_SEPARATOR);
         String name = parts.length > 0 ? parts[0] : nameOrId;
         String version = parts.length > 1 ? parts[1] : null;
         return getFeatures(name, version);
@@ -817,7 +818,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
 
     @Override
     public boolean isRequired(Feature f) {
-        String id = FEATURE_OSGI_REQUIREMENT_PREFIX + f.getName() + "/" + new VersionRange(f.getVersion(), true);
+        String id = FEATURE_OSGI_REQUIREMENT_PREFIX + getFeatureRequirement(f);
         synchronized (lock) {
             Set<String> features = state.requirements.get(ROOT_REGION);
             return features != null && features.contains(id);
@@ -835,7 +836,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
 
     @Override
     public void installFeature(String name, String version) throws Exception {
-        installFeature(version != null ? name + "/" + version : name, EnumSet.noneOf(Option.class));
+        installFeature(getId(name, version), EnumSet.noneOf(Option.class));
     }
 
     @Override
@@ -845,7 +846,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
 
     @Override
     public void installFeature(String name, String version, EnumSet<Option> options) throws Exception {
-        installFeature(version != null ? name + "/" + version : name, options);
+        installFeature(getId(name, version), options);
     }
 
     @Override
@@ -860,12 +861,12 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
 
     @Override
     public void uninstallFeature(String name, String version) throws Exception {
-        uninstallFeature(version != null ? name + "/" + version : name);
+        uninstallFeature(getId(name, version));
     }
 
     @Override
     public void uninstallFeature(String name, String version, EnumSet<Option> options) throws Exception {
-        uninstallFeature(version != null ? name + "/" + version : name, options);
+        uninstallFeature(getId(name, version), options);
     }
 
     @Override
@@ -883,6 +884,10 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
         uninstallFeatures(features, ROOT_REGION, options);
     }
 
+    private String getId(String name, String version) {
+        return version != null ? name + VERSION_SEPARATOR + version : name;
+    }
+
 
     //
     //
@@ -910,8 +915,8 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
         List<String> featuresToRemove = new ArrayList<>();
         for (String feature : features) {
             feature = normalize(feature);
-            String name = feature.substring(0, feature.indexOf("/"));
-            String version = feature.substring(feature.indexOf("/") + 1);
+            String name = feature.substring(0, feature.indexOf(VERSION_SEPARATOR));
+            String version = feature.substring(feature.indexOf(VERSION_SEPARATOR) + 1);
             Pattern pattern = Pattern.compile(name);
             boolean matched = false;
             for (String fKey : getFeatures().keySet()) {
@@ -919,7 +924,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
                 if (matcher.matches()) {
                     Feature f = getFeatureMatching(getFeatures().get(fKey), version);
                     if (f != null) {
-                        String req = f.getName() + "/" + new VersionRange(f.getVersion(), true);
+                        String req = getFeatureRequirement(f);
                         featuresToAdd.add(req);
                         Feature[] installedFeatures = listInstalledFeatures();
                         for (Feature installedFeature : installedFeatures) {
@@ -938,7 +943,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
                 for (String existentFeatureReq : fl) {
                     //remove requirement prefix feature:
                     String existentFeature = existentFeatureReq.substring(FEATURE_OSGI_REQUIREMENT_PREFIX.length());
-                    if (existentFeature.startsWith(name + "/")
+                    if (existentFeature.startsWith(name + VERSION_SEPARATOR)
                             && !featuresToAdd.contains(existentFeature)) {
                         featuresToRemove.add(existentFeature);
                         //do not break cycle to remove all old versions of feature
@@ -975,7 +980,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
             feature = normalize(feature);
             if (feature.endsWith("/0.0.0")) {
                 // Match only on name
-                String nameSep = FEATURE_OSGI_REQUIREMENT_PREFIX + feature.substring(0, feature.indexOf("/") + 1);
+                String nameSep = FEATURE_OSGI_REQUIREMENT_PREFIX + feature.substring(0, feature.indexOf(VERSION_SEPARATOR) + 1);
                 for (String f : fl) {
                     Pattern pattern = Pattern.compile(nameSep.substring(0, nameSep.length() - 1));
                     Matcher matcher = pattern.matcher(f);
@@ -985,8 +990,8 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
                 }
             } else {
                 // Match on name and version
-                String name = feature.substring(0, feature.indexOf("/"));
-                String version = feature.substring(feature.indexOf("/") + 1);
+                String name = feature.substring(0, feature.indexOf(VERSION_SEPARATOR));
+                String version = feature.substring(feature.indexOf(VERSION_SEPARATOR) + 1);
                 Pattern pattern = getFeaturePattern(name, version);
                 for (String f : fl) {
                     Matcher matcher = pattern.matcher(f);
@@ -1050,13 +1055,13 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
     }
 
     protected String normalize(String feature) {
-        if (!feature.contains("/")) {
+        if (!feature.contains(VERSION_SEPARATOR)) {
             feature += "/0.0.0";
         }
-        int idx = feature.indexOf("/");
+        int idx = feature.indexOf(VERSION_SEPARATOR);
         String name = feature.substring(0, idx);
         String version = feature.substring(idx + 1);
-        return name + "/" + VersionCleaner.clean(version);
+        return name + VERSION_SEPARATOR + VersionCleaner.clean(version);
     }
 
     /**
@@ -1406,7 +1411,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
     }
 
     private Pattern getFeaturePattern(String name, String version) {
-        String req = FEATURE_OSGI_REQUIREMENT_PREFIX + name + "/" + new VersionRange(version, true);
+        String req = FEATURE_OSGI_REQUIREMENT_PREFIX + getFeatureRequirement(name, version);
         req = req.replace("[", "\\[");
         req = req.replace("(", "\\(");
         req = req.replace("]", "\\]");
@@ -1415,6 +1420,14 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
         return pattern;
     }
 
+    private String getFeatureRequirement(Feature feature) {
+        return getFeatureRequirement(feature.getName(), feature.getVersion());
+    }
+
+    private String getFeatureRequirement(String name, String version) {
+        return name + VERSION_SEPARATOR + new VersionRange(version, true);
+    }
+
     private String join(List<String> list) {
         StringBuilder sb = new StringBuilder();
         for (int i = 0; i < list.size(); i++) {


[10/11] karaf git commit: Import the class

Posted by gn...@apache.org.
Import the class

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

Branch: refs/heads/master
Commit: 0326b1091c1542d01b08fdf7442e6663ca8bb97c
Parents: 7282301
Author: Guillaume Nodet <gn...@apache.org>
Authored: Mon May 15 14:57:37 2017 +0200
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Mon May 15 14:57:37 2017 +0200

----------------------------------------------------------------------
 .../apache/karaf/features/internal/service/RepositoryImpl.java  | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/0326b109/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java
index 0cd0407..20cbd36 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/RepositoryImpl.java
@@ -25,6 +25,7 @@ import java.util.Set;
 
 import org.apache.felix.utils.manifest.Clause;
 import org.apache.felix.utils.manifest.Parser;
+import org.apache.karaf.features.Feature;
 import org.apache.karaf.features.Repository;
 import org.apache.karaf.features.internal.model.Features;
 import org.apache.karaf.features.internal.model.JaxbUtil;
@@ -78,10 +79,10 @@ public class RepositoryImpl implements Repository {
                 .toArray(URI[]::new);
     }
 
-    public org.apache.karaf.features.Feature[] getFeatures() throws IOException {
+    public Feature[] getFeatures() throws IOException {
         load();
         return features.getFeature()
-                .toArray(new org.apache.karaf.features.Feature[features.getFeature().size()]);
+                .toArray(new Feature[features.getFeature().size()]);
     }
 
 


[03/11] karaf git commit: Remove unused field

Posted by gn...@apache.org.
Remove unused field

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

Branch: refs/heads/master
Commit: c20c3f3e8078ae8df31f1e5cb8b7062cb652efb7
Parents: c5f2a0c
Author: Guillaume Nodet <gn...@apache.org>
Authored: Mon May 15 14:28:37 2017 +0200
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Mon May 15 14:28:37 2017 +0200

----------------------------------------------------------------------
 .../karaf/features/internal/service/FeaturesServiceImpl.java      | 3 ---
 1 file changed, 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/c20c3f3e/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 f85b75e..989ab74 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
@@ -170,8 +170,6 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
 
     private final String blacklisted;
 
-    private final boolean configCfgStore;
-
     private final ThreadLocal<String> outputFile = new ThreadLocal<>();
 
     /**
@@ -255,7 +253,6 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
         this.scheduleDelay = scheduleDelay;
         this.scheduleMaxRun = scheduleMaxRun;
         this.blacklisted = blacklisted;
-        this.configCfgStore = configCfgStore;
         this.executor = Executors.newSingleThreadExecutor();
         loadState();
         checkResolve();


[06/11] karaf git commit: Remove some calls to getFeatures() so not we only call it once for a given method

Posted by gn...@apache.org.
Remove some calls to getFeatures() so not we only call it once for a given method

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

Branch: refs/heads/master
Commit: 6abe1379bc7f89174c07d6e585a37089e5b92288
Parents: 66d85a7
Author: Guillaume Nodet <gn...@apache.org>
Authored: Mon May 15 14:32:52 2017 +0200
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Mon May 15 14:32:52 2017 +0200

----------------------------------------------------------------------
 .../internal/service/FeaturesServiceImpl.java         | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/6abe1379/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 ce318ac..b22ae3c 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
@@ -627,7 +627,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
 
     @Override
     public Feature getFeature(String name) throws Exception {
-        Feature[] features = this.getFeatures(name);
+        Feature[] features = getFeatures(name);
         if (features.length < 1) {
             return null;
         } else {
@@ -637,7 +637,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
 
     @Override
     public Feature getFeature(String name, String version) throws Exception {
-        Feature[] features = this.getFeatures(name, version);
+        Feature[] features = getFeatures(name, version);
         if (features.length < 1) {
             return null;
         } else {
@@ -657,10 +657,11 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
     public Feature[] getFeatures(String name, String version) throws Exception {
         List<Feature> features = new ArrayList<>();
         Pattern pattern = Pattern.compile(name);
-        for (String featureName : getFeatures().keySet()) {
+        Map<String, Map<String, Feature>> allFeatures = getFeatures();
+        for (String featureName : allFeatures.keySet()) {
             Matcher matcher = pattern.matcher(featureName);
             if (matcher.matches()) {
-                Map<String, Feature> versions = getFeatures().get(featureName);
+                Map<String, Feature> versions = allFeatures.get(featureName);
                 Feature matchingFeature = getFeatureMatching(versions, version);
                 if (matchingFeature != null) {
                     features.add(matchingFeature);
@@ -923,6 +924,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
             region = ROOT_REGION;
         }
         Set<String> fl = required.computeIfAbsent(region, k -> new HashSet<>());
+        Map<String, Map<String, Feature>> allFeatures = getFeatures();
         List<String> featuresToAdd = new ArrayList<>();
         List<String> featuresToRemove = new ArrayList<>();
         for (String feature : features) {
@@ -931,10 +933,10 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
             String version = feature.substring(feature.indexOf(VERSION_SEPARATOR) + 1);
             Pattern pattern = Pattern.compile(name);
             boolean matched = false;
-            for (String fKey : getFeatures().keySet()) {
+            for (String fKey : allFeatures.keySet()) {
                 Matcher matcher = pattern.matcher(fKey);
                 if (matcher.matches()) {
-                    Feature f = getFeatureMatching(getFeatures().get(fKey), version);
+                    Feature f = getFeatureMatching(allFeatures.get(fKey), version);
                     if (f != null) {
                         String req = getFeatureRequirement(f);
                         featuresToAdd.add(req);


[09/11] karaf git commit: Minor code refinements

Posted by gn...@apache.org.
Minor code refinements

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

Branch: refs/heads/master
Commit: 7282301c7581e28d8f7f0748bb44ab2c37c1452d
Parents: efa6dc7
Author: Guillaume Nodet <gn...@apache.org>
Authored: Mon May 15 14:34:48 2017 +0200
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Mon May 15 14:34:48 2017 +0200

----------------------------------------------------------------------
 .../karaf/features/internal/service/FeaturesServiceImpl.java    | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/7282301c/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 6991e17..44300e7 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
@@ -751,7 +751,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
                     }
                 }
             } catch (Exception e) {
-                    LOGGER.warn("Can't load features repository {}", uri, e);
+                LOGGER.warn("Can't load features repository {}", uri, e);
             }
         }
         List<Repository> repos;
@@ -1435,8 +1435,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
         req = req.replace("(", "\\(");
         req = req.replace("]", "\\]");
         req = req.replace(")", "\\)");
-        Pattern pattern = Pattern.compile(req);
-        return pattern;
+        return Pattern.compile(req);
     }
 
     private String getFeatureRequirement(Feature feature) {


[05/11] karaf git commit: Add some doc when to not hold a lock

Posted by gn...@apache.org.
Add some doc when to not hold a lock

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

Branch: refs/heads/master
Commit: 66d85a72d806b20e8db24ef277f63da926ae5639
Parents: cba50b4
Author: Guillaume Nodet <gn...@apache.org>
Authored: Mon May 15 14:31:46 2017 +0200
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Mon May 15 14:31:46 2017 +0200

----------------------------------------------------------------------
 .../features/internal/service/FeaturesServiceImpl.java  | 12 ++++++++++++
 1 file changed, 12 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/66d85a72/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 2b18c21..ce318ac 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
@@ -403,6 +403,9 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
         deploymentListeners.remove(listener);
     }
 
+    /*
+     * Should never be called while holding a lock as we're calling outside our bundle.
+     */
     @Override
     public void callListeners(FeatureEvent event) {
         if (eventAdminListener != null) {
@@ -413,6 +416,9 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
         }
     }
 
+    /*
+     * Should never be called while holding a lock as we're calling outside our bundle.
+     */
     @Override
     public void callListeners(DeploymentEvent event) {
         lastDeploymentEvent = event;
@@ -425,6 +431,9 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
         }
     }
 
+    /*
+     * Should never be called while holding a lock as we're calling outside our bundle.
+     */
     protected void callListeners(RepositoryEvent event) {
         if (eventAdminListener != null) {
             eventAdminListener.repositoryEvent(event);
@@ -698,6 +707,9 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
         return flattenFeatures(allFeatures);
     }
 
+    /**
+     * Should not be called while holding a lock.
+     */
     protected Map<String, Map<String, Feature>> getFeatures() throws Exception {
         List<String> uris;
         synchronized (lock) {


[11/11] karaf git commit: Use a TreeSet to make the code more obvious

Posted by gn...@apache.org.
Use a TreeSet to make the code more obvious

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

Branch: refs/heads/master
Commit: 9b99ac740fed65fc518e16088eb9a88194632b61
Parents: 0326b10
Author: Guillaume Nodet <gn...@apache.org>
Authored: Mon May 15 14:57:51 2017 +0200
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Mon May 15 14:57:51 2017 +0200

----------------------------------------------------------------------
 .../karaf/features/internal/service/FeaturesServiceImpl.java  | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/9b99ac74/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 44300e7..d4e7ce1 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
@@ -714,12 +714,12 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
      * Should not be called while holding a lock.
      */
     protected Map<String, Map<String, Feature>> getFeatures() throws Exception {
-        List<String> uris;
+        Set<String> uris;
         synchronized (lock) {
             if (featureCache != null) {
                 return featureCache;
             }
-            uris = new ArrayList<>(state.repositories);
+            uris = new TreeSet<>(state.repositories);
         }
         //the outer map's key is feature name, the inner map's key is feature version
         Map<String, Map<String, Feature>> map = new HashMap<>();
@@ -771,8 +771,7 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
             }
         }
         synchronized (lock) {
-            if (uris.size() == state.repositories.size()
-                    && state.repositories.containsAll(uris)) {
+            if (uris.equals(state.repositories)) {
                 featureCache = map;
             }
         }