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

commit b88890056405e82f56a874c7c0d35311bdac2ace
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Fri Sep 28 18:32:01 2018 +0200

    SLING-7961 : Adjust feature file reading to latest state
---
 .../feature/maven/mojos/AggregateFeatures.java     |  22 +---
 .../feature/maven/mojos/AggregateFeaturesTest.java | 129 +++++++++++----------
 2 files changed, 70 insertions(+), 81 deletions(-)

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 9b5bc1e..213ec8e 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
@@ -17,10 +17,8 @@
 package org.apache.sling.feature.maven.mojos;
 
 import java.io.File;
-import java.io.FileWriter;
 import java.io.IOException;
 import java.io.StringReader;
-import java.io.Writer;
 import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -54,7 +52,6 @@ import org.apache.sling.feature.builder.FeatureBuilder;
 import org.apache.sling.feature.builder.FeatureExtensionHandler;
 import org.apache.sling.feature.builder.FeatureProvider;
 import org.apache.sling.feature.io.json.FeatureJSONReader;
-import org.apache.sling.feature.io.json.FeatureJSONWriter;
 import org.apache.sling.feature.maven.FeatureConstants;
 import org.apache.sling.feature.maven.ProjectHelper;
 import org.apache.sling.feature.maven.Substitution;
@@ -67,7 +64,7 @@ import org.codehaus.plexus.util.AbstractScanner;
  * files. We should also check if this mojo is configured several times, that 
different classifiers are configured.
  */
 @Mojo(name = "aggregate-features",
-    defaultPhase = LifecyclePhase.PACKAGE,
+    defaultPhase = LifecyclePhase.GENERATE_RESOURCES,
     requiresDependencyResolution = ResolutionScope.TEST,
     threadSafe = true
 )
@@ -145,19 +142,10 @@ public class AggregateFeatures extends 
AbstractFeatureMojo {
                 project.getVersion(), aggregateClassifier, 
FeatureConstants.PACKAGING_FEATURE);
         Feature result = FeatureBuilder.assemble(newFeatureID, builderContext, 
featureMap.values().toArray(new Feature[] {}));
 
-        // write the feature
-        final File outputFile = new 
File(this.project.getBuild().getDirectory() + File.separatorChar + 
aggregateClassifier + ".json");
-        outputFile.getParentFile().mkdirs();
-
-        try ( final Writer writer = new FileWriter(outputFile)) {
-            FeatureJSONWriter.write(writer, result);
-        } catch (final IOException e) {
-            throw new MojoExecutionException("Unable to write feature to " + 
outputFile, e);
-        }
-
-        // attach it as an additional artifact
-        projectHelper.attachArtifact(project, 
FeatureConstants.PACKAGING_FEATURE,
-                aggregateClassifier, outputFile);
+        // Add feature to map of features
+        final String key = ":aggregate:" + aggregateClassifier;
+        projectFeatures.put(key, result);
+        ProjectHelper.getAssembledFeatures(this.project).put(key, result);
     }
 
     private Map<ArtifactId, Feature> readFeatures(Collection<FeatureConfig> 
featureConfigs,
diff --git 
a/src/test/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesTest.java 
b/src/test/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesTest.java
index 5206bef..5a32ee9 100644
--- 
a/src/test/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesTest.java
+++ 
b/src/test/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesTest.java
@@ -18,6 +18,7 @@ package org.apache.sling.feature.maven.mojos;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
@@ -156,6 +157,8 @@ public class AggregateFeaturesTest {
         Mockito.when(mockProj.getArtifact()).thenReturn(parentArtifact);
         Mockito.when(mockProj.getContextValue(Feature.class.getName() + 
"/rawmain.json-cache"))
             .thenReturn(featureMap);
+        Mockito.when(mockProj.getContextValue(Feature.class.getName() + 
"/assembledmain.json-cache"))
+            .thenReturn(featureMap);
 
         AggregateFeatures af = new AggregateFeatures();
         af.aggregateClassifier = "aggregated";
@@ -166,41 +169,39 @@ public class AggregateFeaturesTest {
         af.features = featuresDir;
         af.execute();
 
-        File expectedFile = new File(tempDir.toFile(), "/aggregated.json");
-        try (Reader fr = new FileReader(expectedFile)) {
-            Feature genFeat = FeatureJSONReader.read(fr, null);
-            ArtifactId id = genFeat.getId();
-
-            assertEquals("org.foo", id.getGroupId());
-            assertEquals("org.foo.bar", id.getArtifactId());
-            assertEquals("1.2.3-SNAPSHOT", id.getVersion());
-            assertEquals("slingfeature", id.getType());
-            assertEquals("aggregated", id.getClassifier());
-
-            Set<ArtifactId> expectedBundles = new HashSet<>();
-            expectedBundles.add(
-                    new ArtifactId("org.apache.aries", 
"org.apache.aries.util", "1.1.3", null, null));
-            expectedBundles.add(
-                    new ArtifactId("org.apache.sling", "someotherbundle", "1", 
null, null));
-            Set<ArtifactId> actualBundles = new HashSet<>();
-            for (org.apache.sling.feature.Artifact art : genFeat.getBundles()) 
{
-                actualBundles.add(art.getId());
-            }
-            assertEquals(expectedBundles, actualBundles);
-
-            Map<String, Dictionary<String, Object>> expectedConfigs = new 
HashMap<>();
-            expectedConfigs.put("some.pid", new 
Hashtable<>(Collections.singletonMap("x", "y")));
-            Dictionary<String, Object> dict = new Hashtable<>();
-            dict.put("foo", 123L);
-            dict.put("bar", Boolean.TRUE);
-            expectedConfigs.put("another.pid", dict);
-
-            Map<String, Dictionary<String, Object>> actualConfigs = new 
HashMap<>();
-            for (org.apache.sling.feature.Configuration conf : 
genFeat.getConfigurations()) {
-                actualConfigs.put(conf.getPid(), conf.getProperties());
-            }
-            assertEquals(expectedConfigs, actualConfigs);
+        Feature genFeat = featureMap.get(":aggregate:aggregated");
+        assertNotNull(genFeat);
+        ArtifactId id = genFeat.getId();
+
+        assertEquals("org.foo", id.getGroupId());
+        assertEquals("org.foo.bar", id.getArtifactId());
+        assertEquals("1.2.3-SNAPSHOT", id.getVersion());
+        assertEquals("slingfeature", id.getType());
+        assertEquals("aggregated", id.getClassifier());
+
+        Set<ArtifactId> expectedBundles = new HashSet<>();
+        expectedBundles.add(
+                new ArtifactId("org.apache.aries", "org.apache.aries.util", 
"1.1.3", null, null));
+        expectedBundles.add(
+                new ArtifactId("org.apache.sling", "someotherbundle", "1", 
null, null));
+        Set<ArtifactId> actualBundles = new HashSet<>();
+        for (org.apache.sling.feature.Artifact art : genFeat.getBundles()) {
+            actualBundles.add(art.getId());
         }
+        assertEquals(expectedBundles, actualBundles);
+
+        Map<String, Dictionary<String, Object>> expectedConfigs = new 
HashMap<>();
+        expectedConfigs.put("some.pid", new 
Hashtable<>(Collections.singletonMap("x", "y")));
+        Dictionary<String, Object> dict = new Hashtable<>();
+        dict.put("foo", 123L);
+        dict.put("bar", Boolean.TRUE);
+        expectedConfigs.put("another.pid", dict);
+
+        Map<String, Dictionary<String, Object>> actualConfigs = new 
HashMap<>();
+        for (org.apache.sling.feature.Configuration conf : 
genFeat.getConfigurations()) {
+            actualConfigs.put(conf.getPid(), conf.getProperties());
+        }
+        assertEquals(expectedConfigs, actualConfigs);
     }
 
     @Test
@@ -233,6 +234,8 @@ public class AggregateFeaturesTest {
         Mockito.when(mockProj.getArtifact()).thenReturn(parentArtifact);
         Mockito.when(mockProj.getContextValue(Feature.class.getName() + 
"/rawmain.json-cache"))
             .thenReturn(featureMap);
+        Mockito.when(mockProj.getContextValue(Feature.class.getName() + 
"/assembledmain.json-cache"))
+            .thenReturn(featureMap);
 
         AggregateFeatures af = new AggregateFeatures();
         af.aggregateClassifier = "aggregated";
@@ -244,40 +247,38 @@ public class AggregateFeaturesTest {
 
         af.execute();
 
-        File expectedFile = new File(tempDir.toFile(), "/aggregated.json");
-        try (Reader fr = new FileReader(expectedFile)) {
-            Feature genFeat = FeatureJSONReader.read(fr, null);
-            ArtifactId id = genFeat.getId();
+        Feature genFeat = featureMap.get(":aggregate:aggregated");
+        assertNotNull(genFeat);
+        ArtifactId id = genFeat.getId();
 
-            assertEquals("org.foo", id.getGroupId());
-            assertEquals("org.foo.bar", id.getArtifactId());
-            assertEquals("1.2.3-SNAPSHOT", id.getVersion());
-            assertEquals("slingfeature", id.getType());
-            assertEquals("aggregated", id.getClassifier());
+        assertEquals("org.foo", id.getGroupId());
+        assertEquals("org.foo.bar", id.getArtifactId());
+        assertEquals("1.2.3-SNAPSHOT", id.getVersion());
+        assertEquals("slingfeature", id.getType());
+        assertEquals("aggregated", id.getClassifier());
 
-            int numBundlesFound = 0;
-            for (org.apache.sling.feature.Artifact art : genFeat.getBundles()) 
{
-                numBundlesFound++;
-
-                ArtifactId expectedBundleCoords =
-                        new ArtifactId("org.apache.aries", 
"org.apache.aries.util", "1.1.3", null, null);
-                assertEquals(expectedBundleCoords, art.getId());
-            }
-            assertEquals("Expected only one bundle", 1, numBundlesFound);
+        int numBundlesFound = 0;
+        for (org.apache.sling.feature.Artifact art : genFeat.getBundles()) {
+            numBundlesFound++;
 
-            Map<String, Dictionary<String, Object>> expectedConfigs = new 
HashMap<>();
-            expectedConfigs.put("some.pid", new 
Hashtable<>(Collections.singletonMap("x", "y")));
-            Dictionary<String, Object> dict = new Hashtable<>();
-            dict.put("foo", 123L);
-            dict.put("bar", Boolean.TRUE);
-            expectedConfigs.put("another.pid", dict);
-
-            Map<String, Dictionary<String, Object>> actualConfigs = new 
HashMap<>();
-            for (org.apache.sling.feature.Configuration conf : 
genFeat.getConfigurations()) {
-                actualConfigs.put(conf.getPid(), conf.getProperties());
-            }
-            assertEquals(expectedConfigs, actualConfigs);
+            ArtifactId expectedBundleCoords =
+                    new ArtifactId("org.apache.aries", 
"org.apache.aries.util", "1.1.3", null, null);
+            assertEquals(expectedBundleCoords, art.getId());
+        }
+        assertEquals("Expected only one bundle", 1, numBundlesFound);
+
+        Map<String, Dictionary<String, Object>> expectedConfigs = new 
HashMap<>();
+        expectedConfigs.put("some.pid", new 
Hashtable<>(Collections.singletonMap("x", "y")));
+        Dictionary<String, Object> dict = new Hashtable<>();
+        dict.put("foo", 123L);
+        dict.put("bar", Boolean.TRUE);
+        expectedConfigs.put("another.pid", dict);
+
+        Map<String, Dictionary<String, Object>> actualConfigs = new 
HashMap<>();
+        for (org.apache.sling.feature.Configuration conf : 
genFeat.getConfigurations()) {
+            actualConfigs.put(conf.getPid(), conf.getProperties());
         }
+        assertEquals(expectedConfigs, actualConfigs);
     }
 
     //@Test

Reply via email to