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 2019/08/13 07:25:18 UTC
[sling-slingfeature-maven-plugin] branch issues/SLING-8541 updated:
SLING-8541 : slingfeature-maven-plugin should allow for generated feature
model files
This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch issues/SLING-8541
in repository https://gitbox.apache.org/repos/asf/sling-slingfeature-maven-plugin.git
The following commit(s) were added to refs/heads/issues/SLING-8541 by this push:
new eaacb0e SLING-8541 : slingfeature-maven-plugin should allow for generated feature model files
eaacb0e is described below
commit eaacb0e6a8e00822fd1ba54f05ba7d4256a0c520
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue Aug 13 09:25:08 2019 +0200
SLING-8541 : slingfeature-maven-plugin should allow for generated feature model files
---
.../apache/sling/feature/maven/ProjectHelper.java | 10 ++---
.../feature/maven/mojos/AbstractFeatureMojo.java | 49 ++++++++++++++++++----
2 files changed, 44 insertions(+), 15 deletions(-)
diff --git a/src/main/java/org/apache/sling/feature/maven/ProjectHelper.java b/src/main/java/org/apache/sling/feature/maven/ProjectHelper.java
index 50b141b..5b595b9 100644
--- a/src/main/java/org/apache/sling/feature/maven/ProjectHelper.java
+++ b/src/main/java/org/apache/sling/feature/maven/ProjectHelper.java
@@ -24,7 +24,6 @@ import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -108,9 +107,9 @@ public abstract class ProjectHelper {
result = null;
}
if ( result == null ) {
+ result = new TreeMap<>();
final Integer size = (Integer)project.getContextValue(key);
if ( size != null ) {
- result = new TreeMap<>();
for(int i=0; i<size;i++) {
final String text = (String)project.getContextValue(key + "_" + String.valueOf(i));
if ( text == null ) {
@@ -127,10 +126,10 @@ public abstract class ProjectHelper {
throw new RuntimeException(ioe.getMessage(), ioe);
}
}
- project.setContextValue(cacheKey, result);
}
+ project.setContextValue(cacheKey, result);
}
- return result != null ? result : Collections.emptyMap();
+ return result;
}
/**
@@ -157,9 +156,6 @@ public abstract class ProjectHelper {
return "The slingfeature preprocessor did not run. "
+ "Please make sure to set <extensions>true</extensions> for the slingfeature plugin in your pom.";
}
- if (FeatureConstants.PACKAGING_FEATURE.equals(project.getPackaging()) && getFeatures(project).isEmpty()) {
- return "Feature project has no features defined";
- }
return null;
}
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 13dbb40..7e7050d 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
@@ -41,6 +41,7 @@ import org.apache.sling.feature.builder.BuilderContext;
import org.apache.sling.feature.builder.FeatureBuilder;
import org.apache.sling.feature.builder.FeatureProvider;
import org.apache.sling.feature.io.json.FeatureJSONReader;
+import org.apache.sling.feature.maven.FeatureConstants;
import org.apache.sling.feature.maven.FeatureProjectConfig;
import org.apache.sling.feature.maven.ProjectHelper;
@@ -142,7 +143,22 @@ public abstract class AbstractFeatureMojo extends AbstractMojo {
* Directory containing generated feature files
*/
@Parameter
- protected File generatedFeatures;
+ private File generatedFeatures;
+
+ /**
+ * Comma separated list of includes for the generated feature files in the
+ * configured directory. Only feature files specified by this include are
+ * processed.
+ */
+ @Parameter(defaultValue = FeatureProjectConfig.DEFAULT_FEATURE_INCLUDES)
+ private String generatedFeaturesIncludes;
+
+ /**
+ * Comma separated list of excludes for the generated feature files. Feature
+ * files excluded by this configuration are not processed at all.
+ */
+ @Parameter
+ private String generatedFeaturesExcludes;
/**
* The start level for the attached jar/bundle.
@@ -189,20 +205,37 @@ public abstract class AbstractFeatureMojo extends AbstractMojo {
this.project.setContextValue(PROPERTY_HANDLED_GENERATED_FEATURES, Boolean.TRUE);
}
+ if (FeatureConstants.PACKAGING_FEATURE.equals(project.getPackaging())
+ && ProjectHelper.getFeatures(project).isEmpty()) {
+ throw new MojoExecutionException("Feature project has no features defined");
+ }
}
private void handleGeneratedFeatures() throws MojoExecutionException {
- if (this.generatedFeatures != null) {
- if (!this.generatedFeatures.exists()) {
- throw new MojoExecutionException("Directory does not exists: " + this.generatedFeatures);
+ final File dir;
+ if (this.generatedFeatures == null) {
+ final File targetDir = new File(this.project.getBasedir(), this.project.getBuild().getDirectory());
+ final File genDir = new File(targetDir, "generated-features");
+ if (genDir.exists()) {
+ dir = genDir;
+ } else {
+ dir = null;
+ }
+ } else {
+ dir = this.generatedFeatures;
+ }
+ if (dir != null) {
+ if (!dir.exists()) {
+ throw new MojoExecutionException("Directory does not exists: " + dir);
}
- if (!this.generatedFeatures.isDirectory()) {
+ if (!dir.isDirectory()) {
throw new MojoExecutionException(
- "Generated features configuration is not a directory: " + this.generatedFeatures);
+ "Generated features configuration is not a directory: " + dir);
}
final List<File> files = new ArrayList<>();
- ProjectHelper.scan(files, this.generatedFeatures, null, null);
+ ProjectHelper.scan(files, dir, this.generatedFeaturesIncludes,
+ this.generatedFeaturesExcludes);
for (final File file : files) {
getLog().debug("Reading feature file " + file);
@@ -233,7 +266,7 @@ public abstract class AbstractFeatureMojo extends AbstractMojo {
// this is a bit unusual, but as ProjectHelper can only throw RuntimeException
// it's
// more user friendly to catch it and rethrow a mojo friendly exception
- throw new MojoExecutionException(re.getMessage(), re.getCause());
+ throw new MojoExecutionException(re.getMessage(), re.getCause() != null ? re.getCause() : re);
}
}
}