You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by gh...@apache.org on 2019/07/09 08:32:16 UTC

[sling-org-apache-sling-feature-cpconverter] branch feature/SLING-8567-respect-start-level created (now 424e121)

This is an automated email from the ASF dual-hosted git repository.

ghenzler pushed a change to branch feature/SLING-8567-respect-start-level
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-cpconverter.git.


      at 424e121  SLING-8567 respect start levels from JCR path and translate to feature model start-order if present

This branch includes the following new commits:

     new 424e121  SLING-8567 respect start levels from JCR path and translate to feature model start-order if present

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[sling-org-apache-sling-feature-cpconverter] 01/01: SLING-8567 respect start levels from JCR path and translate to feature model start-order if present

Posted by gh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ghenzler pushed a commit to branch feature/SLING-8567-respect-start-level
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-cpconverter.git

commit 424e121130b75f296a2b327b01e4796468c35602
Author: georg.henzler <ge...@netcentric.biz>
AuthorDate: Tue Jul 9 10:31:33 2019 +0200

    SLING-8567 respect start levels from JCR path and translate to feature
    model start-order if present
---
 .../features/DefaultFeaturesManager.java           |   7 ++++++-
 .../cpconverter/features/FeaturesManager.java      |   2 ++
 .../cpconverter/handlers/BundleEntryHandler.java   |  23 +++++++++++++++------
 .../handlers/BundleEntryHandlerTest.java           |  16 +++++++++-----
 .../apps/asd/install.author/9/test-framework.jar   | Bin 0 -> 13288 bytes
 .../jcr_root/apps/asd/install/9/test-framework.jar | Bin 0 -> 13288 bytes
 6 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/cpconverter/features/DefaultFeaturesManager.java b/src/main/java/org/apache/sling/feature/cpconverter/features/DefaultFeaturesManager.java
index f805eef..1a16252 100644
--- a/src/main/java/org/apache/sling/feature/cpconverter/features/DefaultFeaturesManager.java
+++ b/src/main/java/org/apache/sling/feature/cpconverter/features/DefaultFeaturesManager.java
@@ -110,6 +110,10 @@ public class DefaultFeaturesManager implements FeaturesManager {
     }
 
     public void addArtifact(String runMode, ArtifactId id) {
+        addArtifact(runMode, id, null);
+    }
+
+    public void addArtifact(String runMode, ArtifactId id, Integer startOrder) {
         requireNonNull(id, "Artifact can not be attached to a feature without specifying a valid ArtifactId.");
 
         Artifact artifact = new Artifact(id);
@@ -128,7 +132,8 @@ public class DefaultFeaturesManager implements FeaturesManager {
 
             artifacts = extension.getArtifacts();
         } else {
-            artifact.setStartOrder(bundlesStartOrder);
+            int startOrderForBundle = startOrder != null ? startOrder.intValue() : bundlesStartOrder;
+            artifact.setStartOrder(startOrderForBundle);
             artifacts = targetFeature.getBundles();
         }
 
diff --git a/src/main/java/org/apache/sling/feature/cpconverter/features/FeaturesManager.java b/src/main/java/org/apache/sling/feature/cpconverter/features/FeaturesManager.java
index 30851be..9319d26 100644
--- a/src/main/java/org/apache/sling/feature/cpconverter/features/FeaturesManager.java
+++ b/src/main/java/org/apache/sling/feature/cpconverter/features/FeaturesManager.java
@@ -31,6 +31,8 @@ public interface FeaturesManager {
 
     void addArtifact(String runMode, ArtifactId id);
 
+    void addArtifact(String runMode, ArtifactId id, Integer startOrder);
+
     void addConfiguration(String runMode, String pid, Dictionary<String, Object> configurationProperties);
 
     void serialize() throws Exception;
diff --git a/src/main/java/org/apache/sling/feature/cpconverter/handlers/BundleEntryHandler.java b/src/main/java/org/apache/sling/feature/cpconverter/handlers/BundleEntryHandler.java
index e757de0..c5eee53 100644
--- a/src/main/java/org/apache/sling/feature/cpconverter/handlers/BundleEntryHandler.java
+++ b/src/main/java/org/apache/sling/feature/cpconverter/handlers/BundleEntryHandler.java
@@ -33,6 +33,7 @@ import org.apache.jackrabbit.vault.fs.io.Archive.Entry;
 import org.apache.sling.feature.ArtifactId;
 import org.apache.sling.feature.cpconverter.ContentPackage2FeatureModelConverter;
 import org.apache.sling.feature.cpconverter.artifacts.InputStreamArtifactWriter;
+import org.codehaus.plexus.util.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -57,7 +58,7 @@ public final class BundleEntryHandler extends AbstractRegexEntryHandler {
     private final Pattern pomPropertiesPattern = Pattern.compile("META-INF/maven/[^/]+/[^/]+/pom.properties");
 
     public BundleEntryHandler() {
-        super("/jcr_root/(?:apps|libs)/.+/install(\\.([^/]+))?/.+\\.jar");
+        super("/jcr_root/(?:apps|libs)/.+/install(?:\\.([^/]+))?/(?:([0-9]+)/)?.+\\.jar");
     }
 
     @Override
@@ -87,11 +88,9 @@ public final class BundleEntryHandler extends AbstractRegexEntryHandler {
 
         Matcher matcher = getPattern().matcher(path);
         String runMode = null;
+        Integer startLevel = null;
         // we are pretty sure it matches, here
-        if (matcher.matches()) {
-            // there is a specified RunMode
-            runMode = matcher.group(2);
-        } else {
+        if (!matcher.matches()) {
             throw new IllegalStateException("Something went terribly wrong: pattern '"
                                             + getPattern().pattern()
                                             + "' should have matched already with path '"
@@ -99,12 +98,24 @@ public final class BundleEntryHandler extends AbstractRegexEntryHandler {
                                             + "' but it does not, currently");
         }
 
+        if (StringUtils.isNotBlank(matcher.group(1))) {
+            // there is a specified RunMode
+            runMode = matcher.group(1);
+            logger.debug("Runmode {} was extracted from path {}", runMode, path);
+        }
+
+        if (StringUtils.isNotBlank(matcher.group(2))) {
+            // there is a specified Start Level
+            startLevel = Integer.parseInt(matcher.group(2)); // NumberFormatException impossible due to RegEx
+            logger.debug("Start level {} was extracted from path {}", startLevel, path);
+        }
+
         try (InputStream input = archive.openInputStream(entry)) {
             ArtifactId id = new ArtifactId(groupId, artifactId, version, classifier, JAR_TYPE);
 
             converter.getArtifactsDeployer().deploy(new InputStreamArtifactWriter(input), id);
 
-            converter.getFeaturesManager().addArtifact(runMode, id);
+            converter.getFeaturesManager().addArtifact(runMode, id, startLevel);
         }
     }
 
diff --git a/src/test/java/org/apache/sling/feature/cpconverter/handlers/BundleEntryHandlerTest.java b/src/test/java/org/apache/sling/feature/cpconverter/handlers/BundleEntryHandlerTest.java
index 23c9edf..ae2031d 100644
--- a/src/test/java/org/apache/sling/feature/cpconverter/handlers/BundleEntryHandlerTest.java
+++ b/src/test/java/org/apache/sling/feature/cpconverter/handlers/BundleEntryHandlerTest.java
@@ -53,9 +53,12 @@ public final class BundleEntryHandlerTest {
 
     private final EntryHandler bundleEntryHandler;
 
-    public BundleEntryHandlerTest(String bundleLocation, EntryHandler bundleEntryHandler) {
+    private final int startOrder;
+
+    public BundleEntryHandlerTest(String bundleLocation, EntryHandler bundleEntryHandler, int startOrder) {
         this.bundleLocation = bundleLocation;
         this.bundleEntryHandler = bundleEntryHandler;
+        this.startOrder = startOrder;
     }
 
     @Test
@@ -108,6 +111,7 @@ public final class BundleEntryHandlerTest {
         assertFalse(featuresManager.getTargetFeature().getBundles().isEmpty());
         assertEquals(1, feature.getBundles().size());
         assertEquals("org.apache.felix:org.apache.felix.framework:6.0.1", feature.getBundles().get(0).getId().toMvnId());
+        assertEquals(startOrder, feature.getBundles().get(0).getStartOrder());
     }
 
     @Parameters
@@ -115,10 +119,12 @@ public final class BundleEntryHandlerTest {
         final BundleEntryHandler bundleEntryHandler = new BundleEntryHandler();
 
         return Arrays.asList(new Object[][] {
-            { "/jcr_root/apps/asd/install/test-framework-no-pom.jar", bundleEntryHandler },
-            { "/jcr_root/apps/asd/install/test-framework.jar", bundleEntryHandler },
-            { "/jcr_root/apps/asd/install.author/test-framework.jar", bundleEntryHandler },
-            { "/jcr_root/apps/asd/install.publish/test-framework.jar", bundleEntryHandler }
+                { "/jcr_root/apps/asd/install/test-framework-no-pom.jar", bundleEntryHandler, 20 },
+                { "/jcr_root/apps/asd/install/test-framework.jar", bundleEntryHandler, 20 },
+                { "/jcr_root/apps/asd/install/9/test-framework.jar", bundleEntryHandler, 9 },
+                { "/jcr_root/apps/asd/install.author/test-framework.jar", bundleEntryHandler, 20 },
+                { "/jcr_root/apps/asd/install.author/9/test-framework.jar", bundleEntryHandler, 9 },
+                { "/jcr_root/apps/asd/install.publish/test-framework.jar", bundleEntryHandler, 20 }
         });
     }
 
diff --git a/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/apps/asd/install.author/9/test-framework.jar b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/apps/asd/install.author/9/test-framework.jar
new file mode 100644
index 0000000..9ce022d
Binary files /dev/null and b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/apps/asd/install.author/9/test-framework.jar differ
diff --git a/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/apps/asd/install/9/test-framework.jar b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/apps/asd/install/9/test-framework.jar
new file mode 100644
index 0000000..9ce022d
Binary files /dev/null and b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/apps/asd/install/9/test-framework.jar differ