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 f90beda  SLING-7961 : Adjust feature file reading to latest state
f90beda is described below

commit f90beda14aa14a2a1840aa336d8051ead8da8317
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Fri Sep 28 19:22:28 2018 +0200

    SLING-7961 : Adjust feature file reading to latest state
---
 .../org/apache/sling/feature/maven/Preprocessor.java | 20 +++++++++++++++++---
 .../feature/maven/mojos/AbstractFeatureMojo.java     |  7 -------
 .../sling/feature/maven/mojos/AggregateFeatures.java | 17 +++++++++++++----
 3 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/maven/Preprocessor.java 
b/src/main/java/org/apache/sling/feature/maven/Preprocessor.java
index 9ae7a49..b446632 100644
--- a/src/main/java/org/apache/sling/feature/maven/Preprocessor.java
+++ b/src/main/java/org/apache/sling/feature/maven/Preprocessor.java
@@ -23,9 +23,11 @@ import java.io.Reader;
 import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.stream.Collectors;
 
 import org.apache.maven.model.Dependency;
@@ -43,9 +45,6 @@ import org.codehaus.plexus.logging.Logger;
 
 /**
  * The processor processes all feature projects.
- *
- * TODO - we should check that only one feature has no classifier
- *        and that the classifiers are unique within the read set
  */
 public class Preprocessor {
 
@@ -61,6 +60,21 @@ public class Preprocessor {
                 throw new RuntimeException("Feature project has no feature 
defined: " + finfo.project.getId());
             }
 
+            final Set<String> classifiers = new HashSet<>();
+            boolean foundEmpty = false;
+            for(final Feature f : finfo.features.values()) {
+                if ( f.getId().getClassifier() == null ) {
+                    if ( foundEmpty ) {
+                        throw new RuntimeException("More than one feature file 
without classifier in project " + finfo.project.getId());
+                    }
+                    foundEmpty = true;
+                } else {
+                    if ( classifiers.contains(f.getId().getClassifier()) ) {
+                        throw new RuntimeException("Duplicate feature 
classifier " + f.getId().getClassifier() + " used in project " + 
finfo.project.getId());
+                    }
+                    classifiers.add(f.getId().getClassifier());
+                }
+            }
             ProjectHelper.storeProjectInfo(finfo);
         }
     }
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 302a9e5..51bed52 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
@@ -33,7 +33,6 @@ public abstract class AbstractFeatureMojo extends 
AbstractMojo {
 
     /**
      * Directory containing feature files
-     * This parameter is evaluated in the {@link 
DependencyLifecycleParticipant}.
      */
     @Parameter(name = FeatureProjectConfig.CFG_FEATURES,
             required = true,
@@ -42,7 +41,6 @@ public abstract class AbstractFeatureMojo extends 
AbstractMojo {
 
     /**
      * Directory containing test feature files
-     * This parameter is evaluated in the {@link 
DependencyLifecycleParticipant}.
      */
     @Parameter(name = FeatureProjectConfig.CFG_TEST_FEATURES,
             required = true,
@@ -51,7 +49,6 @@ public abstract class AbstractFeatureMojo extends 
AbstractMojo {
 
     /**
      * If set to {@code true} the artifacts from the feature are not as 
dependencies to the project.
-     * This parameter is evaluated in the {@link 
DependencyLifecycleParticipant}.
      */
     @Parameter(name=FeatureProjectConfig.CFG_SKIP_ADD_FEATURE_DEPENDENCIES,
             defaultValue="false")
@@ -59,7 +56,6 @@ public abstract class AbstractFeatureMojo extends 
AbstractMojo {
 
     /**
      * If set to {@code true} the artifacts from the test feature are not as 
dependencies to the project.
-     * This parameter is evaluated in the {@link 
DependencyLifecycleParticipant}.
      */
     
@Parameter(name=FeatureProjectConfig.CFG_SKIP_ADD_TEST_FEATURE_DEPENDENCIES,
             defaultValue="true")
@@ -67,7 +63,6 @@ public abstract class AbstractFeatureMojo extends 
AbstractMojo {
 
     /**
      * If set to {@code true} the main jar artifact is not added to the 
feature.
-     * This parameter is evaluated in the {@link 
DependencyLifecycleParticipant}.
      */
     @Parameter(name=FeatureProjectConfig.CFG_SKIP_ADD_JAR_TO_FEATURE,
             defaultValue="false")
@@ -75,7 +70,6 @@ public abstract class AbstractFeatureMojo extends 
AbstractMojo {
 
     /**
      * If set to {@code true} the main jar artifact is not added to the test 
feature.
-     * This parameter is evaluated in the {@link 
DependencyLifecycleParticipant}.
      */
     @Parameter(name=FeatureProjectConfig.CFG_SKIP_ADD_JAR_TO_TEST_FEATURE,
             defaultValue="false")
@@ -83,7 +77,6 @@ public abstract class AbstractFeatureMojo extends 
AbstractMojo {
 
     /**
      * The start level for the attached jar/bundle.
-     * This parameter is evaluated in the {@link 
DependencyLifecycleParticipant}.
      */
     @Parameter(name=FeatureProjectConfig.CFG_JAR_START_ORDER)
     private int jarStartOrder;
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 213ec8e..7709697 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
@@ -59,9 +59,6 @@ import org.codehaus.plexus.util.AbstractScanner;
 
 /**
  * Aggregate multiple features into a single one.
- *
- * TODO - check that classifier is not clashing with an already used 
classifier from the read
- * files. We should also check if this mojo is configured several times, that 
different classifiers are configured.
  */
 @Mojo(name = "aggregate-features",
     defaultPhase = LifecyclePhase.GENERATE_RESOURCES,
@@ -70,6 +67,8 @@ import org.codehaus.plexus.util.AbstractScanner;
 )
 public class AggregateFeatures extends AbstractFeatureMojo {
 
+    private static final String PREFIX = ":aggregate:";
+
     @Parameter(required = true)
     List<FeatureConfig> aggregates;
 
@@ -98,9 +97,16 @@ public class AggregateFeatures extends AbstractFeatureMojo {
     public void execute() throws MojoExecutionException, MojoFailureException {
         // get map of all project features
         final Map<String, Feature> projectFeatures = 
ProjectHelper.getFeatures(this.project);
+        final String key = PREFIX + aggregateClassifier;
+        if ( projectFeatures.containsKey(key) ) {
+            throw new MojoExecutionException("Duplicate aggregated feature 
definition for classifier " + aggregateClassifier);
+        }
         // ..and hash them by artifact id
         final Map<ArtifactId, Feature> contextFeatures = new HashMap<>();
         for(final Map.Entry<String, Feature> entry : 
projectFeatures.entrySet()) {
+            if ( 
aggregateClassifier.equals(entry.getValue().getId().getClassifier())) {
+                throw new MojoExecutionException("Aggregated feature 
definition is using same classifier as project feature " + aggregateClassifier);
+            }
             contextFeatures.put(entry.getValue().getId(), entry.getValue());
         }
 
@@ -143,7 +149,6 @@ public class AggregateFeatures extends AbstractFeatureMojo {
         Feature result = FeatureBuilder.assemble(newFeatureID, builderContext, 
featureMap.values().toArray(new Feature[] {}));
 
         // Add feature to map of features
-        final String key = ":aggregate:" + aggregateClassifier;
         projectFeatures.put(key, result);
         ProjectHelper.getAssembledFeatures(this.project).put(key, result);
     }
@@ -320,6 +325,10 @@ public class AggregateFeatures extends AbstractFeatureMojo 
{
             setupMatchPatterns();
 
             for ( Map.Entry<String, Feature> entry : features.entrySet() ) {
+                // skip aggregates
+                if ( entry.getKey().startsWith(PREFIX) ) {
+                    continue;
+                }
                 final String name = entry.getKey().substring(prefix.length());
                 final String[] tokenizedName =  tokenizePathToString( name, 
File.separator );
                 if ( isIncluded( name, tokenizedName ) ) {

Reply via email to