karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggrzy...@apache.org
Subject [karaf] 17/17: [KARAF-5376] Do not install blacklisted features and add blacklisted repositories
Date Wed, 06 Dec 2017 19:04:05 GMT
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 4804c96db8db1684cdba315ecbfde2d2b60f2941
Author: Grzegorz Grzybek <gr.grzybek@gmail.com>
AuthorDate: Wed Dec 6 20:03:24 2017 +0100

    [KARAF-5376] Do not install blacklisted features and add blacklisted repositories
---
 .../karaf/features/command/RepoAddCommand.java     |  4 ++++
 .../completers/AvailableFeatureCompleter.java      |  2 +-
 .../org/apache/karaf/features/FeaturesService.java |  2 ++
 .../features/internal/service/FeatureReq.java      | 16 +++++++++++---
 .../internal/service/FeaturesServiceImpl.java      | 25 ++++++++++++++++++----
 5 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/features/command/src/main/java/org/apache/karaf/features/command/RepoAddCommand.java
b/features/command/src/main/java/org/apache/karaf/features/command/RepoAddCommand.java
index 4771053..91ff430 100644
--- a/features/command/src/main/java/org/apache/karaf/features/command/RepoAddCommand.java
+++ b/features/command/src/main/java/org/apache/karaf/features/command/RepoAddCommand.java
@@ -46,6 +46,10 @@ public class RepoAddCommand extends FeaturesCommandSupport {
         if (uri == null) {
             uri = new URI(nameOrUrl);
         }
+        if (featuresService.isRepositoryUriBlacklisted(uri)) {
+            System.out.println("Feature URL " + uri + " is blacklisted");
+            return;
+        }
         System.out.println("Adding feature url " + uri);
         featuresService.addRepository(uri, install);
     }
diff --git a/features/command/src/main/java/org/apache/karaf/features/command/completers/AvailableFeatureCompleter.java
b/features/command/src/main/java/org/apache/karaf/features/command/completers/AvailableFeatureCompleter.java
index e0dc87a..bee4b6d 100644
--- a/features/command/src/main/java/org/apache/karaf/features/command/completers/AvailableFeatureCompleter.java
+++ b/features/command/src/main/java/org/apache/karaf/features/command/completers/AvailableFeatureCompleter.java
@@ -27,7 +27,7 @@ public class AvailableFeatureCompleter extends FeatureCompleterSupport {
 
     @Override
     protected boolean acceptsFeature(Feature feature) {
-        return !featuresService.isInstalled(feature) && !feature.isHidden();
+        return !featuresService.isInstalled(feature) && !feature.isHidden() &&
!feature.isBlacklisted();
     }
 
 }
diff --git a/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java b/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java
index e9cc072..9ff9cdb 100644
--- a/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java
+++ b/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java
@@ -120,6 +120,8 @@ public interface FeaturesService {
      */
     void validateRepository(URI uri) throws Exception;
 
+    boolean isRepositoryUriBlacklisted(URI uri);
+
     void addRepository(URI uri) throws Exception;
 
     void addRepository(URI uri, boolean install) throws Exception;
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureReq.java
b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureReq.java
index 1a34f8b..696d2b7 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureReq.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureReq.java
@@ -52,6 +52,7 @@ public class FeatureReq {
 
     private String name;
     private VersionRange versionRange;
+    private boolean blacklisted = false;
 
     public static FeatureReq parseRequirement(String featureReq) {
         if (!featureReq.startsWith(FEATURE_OSGI_REQUIREMENT_PREFIX)) {
@@ -76,13 +77,14 @@ public class FeatureReq {
         this.versionRange = range(versionRange);
     }
     
-    public FeatureReq(String name, VersionRange versionRange) {
+    public FeatureReq(String name, VersionRange versionRange, boolean blacklisted) {
         this.name = name;
         this.versionRange = versionRange;
+        this.blacklisted = blacklisted;
     }
     
     public FeatureReq(Feature feature) {
-        this(feature.getName(), exactVersion(feature.getVersion()));
+        this(feature.getName(), exactVersion(feature.getVersion()), feature.isBlacklisted());
     }
     
     public String getName() {
@@ -119,7 +121,11 @@ public class FeatureReq {
             for (String available : versions.keySet()) {
                 Version availableVersion = VersionTable.getVersion(available);
                 if (availableVersion.compareTo(latest) >= 0 && versionRange.contains(availableVersion))
{
-                    feature = versions.get(available);
+                    Feature possiblyBlacklisted = versions.get(available);
+                    // return only if there are no more non-blaclisted features
+                    if (feature == null || !possiblyBlacklisted.isBlacklisted()) {
+                        feature = possiblyBlacklisted;
+                    }
                     latest = availableVersion;
                 }
             }
@@ -136,6 +142,10 @@ public class FeatureReq {
         return FEATURE_OSGI_REQUIREMENT_PREFIX + toString();
     }
 
+    public boolean isBlacklisted() {
+        return blacklisted;
+    }
+
     @Override
     public boolean equals(Object o) {
         if (this == o) return true;
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..4f92c57 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 final BundleInstallSupport installSupport;
     private final FeaturesServiceConfig cfg;
     private final RepositoryCache repositories;
+    private final FeaturesProcessor featuresProcessor;
 
     private final ThreadLocal<String> outputFile = new ThreadLocal<>();
 
@@ -150,7 +151,8 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
         this.resolver = resolver;
         this.installSupport = installSupport;
         this.globalRepository = globalRepository;
-        this.repositories = new RepositoryCacheImpl(new FeaturesProcessorImpl(cfg));
+        this.featuresProcessor = new FeaturesProcessorImpl(cfg);
+        this.repositories = new RepositoryCacheImpl(featuresProcessor);
         this.cfg = cfg;
         this.executor = Executors.newSingleThreadExecutor(ThreadUtils.namedThreadFactory("features"));
         loadState();
@@ -355,6 +357,11 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
     }
 
     @Override
+    public boolean isRepositoryUriBlacklisted(URI uri) {
+        return featuresProcessor.isRepositoryBlacklisted(uri.toString());
+    }
+
+    @Override
     public void addRepository(URI uri) throws Exception {
         addRepository(uri, false);
     }
@@ -776,9 +783,19 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
         Set<FeatureReq> existingFeatures = map(requirements, FeatureReq::parseRequirement);
 
         Set<FeatureReq> toAdd = computeFeaturesToAdd(options, toInstall);
-        toAdd.forEach(f -> requirements.add(f.toRequirement()));
-        print("Adding features: " + join(toAdd), options.contains(Option.Verbose));
-        
+        toAdd.forEach(f -> {
+            if (f.isBlacklisted()) {
+                print("Skipping blacklisted feature: " + f, options.contains(Option.Verbose));
+            } else {
+                requirements.add(f.toRequirement());
+            }
+        });
+        List<FeatureReq> notBlacklisted = toAdd.stream()
+                .filter(fr -> !fr.isBlacklisted()).collect(Collectors.toList());
+        if (notBlacklisted.size() > 0) {
+            print("Adding features: " + join(notBlacklisted), options.contains(Option.Verbose));
+        }
+
         if (options.contains(Option.Upgrade)) {
             Set<FeatureReq> toRemove = computeFeaturesToRemoveOnUpdate(toAdd, existingFeatures);
             toRemove.forEach(f -> requirements.remove(f.toRequirement()));

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

Mime
View raw message