Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8FFCE11F18 for ; Tue, 22 Apr 2014 12:41:21 +0000 (UTC) Received: (qmail 50580 invoked by uid 500); 22 Apr 2014 12:41:20 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 50485 invoked by uid 500); 22 Apr 2014 12:41:15 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 50472 invoked by uid 99); 22 Apr 2014 12:41:14 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Apr 2014 12:41:14 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Apr 2014 12:41:11 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 63F3D2388868; Tue, 22 Apr 2014 12:40:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@sling.apache.org From: bdelacretaz@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140422124051.63F3D2388868@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 @@ + + + + 4.0.0 + + + org.apache.sling + sling + 19 + + + org.apache.sling + org.apache.sling.crankstart.api + bundle + 0.0.1-SNAPSHOT + + Apache Sling Crankstart API + 2014 + + + A different way of starting Sling - API module + + + + + + org.apache.felix + maven-bundle-plugin + true + + + org.apache.sling.crankstart.api + + + + + + + + + org.osgi + org.osgi.compendium + 4.2.0 + provided + + + org.apache.felix + org.apache.felix.framework + 4.0.0 + provided + + + 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 osgiFrameworkProperties = new HashMap(); + + public void setOsgiFrameworkProperty(String key, String value) { + osgiFrameworkProperties.put(key, value); + } + + public Map 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 @@ jar 0.0.1-SNAPSHOT - Apache Sling Crankstart Module + Apache Sling Crankstart Launcher 2014 @@ -34,7 +34,7 @@ - org.apache.sling.crankstart.Main + org.apache.sling.crankstart.launcher.Main true @@ -50,7 +50,7 @@ unpack-dependencies - org.osgi,org.apache.felix,org.slf4j,javax.servlet,org.ops4j.pax.url + org.osgi,org.apache.felix,org.slf4j,javax.servlet,org.ops4j.pax.url,org.apache.sling false ${project.build.directory}/classes false @@ -89,11 +89,19 @@ org.osgi org.osgi.compendium 4.2.0 + provided org.apache.felix org.apache.felix.framework 4.0.0 + provided + + + org.apache.sling + org.apache.sling.crankstart.api + 0.0.1-SNAPSHOT + provided org.slf4j 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 bundles = new LinkedList(); + private final CrankstartContext crankstartContext = new CrankstartContext(); private final Logger log = LoggerFactory.getLogger(getClass()); - private final Map osgiProperties = new HashMap(); + private List commands = new ArrayList(); 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 @@ + + + + 4.0.0 + + + org.apache + apache + 10 + + + + org.apache.sling + org.apache.sling.crankstart.reactor + pom + 0.0.1-SNAPSHOT + + Apache Sling Crankstart Reactor + 2014 + + + A different way of starting Sling - reactor pom + + + + api + launcher + +