You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2020/12/15 17:42:07 UTC

[karaf] branch karaf-4.2.x updated: [KARAF-6951] Fix regex support in AddFeaturesToRepo goal

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

jbonofre pushed a commit to branch karaf-4.2.x
in repository https://gitbox.apache.org/repos/asf/karaf.git


The following commit(s) were added to refs/heads/karaf-4.2.x by this push:
     new dacb873  [KARAF-6951] Fix regex support in AddFeaturesToRepo goal
dacb873 is described below

commit dacb8738f07872b33f366cec811123c7d8ff289f
Author: Jean-Baptiste Onofré <jb...@apache.org>
AuthorDate: Mon Dec 14 18:39:48 2020 +0100

    [KARAF-6951] Fix regex support in AddFeaturesToRepo goal
    
    (cherry picked from commit 802de5df1f73f1765f38acb9a53bcffae2b08a64)
---
 .../tooling/features/AbstractFeatureMojo.java      | 35 ++++++++++++----------
 .../tooling/features/AddToRepositoryMojoTest.java  | 10 ++++++-
 2 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/AbstractFeatureMojo.java b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/AbstractFeatureMojo.java
index f933fb0..f13a08c 100644
--- a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/AbstractFeatureMojo.java
+++ b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/AbstractFeatureMojo.java
@@ -177,34 +177,40 @@ public abstract class AbstractFeatureMojo extends MojoSupport {
     protected void addFeatures(List<String> featureNames, Set<Feature> features, Map<String, Feature> featuresMap, boolean transitive) {
         for (String feature : featureNames) {
             String[] split = feature.split("/");
-            Feature f = getMatchingFeature(featuresMap, split[0], split.length > 1 ? split[1] : null);
-            features.add(f);
-            if (transitive) {
-                addFeaturesDependencies(f.getFeature(), features, featuresMap, true);
+            List<Feature> innerFeatures = getMatchingFeature(featuresMap, split[0], split.length > 1 ? split[1] : null);
+            for (Feature f : innerFeatures) {
+                features.add(f);
+                if (transitive) {
+                    addFeaturesDependencies(f.getFeature(), features, featuresMap, true);
+                }
             }
         }
     }
 
     protected void addFeaturesDependencies(List<Dependency> featureNames, Set<Feature> features, Map<String, Feature> featuresMap, boolean transitive) {
         for (Dependency dependency : featureNames) {
-            Feature f = getMatchingFeature(featuresMap, dependency.getName(), dependency.getVersion());
-            features.add(f);
-            if (transitive) {
-                addFeaturesDependencies(f.getFeature(), features, featuresMap, true);
+            List<Feature> innerFeatures = getMatchingFeature(featuresMap, dependency.getName(), dependency.getVersion());
+            for (Feature f : innerFeatures) {
+                features.add(f);
+                if (transitive) {
+                    addFeaturesDependencies(f.getFeature(), features, featuresMap, true);
+                }
             }
         }
     }
 
-    private Feature getMatchingFeature(Map<String, Feature> featuresMap, String feature, String version) {
-        Feature f = null;
+    private List<Feature> getMatchingFeature(Map<String, Feature> featuresMap, String feature, String version) {
+        List<Feature> features = new ArrayList<>();
         Pattern namePattern = Pattern.compile(feature);
         if (version != null && !version.equals(Feature.DEFAULT_VERSION)) {
             // looking for a specific feature with name and version
+            Feature f = null;
             for (String key : featuresMap.keySet()) {
                 String[] nameAndVersion = key.split("/");
                 Matcher matcher = namePattern.matcher(nameAndVersion[0]);
                 if (matcher.matches() && version.equals(nameAndVersion[1])) {
                     f = featuresMap.get(key);
+                    features.add(f);
                 }
             }
             if (f == null) {
@@ -218,7 +224,7 @@ public abstract class AbstractFeatureMojo extends MojoSupport {
                         Version ver = VersionTable.getVersion(verStr);
                         if (versionRange.contains(ver)) {
                             if (f == null || VersionTable.getVersion(f.getVersion()).compareTo(VersionTable.getVersion(featuresMap.get(key).getVersion())) < 0) {    
-                                f = featuresMap.get(key);
+                                features.add(featuresMap.get(key));
                             }
                         }
                     }
@@ -230,15 +236,14 @@ public abstract class AbstractFeatureMojo extends MojoSupport {
                 String[] nameVersion = key.split("/");
                 Matcher matcher = namePattern.matcher(nameVersion[0]);
                 if (matcher.matches()) {
-                    f = featuresMap.get(key);
-                    break;
+                    features.add(featuresMap.get(key));
                 }
             }
         }
-        if (f == null) {
+        if (features.size() == 0) {
             throw new IllegalArgumentException("Unable to find the feature '" + feature + "'");
         }
-        return f;
+        return features;
     }
 
     protected Set<Feature> resolveFeatures() throws MojoExecutionException {
diff --git a/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/AddToRepositoryMojoTest.java b/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/AddToRepositoryMojoTest.java
index de84ce1..d198ab4 100644
--- a/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/AddToRepositoryMojoTest.java
+++ b/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/AddToRepositoryMojoTest.java
@@ -96,6 +96,11 @@ public class AddToRepositoryMojoTest {
         Map<String, Feature> featuresMap = new HashMap<>();
         featuresMap.put("test/1.0.0", testFeature);
 
+        Feature tempFeature = new Feature();
+        tempFeature.setName("temp");
+        tempFeature.setVersion("1.1.0");
+        featuresMap.put("temp/1.1.0", tempFeature);
+
         Feature otherFeature = new Feature();
         otherFeature.setName("other");
         otherFeature.setVersion("2.0.0");
@@ -103,9 +108,12 @@ public class AddToRepositoryMojoTest {
 
         mojo.addFeatures(featuresNames, features, featuresMap, false);
 
-        Assert.assertEquals(1, features.size());
+        Assert.assertEquals(2, features.size());
         Iterator<Feature> iterator = features.iterator();
         Feature check = iterator.next();
+        Assert.assertEquals("temp", check.getName());
+        Assert.assertEquals("1.1.0", check.getVersion());
+        check = iterator.next();
         Assert.assertEquals("test", check.getName());
         Assert.assertEquals("1.0.0", check.getVersion());
     }