Add extension command support, with test in SystemPropertyCommand and launcher-test.crank.txt

git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1595220 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index 8244d96..67552bc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,6 +27,10 @@
                 <configuration>
                     <instructions>
                         <Private-Package>org.apache.sling.crankstart.*</Private-Package>
+                        <Import-Package>
+                            org.apache.sling.crankstart.api,
+                            *
+                        </Import-Package>
                     </instructions>
                 </configuration>
             </plugin>
@@ -52,6 +56,12 @@
             <version>2.2.0</version>
         </dependency>
         <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.crankstart.api</artifactId>
+            <version>${project.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>javax.servlet</groupId>
             <artifactId>servlet-api</artifactId>
             <scope>provided</scope>
diff --git a/src/main/java/org/apache/sling/crankstart/testservices/SystemPropertyCommand.java b/src/main/java/org/apache/sling/crankstart/testservices/SystemPropertyCommand.java
new file mode 100644
index 0000000..40c9e67
--- /dev/null
+++ b/src/main/java/org/apache/sling/crankstart/testservices/SystemPropertyCommand.java
@@ -0,0 +1,59 @@
+/*
+ * 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.testservices;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.crankstart.api.CrankstartCommand;
+import org.apache.sling.crankstart.api.CrankstartCommandLine;
+import org.apache.sling.crankstart.api.CrankstartContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** CrankstartCommand provided by our test-services bundle
+ *  to test crankstart extensions commands provided by OSGi bundles.
+ */
+@Component
+@Service
+public class SystemPropertyCommand implements CrankstartCommand {
+    
+    public static final String I_SYSTEM_PROPERTY = "test.system.property";
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    public boolean appliesTo(CrankstartCommandLine commandLine) {
+        return I_SYSTEM_PROPERTY.equals(commandLine.getVerb());
+    }
+    
+    public String getDescription() {
+        return I_SYSTEM_PROPERTY + ": set a system property";
+    }
+
+    public void execute(CrankstartContext crankstartContext, CrankstartCommandLine commandLine) throws Exception {
+        final String [] parts = commandLine.getQualifier().split(" ");
+        final String key = parts[0];
+        final StringBuilder sb = new StringBuilder();
+        for(int i=1 ; i < parts.length; i++) {
+            if(sb.length() > 0) {
+                sb.append(' ');
+            }
+            sb.append(parts[i]);
+        }
+        final String value = sb.toString();
+        System.setProperty(key, value);
+        log.info("System property [{}] set to [{}]", key, value);
+    }
+}