You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by an...@apache.org on 2019/08/20 21:53:12 UTC

[sling-org-apache-sling-feature-launcher] branch issues/SLING-8483 created (now 5279ad5)

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

andysch pushed a change to branch issues/SLING-8483
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-launcher.git.


      at 5279ad5  SLING-8483 - Added a priority to the Extension Handler to find the most suitable one

This branch includes the following new commits:

     new 5279ad5  SLING-8483 - Added a priority to the Extension Handler to find the most suitable one

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-launcher] 01/01: SLING-8483 - Added a priority to the Extension Handler to find the most suitable one

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

andysch pushed a commit to branch issues/SLING-8483
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-launcher.git

commit 5279ad5da677be9191903302a4a102d58094e1dd
Author: Andreas Schaefer <sc...@iMac.local>
AuthorDate: Tue Aug 20 14:52:56 2019 -0700

    SLING-8483 - Added a priority to the Extension Handler to find the most suitable one
---
 .../apache/sling/feature/launcher/impl/FeatureProcessor.java  | 11 ++++++++++-
 .../impl/extensions/handlers/ContentPackageHandler.java       |  5 +++++
 .../launcher/impl/extensions/handlers/RepoInitHandler.java    |  5 +++++
 .../feature/launcher/spi/extensions/ExtensionHandler.java     |  6 ++++++
 4 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/feature/launcher/impl/FeatureProcessor.java b/src/main/java/org/apache/sling/feature/launcher/impl/FeatureProcessor.java
index 68facce..2fd5bc7 100644
--- a/src/main/java/org/apache/sling/feature/launcher/impl/FeatureProcessor.java
+++ b/src/main/java/org/apache/sling/feature/launcher/impl/FeatureProcessor.java
@@ -21,11 +21,13 @@ import java.io.InputStreamReader;
 import java.io.Reader;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
 import java.util.ServiceLoader;
 import java.util.Spliterator;
 import java.util.Spliterators;
+import java.util.stream.Collectors;
 import java.util.stream.StreamSupport;
 
 import org.apache.sling.feature.Artifact;
@@ -163,7 +165,14 @@ public class FeatureProcessor {
         }
 
         extensions: for(final Extension ext : app.getExtensions()) {
-            for (ExtensionHandler handler : ServiceLoader.load(ExtensionHandler.class,  FeatureProcessor.class.getClassLoader()))
+            List<ExtensionHandler> extensionHandlerList = new ArrayList<>();
+            for (ExtensionHandler handler : ServiceLoader.load(ExtensionHandler.class,  FeatureProcessor.class.getClassLoader())) {
+                extensionHandlerList.add(handler);
+            }
+            List<ExtensionHandler> prioritizedExtensionHandlerList = extensionHandlerList.stream()
+                .sorted(Comparator.comparingInt(ExtensionHandler::getPriority).reversed())
+                .collect(Collectors.toList());
+            for (ExtensionHandler handler : prioritizedExtensionHandlerList)
             {
                 if (handler.handle(new ExtensionContextImpl(ctx, config.getInstallation(), loadedFeatures), ext)) {
                     continue extensions;
diff --git a/src/main/java/org/apache/sling/feature/launcher/impl/extensions/handlers/ContentPackageHandler.java b/src/main/java/org/apache/sling/feature/launcher/impl/extensions/handlers/ContentPackageHandler.java
index a08061c..825be67 100644
--- a/src/main/java/org/apache/sling/feature/launcher/impl/extensions/handlers/ContentPackageHandler.java
+++ b/src/main/java/org/apache/sling/feature/launcher/impl/extensions/handlers/ContentPackageHandler.java
@@ -27,6 +27,11 @@ import org.apache.sling.feature.launcher.spi.extensions.ExtensionHandler;
 public class ContentPackageHandler implements ExtensionHandler
 {
     @Override
+    public int getPriority() {
+        return FALLBACK_PRIORITY;
+    }
+
+    @Override
     public boolean handle(ExtensionContext context, Extension extension) throws IOException
     {
         if (extension.getType() == ExtensionType.ARTIFACTS
diff --git a/src/main/java/org/apache/sling/feature/launcher/impl/extensions/handlers/RepoInitHandler.java b/src/main/java/org/apache/sling/feature/launcher/impl/extensions/handlers/RepoInitHandler.java
index 34ac652..329148a 100644
--- a/src/main/java/org/apache/sling/feature/launcher/impl/extensions/handlers/RepoInitHandler.java
+++ b/src/main/java/org/apache/sling/feature/launcher/impl/extensions/handlers/RepoInitHandler.java
@@ -29,6 +29,11 @@ public class RepoInitHandler implements ExtensionHandler
     private static final AtomicInteger index = new AtomicInteger(1);
 
     @Override
+    public int getPriority() {
+        return FALLBACK_PRIORITY;
+    }
+
+    @Override
     public boolean handle(ExtensionContext context, Extension extension) throws Exception
     {
         if (extension.getName().equals(Extension.EXTENSION_NAME_REPOINIT)) {
diff --git a/src/main/java/org/apache/sling/feature/launcher/spi/extensions/ExtensionHandler.java b/src/main/java/org/apache/sling/feature/launcher/spi/extensions/ExtensionHandler.java
index acb8347..a4cef73 100644
--- a/src/main/java/org/apache/sling/feature/launcher/spi/extensions/ExtensionHandler.java
+++ b/src/main/java/org/apache/sling/feature/launcher/spi/extensions/ExtensionHandler.java
@@ -20,5 +20,11 @@ import org.apache.sling.feature.Extension;
 
 public interface ExtensionHandler
 {
+    /** Priority for Extension Handlers that are just a fallback instance **/
+    int FALLBACK_PRIORITY = -1;
+
+    /** @return The priority of the Extension Handler to select the most appropriate one. The one with the highest priority is selected **/
+    int getPriority();
+
     public boolean handle(ExtensionContext context, Extension extension) throws Exception;
 }