[1/4] karaf git commit: [KARAF-5300] Reuse and extract feature matching code
Repository: karaf Updated Branches: refs/heads/master 5a8133dbb -> 1c4149b6f [KARAF-5300] Reuse and extract feature matching code Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/1c4149b6 Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/1c4149b6 Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/1c4149b6 Branch: refs/heads/master Commit: 1c4149b6f510be94522b4bfa529b163c610f87a3 Parents: 4328939 Author: Christian Schneider Authored: Thu Aug 10 15:30:59 2017 +0200 Committer: Christian Schneider Committed: Mon Aug 21 10:58:39 2017 +0200 -- .../internal/service/FeaturesServiceImpl.java | 79 +++- 1 file changed, 43 insertions(+), 36 deletions(-) -- http://git-wip-us.apache.org/repos/asf/karaf/blob/1c4149b6/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 2767bc8..574998a 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 @@ -520,15 +520,15 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall @Override public Feature[] getFeatures(String nameOrId) throws Exception { -return getFeatures(new FeatureReq(nameOrId)); +return toArray(getFeatures(new FeatureReq(nameOrId))); } @Override public Feature[] getFeatures(String name, String version) throws Exception { -return getFeatures(new FeatureReq(name, version)); +return toArray(getFeatures(new FeatureReq(name, version))); } -private Feature[] getFeatures(FeatureReq featureReq) throws Exception { +private Collection getFeatures(FeatureReq featureReq) throws Exception { List features = new ArrayList<>(); Pattern pattern = Pattern.compile(featureReq.getName()); Map> allFeatures = getFeatureCache(); @@ -541,6 +541,10 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall } } } +return features; +} + +private Feature[] toArray(Collection features) { return features.toArray(new Feature[features.size()]); } @@ -819,33 +823,33 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall private Set computeFeaturesToAdd(EnumSet options, Set toInstall) throws Exception { Feature[] installedFeatures = listInstalledFeatures(); -Map> allFeatures = getFeatureCache(); Set toAdd = new HashSet<>(); -for (FeatureReq feature : toInstall) { -Pattern pattern = Pattern.compile(feature.getName()); -boolean matched = false; -for (String fKey : allFeatures.keySet()) { -Matcher matcher = pattern.matcher(fKey); -if (matcher.matches()) { -Feature f = getFeatureMatching(fKey, feature.getVersionRange()); -if (f != null) { -toAdd.add(new FeatureReq(f)); -for (Feature installedFeature : installedFeatures) { -if (installedFeature.getName().equals(f.getName()) && installedFeature.getVersion().equals(f.getVersion())) { -LOGGER.info("The specified feature: '{}' version '{}' {}",f.getName(),f.getVersion(),f.getVersion().endsWith("SNAPSHOT") ? "has been upgraded": "is already installed"); -} -} -matched = true; +for (FeatureReq featureReq : toInstall) { +Collection matching = getFeatures(featureReq); +for (Feature f: matching) { +toAdd.add(new FeatureReq(f)); +for (Feature installedFeature : installedFeatures) { +if (isSameFeature(f, installedFeature)) { +logInstalledOrUpdated(f); } } } -if (!matched && !options.contains(Option.NoFailOnFeatureNotFound)) { -throw new IllegalArgumentException("No matching features for " + feature); +if (matching.isEmpty() && !options.contains(Option.NoFailOnFeatureNotFound)) { +throw new IllegalArgumentException("No matching features for " + featureReq); } }
[7/9] karaf git commit: [KARAF-5300] Reuse and extract feature matching code
[KARAF-5300] Reuse and extract feature matching code Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/1c4149b6 Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/1c4149b6 Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/1c4149b6 Branch: refs/heads/model_features Commit: 1c4149b6f510be94522b4bfa529b163c610f87a3 Parents: 4328939 Author: Christian Schneider Authored: Thu Aug 10 15:30:59 2017 +0200 Committer: Christian Schneider Committed: Mon Aug 21 10:58:39 2017 +0200 -- .../internal/service/FeaturesServiceImpl.java | 79 +++- 1 file changed, 43 insertions(+), 36 deletions(-) -- http://git-wip-us.apache.org/repos/asf/karaf/blob/1c4149b6/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 2767bc8..574998a 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 @@ -520,15 +520,15 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall @Override public Feature[] getFeatures(String nameOrId) throws Exception { -return getFeatures(new FeatureReq(nameOrId)); +return toArray(getFeatures(new FeatureReq(nameOrId))); } @Override public Feature[] getFeatures(String name, String version) throws Exception { -return getFeatures(new FeatureReq(name, version)); +return toArray(getFeatures(new FeatureReq(name, version))); } -private Feature[] getFeatures(FeatureReq featureReq) throws Exception { +private Collection getFeatures(FeatureReq featureReq) throws Exception { List features = new ArrayList<>(); Pattern pattern = Pattern.compile(featureReq.getName()); Map> allFeatures = getFeatureCache(); @@ -541,6 +541,10 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall } } } +return features; +} + +private Feature[] toArray(Collection features) { return features.toArray(new Feature[features.size()]); } @@ -819,33 +823,33 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall private Set computeFeaturesToAdd(EnumSet options, Set toInstall) throws Exception { Feature[] installedFeatures = listInstalledFeatures(); -Map> allFeatures = getFeatureCache(); Set toAdd = new HashSet<>(); -for (FeatureReq feature : toInstall) { -Pattern pattern = Pattern.compile(feature.getName()); -boolean matched = false; -for (String fKey : allFeatures.keySet()) { -Matcher matcher = pattern.matcher(fKey); -if (matcher.matches()) { -Feature f = getFeatureMatching(fKey, feature.getVersionRange()); -if (f != null) { -toAdd.add(new FeatureReq(f)); -for (Feature installedFeature : installedFeatures) { -if (installedFeature.getName().equals(f.getName()) && installedFeature.getVersion().equals(f.getVersion())) { -LOGGER.info("The specified feature: '{}' version '{}' {}",f.getName(),f.getVersion(),f.getVersion().endsWith("SNAPSHOT") ? "has been upgraded": "is already installed"); -} -} -matched = true; +for (FeatureReq featureReq : toInstall) { +Collection matching = getFeatures(featureReq); +for (Feature f: matching) { +toAdd.add(new FeatureReq(f)); +for (Feature installedFeature : installedFeatures) { +if (isSameFeature(f, installedFeature)) { +logInstalledOrUpdated(f); } } } -if (!matched && !options.contains(Option.NoFailOnFeatureNotFound)) { -throw new IllegalArgumentException("No matching features for " + feature); +if (matching.isEmpty() && !options.contains(Option.NoFailOnFeatureNotFound)) { +throw new IllegalArgumentException("No matching features for " + featureReq); } } return toAdd; } +private void logInstalledOrUpdated(Featu
[25/27] karaf git commit: [KARAF-5300] Reuse and extract feature matching code
[KARAF-5300] Reuse and extract feature matching code Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/6576f476 Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/6576f476 Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/6576f476 Branch: refs/heads/model_features Commit: 6576f476581367a83e7c42ac0e516bb710d3d7db Parents: 69fcb36 Author: Christian Schneider Authored: Thu Aug 10 15:30:59 2017 +0200 Committer: Christian Schneider Committed: Thu Aug 17 16:29:30 2017 +0200 -- .../internal/service/FeaturesServiceImpl.java | 79 +++- 1 file changed, 43 insertions(+), 36 deletions(-) -- http://git-wip-us.apache.org/repos/asf/karaf/blob/6576f476/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 2767bc8..574998a 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 @@ -520,15 +520,15 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall @Override public Feature[] getFeatures(String nameOrId) throws Exception { -return getFeatures(new FeatureReq(nameOrId)); +return toArray(getFeatures(new FeatureReq(nameOrId))); } @Override public Feature[] getFeatures(String name, String version) throws Exception { -return getFeatures(new FeatureReq(name, version)); +return toArray(getFeatures(new FeatureReq(name, version))); } -private Feature[] getFeatures(FeatureReq featureReq) throws Exception { +private Collection getFeatures(FeatureReq featureReq) throws Exception { List features = new ArrayList<>(); Pattern pattern = Pattern.compile(featureReq.getName()); Map> allFeatures = getFeatureCache(); @@ -541,6 +541,10 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall } } } +return features; +} + +private Feature[] toArray(Collection features) { return features.toArray(new Feature[features.size()]); } @@ -819,33 +823,33 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall private Set computeFeaturesToAdd(EnumSet options, Set toInstall) throws Exception { Feature[] installedFeatures = listInstalledFeatures(); -Map> allFeatures = getFeatureCache(); Set toAdd = new HashSet<>(); -for (FeatureReq feature : toInstall) { -Pattern pattern = Pattern.compile(feature.getName()); -boolean matched = false; -for (String fKey : allFeatures.keySet()) { -Matcher matcher = pattern.matcher(fKey); -if (matcher.matches()) { -Feature f = getFeatureMatching(fKey, feature.getVersionRange()); -if (f != null) { -toAdd.add(new FeatureReq(f)); -for (Feature installedFeature : installedFeatures) { -if (installedFeature.getName().equals(f.getName()) && installedFeature.getVersion().equals(f.getVersion())) { -LOGGER.info("The specified feature: '{}' version '{}' {}",f.getName(),f.getVersion(),f.getVersion().endsWith("SNAPSHOT") ? "has been upgraded": "is already installed"); -} -} -matched = true; +for (FeatureReq featureReq : toInstall) { +Collection matching = getFeatures(featureReq); +for (Feature f: matching) { +toAdd.add(new FeatureReq(f)); +for (Feature installedFeature : installedFeatures) { +if (isSameFeature(f, installedFeature)) { +logInstalledOrUpdated(f); } } } -if (!matched && !options.contains(Option.NoFailOnFeatureNotFound)) { -throw new IllegalArgumentException("No matching features for " + feature); +if (matching.isEmpty() && !options.contains(Option.NoFailOnFeatureNotFound)) { +throw new IllegalArgumentException("No matching features for " + featureReq); } } return toAdd; } +private void logInstalledOrUpdated(Featu
[6/7] karaf git commit: [KARAF-5300] Reuse and extract feature matching code
[KARAF-5300] Reuse and extract feature matching code Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/a59edf05 Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/a59edf05 Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/a59edf05 Branch: refs/heads/model_features Commit: a59edf0569426b5745859532bf3cf25c0ccf36b7 Parents: 267f5b0 Author: Christian Schneider Authored: Thu Aug 10 15:30:59 2017 +0200 Committer: Christian Schneider Committed: Mon Aug 14 10:43:50 2017 +0200 -- .../internal/service/FeaturesServiceImpl.java | 79 +++- 1 file changed, 43 insertions(+), 36 deletions(-) -- http://git-wip-us.apache.org/repos/asf/karaf/blob/a59edf05/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 2518a09..7b61ea8 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 @@ -519,15 +519,15 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall @Override public Feature[] getFeatures(String nameOrId) throws Exception { -return getFeatures(new FeatureReq(nameOrId)); +return toArray(getFeatures(new FeatureReq(nameOrId))); } @Override public Feature[] getFeatures(String name, String version) throws Exception { -return getFeatures(new FeatureReq(name, version)); +return toArray(getFeatures(new FeatureReq(name, version))); } -private Feature[] getFeatures(FeatureReq featureReq) throws Exception { +private Collection getFeatures(FeatureReq featureReq) throws Exception { List features = new ArrayList<>(); Pattern pattern = Pattern.compile(featureReq.getName()); Map> allFeatures = getFeatureCache(); @@ -540,6 +540,10 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall } } } +return features; +} + +private Feature[] toArray(Collection features) { return features.toArray(new Feature[features.size()]); } @@ -818,33 +822,33 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall private Set computeFeaturesToAdd(EnumSet options, Set toInstall) throws Exception { Feature[] installedFeatures = listInstalledFeatures(); -Map> allFeatures = getFeatureCache(); Set toAdd = new HashSet<>(); -for (FeatureReq feature : toInstall) { -Pattern pattern = Pattern.compile(feature.getName()); -boolean matched = false; -for (String fKey : allFeatures.keySet()) { -Matcher matcher = pattern.matcher(fKey); -if (matcher.matches()) { -Feature f = getFeatureMatching(fKey, feature.getVersionRange()); -if (f != null) { -toAdd.add(new FeatureReq(f)); -for (Feature installedFeature : installedFeatures) { -if (installedFeature.getName().equals(f.getName()) && installedFeature.getVersion().equals(f.getVersion())) { -LOGGER.info("The specified feature: '{}' version '{}' {}",f.getName(),f.getVersion(),f.getVersion().endsWith("SNAPSHOT") ? "has been upgraded": "is already installed"); -} -} -matched = true; +for (FeatureReq featureReq : toInstall) { +Collection matching = getFeatures(featureReq); +for (Feature f: matching) { +toAdd.add(new FeatureReq(f)); +for (Feature installedFeature : installedFeatures) { +if (isSameFeature(f, installedFeature)) { +logInstalledOrUpdated(f); } } } -if (!matched && !options.contains(Option.NoFailOnFeatureNotFound)) { -throw new IllegalArgumentException("No matching features for " + feature); +if (matching.isEmpty() && !options.contains(Option.NoFailOnFeatureNotFound)) { +throw new IllegalArgumentException("No matching features for " + featureReq); } } return toAdd; } +private void logInstalledOrUpdated(Featu
[1/5] karaf git commit: [KARAF-5300] Reuse and extract feature matching code
Repository: karaf Updated Branches: refs/heads/master 0400c2d7a -> 2b6ca1865 [KARAF-5300] Reuse and extract feature matching code Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/2b6ca186 Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/2b6ca186 Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/2b6ca186 Branch: refs/heads/master Commit: 2b6ca186567337cce0ae1e0984076e8492fcf3e7 Parents: d9ab1ab Author: Christian Schneider Authored: Thu Aug 10 15:30:59 2017 +0200 Committer: Christian Schneider Committed: Mon Aug 14 09:53:39 2017 +0200 -- .../internal/service/FeaturesServiceImpl.java | 79 +++- 1 file changed, 43 insertions(+), 36 deletions(-) -- http://git-wip-us.apache.org/repos/asf/karaf/blob/2b6ca186/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 2518a09..7b61ea8 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 @@ -519,15 +519,15 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall @Override public Feature[] getFeatures(String nameOrId) throws Exception { -return getFeatures(new FeatureReq(nameOrId)); +return toArray(getFeatures(new FeatureReq(nameOrId))); } @Override public Feature[] getFeatures(String name, String version) throws Exception { -return getFeatures(new FeatureReq(name, version)); +return toArray(getFeatures(new FeatureReq(name, version))); } -private Feature[] getFeatures(FeatureReq featureReq) throws Exception { +private Collection getFeatures(FeatureReq featureReq) throws Exception { List features = new ArrayList<>(); Pattern pattern = Pattern.compile(featureReq.getName()); Map> allFeatures = getFeatureCache(); @@ -540,6 +540,10 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall } } } +return features; +} + +private Feature[] toArray(Collection features) { return features.toArray(new Feature[features.size()]); } @@ -818,33 +822,33 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall private Set computeFeaturesToAdd(EnumSet options, Set toInstall) throws Exception { Feature[] installedFeatures = listInstalledFeatures(); -Map> allFeatures = getFeatureCache(); Set toAdd = new HashSet<>(); -for (FeatureReq feature : toInstall) { -Pattern pattern = Pattern.compile(feature.getName()); -boolean matched = false; -for (String fKey : allFeatures.keySet()) { -Matcher matcher = pattern.matcher(fKey); -if (matcher.matches()) { -Feature f = getFeatureMatching(fKey, feature.getVersionRange()); -if (f != null) { -toAdd.add(new FeatureReq(f)); -for (Feature installedFeature : installedFeatures) { -if (installedFeature.getName().equals(f.getName()) && installedFeature.getVersion().equals(f.getVersion())) { -LOGGER.info("The specified feature: '{}' version '{}' {}",f.getName(),f.getVersion(),f.getVersion().endsWith("SNAPSHOT") ? "has been upgraded": "is already installed"); -} -} -matched = true; +for (FeatureReq featureReq : toInstall) { +Collection matching = getFeatures(featureReq); +for (Feature f: matching) { +toAdd.add(new FeatureReq(f)); +for (Feature installedFeature : installedFeatures) { +if (isSameFeature(f, installedFeature)) { +logInstalledOrUpdated(f); } } } -if (!matched && !options.contains(Option.NoFailOnFeatureNotFound)) { -throw new IllegalArgumentException("No matching features for " + feature); +if (matching.isEmpty() && !options.contains(Option.NoFailOnFeatureNotFound)) { +throw new IllegalArgumentException("No matching features for " + featureReq); } }
[11/14] karaf git commit: [KARAF-5300] Reuse and extract feature matching code
[KARAF-5300] Reuse and extract feature matching code Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/bdffc0c7 Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/bdffc0c7 Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/bdffc0c7 Branch: refs/heads/model_features Commit: bdffc0c7413e40d4fc1461b27a9f792bfcaadb8c Parents: 89b2a44 Author: Christian Schneider Authored: Thu Aug 10 15:30:59 2017 +0200 Committer: Christian Schneider Committed: Sat Aug 12 09:12:13 2017 +0200 -- .../internal/service/FeaturesServiceImpl.java | 79 +++- 1 file changed, 43 insertions(+), 36 deletions(-) -- http://git-wip-us.apache.org/repos/asf/karaf/blob/bdffc0c7/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 2518a09..7b61ea8 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 @@ -519,15 +519,15 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall @Override public Feature[] getFeatures(String nameOrId) throws Exception { -return getFeatures(new FeatureReq(nameOrId)); +return toArray(getFeatures(new FeatureReq(nameOrId))); } @Override public Feature[] getFeatures(String name, String version) throws Exception { -return getFeatures(new FeatureReq(name, version)); +return toArray(getFeatures(new FeatureReq(name, version))); } -private Feature[] getFeatures(FeatureReq featureReq) throws Exception { +private Collection getFeatures(FeatureReq featureReq) throws Exception { List features = new ArrayList<>(); Pattern pattern = Pattern.compile(featureReq.getName()); Map> allFeatures = getFeatureCache(); @@ -540,6 +540,10 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall } } } +return features; +} + +private Feature[] toArray(Collection features) { return features.toArray(new Feature[features.size()]); } @@ -818,33 +822,33 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall private Set computeFeaturesToAdd(EnumSet options, Set toInstall) throws Exception { Feature[] installedFeatures = listInstalledFeatures(); -Map> allFeatures = getFeatureCache(); Set toAdd = new HashSet<>(); -for (FeatureReq feature : toInstall) { -Pattern pattern = Pattern.compile(feature.getName()); -boolean matched = false; -for (String fKey : allFeatures.keySet()) { -Matcher matcher = pattern.matcher(fKey); -if (matcher.matches()) { -Feature f = getFeatureMatching(fKey, feature.getVersionRange()); -if (f != null) { -toAdd.add(new FeatureReq(f)); -for (Feature installedFeature : installedFeatures) { -if (installedFeature.getName().equals(f.getName()) && installedFeature.getVersion().equals(f.getVersion())) { -LOGGER.info("The specified feature: '{}' version '{}' {}",f.getName(),f.getVersion(),f.getVersion().endsWith("SNAPSHOT") ? "has been upgraded": "is already installed"); -} -} -matched = true; +for (FeatureReq featureReq : toInstall) { +Collection matching = getFeatures(featureReq); +for (Feature f: matching) { +toAdd.add(new FeatureReq(f)); +for (Feature installedFeature : installedFeatures) { +if (isSameFeature(f, installedFeature)) { +logInstalledOrUpdated(f); } } } -if (!matched && !options.contains(Option.NoFailOnFeatureNotFound)) { -throw new IllegalArgumentException("No matching features for " + feature); +if (matching.isEmpty() && !options.contains(Option.NoFailOnFeatureNotFound)) { +throw new IllegalArgumentException("No matching features for " + featureReq); } } return toAdd; } +private void logInstalledOrUpdated(Featu
[07/10] karaf git commit: [KARAF-5300] Reuse and extract feature matching code
[KARAF-5300] Reuse and extract feature matching code Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/cd938d50 Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/cd938d50 Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/cd938d50 Branch: refs/heads/model_features Commit: cd938d5017fecfc9a603b1367b12fee11c81bd29 Parents: 5c88795 Author: Christian Schneider Authored: Thu Aug 10 15:30:59 2017 +0200 Committer: Christian Schneider Committed: Thu Aug 10 15:54:06 2017 +0200 -- .../internal/service/FeaturesServiceImpl.java | 79 +++- 1 file changed, 43 insertions(+), 36 deletions(-) -- http://git-wip-us.apache.org/repos/asf/karaf/blob/cd938d50/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 2518a09..7b61ea8 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 @@ -519,15 +519,15 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall @Override public Feature[] getFeatures(String nameOrId) throws Exception { -return getFeatures(new FeatureReq(nameOrId)); +return toArray(getFeatures(new FeatureReq(nameOrId))); } @Override public Feature[] getFeatures(String name, String version) throws Exception { -return getFeatures(new FeatureReq(name, version)); +return toArray(getFeatures(new FeatureReq(name, version))); } -private Feature[] getFeatures(FeatureReq featureReq) throws Exception { +private Collection getFeatures(FeatureReq featureReq) throws Exception { List features = new ArrayList<>(); Pattern pattern = Pattern.compile(featureReq.getName()); Map> allFeatures = getFeatureCache(); @@ -540,6 +540,10 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall } } } +return features; +} + +private Feature[] toArray(Collection features) { return features.toArray(new Feature[features.size()]); } @@ -818,33 +822,33 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall private Set computeFeaturesToAdd(EnumSet options, Set toInstall) throws Exception { Feature[] installedFeatures = listInstalledFeatures(); -Map> allFeatures = getFeatureCache(); Set toAdd = new HashSet<>(); -for (FeatureReq feature : toInstall) { -Pattern pattern = Pattern.compile(feature.getName()); -boolean matched = false; -for (String fKey : allFeatures.keySet()) { -Matcher matcher = pattern.matcher(fKey); -if (matcher.matches()) { -Feature f = getFeatureMatching(fKey, feature.getVersionRange()); -if (f != null) { -toAdd.add(new FeatureReq(f)); -for (Feature installedFeature : installedFeatures) { -if (installedFeature.getName().equals(f.getName()) && installedFeature.getVersion().equals(f.getVersion())) { -LOGGER.info("The specified feature: '{}' version '{}' {}",f.getName(),f.getVersion(),f.getVersion().endsWith("SNAPSHOT") ? "has been upgraded": "is already installed"); -} -} -matched = true; +for (FeatureReq featureReq : toInstall) { +Collection matching = getFeatures(featureReq); +for (Feature f: matching) { +toAdd.add(new FeatureReq(f)); +for (Feature installedFeature : installedFeatures) { +if (isSameFeature(f, installedFeature)) { +logInstalledOrUpdated(f); } } } -if (!matched && !options.contains(Option.NoFailOnFeatureNotFound)) { -throw new IllegalArgumentException("No matching features for " + feature); +if (matching.isEmpty() && !options.contains(Option.NoFailOnFeatureNotFound)) { +throw new IllegalArgumentException("No matching features for " + featureReq); } } return toAdd; } +private void logInstalledOrUpdated(Featu
karaf git commit: [KARAF-5300] Reuse and extract feature matching code
Repository: karaf Updated Branches: refs/heads/model_features e23d7bd69 -> 8fbce8a34 [KARAF-5300] Reuse and extract feature matching code Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/8fbce8a3 Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/8fbce8a3 Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/8fbce8a3 Branch: refs/heads/model_features Commit: 8fbce8a347f22ce1c6f9a447df418230b0cf2023 Parents: e23d7bd Author: Christian Schneider Authored: Thu Aug 10 15:30:59 2017 +0200 Committer: Christian Schneider Committed: Thu Aug 10 15:30:59 2017 +0200 -- .../internal/service/FeaturesServiceImpl.java | 79 +++- 1 file changed, 43 insertions(+), 36 deletions(-) -- http://git-wip-us.apache.org/repos/asf/karaf/blob/8fbce8a3/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 2518a09..7b61ea8 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 @@ -519,15 +519,15 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall @Override public Feature[] getFeatures(String nameOrId) throws Exception { -return getFeatures(new FeatureReq(nameOrId)); +return toArray(getFeatures(new FeatureReq(nameOrId))); } @Override public Feature[] getFeatures(String name, String version) throws Exception { -return getFeatures(new FeatureReq(name, version)); +return toArray(getFeatures(new FeatureReq(name, version))); } -private Feature[] getFeatures(FeatureReq featureReq) throws Exception { +private Collection getFeatures(FeatureReq featureReq) throws Exception { List features = new ArrayList<>(); Pattern pattern = Pattern.compile(featureReq.getName()); Map> allFeatures = getFeatureCache(); @@ -540,6 +540,10 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall } } } +return features; +} + +private Feature[] toArray(Collection features) { return features.toArray(new Feature[features.size()]); } @@ -818,33 +822,33 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall private Set computeFeaturesToAdd(EnumSet options, Set toInstall) throws Exception { Feature[] installedFeatures = listInstalledFeatures(); -Map> allFeatures = getFeatureCache(); Set toAdd = new HashSet<>(); -for (FeatureReq feature : toInstall) { -Pattern pattern = Pattern.compile(feature.getName()); -boolean matched = false; -for (String fKey : allFeatures.keySet()) { -Matcher matcher = pattern.matcher(fKey); -if (matcher.matches()) { -Feature f = getFeatureMatching(fKey, feature.getVersionRange()); -if (f != null) { -toAdd.add(new FeatureReq(f)); -for (Feature installedFeature : installedFeatures) { -if (installedFeature.getName().equals(f.getName()) && installedFeature.getVersion().equals(f.getVersion())) { -LOGGER.info("The specified feature: '{}' version '{}' {}",f.getName(),f.getVersion(),f.getVersion().endsWith("SNAPSHOT") ? "has been upgraded": "is already installed"); -} -} -matched = true; +for (FeatureReq featureReq : toInstall) { +Collection matching = getFeatures(featureReq); +for (Feature f: matching) { +toAdd.add(new FeatureReq(f)); +for (Feature installedFeature : installedFeatures) { +if (isSameFeature(f, installedFeature)) { +logInstalledOrUpdated(f); } } } -if (!matched && !options.contains(Option.NoFailOnFeatureNotFound)) { -throw new IllegalArgumentException("No matching features for " + feature); +if (matching.isEmpty() && !options.contains(Option.NoFailOnFeatureNotFound)) { +throw new IllegalArgumentException("No matching features for " + featureReq); }