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 3f304cb  SLING-8214 Provide a way to handle bundles with same symbolic 
name but different mvn group/artifact ids
3f304cb is described below

commit 3f304cb0332968cf0a057df1a4508e8d5ccfce41
Author: David Bosschaert <[email protected]>
AuthorDate: Tue Jan 22 10:48:16 2019 +0000

    SLING-8214 Provide a way to handle bundles with same symbolic name but 
different mvn group/artifact ids
    
    These test the functionality implemented in the core feature model from
    the Maven plugin
---
 .../maven/mojos/AggregateFeaturesMojoTest.java     | 99 ++++++++++++++++++++++
 .../resources/aggregate-features/dir6/test_c.json  |  6 ++
 .../resources/aggregate-features/dir6/test_d.json  |  9 ++
 3 files changed, 114 insertions(+)

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 a7faac6..0ac8113 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
@@ -590,6 +590,105 @@ public class AggregateFeaturesMojoTest {
                 ArtifactId.fromMvnId("org.apache.sling:somebundle:1.0.0"))));
     }
 
+    @Test
+    public void testOverrideWithManualArtifactIDNoOverride() throws Exception {
+        File featuresDir = new File(
+                getClass().getResource("/aggregate-features/dir6").getFile());
+
+        Map<String, Feature> featureMap = new HashMap<>();
+        for (File f : featuresDir.listFiles((d,f) -> f.endsWith(".json"))) {
+            Feature feat = FeatureJSONReader.read(new FileReader(f), null);
+            featureMap.put(f.getAbsolutePath(), feat);
+        }
+
+        Aggregate ag = new Aggregate();
+        ag.setFilesInclude("*.json");
+        ag.classifier = "myagg";
+
+        Build mockBuild = Mockito.mock(Build.class);
+        Mockito.when(mockBuild.getDirectory()).thenReturn(tempDir.toString());
+
+        Artifact parentArt = createMockArtifact();
+        MavenProject mockProj = Mockito.mock(MavenProject.class);
+        Mockito.when(mockProj.getBuild()).thenReturn(mockBuild);
+        Mockito.when(mockProj.getGroupId()).thenReturn("org.apache.sling");
+        
Mockito.when(mockProj.getArtifactId()).thenReturn("org.apache.sling.test");
+        Mockito.when(mockProj.getVersion()).thenReturn("1.0.1");
+        Mockito.when(mockProj.getArtifact()).thenReturn(parentArt);
+        Mockito.when(mockProj.getContextValue(Feature.class.getName() + 
"/rawmain.json-cache"))
+            .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();
+        af.aggregates = Collections.singletonList(ag);
+        af.project = mockProj;
+        af.projectHelper = new DefaultMavenProjectHelper();
+        af.features = featuresDir;
+        af.handlerConfiguration = new HashMap<>();
+
+        try {
+            af.execute();
+            fail("Should have thrown an exception as "
+                    + "org.apache.sling:somebundle has as alias 
org.apache.sling:myotherbundle");
+        } catch (Exception e) {
+            String msg = e.getMessage();
+            assertTrue(msg.contains("override rule required"));
+            assertTrue(msg.contains("org.apache.sling:myotherbundle:"));
+            assertTrue(msg.contains("org.apache.sling:somebundle:"));
+        }
+    }
+
+    @Test
+    public void testOverrideWithManualArtifactID() throws Exception {
+        File featuresDir = new File(
+                getClass().getResource("/aggregate-features/dir6").getFile());
+
+        Map<String, Feature> featureMap = new HashMap<>();
+        for (File f : featuresDir.listFiles((d,f) -> f.endsWith(".json"))) {
+            Feature feat = FeatureJSONReader.read(new FileReader(f), null);
+            featureMap.put(f.getAbsolutePath(), feat);
+        }
+
+        Aggregate ag = new Aggregate();
+        ag.setFilesInclude("test_c.json");
+        ag.setFilesInclude("test_d.json");
+        ag.classifier = "myagg";
+        ag.artifactsOverrides = 
Arrays.asList("org.apache.sling:myotherbundle:LATEST");
+
+        Build mockBuild = Mockito.mock(Build.class);
+        Mockito.when(mockBuild.getDirectory()).thenReturn(tempDir.toString());
+
+        Artifact parentArt = createMockArtifact();
+        MavenProject mockProj = Mockito.mock(MavenProject.class);
+        Mockito.when(mockProj.getBuild()).thenReturn(mockBuild);
+        Mockito.when(mockProj.getGroupId()).thenReturn("org.apache.sling");
+        
Mockito.when(mockProj.getArtifactId()).thenReturn("org.apache.sling.test");
+        Mockito.when(mockProj.getVersion()).thenReturn("1.0.1");
+        Mockito.when(mockProj.getArtifact()).thenReturn(parentArt);
+        Mockito.when(mockProj.getContextValue(Feature.class.getName() + 
"/rawmain.json-cache"))
+            .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();
+        af.aggregates = Collections.singletonList(ag);
+        af.project = mockProj;
+        af.projectHelper = new DefaultMavenProjectHelper();
+        af.features = featuresDir;
+        af.handlerConfiguration = new HashMap<>();
+
+        af.execute();
+
+        Feature genFeat = featureMap.get(":aggregate:myagg");
+        Bundles bundles = genFeat.getBundles();
+        assertEquals(1, bundles.size());
+        assertTrue(bundles.contains(new org.apache.sling.feature.Artifact(
+                ArtifactId.fromMvnId("org.apache.sling:somebundle:1.0.0"))));
+    }
+
     private Artifact createMockArtifact() {
         Artifact parentArtifact = Mockito.mock(Artifact.class);
         Mockito.when(parentArtifact.getGroupId()).thenReturn("gid");
diff --git a/src/test/resources/aggregate-features/dir6/test_c.json 
b/src/test/resources/aggregate-features/dir6/test_c.json
new file mode 100644
index 0000000..4232bb8
--- /dev/null
+++ b/src/test/resources/aggregate-features/dir6/test_c.json
@@ -0,0 +1,6 @@
+{
+  "id":"test:test:1.0.0:c:slingosgifeature",
+  "bundles":[
+    "org.apache.sling:myotherbundle:3"
+  ]
+}
diff --git a/src/test/resources/aggregate-features/dir6/test_d.json 
b/src/test/resources/aggregate-features/dir6/test_d.json
new file mode 100644
index 0000000..be0f48a
--- /dev/null
+++ b/src/test/resources/aggregate-features/dir6/test_d.json
@@ -0,0 +1,9 @@
+{
+  "id":"test:test:1.0.0:d:slingosgifeature",
+  "bundles":[
+    {
+      "id": "org.apache.sling:somebundle:1.0.0",
+      "alias": "org.apache.sling:myotherbundle"
+    }
+  ]
+}

Reply via email to