You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:25:00 UTC
[sling-org-apache-sling-crankstart-launcher] 03/31: Get OSGi
dependencies from Maven repository as well
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.crankstart.launcher-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-crankstart-launcher.git
commit 3ae1a28837db5cc834682f7058e3bdc13e07461e
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Tue Apr 22 15:38:20 2014 +0000
Get OSGi dependencies from Maven repository as well
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/crankstart/launcher@1589176 13f79535-47bb-0310-9956-ffa450edef68
---
default.crank.txt | 31 ++++++---
pom.xml | 25 ++-----
.../launcher/CrankstartFileProcessor.java | 81 ----------------------
.../org/apache/sling/crankstart/launcher/Main.java | 40 +++++++++--
.../org/apache/sling/crankstart/MavenUrlTest.java | 35 ----------
5 files changed, 64 insertions(+), 148 deletions(-)
diff --git a/default.crank.txt b/default.crank.txt
index 3d581f0..7116683 100644
--- a/default.crank.txt
+++ b/default.crank.txt
@@ -1,21 +1,32 @@
# Minimal webconsole example for the Sling crankstart launcher
-# OSGi framework properties
+# Set bootstrap classpath, mvn: protocol can be used
+classpath mvn:org.apache.felix/org.apache.felix.framework/4.4.0
+classpath mvn:org.osgi/org.osgi.compendium/4.2.0
+classpath mvn:org.slf4j/slf4j-api/1.6.2
+classpath mvn:org.slf4j/slf4j-simple/1.6.2
+classpath mvn:org.ops4j.pax.url/pax-url-aether/1.6.0
+classpath mvn:org.ops4j.pax.url/pax-url-commons/1.6.0
+
+# Except the bootstrap launcher, crankstart jars are also provided via classpath
+classpath mvn:org.apache.sling/org.apache.sling.crankstart.core/0.0.1-SNAPSHOT
+classpath mvn:org.apache.sling/org.apache.sling.crankstart.api/0.0.1-SNAPSHOT
+
+# Set OSGi framework properties
osgi.property org.osgi.service.http.port 1234
# Once OSGi properties are set, start the framework
start.framework
# Install a minimal set of bundles for now, just to
-# demonstrate that we can start the webconsole
-# Crankstart gets bundles from a Maven repository, which
-# is not configurable for now.
-bundle org.apache.felix/org.apache.felix.configadmin/1.2.8
-bundle org.apache.felix/org.apache.felix.http.jetty/2.2.0
-bundle org.apache.felix/org.apache.felix.metatype/1.0.4
-bundle org.apache.felix/org.apache.felix.scr/1.6.0
-bundle org.apache.felix/org.apache.felix.webconsole/3.1.6
-bundle org.apache.sling/org.apache.sling.commons.log/2.1.2
+# demonstrate that we can start the webconsole.
+# mvn: protocol can be used.
+bundle mvn:org.apache.felix/org.apache.felix.configadmin/1.2.8
+bundle mvn:org.apache.felix/org.apache.felix.http.jetty/2.2.0
+bundle mvn:org.apache.felix/org.apache.felix.metatype/1.0.4
+bundle mvn:org.apache.felix/org.apache.felix.scr/1.6.0
+bundle mvn:org.apache.felix/org.apache.felix.webconsole/3.1.6
+bundle mvn:org.apache.sling/org.apache.sling.commons.log/2.1.2
# Start all bundles and log a friendly message
start.all.bundles
diff --git a/pom.xml b/pom.xml
index 54e8c79..a91b9f2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -50,7 +50,7 @@
<goal>unpack-dependencies</goal>
</goals>
<configuration>
- <includeGroupIds>org.osgi,org.apache.felix,org.slf4j,javax.servlet,org.ops4j.pax.url,org.apache.sling</includeGroupIds>
+ <includeGroupIds>org.slf4j,org.ops4j.pax.url</includeGroupIds>
<excludeTransitive>false</excludeTransitive>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<overWriteReleases>false</overWriteReleases>
@@ -85,21 +85,15 @@
</build>
<dependencies>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.compendium</artifactId>
- <version>4.2.0</version>
- <scope>provided</scope>
- </dependency>
<dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.framework</artifactId>
- <version>4.0.0</version>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.crankstart.api</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.crankstart.api</artifactId>
+ <artifactId>org.apache.sling.crankstart.core</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
@@ -107,12 +101,13 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.2</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.2</version>
- <scope>test</scope>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.url</groupId>
@@ -126,11 +121,5 @@
<version>${pax.url.version}</version>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.11</version>
- <scope>test</scope>
- </dependency>
</dependencies>
</project>
diff --git a/src/main/java/org/apache/sling/crankstart/launcher/CrankstartFileProcessor.java b/src/main/java/org/apache/sling/crankstart/launcher/CrankstartFileProcessor.java
deleted file mode 100644
index c3e6794..0000000
--- a/src/main/java/org/apache/sling/crankstart/launcher/CrankstartFileProcessor.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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.crankstart.launcher;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.Reader;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.sling.crankstart.api.CrankstartCommand;
-import org.apache.sling.crankstart.api.CrankstartContext;
-import org.apache.sling.crankstart.launcher.commands.InstallBundle;
-import org.apache.sling.crankstart.launcher.commands.Log;
-import org.apache.sling.crankstart.launcher.commands.SetOsgiFrameworkProperty;
-import org.apache.sling.crankstart.launcher.commands.StartBundles;
-import org.apache.sling.crankstart.launcher.commands.StartFramework;
-import org.osgi.framework.BundleException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/** Process a crankstart file */
-public class CrankstartFileProcessor {
- private final CrankstartContext crankstartContext = new CrankstartContext();
- private final Logger log = LoggerFactory.getLogger(getClass());
- private List<CrankstartCommand> commands = new ArrayList<CrankstartCommand>();
-
- public CrankstartFileProcessor() {
- System.setProperty( "java.protocol.handler.pkgs", "org.ops4j.pax.url" );
-
- commands.add(new InstallBundle());
- commands.add(new Log());
- commands.add(new SetOsgiFrameworkProperty());
- commands.add(new StartBundles());
- commands.add(new StartFramework());
- }
-
- public void process(Reader input) throws IOException, BundleException {
- final BufferedReader r = new BufferedReader(input);
- String line = null;
- while((line = r.readLine()) != null) {
- if(line.length() == 0 || line.startsWith("#")) {
- // ignore comments and blank lines
- } else {
- for(CrankstartCommand c : commands) {
- if(c.appliesTo(line)) {
- try {
- c.execute(crankstartContext, line);
- } catch(Exception e) {
- log.warn("Command execution failed", e);
- }
- break;
- }
- }
- }
- }
- }
-
- public void waitForExit() throws InterruptedException {
- if(crankstartContext.getOsgiFramework() == null) {
- throw new IllegalStateException("OSGi framework not started");
- }
- log.info("Waiting for OSGi framework to exit...");
- crankstartContext.getOsgiFramework().waitForStop(0);
- log.info("OSGi framework exited");
- }
-}
diff --git a/src/main/java/org/apache/sling/crankstart/launcher/Main.java b/src/main/java/org/apache/sling/crankstart/launcher/Main.java
index e858143..225d859 100644
--- a/src/main/java/org/apache/sling/crankstart/launcher/Main.java
+++ b/src/main/java/org/apache/sling/crankstart/launcher/Main.java
@@ -16,12 +16,23 @@
*/
package org.apache.sling.crankstart.launcher;
+import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
+import java.io.IOException;
import java.io.Reader;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+import org.apache.sling.crankstart.api.CrankstartConstants;
/** Execute a crankstart file */
public class Main {
+ public static final String CLASSPATH_PREFIX = "classpath ";
+
public static void main(String [] args) throws Exception {
String crankFile = "default.crank.txt";
if(args.length < 1) {
@@ -30,11 +41,32 @@ public class Main {
} else {
crankFile = args[0];
}
- final Reader r = new FileReader(new File(crankFile));
+ System.setProperty(CrankstartConstants.CRANKSTART_INPUT_FILENAME, crankFile);
+ System.setProperty( "java.protocol.handler.pkgs", "org.ops4j.pax.url" );
+ final URL [] launcherClasspath = getClasspath(crankFile);
+
+ final URLClassLoader launcherClassloader = new URLClassLoader(launcherClasspath, null);
+ final String callableClass = "org.apache.sling.crankstart.core.CrankstartFileProcessor";
+
+ @SuppressWarnings("unchecked")
+ final Callable<Object> c = (Callable<Object>)launcherClassloader.loadClass(callableClass).newInstance();
+ c.call();
+ }
+
+ private static URL[] getClasspath(String filename) throws IOException {
+ final List<URL> urls = new ArrayList<URL>();
+ final Reader input = new FileReader(new File(filename));
+ final BufferedReader r = new BufferedReader(input);
try {
- final CrankstartFileProcessor p = new CrankstartFileProcessor();
- p.process(r);
- p.waitForExit();
+ String line = null;
+ while((line = r.readLine()) != null) {
+ if(line.length() == 0 || line.startsWith("#")) {
+ // ignore comments and blank lines
+ } else if(line.startsWith(CLASSPATH_PREFIX)){
+ urls.add(new URL(line.substring(CLASSPATH_PREFIX.length()).trim()));
+ }
+ }
+ return urls.toArray(new URL[] {});
} finally {
r.close();
}
diff --git a/src/test/java/org/apache/sling/crankstart/MavenUrlTest.java b/src/test/java/org/apache/sling/crankstart/MavenUrlTest.java
deleted file mode 100644
index ebd66bb..0000000
--- a/src/test/java/org/apache/sling/crankstart/MavenUrlTest.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.crankstart;
-
-import java.io.IOException;
-import java.net.URL;
-
-import org.junit.Test;
-
-public class MavenUrlTest {
- @Test
- public void testResolveArtifactl() throws IOException {
- System.setProperty( "java.protocol.handler.pkgs", "org.ops4j.pax.url" );
-
- //TODO does pax url use the default local repo?
- //System.setProperty( "org.ops4j.pax.url.mvn.localRepository", localRepoPath );
-
- final URL url = new URL( "mvn:commons-lang/commons-lang/1.0" );
- url.openStream().close();
- }
-}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.