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:41:29 UTC
[karaf] branch master 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 master
in repository https://gitbox.apache.org/repos/asf/karaf.git
The following commit(s) were added to refs/heads/master by this push:
new 802de5d [KARAF-6951] Fix regex support in AddFeaturesToRepo goal
new bb175f9 Merge pull request #1266 from jbonofre/KARAF-6951
802de5d is described below
commit 802de5df1f73f1765f38acb9a53bcffae2b08a64
Author: Jean-Baptiste Onofré <jb...@apache.org>
AuthorDate: Mon Dec 14 18:39:48 2020 +0100
[KARAF-6951] Fix regex support in AddFeaturesToRepo goal
---
.../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 0fa4ae7..1db2d1a 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
@@ -185,34 +185,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) {
@@ -226,7 +232,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));
}
}
}
@@ -238,15 +244,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());
}