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 6dbfffc SLING-8096 Make it possible to configure Merge Handlers and
Post Processors
6dbfffc is described below
commit 6dbfffcf01e9785114f36e5628bb4d735d4e09bd
Author: David Bosschaert <[email protected]>
AuthorDate: Mon Nov 12 15:16:12 2018 +0000
SLING-8096 Make it possible to configure Merge Handlers and Post Processors
---
.../feature/maven/mojos/AggregateFeaturesMojo.java | 10 ++++++
.../maven/mojos/AggregateFeaturesMojoTest.java | 21 +++++++++---
.../feature/maven/mojos/plugins/TestPlugin3.java | 38 ++++++++++++++++++++++
.../org.apache.sling.feature.builder.MergeHandler | 1 +
.../resources/aggregate-features/dir3/test_y.json | 5 +--
.../resources/aggregate-features/dir3/test_z.json | 2 +-
6 files changed, 69 insertions(+), 8 deletions(-)
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 dc6d1e3..ef50a1d 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
@@ -17,8 +17,10 @@
package org.apache.sling.feature.maven.mojos;
import java.io.File;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import java.util.ServiceLoader;
import java.util.Spliterator;
import java.util.Spliterators;
@@ -58,6 +60,10 @@ public class AggregateFeaturesMojo extends
AbstractIncludingFeatureMojo {
@Parameter(required = true)
List<Aggregate> aggregates;
+ @Parameter
+ Map<String, Properties> handlerConfiguration = new HashMap<>();
+
+ @SuppressWarnings("unchecked")
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
for (final Aggregate aggregate : aggregates) {
@@ -130,6 +136,10 @@ public class AggregateFeaturesMojo extends
AbstractIncludingFeatureMojo {
ServiceLoader.load(PostProcessHandler.class).iterator(), Spliterator.ORDERED),
false).toArray(PostProcessHandler[]::new));
+ @SuppressWarnings("rawtypes")
+ Map<String, Map<String,String>> hc = (Map) handlerConfiguration;
+ builderContext.getHandlerConfiguration().putAll(hc);
+
final ArtifactId newFeatureID = new
ArtifactId(project.getGroupId(), project.getArtifactId(),
project.getVersion(), aggregate.classifier,
FeatureConstants.PACKAGING_FEATURE);
final Feature result = FeatureBuilder.assemble(newFeatureID,
builderContext,
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 fd5cbb0..f8ab84d 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,11 +16,6 @@
*/
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;
@@ -34,6 +29,7 @@ import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
@@ -64,6 +60,12 @@ 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 {
private Path tempDir;
private static Map<String, ArtifactId> pluginCallbacks;
@@ -584,6 +586,12 @@ public class AggregateFeaturesMojoTest {
af.project = mockProj;
af.projectHelper = new DefaultMavenProjectHelper();
af.features = featuresDir;
+ af.handlerConfiguration = new HashMap<>();
+
+ Properties p3props = new Properties();
+ p3props.put("test3cfg", "myval");
+ p3props.put("test3cfg3", "somethingelse");
+ af.handlerConfiguration.put("TestPlugin3", p3props);
assertEquals("Precondition", 0, pluginCallbacks.size());
af.execute();
@@ -595,6 +603,9 @@ public class AggregateFeaturesMojoTest {
assertEquals(id, pluginCallbacks.get("TestPlugin2 - extension1"));
assertEquals(id, pluginCallbacks.get("TestPlugin2 - extension2"));
assertEquals(id, pluginCallbacks.get("TestPlugin2 - extension3"));
+
+ ArtifactId id2 = new ArtifactId("test", "test", "9.9.9", "y",
"slingosgifeature");
+ assertEquals(id2, pluginCallbacks.get("TestPlugin3 - myval-Hi there"));
}
private Artifact createMockArtifact() {
diff --git
a/src/test/java/org/apache/sling/feature/maven/mojos/plugins/TestPlugin3.java
b/src/test/java/org/apache/sling/feature/maven/mojos/plugins/TestPlugin3.java
new file mode 100644
index 0000000..282da8e
--- /dev/null
+++
b/src/test/java/org/apache/sling/feature/maven/mojos/plugins/TestPlugin3.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package org.apache.sling.feature.maven.mojos.plugins;
+
+import org.apache.sling.feature.Extension;
+import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.builder.HandlerContext;
+import org.apache.sling.feature.builder.MergeHandler;
+import org.apache.sling.feature.maven.mojos.AggregateFeaturesMojoTest;
+
+public class TestPlugin3 implements MergeHandler {
+
+ @Override
+ public boolean canMerge(Extension extension) {
+ return extension.getName().equals("extension4");
+ }
+
+ @Override
+ public void merge(HandlerContext context, Feature target, Feature source,
Extension targetEx, Extension sourceEx) {
+ AggregateFeaturesMojoTest.addPluginCallback("TestPlugin3 - " +
+ context.getConfiguration().get("test3cfg") + "-" +
sourceEx.getText(),
+ source.getId());
+ }
+}
diff --git
a/src/test/resources/META-INF/services/org.apache.sling.feature.builder.MergeHandler
b/src/test/resources/META-INF/services/org.apache.sling.feature.builder.MergeHandler
new file mode 100644
index 0000000..46dff65
--- /dev/null
+++
b/src/test/resources/META-INF/services/org.apache.sling.feature.builder.MergeHandler
@@ -0,0 +1 @@
+org.apache.sling.feature.maven.mojos.plugins.TestPlugin3
diff --git a/src/test/resources/aggregate-features/dir3/test_y.json
b/src/test/resources/aggregate-features/dir3/test_y.json
index d433d0b..88f690e 100644
--- a/src/test/resources/aggregate-features/dir3/test_y.json
+++ b/src/test/resources/aggregate-features/dir3/test_y.json
@@ -1,5 +1,5 @@
{
- "id":"test:test:9.9.9:y:slingfeature",
+ "id":"test:test:slingosgifeature:y:9.9.9",
"bundles":[
{
"id":"org.apache.aries:org.apache.aries.util:1.1.3",
@@ -10,5 +10,6 @@
],
"extension2:ARTIFACTS|true": [
"org.apache.sling:org.apache.sling.foobar:1.0.0"
- ]
+ ],
+ "extension4:TEXT|false:": "Hi there"
}
diff --git a/src/test/resources/aggregate-features/dir3/test_z.json
b/src/test/resources/aggregate-features/dir3/test_z.json
index ce08448..920392b 100644
--- a/src/test/resources/aggregate-features/dir3/test_z.json
+++ b/src/test/resources/aggregate-features/dir3/test_z.json
@@ -1,5 +1,5 @@
{
- "id":"test:test:1.0.1:z:slingfeature",
+ "id":"test:test:slingosgifeature:z:1.0.1",
"configurations": {
"some.pid": {
"x": "y"