incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1588307 - in /sling/trunk/contrib/crankstart: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/sling/ src/main/java/org/apache/sling/crankstart/ src/test/ src/test/java/ src/test/java/o...
Date Thu, 17 Apr 2014 16:43:05 GMT
Author: bdelacretaz
Date: Thu Apr 17 16:43:04 2014
New Revision: 1588307

URL: http://svn.apache.org/r1588307
Log:
initial crankstart prototype - putting it here instead of whiteboard so that it is mirrored
to https://github.com/apache/sling

Added:
    sling/trunk/contrib/crankstart/   (with props)
    sling/trunk/contrib/crankstart/README.md
    sling/trunk/contrib/crankstart/default.crank.txt
    sling/trunk/contrib/crankstart/pom.xml
    sling/trunk/contrib/crankstart/src/
    sling/trunk/contrib/crankstart/src/main/
    sling/trunk/contrib/crankstart/src/main/java/
    sling/trunk/contrib/crankstart/src/main/java/org/
    sling/trunk/contrib/crankstart/src/main/java/org/apache/
    sling/trunk/contrib/crankstart/src/main/java/org/apache/sling/
    sling/trunk/contrib/crankstart/src/main/java/org/apache/sling/crankstart/
    sling/trunk/contrib/crankstart/src/main/java/org/apache/sling/crankstart/CrankstartFileProcessor.java
    sling/trunk/contrib/crankstart/src/main/java/org/apache/sling/crankstart/Main.java
    sling/trunk/contrib/crankstart/src/test/
    sling/trunk/contrib/crankstart/src/test/java/
    sling/trunk/contrib/crankstart/src/test/java/org/
    sling/trunk/contrib/crankstart/src/test/java/org/apache/
    sling/trunk/contrib/crankstart/src/test/java/org/apache/sling/
    sling/trunk/contrib/crankstart/src/test/java/org/apache/sling/crankstart/
    sling/trunk/contrib/crankstart/src/test/java/org/apache/sling/crankstart/MavenUrlTest.java

Propchange: sling/trunk/contrib/crankstart/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Apr 17 16:43:04 2014
@@ -0,0 +1,11 @@
+target
+bin
+*.iml
+*.ipr
+*.iws
+.settings
+.project
+.classpath
+.externalToolBuilders
+maven-eclipse.xml
+felix-cache

Added: sling/trunk/contrib/crankstart/README.md
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/README.md?rev=1588307&view=auto
==============================================================================
--- sling/trunk/contrib/crankstart/README.md (added)
+++ sling/trunk/contrib/crankstart/README.md Thu Apr 17 16:43:04 2014
@@ -0,0 +1,13 @@
+Apache Sling Crankstart
+=======================
+
+This is an early prototype of a different way of starting Sling,
+based on a single text file that describes the Sling configuration.
+
+For now, the crank start launcher reads a .crank.txt file, starts 
+the OSGi framework and installs and starts bundles that it gets from
+a Maven repository.
+
+Note that this module is in contrib for now: it might be completely
+changed, abandoned etc. - there's no guarantes that this will ever
+become a supported Sling component.
\ No newline at end of file

Added: sling/trunk/contrib/crankstart/default.crank.txt
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/default.crank.txt?rev=1588307&view=auto
==============================================================================
--- sling/trunk/contrib/crankstart/default.crank.txt (added)
+++ sling/trunk/contrib/crankstart/default.crank.txt Thu Apr 17 16:43:04 2014
@@ -0,0 +1,18 @@
+# Minimal HTTP server example for Sling crankstart
+
+# OSGi framework properties
+osgi.property org.osgi.service.http.port 1234 
+
+# Start framework and install bundles
+start.framework
+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 now
+start.all.bundles
+log OSGi webconsole should soon be available at http://localhost:1234/system/console
+ 
\ No newline at end of file

Added: sling/trunk/contrib/crankstart/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/pom.xml?rev=1588307&view=auto
==============================================================================
--- sling/trunk/contrib/crankstart/pom.xml (added)
+++ sling/trunk/contrib/crankstart/pom.xml Thu Apr 17 16:43:04 2014
@@ -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</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>2.0.0-SNAPSHOT</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>

Added: sling/trunk/contrib/crankstart/src/main/java/org/apache/sling/crankstart/CrankstartFileProcessor.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/src/main/java/org/apache/sling/crankstart/CrankstartFileProcessor.java?rev=1588307&view=auto
==============================================================================
--- sling/trunk/contrib/crankstart/src/main/java/org/apache/sling/crankstart/CrankstartFileProcessor.java
(added)
+++ sling/trunk/contrib/crankstart/src/main/java/org/apache/sling/crankstart/CrankstartFileProcessor.java
Thu Apr 17 16:43:04 2014
@@ -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());
+    }
+
+}

Added: sling/trunk/contrib/crankstart/src/main/java/org/apache/sling/crankstart/Main.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/src/main/java/org/apache/sling/crankstart/Main.java?rev=1588307&view=auto
==============================================================================
--- sling/trunk/contrib/crankstart/src/main/java/org/apache/sling/crankstart/Main.java (added)
+++ sling/trunk/contrib/crankstart/src/main/java/org/apache/sling/crankstart/Main.java Thu
Apr 17 16:43:04 2014
@@ -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

Added: sling/trunk/contrib/crankstart/src/test/java/org/apache/sling/crankstart/MavenUrlTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/src/test/java/org/apache/sling/crankstart/MavenUrlTest.java?rev=1588307&view=auto
==============================================================================
--- sling/trunk/contrib/crankstart/src/test/java/org/apache/sling/crankstart/MavenUrlTest.java
(added)
+++ sling/trunk/contrib/crankstart/src/test/java/org/apache/sling/crankstart/MavenUrlTest.java
Thu Apr 17 16:43:04 2014
@@ -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();
+       }
+}



Mime
View raw message