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:24:58 UTC
[sling-org-apache-sling-crankstart-launcher] 01/31: Make space for
api module
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 d0029e2675e5bdd73a7c083827b8746c7c62c8dc
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Tue Apr 22 11:51:14 2014 +0000
Make space for api module
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/crankstart/launcher@1589096 13f79535-47bb-0310-9956-ffa450edef68
---
default.crank.txt | 23 ++++
pom.xml | 128 +++++++++++++++++++
.../sling/crankstart/CrankstartFileProcessor.java | 140 +++++++++++++++++++++
.../java/org/apache/sling/crankstart/Main.java | 42 +++++++
.../org/apache/sling/crankstart/MavenUrlTest.java | 35 ++++++
5 files changed, 368 insertions(+)
diff --git a/default.crank.txt b/default.crank.txt
new file mode 100644
index 0000000..3d581f0
--- /dev/null
+++ b/default.crank.txt
@@ -0,0 +1,23 @@
+# Minimal webconsole example for the Sling crankstart launcher
+
+# 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
+
+# Start all bundles and log a friendly message
+start.all.bundles
+log OSGi webconsole should soon be available at http://localhost:1234/system/console
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..72a30d4
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,128 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache</groupId>
+ <artifactId>apache</artifactId>
+ <version>10</version>
+ <relativePath />
+ </parent>
+
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.crankstart.launcher</artifactId>
+ <packaging>jar</packaging>
+ <version>0.0.1-SNAPSHOT</version>
+
+ <name>Apache Sling Crankstart Module</name>
+ <inceptionYear>2014</inceptionYear>
+
+ <description>
+ A different way of starting Sling
+ </description>
+
+ <properties>
+ <pax.url.version>1.6.0</pax.url.version>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>org.apache.sling.crankstart.Main</mainClass>
+ <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>embed-dependencies</id>
+ <goals>
+ <goal>unpack-dependencies</goal>
+ </goals>
+ <configuration>
+ <includeGroupIds>org.osgi,org.apache.felix,org.slf4j,javax.servlet,org.ops4j.pax.url</includeGroupIds>
+ <excludeTransitive>false</excludeTransitive>
+ <outputDirectory>${project.build.directory}/classes</outputDirectory>
+ <overWriteReleases>false</overWriteReleases>
+ <overWriteSnapshots>false</overWriteSnapshots>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-clean-plugin</artifactId>
+ <version>2.2</version>
+ <configuration>
+ <filesets>
+ <fileset>
+ <directory>${basedir}</directory>
+ <includes>
+ <include>felix-cache</include>
+ </includes>
+ </fileset>
+ </filesets>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <version>4.2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.framework</artifactId>
+ <version>4.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.6.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.6.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.url</groupId>
+ <artifactId>pax-url-aether</artifactId>
+ <version>${pax.url.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.url</groupId>
+ <artifactId>pax-url-commons</artifactId>
+ <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/CrankstartFileProcessor.java b/src/main/java/org/apache/sling/crankstart/CrankstartFileProcessor.java
new file mode 100644
index 0000000..424064b
--- /dev/null
+++ b/src/main/java/org/apache/sling/crankstart/CrankstartFileProcessor.java
@@ -0,0 +1,140 @@
+/*
+ * 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.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.launch.Framework;
+import org.osgi.framework.launch.FrameworkFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Process a crankstart file */
+public class CrankstartFileProcessor {
+ public static final String I_BUNDLE = "bundle ";
+ public static final String I_START_ALL_BUNDLES = "start.all.bundles";
+ public static final String I_LOG = "log";
+ public static final String I_START_FRAMEWORK = "start.framework";
+ public static final String I_OSGI_PROPERTY = "osgi.property";
+
+ private Framework framework;
+ private final List<Bundle> bundles = new LinkedList<Bundle>();
+ private final Logger log = LoggerFactory.getLogger(getClass());
+ private final Map<String, String> osgiProperties = new HashMap<String, String>();
+
+ public CrankstartFileProcessor() {
+ System.setProperty( "java.protocol.handler.pkgs", "org.ops4j.pax.url" );
+ }
+
+ public void process(Reader input) throws IOException, BundleException {
+ final BufferedReader r = new BufferedReader(input);
+ String line = null;
+ while((line = r.readLine()) != null) {
+ processLine(line);
+ }
+ }
+
+ private String removePrefix(String line, String prefix) {
+ return line.substring(prefix.length()).trim();
+ }
+
+ private void processLine(String line) throws IOException, BundleException {
+ line = line.trim();
+ if(line.length() == 0 || line.startsWith("#")) {
+ // ignore comments and blank lines
+ } else if(line.startsWith(I_BUNDLE)) {
+ bundle(removePrefix(line, I_BUNDLE));
+ } else if(line.startsWith(I_START_ALL_BUNDLES)) {
+ startAllBundles();
+ } else if(line.startsWith(I_LOG)) {
+ log.info(removePrefix(line, I_LOG));
+ } else if(line.startsWith(I_START_FRAMEWORK)) {
+ startFramework();
+ } else if(line.startsWith(I_OSGI_PROPERTY)) {
+ osgiProperty(removePrefix(line, I_OSGI_PROPERTY));
+ } else {
+ log.warn("Invalid command line: [{}]", line);
+ }
+ }
+
+ private void osgiProperty(String line) {
+ final String [] parts = line.split(" ");
+ if(parts.length != 2) {
+ log.warn("Invalid OSGi property [{}]", line);
+ return;
+ }
+ final String key = parts[0].trim();
+ final String value = parts[1].trim();
+ log.info("Setting OSGI property {}={}", key, value);
+ osgiProperties.put(key, value);
+ }
+
+ private void startFramework() throws BundleException {
+ if(framework != null) {
+ throw new IllegalStateException("OSGi framework already created");
+ }
+
+ // TODO get framework as a Maven artifact?
+ FrameworkFactory frameworkFactory = java.util.ServiceLoader.load(FrameworkFactory.class).iterator().next();
+ framework = frameworkFactory.newFramework(osgiProperties);
+ framework.start();
+
+ log.info("OSGi framework started");
+ }
+
+ private void bundle(String line) throws IOException, BundleException {
+ final URL url = new URL( "mvn:" + line);
+ final BundleContext ctx = framework.getBundleContext();
+ final String ref = "crankstart://" + line;
+ final InputStream bundleStream = url.openStream();
+ try {
+ bundles.add(ctx.installBundle(ref, url.openStream()));
+ log.info("bundle installed: {}", ref);
+ } finally {
+ bundleStream.close();
+ }
+ }
+
+ public void waitForExit() throws InterruptedException {
+ log.info("Waiting for OSGi framework to exit...");
+ framework.waitForStop(0);
+ }
+
+ private void startAllBundles() throws BundleException {
+ for (Bundle bundle : bundles) {
+ log.info("Starting bundle {}", bundle.getSymbolicName());
+ bundle.start();
+ }
+
+ // TODO check that all bundles have started?
+ // or use a crankstart instruction for that?
+
+ log.info("{} bundles installed", bundles.size());
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/crankstart/Main.java b/src/main/java/org/apache/sling/crankstart/Main.java
new file mode 100644
index 0000000..04c4a90
--- /dev/null
+++ b/src/main/java/org/apache/sling/crankstart/Main.java
@@ -0,0 +1,42 @@
+/*
+ * 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.File;
+import java.io.FileReader;
+import java.io.Reader;
+
+/** Execute a crankstart file */
+public class Main {
+ public static void main(String [] args) throws Exception {
+ String crankFile = "default.crank.txt";
+ if(args.length < 1) {
+ System.err.println("Using default crank file " + crankFile);
+ System.err.println("To use a different one, provide its name as a jar file argument");
+ } else {
+ crankFile = args[0];
+ }
+ final Reader r = new FileReader(new File(crankFile));
+ try {
+ final CrankstartFileProcessor p = new CrankstartFileProcessor();
+ p.process(r);
+ p.waitForExit();
+ } finally {
+ r.close();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/crankstart/MavenUrlTest.java b/src/test/java/org/apache/sling/crankstart/MavenUrlTest.java
new file mode 100644
index 0000000..ebd66bb
--- /dev/null
+++ b/src/test/java/org/apache/sling/crankstart/MavenUrlTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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>.