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/11/13 13:46:34 UTC
[sling-slingfeature-maven-plugin] branch master updated: SLING-8101
: Mojos that require extensions to be activated should warn or fail if
extensions are not activated
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 605745d SLING-8101 : Mojos that require extensions to be activated should warn or fail if extensions are not activated
605745d is described below
commit 605745d2ed87fd919a498c28e3e7c184363a6491
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue Nov 13 14:46:24 2018 +0100
SLING-8101 : Mojos that require extensions to be activated should warn or fail if extensions are not activated
---
.../org/apache/sling/feature/maven/ProjectHelper.java | 8 ++++++++
.../feature/maven/mojos/AggregateFeaturesMojo.java | 1 +
.../sling/feature/maven/mojos/AnalyseFeaturesMojo.java | 1 +
.../sling/feature/maven/mojos/AttachFeaturesMojo.java | 1 +
.../sling/feature/maven/mojos/RepositoryMojo.java | 2 ++
.../sling/feature/maven/mojos/UpdateVersionsMojo.java | 1 +
.../feature/maven/mojos/AggregateFeaturesMojoTest.java | 17 +++++++++++++----
7 files changed, 27 insertions(+), 4 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 abbe173..b5d6b26 100644
--- a/src/main/java/org/apache/sling/feature/maven/ProjectHelper.java
+++ b/src/main/java/org/apache/sling/feature/maven/ProjectHelper.java
@@ -133,6 +133,14 @@ public abstract class ProjectHelper {
store(info.project, RAW_TEST_FEATURE_JSON, info.testFeatures);
store(info.project, ASSEMBLED_FEATURE_JSON, info.assembledFeatures);
store(info.project, ASSEMBLED_TEST_FEATURE_JSON, info.assembledTestFeatures);
+ info.project.setContextValue(Preprocessor.class.getName(), Boolean.TRUE);
+ }
+
+ public static void checkPreprocessorRun(final MavenProject project) {
+ if (project.getContextValue(Preprocessor.class.getName()) == null) {
+ throw new RuntimeException("The slingfeature preprocessor did not run. "
+ + "Please make sure to set <extensions>true</extensions> for the slingfeature plugin in your pom.");
+ }
}
/**
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 7a322e4..af550ce 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
@@ -66,6 +66,7 @@ public class AggregateFeaturesMojo extends AbstractIncludingFeatureMojo {
@SuppressWarnings("unchecked")
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
+ ProjectHelper.checkPreprocessorRun(this.project);
for (final Aggregate aggregate : aggregates) {
// check classifier
ProjectHelper.validateFeatureClassifiers(this.project, aggregate.classifier);
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 7db7187..4812488 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
@@ -56,6 +56,7 @@ public class AnalyseFeaturesMojo extends AbstractIncludingFeatureMojo {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
+ ProjectHelper.checkPreprocessorRun(this.project);
List<Scan> list = scans;
if (list == null || list.isEmpty()) {
// use default configuration
diff --git a/src/main/java/org/apache/sling/feature/maven/mojos/AttachFeaturesMojo.java b/src/main/java/org/apache/sling/feature/maven/mojos/AttachFeaturesMojo.java
index d184ece..b217c34 100644
--- a/src/main/java/org/apache/sling/feature/maven/mojos/AttachFeaturesMojo.java
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/AttachFeaturesMojo.java
@@ -75,6 +75,7 @@ public class AttachFeaturesMojo extends AbstractFeatureMojo {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
+ ProjectHelper.checkPreprocessorRun(this.project);
this.attachClassifierFeatures(ProjectHelper.getFeatures(this.project).values());
if ( this.attachTestFeatures ) {
diff --git a/src/main/java/org/apache/sling/feature/maven/mojos/RepositoryMojo.java b/src/main/java/org/apache/sling/feature/maven/mojos/RepositoryMojo.java
index c55e042..edaae60 100644
--- a/src/main/java/org/apache/sling/feature/maven/mojos/RepositoryMojo.java
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/RepositoryMojo.java
@@ -27,6 +27,7 @@ import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.maven.ProjectHelper;
/**
* Create a Maven repository structure from the referenced artifacts in the features.
@@ -44,6 +45,7 @@ public class RepositoryMojo extends AbstractRepositoryMojo {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
+ ProjectHelper.checkPreprocessorRun(this.project);
if (repositories == null || repositories.isEmpty()) {
final File artifactDir = new File(this.project.getBuild().getDirectory(), this.repositoryDir);
this.doExecute(artifactDir, this.selectAllFeatureFilesAndAggregates(), null);
diff --git a/src/main/java/org/apache/sling/feature/maven/mojos/UpdateVersionsMojo.java b/src/main/java/org/apache/sling/feature/maven/mojos/UpdateVersionsMojo.java
index 9107c3d..0e53b86 100644
--- a/src/main/java/org/apache/sling/feature/maven/mojos/UpdateVersionsMojo.java
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/UpdateVersionsMojo.java
@@ -163,6 +163,7 @@ public class UpdateVersionsMojo extends AbstractIncludingFeatureMojo {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
+ ProjectHelper.checkPreprocessorRun(this.project);
// get the features
final Map<String, Feature> assembledFeatures = this.getFeatures();
if (assembledFeatures.isEmpty()) {
diff --git a/src/test/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojoTest.java b/src/test/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojoTest.java
index f8ab84d..01408c8 100644
--- a/src/test/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojoTest.java
+++ b/src/test/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojoTest.java
@@ -16,6 +16,11 @@
*/
package org.apache.sling.feature.maven.mojos;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.io.File;
import java.io.FileReader;
import java.nio.file.Files;
@@ -55,15 +60,12 @@ import org.apache.sling.feature.ArtifactId;
import org.apache.sling.feature.Feature;
import org.apache.sling.feature.io.json.FeatureJSONReader;
import org.apache.sling.feature.maven.FeatureConstants;
+import org.apache.sling.feature.maven.Preprocessor;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
@SuppressWarnings("deprecation")
public class AggregateFeaturesMojoTest {
@@ -119,6 +121,7 @@ public class AggregateFeaturesMojoTest {
.thenReturn(featureMap);
Mockito.when(mockProj.getContextValue(Feature.class.getName() + "/assembledmain.json-cache"))
.thenReturn(featureMap);
+ Mockito.when(mockProj.getContextValue(Preprocessor.class.getName())).thenReturn(Boolean.TRUE);
AggregateFeaturesMojo af = new AggregateFeaturesMojo();
fc.classifier = "aggregated";
@@ -194,6 +197,7 @@ public class AggregateFeaturesMojoTest {
.thenReturn(featureMap);
Mockito.when(mockProj.getContextValue(Feature.class.getName() + "/assembledmain.json-cache"))
.thenReturn(featureMap);
+ Mockito.when(mockProj.getContextValue(Preprocessor.class.getName())).thenReturn(Boolean.TRUE);
AggregateFeaturesMojo af = new AggregateFeaturesMojo();
fc.classifier = "aggregated";
@@ -266,6 +270,7 @@ public class AggregateFeaturesMojoTest {
.thenReturn(featureMap);
Mockito.when(mockProj.getContextValue(Feature.class.getName() + "/assembledmain.json-cache"))
.thenReturn(featureMap);
+ Mockito.when(mockProj.getContextValue(Preprocessor.class.getName())).thenReturn(Boolean.TRUE);
AggregateFeaturesMojo af = new AggregateFeaturesMojo();
fc.classifier = "aggregated";
@@ -310,6 +315,7 @@ public class AggregateFeaturesMojoTest {
.thenReturn(featureMap);
Mockito.when(mockProj.getContextValue(Feature.class.getName() + "/assembledmain.json-cache"))
.thenReturn(featureMap);
+ Mockito.when(mockProj.getContextValue(Preprocessor.class.getName())).thenReturn(Boolean.TRUE);
AggregateFeaturesMojo af = new AggregateFeaturesMojo();
fc.classifier = "aggregated";
@@ -361,6 +367,7 @@ public class AggregateFeaturesMojoTest {
.thenReturn(featureMap);
Mockito.when(mockProj.getContextValue(Feature.class.getName() + "/assembledmain.json-cache"))
.thenReturn(featureMap);
+ Mockito.when(mockProj.getContextValue(Preprocessor.class.getName())).thenReturn(Boolean.TRUE);
AggregateFeaturesMojo af = new AggregateFeaturesMojo();
@@ -429,6 +436,7 @@ public class AggregateFeaturesMojoTest {
.thenReturn(featureMap);
Mockito.when(mockProj.getContextValue(Feature.class.getName() + "/assembledmain.json-cache"))
.thenReturn(featureMap);
+ Mockito.when(mockProj.getContextValue(Preprocessor.class.getName())).thenReturn(Boolean.TRUE);
AggregateFeaturesMojo af = new AggregateFeaturesMojo();
fc.classifier = "mynewfeature";
@@ -579,6 +587,7 @@ public class AggregateFeaturesMojoTest {
.thenReturn(featureMap);
Mockito.when(mockProj.getContextValue(Feature.class.getName() + "/assembledmain.json-cache"))
.thenReturn(featureMap);
+ Mockito.when(mockProj.getContextValue(Preprocessor.class.getName())).thenReturn(Boolean.TRUE);
AggregateFeaturesMojo af = new AggregateFeaturesMojo();
fc.classifier = "aggregated";