incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1589114 - in /sling/trunk/contrib/crankstart: ./ api/ api/src/ api/src/main/ api/src/main/java/ api/src/main/java/org/ api/src/main/java/org/apache/ api/src/main/java/org/apache/sling/ api/src/main/java/org/apache/sling/crankstart/ api/src...
Date Tue, 22 Apr 2014 12:40:50 GMT
Author: bdelacretaz
Date: Tue Apr 22 12:40:50 2014
New Revision: 1589114

URL: http://svn.apache.org/r1589114
Log:
Use more flexible command pattern

Added:
    sling/trunk/contrib/crankstart/api/   (with props)
    sling/trunk/contrib/crankstart/api/pom.xml
    sling/trunk/contrib/crankstart/api/src/
    sling/trunk/contrib/crankstart/api/src/main/
    sling/trunk/contrib/crankstart/api/src/main/java/
    sling/trunk/contrib/crankstart/api/src/main/java/org/
    sling/trunk/contrib/crankstart/api/src/main/java/org/apache/
    sling/trunk/contrib/crankstart/api/src/main/java/org/apache/sling/
    sling/trunk/contrib/crankstart/api/src/main/java/org/apache/sling/crankstart/
    sling/trunk/contrib/crankstart/api/src/main/java/org/apache/sling/crankstart/api/
    sling/trunk/contrib/crankstart/api/src/main/java/org/apache/sling/crankstart/api/CrankstartCommand.java
    sling/trunk/contrib/crankstart/api/src/main/java/org/apache/sling/crankstart/api/CrankstartContext.java
    sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/
    sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/CrankstartFileProcessor.java
      - copied, changed from r1589096, sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/CrankstartFileProcessor.java
    sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/Main.java
      - copied, changed from r1589096, sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/Main.java
    sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/
    sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/InstallBundle.java
    sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/Log.java
    sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/SetOsgiFrameworkProperty.java
    sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/StartBundles.java
    sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/StartFramework.java
    sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/U.java
    sling/trunk/contrib/crankstart/pom.xml
Removed:
    sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/CrankstartFileProcessor.java
    sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/Main.java
Modified:
    sling/trunk/contrib/crankstart/launcher/pom.xml

Propchange: sling/trunk/contrib/crankstart/api/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Apr 22 12:40:50 2014
@@ -0,0 +1,12 @@
+target
+bin
+*.iml
+*.ipr
+*.iws
+.settings
+.project
+.classpath
+.externalToolBuilders
+maven-eclipse.xml
+felix-cache
+

Added: sling/trunk/contrib/crankstart/api/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/api/pom.xml?rev=1589114&view=auto
==============================================================================
--- sling/trunk/contrib/crankstart/api/pom.xml (added)
+++ sling/trunk/contrib/crankstart/api/pom.xml Tue Apr 22 12:40:50 2014
@@ -0,0 +1,53 @@
+<?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.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>19</version>
+    </parent>
+
+    <groupId>org.apache.sling</groupId>
+    <artifactId>org.apache.sling.crankstart.api</artifactId>
+    <packaging>bundle</packaging>
+    <version>0.0.1-SNAPSHOT</version>
+
+    <name>Apache Sling Crankstart API</name>
+    <inceptionYear>2014</inceptionYear>
+    
+    <description>
+        A different way of starting Sling - API module
+    </description>
+
+    <build>
+        <plugins>
+             <plugin>
+               <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Export-Package>org.apache.sling.crankstart.api</Export-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </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>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+</project>

Added: sling/trunk/contrib/crankstart/api/src/main/java/org/apache/sling/crankstart/api/CrankstartCommand.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/api/src/main/java/org/apache/sling/crankstart/api/CrankstartCommand.java?rev=1589114&view=auto
==============================================================================
--- sling/trunk/contrib/crankstart/api/src/main/java/org/apache/sling/crankstart/api/CrankstartCommand.java
(added)
+++ sling/trunk/contrib/crankstart/api/src/main/java/org/apache/sling/crankstart/api/CrankstartCommand.java
Tue Apr 22 12:40:50 2014
@@ -0,0 +1,22 @@
+/*
+ * 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.api;
+
+public interface CrankstartCommand {
+    public boolean appliesTo(String commandLine);
+    public void execute(CrankstartContext crankstartContext, String commandLine) throws Exception;
+}
\ No newline at end of file

Added: sling/trunk/contrib/crankstart/api/src/main/java/org/apache/sling/crankstart/api/CrankstartContext.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/api/src/main/java/org/apache/sling/crankstart/api/CrankstartContext.java?rev=1589114&view=auto
==============================================================================
--- sling/trunk/contrib/crankstart/api/src/main/java/org/apache/sling/crankstart/api/CrankstartContext.java
(added)
+++ sling/trunk/contrib/crankstart/api/src/main/java/org/apache/sling/crankstart/api/CrankstartContext.java
Tue Apr 22 12:40:50 2014
@@ -0,0 +1,47 @@
+/*
+ * 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.api;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.osgi.framework.launch.Framework;
+
+public class CrankstartContext {
+    private Framework osgiFramework;
+    private final Map<String, String> osgiFrameworkProperties = new HashMap<String,
String>();
+    
+    public void setOsgiFrameworkProperty(String key, String value) {
+        osgiFrameworkProperties.put(key, value);
+    }
+    
+    public Map<String, String> getOsgiFrameworkProperties() {
+        return Collections.unmodifiableMap(osgiFrameworkProperties);
+    }
+    
+    public void setOsgiFramework(Framework f) {
+        if(osgiFramework != null) {
+            throw new IllegalStateException("OSGi framework already set");
+        }
+        osgiFramework = f;
+    }
+    
+    public Framework getOsgiFramework() {
+        return osgiFramework;
+    }
+}
\ No newline at end of file

Modified: sling/trunk/contrib/crankstart/launcher/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/launcher/pom.xml?rev=1589114&r1=1589113&r2=1589114&view=diff
==============================================================================
--- sling/trunk/contrib/crankstart/launcher/pom.xml (original)
+++ sling/trunk/contrib/crankstart/launcher/pom.xml Tue Apr 22 12:40:50 2014
@@ -15,7 +15,7 @@
     <packaging>jar</packaging>
     <version>0.0.1-SNAPSHOT</version>
 
-    <name>Apache Sling Crankstart Module</name>
+    <name>Apache Sling Crankstart Launcher</name>
     <inceptionYear>2014</inceptionYear>
     
     <description>
@@ -34,7 +34,7 @@
                 <configuration>
                     <archive>
                         <manifest>
-                            <mainClass>org.apache.sling.crankstart.Main</mainClass>
+                            <mainClass>org.apache.sling.crankstart.launcher.Main</mainClass>
                             <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                         </manifest>
                     </archive>
@@ -50,7 +50,7 @@
                             <goal>unpack-dependencies</goal>
                         </goals>
                         <configuration>
-                            <includeGroupIds>org.osgi,org.apache.felix,org.slf4j,javax.servlet,org.ops4j.pax.url</includeGroupIds>
+                            <includeGroupIds>org.osgi,org.apache.felix,org.slf4j,javax.servlet,org.ops4j.pax.url,org.apache.sling</includeGroupIds>
                             <excludeTransitive>false</excludeTransitive>
                             <outputDirectory>${project.build.directory}/classes</outputDirectory>
                             <overWriteReleases>false</overWriteReleases>
@@ -89,11 +89,19 @@
             <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>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <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.slf4j</groupId>

Copied: sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/CrankstartFileProcessor.java
(from r1589096, sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/CrankstartFileProcessor.java)
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/CrankstartFileProcessor.java?p2=sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/CrankstartFileProcessor.java&p1=sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/CrankstartFileProcessor.java&r1=1589096&r2=1589114&rev=1589114&view=diff
==============================================================================
--- sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/CrankstartFileProcessor.java
(original)
+++ sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/CrankstartFileProcessor.java
Tue Apr 22 12:40:50 2014
@@ -14,127 +14,68 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sling.crankstart;
+package org.apache.sling.crankstart.launcher;
 
 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.ArrayList;
 import java.util.List;
-import java.util.Map;
 
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
+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.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 CrankstartContext crankstartContext = new CrankstartContext();
     private final Logger log = LoggerFactory.getLogger(getClass());
-    private final Map<String, String> osgiProperties = new HashMap<String, String>();
+    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) {
-            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();
+            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 {
-        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();
+        if(crankstartContext.getOsgiFramework() == null) {
+            throw new IllegalStateException("OSGi framework not started");
         }
-        
-        // TODO check that all bundles have started? 
-        // or use a crankstart instruction for that? 
-        
-        log.info("{} bundles installed", bundles.size());
+        log.info("Waiting for OSGi framework to exit...");
+        crankstartContext.getOsgiFramework().waitForStop(0);
+        log.info("OSGi framework exited");
     }
-
 }

Copied: sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/Main.java
(from r1589096, sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/Main.java)
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/Main.java?p2=sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/Main.java&p1=sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/Main.java&r1=1589096&r2=1589114&rev=1589114&view=diff
==============================================================================
--- sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/Main.java
(original)
+++ sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/Main.java
Tue Apr 22 12:40:50 2014
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sling.crankstart;
+package org.apache.sling.crankstart.launcher;
 
 import java.io.File;
 import java.io.FileReader;

Added: sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/InstallBundle.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/InstallBundle.java?rev=1589114&view=auto
==============================================================================
--- sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/InstallBundle.java
(added)
+++ sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/InstallBundle.java
Tue Apr 22 12:40:50 2014
@@ -0,0 +1,52 @@
+/*
+ * 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.commands;
+
+import java.io.InputStream;
+import java.net.URL;
+
+import org.apache.sling.crankstart.api.CrankstartCommand;
+import org.apache.sling.crankstart.api.CrankstartContext;
+import org.osgi.framework.BundleContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** CrankstartCommand that installs a bundle */
+public class InstallBundle implements CrankstartCommand {
+    public static final String I_BUNDLE = "bundle ";
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    
+    @Override
+    public boolean appliesTo(String commandLine) {
+        return commandLine.startsWith(I_BUNDLE);
+    }
+
+    @Override
+    public void execute(CrankstartContext crankstartContext, String commandLine) throws Exception
{
+        final String bundleRef = U.removePrefix(I_BUNDLE, commandLine);
+        final URL url = new URL( "mvn:" + bundleRef);
+        final BundleContext ctx = crankstartContext.getOsgiFramework().getBundleContext();
+        final String ref = "crankstart://" + bundleRef;
+        final InputStream bundleStream = url.openStream();
+        try {
+            ctx.installBundle(ref, url.openStream());
+            log.info("bundle installed: {}", ref);
+        } finally {
+            bundleStream.close();
+        }
+    }
+}

Added: sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/Log.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/Log.java?rev=1589114&view=auto
==============================================================================
--- sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/Log.java
(added)
+++ sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/Log.java
Tue Apr 22 12:40:50 2014
@@ -0,0 +1,38 @@
+/*
+ * 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.commands;
+
+import org.apache.sling.crankstart.api.CrankstartCommand;
+import org.apache.sling.crankstart.api.CrankstartContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** CrankstartCommand that logs a message */
+public class Log implements CrankstartCommand {
+    public static final String I_LOG = "log";
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    
+    @Override
+    public boolean appliesTo(String commandLine) {
+        return commandLine.startsWith(I_LOG);
+    }
+
+    @Override
+    public void execute(CrankstartContext crankstartContext, String commandLine) throws Exception
{
+        log.info(U.removePrefix(I_LOG, commandLine));
+    }
+}

Added: sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/SetOsgiFrameworkProperty.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/SetOsgiFrameworkProperty.java?rev=1589114&view=auto
==============================================================================
--- sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/SetOsgiFrameworkProperty.java
(added)
+++ sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/SetOsgiFrameworkProperty.java
Tue Apr 22 12:40:50 2014
@@ -0,0 +1,47 @@
+/*
+ * 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.commands;
+
+import org.apache.sling.crankstart.api.CrankstartCommand;
+import org.apache.sling.crankstart.api.CrankstartContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** CrankstartCommand that logs a message */
+public class SetOsgiFrameworkProperty implements CrankstartCommand {
+    public static final String I_OSGI_PROPERTY = "osgi.property";
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    
+    @Override
+    public boolean appliesTo(String commandLine) {
+        return commandLine.startsWith(I_OSGI_PROPERTY);
+    }
+
+    @Override
+    public void execute(CrankstartContext crankstartContext, String commandLine) throws Exception
{
+        final String args = U.removePrefix(I_OSGI_PROPERTY, commandLine);
+        final String [] parts = args.split(" ");
+        if(parts.length != 2) {
+            log.warn("Invalid OSGi property statement, ignored: [{}]", commandLine);
+            return;
+        }
+        final String key = parts[0].trim();
+        final String value = parts[1].trim();
+        log.info("Setting OSGI property {}={}", key, value);
+        crankstartContext.setOsgiFrameworkProperty(key, value);
+    }
+}

Added: sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/StartBundles.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/StartBundles.java?rev=1589114&view=auto
==============================================================================
--- sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/StartBundles.java
(added)
+++ sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/StartBundles.java
Tue Apr 22 12:40:50 2014
@@ -0,0 +1,48 @@
+/*
+ * 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.commands;
+
+import org.apache.sling.crankstart.api.CrankstartCommand;
+import org.apache.sling.crankstart.api.CrankstartContext;
+import org.osgi.framework.Bundle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** CrankstartCommand that logs a message */
+public class StartBundles implements CrankstartCommand {
+    public static final String I_START_ALL_BUNDLES = "start.all.bundles";
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    
+    @Override
+    public boolean appliesTo(String commandLine) {
+        return commandLine.startsWith(I_START_ALL_BUNDLES);
+    }
+
+    @Override
+    public void execute(CrankstartContext crankstartContext, String commandLine) throws Exception
{
+        int count = 0;
+        for (Bundle bundle : crankstartContext.getOsgiFramework().getBundleContext().getBundles())
{
+            log.info("Starting bundle {}", bundle.getSymbolicName());
+            bundle.start();
+            count++;
+        }
+        
+        // TODO check that all bundles have started? 
+        // or use a crankstart instruction for that?
+        log.info("{} bundles processed", count);
+    }
+}

Added: sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/StartFramework.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/StartFramework.java?rev=1589114&view=auto
==============================================================================
--- sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/StartFramework.java
(added)
+++ sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/StartFramework.java
Tue Apr 22 12:40:50 2014
@@ -0,0 +1,43 @@
+/*
+ * 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.commands;
+
+import org.apache.sling.crankstart.api.CrankstartCommand;
+import org.apache.sling.crankstart.api.CrankstartContext;
+import org.osgi.framework.launch.FrameworkFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** CrankstartCommand that logs a message */
+public class StartFramework implements CrankstartCommand {
+    public static final String I_START_FRAMEWORK = "start.framework";
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    
+    @Override
+    public boolean appliesTo(String commandLine) {
+        return commandLine.startsWith(I_START_FRAMEWORK);
+    }
+
+    @Override
+    public void execute(CrankstartContext crankstartContext, String commandLine) throws Exception
{
+        // TODO get framework as a Maven artifact?
+        FrameworkFactory frameworkFactory = java.util.ServiceLoader.load(FrameworkFactory.class).iterator().next();
+        crankstartContext.setOsgiFramework(frameworkFactory.newFramework(crankstartContext.getOsgiFrameworkProperties()));
+        crankstartContext.getOsgiFramework().start();
+        log.info("OSGi framework started");
+    }
+}

Added: sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/U.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/U.java?rev=1589114&view=auto
==============================================================================
--- sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/U.java
(added)
+++ sling/trunk/contrib/crankstart/launcher/src/main/java/org/apache/sling/crankstart/launcher/commands/U.java
Tue Apr 22 12:40:50 2014
@@ -0,0 +1,23 @@
+/*
+ * 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.commands;
+
+class U {
+    static String removePrefix(String prefix, String line) {
+        return line.substring(prefix.length()).trim();
+    }
+}

Added: sling/trunk/contrib/crankstart/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/pom.xml?rev=1589114&view=auto
==============================================================================
--- sling/trunk/contrib/crankstart/pom.xml (added)
+++ sling/trunk/contrib/crankstart/pom.xml Tue Apr 22 12:40:50 2014
@@ -0,0 +1,29 @@
+<?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.reactor</artifactId>
+    <packaging>pom</packaging>
+    <version>0.0.1-SNAPSHOT</version>
+
+    <name>Apache Sling Crankstart Reactor</name>
+    <inceptionYear>2014</inceptionYear>
+    
+    <description>
+        A different way of starting Sling - reactor pom
+    </description>
+
+    <modules>
+      <module>api</module>
+      <module>launcher</module>
+    </modules>
+</project>



Mime
View raw message