You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2014/05/14 17:51:17 UTC
svn commit: r1594621 - in /sling/trunk/contrib/crankstart: core/
core/src/main/java/org/apache/sling/crankstart/core/
core/src/main/java/org/apache/sling/crankstart/core/commands/ launcher/
Author: bdelacretaz
Date: Wed May 14 15:51:17 2014
New Revision: 1594621
URL: http://svn.apache.org/r1594621
Log:
SLING-3528 - configure command, based on a contribution by Artyom Stetsenko, thanks!
Added:
sling/trunk/contrib/crankstart/core/src/main/java/org/apache/sling/crankstart/core/commands/Configure.java
Removed:
sling/trunk/contrib/crankstart/core/default.crank.txt
Modified:
sling/trunk/contrib/crankstart/core/src/main/java/org/apache/sling/crankstart/core/CrankstartFileProcessor.java
sling/trunk/contrib/crankstart/launcher/sling.crank.txt
Modified: sling/trunk/contrib/crankstart/core/src/main/java/org/apache/sling/crankstart/core/CrankstartFileProcessor.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/core/src/main/java/org/apache/sling/crankstart/core/CrankstartFileProcessor.java?rev=1594621&r1=1594620&r2=1594621&view=diff
==============================================================================
--- sling/trunk/contrib/crankstart/core/src/main/java/org/apache/sling/crankstart/core/CrankstartFileProcessor.java (original)
+++ sling/trunk/contrib/crankstart/core/src/main/java/org/apache/sling/crankstart/core/CrankstartFileProcessor.java Wed May 14 15:51:17 2014
@@ -28,6 +28,7 @@ import org.apache.sling.crankstart.api.C
import org.apache.sling.crankstart.api.CrankstartCommandLine;
import org.apache.sling.crankstart.api.CrankstartConstants;
import org.apache.sling.crankstart.api.CrankstartContext;
+import org.apache.sling.crankstart.core.commands.Configure;
import org.apache.sling.crankstart.core.commands.InstallBundle;
import org.apache.sling.crankstart.core.commands.Log;
import org.apache.sling.crankstart.core.commands.SetOsgiFrameworkProperty;
@@ -48,6 +49,7 @@ public class CrankstartFileProcessor imp
commands.add(new SetOsgiFrameworkProperty());
commands.add(new StartBundles());
commands.add(new StartFramework());
+ commands.add(new Configure());
}
public Object call() throws Exception {
Added: sling/trunk/contrib/crankstart/core/src/main/java/org/apache/sling/crankstart/core/commands/Configure.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/core/src/main/java/org/apache/sling/crankstart/core/commands/Configure.java?rev=1594621&view=auto
==============================================================================
--- sling/trunk/contrib/crankstart/core/src/main/java/org/apache/sling/crankstart/core/commands/Configure.java (added)
+++ sling/trunk/contrib/crankstart/core/src/main/java/org/apache/sling/crankstart/core/commands/Configure.java Wed May 14 15:51:17 2014
@@ -0,0 +1,66 @@
+/*
+ * 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.core.commands;
+
+import java.util.Dictionary;
+
+import org.apache.sling.crankstart.api.CrankstartCommand;
+import org.apache.sling.crankstart.api.CrankstartCommandLine;
+import org.apache.sling.crankstart.api.CrankstartContext;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** CrankstartCommand that logs a message */
+public class Configure implements CrankstartCommand {
+ public static final String I_CONFIGURE = "config";
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ @Override
+ public boolean appliesTo(CrankstartCommandLine commandLine) {
+ return I_CONFIGURE.equals(commandLine.getVerb());
+ }
+
+ @Override
+ public void execute(CrankstartContext crankstartContext, CrankstartCommandLine commandLine) throws Exception {
+ final String pid = commandLine.getQualifier();
+ final Dictionary<String, Object> properties = commandLine.getProperties();
+ final BundleContext bundleContext = crankstartContext.getOsgiFramework().getBundleContext();
+
+ // TODO: wait for configadmin service?
+ final String CONFIG_ADMIN_CLASS = "org.osgi.service.cm.ConfigurationAdmin";
+ final ServiceReference configAdminRef = bundleContext.getServiceReference(CONFIG_ADMIN_CLASS);
+ if(configAdminRef == null) {
+ throw new IllegalStateException("Required service is missing:" + CONFIG_ADMIN_CLASS);
+ }
+ final Object configAdminService = bundleContext.getService(configAdminRef);
+
+ // TODO: handle configuration factories
+ // For now, use reflection to minimize coupling with the OSGi framework that we are talking to
+ final Object config = configAdminService.getClass()
+ .getMethod("getConfiguration", String.class)
+ .invoke(configAdminService, pid);
+ config.getClass()
+ .getMethod("setBundleLocation", String.class)
+ .invoke(config, (String)null);
+ config.getClass()
+ .getMethod("update", Dictionary.class)
+ .invoke(config, properties);
+ log.info("Updated configuration {}: {}", pid, properties);
+ }
+}
Modified: sling/trunk/contrib/crankstart/launcher/sling.crank.txt
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/launcher/sling.crank.txt?rev=1594621&r1=1594620&r2=1594621&view=diff
==============================================================================
--- sling/trunk/contrib/crankstart/launcher/sling.crank.txt (original)
+++ sling/trunk/contrib/crankstart/launcher/sling.crank.txt Wed May 14 15:51:17 2014
@@ -28,14 +28,26 @@ osgi.property org.osgi.framework.startle
# Once OSGi properties are set, start the framework
start.framework
-# Install bundles
-# mvn: protocol can be used.
-bundle mvn:org.apache.felix/org.apache.felix.http.jetty/2.2.0
+# Start a minimal set of bundles to get the ConfigurationAdmin service
+# mvn: protocol can be used to get bundles
bundle mvn:org.slf4j/slf4j-api/1.7.6
bundle mvn:org.apache.sling/org.apache.sling.commons.log/4.0.0
bundle mvn:org.apache.sling/org.apache.sling.commons.logservice/1.0.2
bundle mvn:org.slf4j/jcl-over-slf4j/1.7.6
bundle mvn:org.slf4j/log4j-over-slf4j/1.7.6
+bundle mvn:org.apache.felix/org.apache.felix.configadmin/1.6.0
+start.all.bundles
+
+# Now set example configurations
+config some.example.config
+ some.search.path = /test1:123
+ some.search.path = /test2:456
+ another.property = This is just a test configuration
+config a.second.config
+ foo = bar
+
+# Install other bundles
+bundle mvn:org.apache.felix/org.apache.felix.http.jetty/2.2.0
bundle mvn:org.apache.sling/org.apache.sling.settings/1.3.0
bundle mvn:org.apache.sling/org.apache.sling.fragment.xml/1.0.2
bundle mvn:org.apache.sling/org.apache.sling.fragment.transaction/1.0.0
@@ -44,7 +56,6 @@ bundle mvn:org.apache.sling/org.apache.s
bundle mvn:org.apache.sling/org.apache.sling.launchpad.installer/1.2.0
bundle mvn:org.apache.sling/org.apache.sling.installer.core/3.5.0
bundle mvn:org.apache.sling/org.apache.sling.installer.provider.file/1.0.2
-bundle mvn:org.apache.felix/org.apache.felix.configadmin/1.6.0
bundle mvn:org.apache.felix/org.apache.felix.eventadmin/1.3.2
bundle mvn:commons-io/commons-io/1.4
bundle mvn:commons-fileupload/commons-fileupload/1.3.1
@@ -56,6 +67,7 @@ bundle mvn:org.apache.geronimo.bundles/c
bundle mvn:org.apache.sling/org.apache.sling.commons.osgi/2.2.1-SNAPSHOT
bundle mvn:org.apache.sling/org.apache.sling.commons.mime/2.1.4
bundle mvn:org.apache.sling/org.apache.sling.commons.classloader/1.3.0
+bundle mvn:org.apache.sling/org.apache.sling.commons.compiler/2.1.1-SNAPSHOT
bundle mvn:org.apache.sling/org.apache.sling.commons.scheduler/2.4.2
bundle mvn:org.apache.sling/org.apache.sling.commons.threads/3.2.0
bundle mvn:org.apache.sling/org.apache.sling.discovery.api/1.0.0