You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2018/09/28 16:05:34 UTC
[sling-slingfeature-maven-plugin] branch master updated: SLING-7962
: Add mojo for downloading all artifacts and putting them into a build
directory. Fix includes/excludes
This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-slingfeature-maven-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 172ea92 SLING-7962 : Add mojo for downloading all artifacts and putting them into a build directory. Fix includes/excludes
172ea92 is described below
commit 172ea929acb267cc02dea777b6d72bea4a0390b7
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Fri Sep 28 18:05:24 2018 +0200
SLING-7962 : Add mojo for downloading all artifacts and putting them into a build directory. Fix includes/excludes
---
.../feature/maven/mojos/AbstractFeatureMojo.java | 12 +++--
.../feature/maven/mojos/AggregateFeatures.java | 10 ++--
.../feature/maven/mojos/AggregateFeaturesTest.java | 53 +++++++++++-----------
3 files changed, 42 insertions(+), 33 deletions(-)
diff --git a/src/main/java/org/apache/sling/feature/maven/mojos/AbstractFeatureMojo.java b/src/main/java/org/apache/sling/feature/maven/mojos/AbstractFeatureMojo.java
index 04ef151..302a9e5 100644
--- a/src/main/java/org/apache/sling/feature/maven/mojos/AbstractFeatureMojo.java
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/AbstractFeatureMojo.java
@@ -35,15 +35,19 @@ public abstract class AbstractFeatureMojo extends AbstractMojo {
* Directory containing feature files
* This parameter is evaluated in the {@link DependencyLifecycleParticipant}.
*/
- @Parameter(name = FeatureProjectConfig.CFG_FEATURES)
- private String features;
+ @Parameter(name = FeatureProjectConfig.CFG_FEATURES,
+ required = true,
+ defaultValue = FeatureProjectConfig.DEFAULT_FEATURE_DIR)
+ protected File features;
/**
* Directory containing test feature files
* This parameter is evaluated in the {@link DependencyLifecycleParticipant}.
*/
- @Parameter(name = FeatureProjectConfig.CFG_TEST_FEATURES)
- private String testFeatures;
+ @Parameter(name = FeatureProjectConfig.CFG_TEST_FEATURES,
+ required = true,
+ defaultValue = FeatureProjectConfig.DEFAULT_TEST_FEATURE_DIR)
+ private File testFeatures;
/**
* If set to {@code true} the artifacts from the feature are not as dependencies to the project.
diff --git a/src/main/java/org/apache/sling/feature/maven/mojos/AggregateFeatures.java b/src/main/java/org/apache/sling/feature/maven/mojos/AggregateFeatures.java
index 10f753d..9b5bc1e 100644
--- a/src/main/java/org/apache/sling/feature/maven/mojos/AggregateFeatures.java
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/AggregateFeatures.java
@@ -229,7 +229,8 @@ public class AggregateFeatures extends AbstractFeatureMojo {
private void readFeaturesFromDirectory(FeatureConfig fc,
Map<ArtifactId, Feature> featureMap,
Map<String, Feature> contextFeatures) throws IOException {
- final FeatureScanner scanner = new FeatureScanner(contextFeatures);
+ final String prefix = this.features.getAbsolutePath().concat(File.separator);
+ final FeatureScanner scanner = new FeatureScanner(contextFeatures, prefix);
if ( !fc.includes.isEmpty() ) {
scanner.setIncludes(fc.includes.toArray(new String[fc.includes.size()]));
}
@@ -317,8 +318,11 @@ public class AggregateFeatures extends AbstractFeatureMojo {
private final Map<ArtifactId, Feature> included = new LinkedHashMap<>();
- public FeatureScanner(final Map<String, Feature> features) {
+ private final String prefix;
+
+ public FeatureScanner(final Map<String, Feature> features, final String prefix) {
this.features = features;
+ this.prefix = prefix;
}
@@ -328,7 +332,7 @@ public class AggregateFeatures extends AbstractFeatureMojo {
setupMatchPatterns();
for ( Map.Entry<String, Feature> entry : features.entrySet() ) {
- final String name = entry.getKey();
+ final String name = entry.getKey().substring(prefix.length());
final String[] tokenizedName = tokenizePathToString( name, File.separator );
if ( isIncluded( name, tokenizedName ) ) {
if ( !isExcluded( name, tokenizedName ) ) {
diff --git a/src/test/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesTest.java b/src/test/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesTest.java
index 8e7503b..5206bef 100644
--- a/src/test/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesTest.java
+++ b/src/test/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesTest.java
@@ -16,6 +16,29 @@
*/
package org.apache.sling.feature.maven.mojos;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.Reader;
+import java.lang.reflect.Field;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Set;
+
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -39,29 +62,6 @@ import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
-import java.io.File;
-import java.io.FileReader;
-import java.io.Reader;
-import java.lang.reflect.Field;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Map;
-import java.util.Set;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
public class AggregateFeaturesTest {
private Path tempDir;
private static Map<String, ArtifactId> pluginCallbacks;
@@ -138,7 +138,7 @@ public class AggregateFeaturesTest {
Map<String, Feature> featureMap = new HashMap<>();
for (File f : featuresDir.listFiles((d,f) -> f.endsWith(".json"))) {
Feature feat = FeatureJSONReader.read(new FileReader(f), null);
- featureMap.put(f.getName(), feat);
+ featureMap.put(f.getAbsolutePath(), feat);
}
FeatureConfig fc = new FeatureConfig();
@@ -163,7 +163,7 @@ public class AggregateFeaturesTest {
af.project = mockProj;
af.projectHelper = new DefaultMavenProjectHelper();
setPrivateField(af.projectHelper, "artifactHandlerManager", Mockito.mock(ArtifactHandlerManager.class));
-
+ af.features = featuresDir;
af.execute();
File expectedFile = new File(tempDir.toFile(), "/aggregated.json");
@@ -211,7 +211,7 @@ public class AggregateFeaturesTest {
Map<String, Feature> featureMap = new HashMap<>();
for (File f : featuresDir.listFiles((d,f) -> f.endsWith(".json"))) {
Feature feat = FeatureJSONReader.read(new FileReader(f), null);
- featureMap.put(f.getName(), feat);
+ featureMap.put(f.getAbsolutePath(), feat);
}
FeatureConfig fc = new FeatureConfig();
@@ -240,6 +240,7 @@ public class AggregateFeaturesTest {
af.project = mockProj;
af.projectHelper = new DefaultMavenProjectHelper();
setPrivateField(af.projectHelper, "artifactHandlerManager", Mockito.mock(ArtifactHandlerManager.class));
+ af.features = featuresDir;
af.execute();