You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by da...@apache.org on 2018/07/02 14:46:57 UTC

[sling-slingfeature-maven-plugin] branch master updated: Unit test regarding attaching features with classifiers to the project

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

commit 3060481f75ab281d682f022a1f984a1793dbdc75
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Mon Jul 2 15:46:28 2018 +0100

    Unit test regarding attaching features with classifiers to the project
---
 pom.xml                                            |  1 +
 .../sling/feature/maven/FeatureConstants.java      |  4 +-
 .../sling/feature/maven/mojos/AttachFeature.java   |  7 ++-
 .../feature/maven/mojos/AttachFeatureTest.java     | 51 ++++++++++++++++++++++
 .../features/processed/test_a.json                 |  9 ++++
 .../features/processed/test_b.json                 |  8 ++++
 .../features/processed/test_c.json                 |  3 ++
 .../features/processed/unrelated.txt               |  1 +
 8 files changed, 81 insertions(+), 3 deletions(-)

diff --git a/pom.xml b/pom.xml
index 8a97156..d8d7047 100644
--- a/pom.xml
+++ b/pom.xml
@@ -103,6 +103,7 @@
                 <configuration>
                     <excludes>
                         <exclude>src/site/markdown/**</exclude>
+                        <exclude>src/test/resources/**/*.txt</exclude>
                     </excludes>
                 </configuration>
             </plugin>
diff --git a/src/main/java/org/apache/sling/feature/maven/FeatureConstants.java b/src/main/java/org/apache/sling/feature/maven/FeatureConstants.java
index 96a3b2c..e5d1a0b 100644
--- a/src/main/java/org/apache/sling/feature/maven/FeatureConstants.java
+++ b/src/main/java/org/apache/sling/feature/maven/FeatureConstants.java
@@ -18,7 +18,7 @@ package org.apache.sling.feature.maven;
 
 public abstract class FeatureConstants {
 
-    public static final String PACKAGING_FEATURE = "osgifeature";
+    public static final String PACKAGING_FEATURE = "slingfeature";
 
     public static final String PACKAGING_APPLICATION = "osgiapp";
 
@@ -28,5 +28,7 @@ public abstract class FeatureConstants {
 
     public static final String FEATURE_ARTIFACT_NAME = "feature.json";
 
+    public static final String FEATURE_PROCESSED_LOCATION = "/features/processed";
+
     public static final String TEST_FEATURE_ARTIFACT_NAME = "testfeature.json";
 }
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 e0942db..c2c5e00 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
@@ -77,8 +77,12 @@ public class AttachFeature extends AbstractFeatureMojo {
         attach(ProjectHelper.getFeature(this.project), FeatureConstants.FEATURE_ARTIFACT_NAME, FeatureConstants.CLASSIFIER_FEATURE);
         attach(ProjectHelper.getTestFeature(this.project), FeatureConstants.TEST_FEATURE_ARTIFACT_NAME, FeatureConstants.CLASSIFIER_TEST_FEATURE);
 
+        attachClassifierFeatures();
+    }
+
+    void attachClassifierFeatures() throws MojoExecutionException {
         // Find all features that have a classifier and attach each of them
-        String processedFeatures = project.getBuild().getDirectory() + "/features/processed";
+        String processedFeatures = project.getBuild().getDirectory() + FeatureConstants.FEATURE_PROCESSED_LOCATION;
         for (File f : new File(processedFeatures).listFiles((d,f) -> f.endsWith(".json"))) {
             try {
                 Feature feat = FeatureJSONReader.read(new FileReader(f), null, SubstituteVariables.NONE);
@@ -90,6 +94,5 @@ public class AttachFeature extends AbstractFeatureMojo {
                 throw new MojoExecutionException("Unable to attach embedded features", e);
             }
         }
-
     }
 }
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
new file mode 100644
index 0000000..ac76e75
--- /dev/null
+++ b/src/test/java/org/apache/sling/feature/maven/mojos/AttachFeatureTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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;
+
+import org.apache.maven.model.Build;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectHelper;
+import org.apache.sling.feature.maven.FeatureConstants;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import java.io.File;
+
+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 featuresDir = feat_a.getParentFile().getParentFile().getParentFile();
+
+        Build build = new Build();
+        build.setDirectory(featuresDir.getCanonicalPath());
+
+        MavenProject project = new MavenProject();
+        project.setBuild(build);
+
+        AttachFeature af = new AttachFeature();
+        af.project = project;
+
+        MavenProjectHelper helper = Mockito.mock(MavenProjectHelper.class);
+        af.projectHelper = helper;
+
+        af.attachClassifierFeatures();
+        Mockito.verify(helper).attachArtifact(project, FeatureConstants.PACKAGING_FEATURE, "testa", feat_a);
+        Mockito.verify(helper).attachArtifact(project, FeatureConstants.PACKAGING_FEATURE, "testc", feat_c);
+    }
+}
diff --git a/src/test/resources/attach-resources/features/processed/test_a.json b/src/test/resources/attach-resources/features/processed/test_a.json
new file mode 100644
index 0000000..b3832d1
--- /dev/null
+++ b/src/test/resources/attach-resources/features/processed/test_a.json
@@ -0,0 +1,9 @@
+{
+  "id":"testing:test_a:slingfeature:testa:1.0.0",
+  "bundles":[
+    {
+      "id":"org.apache.aries:org.apache.aries.util:1.1.3",
+      "start-level":"20"
+    }
+  ]
+}
diff --git a/src/test/resources/attach-resources/features/processed/test_b.json b/src/test/resources/attach-resources/features/processed/test_b.json
new file mode 100644
index 0000000..4d8b1c2
--- /dev/null
+++ b/src/test/resources/attach-resources/features/processed/test_b.json
@@ -0,0 +1,8 @@
+{
+  "id":"testing:test_b:1.0.0",
+  "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
new file mode 100644
index 0000000..b419720
--- /dev/null
+++ b/src/test/resources/attach-resources/features/processed/test_c.json
@@ -0,0 +1,3 @@
+{
+  "id":"testing:test_c:slingfeature:testc:1.0.0"
+}
diff --git a/src/test/resources/attach-resources/features/processed/unrelated.txt b/src/test/resources/attach-resources/features/processed/unrelated.txt
new file mode 100644
index 0000000..7ccc37f
--- /dev/null
+++ b/src/test/resources/attach-resources/features/processed/unrelated.txt
@@ -0,0 +1 @@
+some unrelated text file
\ No newline at end of file