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

davidb 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 ee788d9  SLING-8169 Bundle Import/Export Analyser needs to take API 
Regions into account
ee788d9 is described below

commit ee788d97f13346325aa5ae28ff6539ccd053a28b
Author: David Bosschaert <bossc...@adobe.com>
AuthorDate: Wed Jan 16 16:57:13 2019 +0000

    SLING-8169 Bundle Import/Export Analyser needs to take API Regions into 
account
    
    Configure a fileStorage location in the plugin that Mojos use to
    communicate information.
---
 pom.xml                                            |  4 +++
 .../feature/maven/mojos/AggregateFeaturesMojo.java | 27 +++++++++++++++-
 .../feature/maven/mojos/AnalyseFeaturesMojo.java   | 37 +++++++++++++++++-----
 3 files changed, 59 insertions(+), 9 deletions(-)

diff --git a/pom.xml b/pom.xml
index 655dd54..704548b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -113,6 +113,10 @@
                         <pomInclude>**/pom.xml</pomInclude>
                     </pomIncludes>
                     <postBuildHookScript>verify</postBuildHookScript>
+                    <properties>
+                        <!-- The API Region files are produced by the API 
Regions merge extension which is not run here -->
+                        <skipAPIRegionFileErrors>true</skipAPIRegionFileErrors>
+                    </properties>
                 </configuration>
                 <executions>
                     <execution>
diff --git 
a/src/main/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojo.java 
b/src/main/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojo.java
index aa340f2..80e350f 100644
--- 
a/src/main/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojo.java
+++ 
b/src/main/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojo.java
@@ -35,6 +35,7 @@ import org.apache.sling.feature.maven.ProjectHelper;
 
 import java.io.File;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -53,6 +54,8 @@ import java.util.stream.StreamSupport;
     threadSafe = true
 )
 public class AggregateFeaturesMojo extends AbstractIncludingFeatureMojo {
+    private static final String FILE_STORAGE_CONFIG_KEY = "fileStorage";
+    private static final String HANDLER_CONFIG_WILDCARD = "*";
 
     /**
      * The definition of the features used to create the new feature.
@@ -139,8 +142,24 @@ public class AggregateFeaturesMojo extends 
AbstractIncludingFeatureMojo {
                     ServiceLoader.load(PostProcessHandler.class).iterator(), 
Spliterator.ORDERED),
                     false).toArray(PostProcessHandler[]::new));
 
+            boolean wildcardSet = false;
             for (final Map.Entry<String, Properties> entry : 
handlerConfiguration.entrySet()) {
-                builderContext.setHandlerConfiguration(entry.getKey(), 
ProjectHelper.propertiesToMap(entry.getValue()));
+                String key = entry.getKey();
+                Properties props = entry.getValue();
+
+                if (HANDLER_CONFIG_WILDCARD.equals(key)) {
+                    if (!props.containsKey(FILE_STORAGE_CONFIG_KEY)) {
+                        props.put(FILE_STORAGE_CONFIG_KEY, 
getFeatureModelStorage());
+                    }
+                    wildcardSet = true;
+                }
+
+                builderContext.setHandlerConfiguration(key, 
ProjectHelper.propertiesToMap(props));
+            }
+
+            if (!wildcardSet) {
+                builderContext.setHandlerConfiguration(HANDLER_CONFIG_WILDCARD,
+                        Collections.singletonMap(FILE_STORAGE_CONFIG_KEY, 
getFeatureModelStorage()));
             }
 
             final ArtifactId newFeatureID = new 
ArtifactId(project.getGroupId(), project.getArtifactId(),
@@ -172,4 +191,10 @@ public class AggregateFeaturesMojo extends 
AbstractIncludingFeatureMojo {
             ProjectHelper.getFeatures(this.project).put(key, result);
         }
     }
+
+    private String getFeatureModelStorage() {
+        String featureModelFileStorage = project.getBuild().getDirectory() + 
"/sling-slingfeature-maven-plugin-fmtmp";
+        new File(featureModelFileStorage).mkdirs();
+        return featureModelFileStorage;
+    }
 }
diff --git 
a/src/main/java/org/apache/sling/feature/maven/mojos/AnalyseFeaturesMojo.java 
b/src/main/java/org/apache/sling/feature/maven/mojos/AnalyseFeaturesMojo.java
index 34f87ab..c6c1356 100644
--- 
a/src/main/java/org/apache/sling/feature/maven/mojos/AnalyseFeaturesMojo.java
+++ 
b/src/main/java/org/apache/sling/feature/maven/mojos/AnalyseFeaturesMojo.java
@@ -16,12 +16,6 @@
  */
 package org.apache.sling.feature.maven.mojos;
 
-import java.io.File;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
 import org.apache.maven.model.Dependency;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
@@ -38,6 +32,14 @@ import org.apache.sling.feature.builder.ArtifactProvider;
 import org.apache.sling.feature.maven.ProjectHelper;
 import org.apache.sling.feature.scanner.Scanner;
 
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 /**
  * Analyse the feature.
  */
@@ -48,6 +50,10 @@ import org.apache.sling.feature.scanner.Scanner;
     )
 public class AnalyseFeaturesMojo extends AbstractIncludingFeatureMojo {
 
+    private static final String FILE_STORAGE_CONFIG_KEY = "fileStorage";
+
+    private static final String ANALYSER_CONFIG_WILDCARD = "*";
+
     @Parameter
     private List<Scan> scans;
 
@@ -85,12 +91,14 @@ public class AnalyseFeaturesMojo extends 
AbstractIncludingFeatureMojo {
         boolean hasErrors = false;
         for (final Scan an : list) {
             try {
+                Map<String, Map<String, String>> taskConfiguration = 
an.getTaskConfiguration();
+                addTaskConfigurationDefaults(taskConfiguration);
 
                 getLog().debug(MessageUtils.buffer().a("Setting up the 
").strong("Analyser").a(" with following configuration:").toString());
-                getLog().debug(" * Task Configuration = " + 
an.getTaskConfiguration());
+                getLog().debug(" * Task Configuration = " + taskConfiguration);
                 getLog().debug(" * Include Tasks = " + an.getIncludeTasks());
                 getLog().debug(" * Exclude Tasks = " + an.getExcludeTasks());
-                final Analyser analyser = new Analyser(scanner, 
an.getTaskConfiguration(), an.getIncludeTasks(), an.getExcludeTasks());
+                final Analyser analyser = new Analyser(scanner, 
taskConfiguration, an.getIncludeTasks(), an.getExcludeTasks());
                 getLog().debug(MessageUtils.buffer().strong("Analyser").a(" 
successfully set up").toString());
 
                 getLog().debug("Retrieving Feature files...");
@@ -145,4 +153,17 @@ public class AnalyseFeaturesMojo extends 
AbstractIncludingFeatureMojo {
             throw new MojoFailureException("One or more features Analyzer 
detected Feature error(s), please read the plugin log for more datils");
         }
     }
+
+    private void addTaskConfigurationDefaults(Map<String, Map<String, String>> 
taskConfiguration) {
+        String featureModelFileStorage = project.getBuild().getDirectory() + 
"/sling-slingfeature-maven-plugin-fmtmp";
+        Map<String, String> wildCardCfg = 
taskConfiguration.get(ANALYSER_CONFIG_WILDCARD);
+        if (wildCardCfg == null) {
+            wildCardCfg = new HashMap<String, String>();
+            taskConfiguration.put(ANALYSER_CONFIG_WILDCARD, wildCardCfg);
+        }
+        if (!wildCardCfg.containsKey(FILE_STORAGE_CONFIG_KEY)) {
+            new File(featureModelFileStorage).mkdirs();
+            wildCardCfg.put(FILE_STORAGE_CONFIG_KEY, featureModelFileStorage);
+        }
+    }
 }

Reply via email to