From commits-return-79621-archive-asf-public=cust-asf.ponee.io@sling.apache.org Thu May 2 13:54:27 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 6839B180671 for ; Thu, 2 May 2019 15:54:27 +0200 (CEST) Received: (qmail 67009 invoked by uid 500); 2 May 2019 13:54:26 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 67000 invoked by uid 99); 2 May 2019 13:54:26 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 May 2019 13:54:26 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 89C88871D3; Thu, 2 May 2019 13:54:26 +0000 (UTC) Date: Thu, 02 May 2019 13:54:26 +0000 To: "commits@sling.apache.org" Subject: [sling-org-apache-sling-feature-launcher] branch master updated: SLING-8386: Make the Launcher implementation and framework artefact configurable and update to felix 6.0.3 as default MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <155680526651.28585.15246422199903778429@gitbox.apache.org> From: pauls@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: sling-org-apache-sling-feature-launcher X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 1d6976eb6cdcd769633a1b7e756eb427b1392297 X-Git-Newrev: c5de9e48f41cf2f4e8abcfd46b20ec4a09238b33 X-Git-Rev: c5de9e48f41cf2f4e8abcfd46b20ec4a09238b33 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated This is an automated email from the ASF dual-hosted git repository. pauls pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-launcher.git The following commit(s) were added to refs/heads/master by this push: new c5de9e4 SLING-8386: Make the Launcher implementation and framework artefact configurable and update to felix 6.0.3 as default c5de9e4 is described below commit c5de9e48f41cf2f4e8abcfd46b20ec4a09238b33 Author: Karl Pauls AuthorDate: Thu May 2 15:54:16 2019 +0200 SLING-8386: Make the Launcher implementation and framework artefact configurable and update to felix 6.0.3 as default --- .../sling/feature/launcher/impl/Bootstrap.java | 27 ++++++++++++++++++---- .../feature/launcher/impl/LauncherConfig.java | 10 ++++++++ .../apache/sling/feature/launcher/impl/Main.java | 13 +++++++---- .../launcher/impl/launchers/AbstractRunner.java | 3 --- .../launcher/impl/launchers/FrameworkLauncher.java | 6 ++++- .../org.apache.sling.feature.launcher.spi.Launcher | 1 + 6 files changed, 47 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/apache/sling/feature/launcher/impl/Bootstrap.java b/src/main/java/org/apache/sling/feature/launcher/impl/Bootstrap.java index fc498d6..400860b 100644 --- a/src/main/java/org/apache/sling/feature/launcher/impl/Bootstrap.java +++ b/src/main/java/org/apache/sling/feature/launcher/impl/Bootstrap.java @@ -24,8 +24,10 @@ import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.ServiceLoader; import org.apache.sling.feature.ArtifactId; import org.apache.sling.feature.Feature; @@ -60,7 +62,7 @@ public class Bootstrap { * @throws IllegalArgumentException If the provided version is invalid */ private ArtifactId getFelixFrameworkId(final String version) { - return new ArtifactId("org.apache.felix", "org.apache.felix.framework", version != null ? version : "6.0.1", + return new ArtifactId("org.apache.felix", "org.apache.felix.framework", version != null ? version : "6.0.3", null, null); } @@ -111,7 +113,13 @@ public class Bootstrap { this.logger.info("Initializing..."); prepare(); - final Launcher launcher = new FrameworkLauncher(); + Iterator iterator = ServiceLoader.load(Launcher.class).iterator(); + if (!iterator.hasNext()) { + this.logger.error("Unable to find launcher service."); + System.exit(1); + } + + final Launcher launcher = iterator.next(); try (ArtifactManager artifactManager = ArtifactManager.getArtifactManager(this.config)) { @@ -148,7 +156,9 @@ public class Bootstrap { } }; - launcher.prepare(ctx, getFelixFrameworkId(this.config.getFrameworkVersion()), app); + launcher.prepare(ctx, this.config.getFrameworkArtifact() != null ? + ArtifactId.fromMvnId(this.config.getFrameworkArtifact()) : + getFelixFrameworkId(this.config.getFrameworkVersion()), app); FeatureProcessor.prepareLauncher(ctx, this.config, app, loadedFeatures); @@ -255,7 +265,7 @@ public class Bootstrap { installation.getFrameworkProperties().put(START_LEVEL_PROP, "30"); } - while (launcher.run(installation, createClassLoader(installation)) == FrameworkEvent.STOPPED_SYSTEM_REFRESHED) { + while (launcher.run(installation, createClassLoader(installation, launcher.getClass().getProtectionDomain().getCodeSource().getLocation())) == FrameworkEvent.STOPPED_SYSTEM_REFRESHED) { this.logger.info("Framework restart due to extension refresh"); } } @@ -266,7 +276,7 @@ public class Bootstrap { * @return The classloader. * @throws Exception If anything goes wrong */ - public ClassLoader createClassLoader(final Installation installation) throws Exception { + public ClassLoader createClassLoader(final Installation installation, URL... extra) throws Exception { final List list = new ArrayList<>(); for(final File f : installation.getAppJars()) { try { @@ -275,8 +285,15 @@ public class Bootstrap { // ignore } } + list.add(Bootstrap.class.getProtectionDomain().getCodeSource().getLocation()); + if (extra != null) { + for (URL url : extra) { + list.add(url); + } + } + final URL[] urls = list.toArray(new URL[list.size()]); if (this.logger.isDebugEnabled()) { diff --git a/src/main/java/org/apache/sling/feature/launcher/impl/LauncherConfig.java b/src/main/java/org/apache/sling/feature/launcher/impl/LauncherConfig.java index dfc8ef4..c011385 100644 --- a/src/main/java/org/apache/sling/feature/launcher/impl/LauncherConfig.java +++ b/src/main/java/org/apache/sling/feature/launcher/impl/LauncherConfig.java @@ -51,6 +51,8 @@ public class LauncherConfig private volatile String frameworkVersion; + private volatile String frameworkArtifact; + /** * Create a new configuration object. * Set the default values @@ -113,4 +115,12 @@ public class LauncherConfig public void setFrameworkVersion(final String frameworkVersion) { this.frameworkVersion = frameworkVersion; } + + public String getFrameworkArtifact() { + return frameworkArtifact; + } + + public void setFrameworkArtifact(final String frameworkArtifact) { + this.frameworkArtifact = frameworkArtifact; + } } diff --git a/src/main/java/org/apache/sling/feature/launcher/impl/Main.java b/src/main/java/org/apache/sling/feature/launcher/impl/Main.java index 0a3122b..e14321a 100644 --- a/src/main/java/org/apache/sling/feature/launcher/impl/Main.java +++ b/src/main/java/org/apache/sling/feature/launcher/impl/Main.java @@ -70,7 +70,8 @@ public class Main { final Option cacheOption = new Option("c", true, "Set cache dir"); final Option homeOption = new Option("p", true, "Set home dir"); - final Option frameworkOption = new Option("fv", true, "Set felix framework version"); + final Option frameworkVersionOption = new Option("fv", true, "Set felix framework version"); + final Option frameworkArtifactOption = new Option("fa", true, "Set framework artifact (overrides felix framework version)"); options.addOption(artifactClashOverride); options.addOption(repoOption); @@ -80,7 +81,8 @@ public class Main { options.addOption(debugOption); options.addOption(cacheOption); options.addOption(homeOption); - options.addOption(frameworkOption); + options.addOption(frameworkVersionOption); + options.addOption(frameworkArtifactOption); final CommandLineParser clp = new BasicParser(); try { @@ -124,8 +126,11 @@ public class Main { if (cl.hasOption(homeOption.getOpt())) { config.setHomeDirectory(new File(cl.getOptionValue(homeOption.getOpt()))); } - if (cl.hasOption(frameworkOption.getOpt())) { - config.setFrameworkVersion(cl.getOptionValue(frameworkOption.getOpt())); + if (cl.hasOption(frameworkVersionOption.getOpt())) { + config.setFrameworkVersion(cl.getOptionValue(frameworkVersionOption.getOpt())); + } + if (cl.hasOption(frameworkArtifactOption.getOpt())) { + config.setFrameworkArtifact(cl.getOptionValue(frameworkArtifactOption.getOpt())); } } catch ( final ParseException pe) { Main.LOG().error("Unable to parse command line: {}", pe.getMessage(), pe); diff --git a/src/main/java/org/apache/sling/feature/launcher/impl/launchers/AbstractRunner.java b/src/main/java/org/apache/sling/feature/launcher/impl/launchers/AbstractRunner.java index 981f887..af15614 100644 --- a/src/main/java/org/apache/sling/feature/launcher/impl/launchers/AbstractRunner.java +++ b/src/main/java/org/apache/sling/feature/launcher/impl/launchers/AbstractRunner.java @@ -32,9 +32,6 @@ import java.util.List; import java.util.Map; import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import org.osgi.framework.Bundle; diff --git a/src/main/java/org/apache/sling/feature/launcher/impl/launchers/FrameworkLauncher.java b/src/main/java/org/apache/sling/feature/launcher/impl/launchers/FrameworkLauncher.java index 503cbdd..22b4c32 100644 --- a/src/main/java/org/apache/sling/feature/launcher/impl/launchers/FrameworkLauncher.java +++ b/src/main/java/org/apache/sling/feature/launcher/impl/launchers/FrameworkLauncher.java @@ -90,7 +90,7 @@ public class FrameworkLauncher implements Launcher { context.getLogger().debug(""); } - final Class runnerClass = cl.loadClass(FrameworkRunner.class.getName()); + final Class runnerClass = cl.loadClass(getFrameworkRunnerClass()); final Constructor constructor = runnerClass.getDeclaredConstructor(Map.class, Map.class, List.class, List.class); constructor.setAccessible(true); @@ -100,4 +100,8 @@ public class FrameworkLauncher implements Launcher { return restart.call(); // nothing else to do, constructor starts everything } + + protected String getFrameworkRunnerClass() { + return FrameworkRunner.class.getName(); + } } diff --git a/src/main/resources/META-INF/services/org.apache.sling.feature.launcher.spi.Launcher b/src/main/resources/META-INF/services/org.apache.sling.feature.launcher.spi.Launcher new file mode 100644 index 0000000..21483ff --- /dev/null +++ b/src/main/resources/META-INF/services/org.apache.sling.feature.launcher.spi.Launcher @@ -0,0 +1 @@ +org.apache.sling.feature.launcher.impl.launchers.FrameworkLauncher \ No newline at end of file