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/06 12:25:24 UTC

[karaf] branch KARAF-5376-overrides_v2 updated: [KARAF-5273] Allow to use feature identifiers in karaf-maven-plugin:assembly config, profiles and profile builder

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


The following commit(s) were added to refs/heads/KARAF-5376-overrides_v2 by this push:
     new 494820f  [KARAF-5273] Allow to use feature identifiers in karaf-maven-plugin:assembly config, profiles and profile builder
494820f is described below

commit 494820f9a76e3cfc7a0de7bcb7c0a308642168a6
Author: Grzegorz Grzybek <gr...@gmail.com>
AuthorDate: Wed Dec 6 13:25:15 2017 +0100

    [KARAF-5273] Allow to use feature identifiers in karaf-maven-plugin:assembly config, profiles and profile builder
---
 .../org/apache/karaf/profile/assembly/Builder.java | 24 +++++----
 .../karaf/profile/assembly/FeatureSelector.java    | 58 +++++++++++++++++++---
 2 files changed, 67 insertions(+), 15 deletions(-)

diff --git a/profile/src/main/java/org/apache/karaf/profile/assembly/Builder.java b/profile/src/main/java/org/apache/karaf/profile/assembly/Builder.java
index 413eaec..bc19b61 100644
--- a/profile/src/main/java/org/apache/karaf/profile/assembly/Builder.java
+++ b/profile/src/main/java/org/apache/karaf/profile/assembly/Builder.java
@@ -1426,14 +1426,17 @@ public class Builder {
         Feature generated = new Feature();
         generated.setName(UUID.randomUUID().toString());
         // Add feature dependencies
-        for (String dependency : bootEffective.getFeatures()) {
-            Dependency dep = generatedDep.get(dependency);
-            if (dep == null) {
-                dep = createDependency(dependency);
-                generated.getFeature().add(dep);
-                generatedDep.put(dep.getName(), dep);
+        for (String nameOrPattern : bootEffective.getFeatures()) {
+            // KARAF-5273: feature may be a pattern
+            for (String dependency : FeatureSelector.getMatchingFeatures(nameOrPattern, bootRepositories.values())) {
+                Dependency dep = generatedDep.get(dependency);
+                if (dep == null) {
+                    dep = createDependency(dependency);
+                    generated.getFeature().add(dep);
+                    generatedDep.put(dep.getName(), dep);
+                }
+                dep.setDependency(false);
             }
-            dep.setDependency(false);
         }
         // Add bundles
         for (String location : bootEffective.getBundles()) {
@@ -1819,9 +1822,12 @@ public class Builder {
         // Add optional resources available through OSGi resource repository
         request.globalRepository = repositoryOfOptionalResources(manager, optionals);
 
-        // Specify feature requirements (already prefixed with "feature:")
+        // Specify feature requirements
         for (String feature : features) {
-            MapUtils.addToMapSet(request.requirements, FeaturesService.ROOT_REGION, feature);
+            // KARAF-5273: feature may be a pattern
+            for (String featureName : FeatureSelector.getMatchingFeatures(feature, repositories)) {
+                MapUtils.addToMapSet(request.requirements, FeaturesService.ROOT_REGION, featureName);
+            }
         }
         // Specify bundle requirements
         for (String bundle : bundles) {
diff --git a/profile/src/main/java/org/apache/karaf/profile/assembly/FeatureSelector.java b/profile/src/main/java/org/apache/karaf/profile/assembly/FeatureSelector.java
index 2735592..9ab8b4f 100644
--- a/profile/src/main/java/org/apache/karaf/profile/assembly/FeatureSelector.java
+++ b/profile/src/main/java/org/apache/karaf/profile/assembly/FeatureSelector.java
@@ -16,45 +16,91 @@
  */
 package org.apache.karaf.profile.assembly;
 
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.stream.Collectors;
 
 import org.apache.felix.utils.version.VersionTable;
+import org.apache.karaf.features.FeaturePattern;
 import org.apache.karaf.features.internal.model.Dependency;
 import org.apache.karaf.features.internal.model.Feature;
+import org.apache.karaf.features.internal.model.Features;
 import org.apache.karaf.features.internal.service.FeatureReq;
 
 public class FeatureSelector {
+
+    private final Set<Feature> allFeatures;
     Map<String, Set<Feature>> featuresCache;
 
     public FeatureSelector(Set<Feature> features) {
+        allFeatures = features;
         featuresCache = new HashMap<>();
         for (Feature feature : features) {
             featuresCache.computeIfAbsent(feature.getName(), fn -> new HashSet<>())
                 .add(feature);
         }
     }
-    
+
+    /**
+     * Assuming <code>idOrPattern</code> may be a pattern (with glob and version range), get all matching features
+     * @param idOrPattern
+     * @param repositories
+     * @return
+     */
+    public static Collection<String> getMatchingFeatures(String idOrPattern, Collection<Features> repositories) {
+        List<String> result = new LinkedList<>();
+        FeaturePattern pattern = new FeaturePattern(idOrPattern);
+        for (Features features : repositories) {
+            for (Feature feature : features.getFeature()) {
+                // blacklisting will be applied anyway, so no need to do it here
+                if (/*!feature.isBlacklisted() && */pattern.matches(feature.getName(), feature.getVersion())) {
+                    result.add(feature.getId());
+                }
+            }
+        }
+        return result;
+    }
+
+    /**
+     * Get all matching features
+     * @param idOrPattern
+     * @param features
+     * @return
+     */
+    public static Collection<String> getMatchingFeatures(FeaturePattern idOrPattern, Collection<Feature> features) {
+        List<String> result = new LinkedList<>();
+        for (Feature feature : features) {
+            // blacklisting will be applied anyway, so no need to do it here
+            if (/*!feature.isBlacklisted() && */idOrPattern.matches(feature.getName(), feature.getVersion())) {
+                result.add(feature.getId());
+            }
+        }
+        return result;
+    }
+
     /**
      * Features matching the given feature selectors including dependent features
-     * 
+     *
      * @param features feature selector name, name/version, name/version-range
-     * 
-     * @return matching features 
+     *
+     * @return matching features
      */
     public Set<Feature> getMatching(List<String> features) {
         Set<Feature> selected = new HashSet<>();
         for (String feature : features) {
-            addFeatures(feature, selected, true);
+            for (String featureId : getMatchingFeatures(new FeaturePattern(feature), allFeatures)) {
+                addFeatures(featureId, selected, true);
+            }
         }
         return selected;
     }
-    
+
     private void addFeatures(String feature, Set<Feature> features, boolean mandatory) {
         Set<Feature> set = getMatching(feature);
         if (mandatory && set.isEmpty()) {

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