You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by pa...@apache.org on 2019/05/02 13:54:26 UTC
[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
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 <ka...@gmail.com>
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<Launcher> 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<URL> 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