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 d9d1fef  Expanded unit test regarding attaching features with 
classifiers to the project
d9d1fef is described below

commit d9d1fef193f1edf5244a378998d9c4bf7213fe03
Author: David Bosschaert <[email protected]>
AuthorDate: Tue Jul 3 09:44:24 2018 +0100

    Expanded unit test regarding attaching features with classifiers to the 
project
---
 pom.xml                                                   |  2 +-
 .../apache/sling/feature/maven/mojos/AttachFeature.java   | 15 ++++++++++++++-
 .../sling/feature/maven/mojos/AttachFeatureTest.java      |  8 ++++++--
 .../attach-resources/features/processed/test_a.json       |  2 +-
 .../attach-resources/features/processed/test_b.json       |  2 +-
 .../attach-resources/features/processed/test_c.json       |  2 +-
 .../attach-resources/features/processed/test_d.json       |  3 +++
 .../attach-resources/features/processed/test_e.json       |  3 +++
 .../attach-resources/features/processed/test_f.json       |  3 +++
 9 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/pom.xml b/pom.xml
index d8d7047..c9a2f22 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,7 +22,7 @@
     </parent>
 
     <artifactId>slingfeature-maven-plugin</artifactId>
-    <version>0.2.0-SNAPSHOT</version>
+    <version>0.1.9-T20180702155700-3060481</version>
     <packaging>maven-plugin</packaging>
 
     <name>Apache Sling OSGi Feature Maven Plugin</name>
diff --git 
a/src/main/java/org/apache/sling/feature/maven/mojos/AttachFeature.java 
b/src/main/java/org/apache/sling/feature/maven/mojos/AttachFeature.java
index c2c5e00..2c75baa 100644
--- a/src/main/java/org/apache/sling/feature/maven/mojos/AttachFeature.java
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/AttachFeature.java
@@ -21,6 +21,7 @@ import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.ResolutionScope;
+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.io.json.FeatureJSONReader.SubstituteVariables;
@@ -65,6 +66,8 @@ public class AttachFeature extends AbstractFeatureMojo {
                  && (FeatureConstants.CLASSIFIER_FEATURE.equals(classifier))) {
                 project.getArtifact().setFile(outputFile);
             } else {
+                // TODO do we need to check that the feature's GAV matches the 
project's GAV?
+
                 // otherwise attach it as an additional artifact
                 projectHelper.attachArtifact(project, 
FeatureConstants.PACKAGING_FEATURE,
                     classifier, outputFile);
@@ -86,7 +89,17 @@ public class AttachFeature extends AbstractFeatureMojo {
         for (File f : new File(processedFeatures).listFiles((d,f) -> 
f.endsWith(".json"))) {
             try {
                 Feature feat = FeatureJSONReader.read(new FileReader(f), null, 
SubstituteVariables.NONE);
-                String classifier = feat.getId().getClassifier();
+
+                ArtifactId aid = feat.getId();
+                // Only attach features that have the same GAV, they will 
differ in classifier
+                if (!aid.getGroupId().equals(project.getGroupId()))
+                    continue;
+                if (!aid.getArtifactId().equals(project.getArtifactId()))
+                    continue;
+                if (!aid.getVersion().equals(project.getVersion()))
+                    continue;
+
+                String classifier = aid.getClassifier();
                 if (classifier == null || classifier.length() == 0)
                     continue;
                 projectHelper.attachArtifact(project, 
FeatureConstants.PACKAGING_FEATURE, classifier, f);
diff --git 
a/src/test/java/org/apache/sling/feature/maven/mojos/AttachFeatureTest.java 
b/src/test/java/org/apache/sling/feature/maven/mojos/AttachFeatureTest.java
index ac76e75..949e945 100644
--- a/src/test/java/org/apache/sling/feature/maven/mojos/AttachFeatureTest.java
+++ b/src/test/java/org/apache/sling/feature/maven/mojos/AttachFeatureTest.java
@@ -29,13 +29,16 @@ public class AttachFeatureTest {
     @Test
     public void testAttachArtifacts() throws Exception {
         File feat_a = new 
File(getClass().getResource("/attach-resources/features/processed/test_a.json").toURI());
-        File feat_c = new 
File(getClass().getResource("/attach-resources/features/processed/test_c.json").toURI());
+        File feat_d = new 
File(getClass().getResource("/attach-resources/features/processed/test_d.json").toURI());
         File featuresDir = 
feat_a.getParentFile().getParentFile().getParentFile();
 
         Build build = new Build();
         build.setDirectory(featuresDir.getCanonicalPath());
 
         MavenProject project = new MavenProject();
+        project.setGroupId("testing");
+        project.setArtifactId("test");
+        project.setVersion("1.0.1");
         project.setBuild(build);
 
         AttachFeature af = new AttachFeature();
@@ -46,6 +49,7 @@ public class AttachFeatureTest {
 
         af.attachClassifierFeatures();
         Mockito.verify(helper).attachArtifact(project, 
FeatureConstants.PACKAGING_FEATURE, "testa", feat_a);
-        Mockito.verify(helper).attachArtifact(project, 
FeatureConstants.PACKAGING_FEATURE, "testc", feat_c);
+        Mockito.verify(helper).attachArtifact(project, 
FeatureConstants.PACKAGING_FEATURE, "testd", feat_d);
+        Mockito.verifyNoMoreInteractions(helper);
     }
 }
diff --git a/src/test/resources/attach-resources/features/processed/test_a.json 
b/src/test/resources/attach-resources/features/processed/test_a.json
index b3832d1..c16ba64 100644
--- a/src/test/resources/attach-resources/features/processed/test_a.json
+++ b/src/test/resources/attach-resources/features/processed/test_a.json
@@ -1,5 +1,5 @@
 {
-  "id":"testing:test_a:slingfeature:testa:1.0.0",
+  "id":"testing:test:slingfeature:testa:1.0.1",
   "bundles":[
     {
       "id":"org.apache.aries:org.apache.aries.util:1.1.3",
diff --git a/src/test/resources/attach-resources/features/processed/test_b.json 
b/src/test/resources/attach-resources/features/processed/test_b.json
index 4d8b1c2..09a197a 100644
--- a/src/test/resources/attach-resources/features/processed/test_b.json
+++ b/src/test/resources/attach-resources/features/processed/test_b.json
@@ -1,5 +1,5 @@
 {
-  "id":"testing:test_b:1.0.0",
+  "id":"testing:test:1.0.1",
   "configurations": {
     "some.pid": {
       "x": "y"
diff --git a/src/test/resources/attach-resources/features/processed/test_c.json 
b/src/test/resources/attach-resources/features/processed/test_c.json
index b419720..76262d5 100644
--- a/src/test/resources/attach-resources/features/processed/test_c.json
+++ b/src/test/resources/attach-resources/features/processed/test_c.json
@@ -1,3 +1,3 @@
 {
-  "id":"testing:test_c:slingfeature:testc:1.0.0"
+  "id":"testing:test_c:slingfeature:testc:1.0.1"
 }
diff --git a/src/test/resources/attach-resources/features/processed/test_d.json 
b/src/test/resources/attach-resources/features/processed/test_d.json
new file mode 100644
index 0000000..373da07
--- /dev/null
+++ b/src/test/resources/attach-resources/features/processed/test_d.json
@@ -0,0 +1,3 @@
+{
+  "id":"testing:test:slingfeature:testd:1.0.1"
+}
diff --git a/src/test/resources/attach-resources/features/processed/test_e.json 
b/src/test/resources/attach-resources/features/processed/test_e.json
new file mode 100644
index 0000000..1c22d6e
--- /dev/null
+++ b/src/test/resources/attach-resources/features/processed/test_e.json
@@ -0,0 +1,3 @@
+{
+  "id":"toasting:test:slingfeature:teste:1.0.1"
+}
diff --git a/src/test/resources/attach-resources/features/processed/test_f.json 
b/src/test/resources/attach-resources/features/processed/test_f.json
new file mode 100644
index 0000000..a68009a
--- /dev/null
+++ b/src/test/resources/attach-resources/features/processed/test_f.json
@@ -0,0 +1,3 @@
+{
+  "id":"testing:test:slingfeature:testf:2.0.2"
+}

Reply via email to