ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ange...@apache.org
Subject svn commit: r1049027 - in /incubator/ace/trunk/ace-launcher: ./ src/main/java/org/apache/ace/launcher/ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/ace/ src/test/java/org/apache/ace/launcher/
Date Tue, 14 Dec 2010 10:36:30 GMT
Author: angelos
Date: Tue Dec 14 10:36:30 2010
New Revision: 1049027

URL: http://svn.apache.org/viewvc?rev=1049027&view=rev
Log:
ACE-99 The launcher now can take the --fwOption command line parameter, allowing you to set
additional framework properties.

Added:
    incubator/ace/trunk/ace-launcher/src/test/
    incubator/ace/trunk/ace-launcher/src/test/java/
    incubator/ace/trunk/ace-launcher/src/test/java/org/
    incubator/ace/trunk/ace-launcher/src/test/java/org/apache/
    incubator/ace/trunk/ace-launcher/src/test/java/org/apache/ace/
    incubator/ace/trunk/ace-launcher/src/test/java/org/apache/ace/launcher/
    incubator/ace/trunk/ace-launcher/src/test/java/org/apache/ace/launcher/FindFrameworkPropertiesTest.java
Modified:
    incubator/ace/trunk/ace-launcher/pom.xml
    incubator/ace/trunk/ace-launcher/src/main/java/org/apache/ace/launcher/Main.java

Modified: incubator/ace/trunk/ace-launcher/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-launcher/pom.xml?rev=1049027&r1=1049026&r2=1049027&view=diff
==============================================================================
--- incubator/ace/trunk/ace-launcher/pom.xml (original)
+++ incubator/ace/trunk/ace-launcher/pom.xml Tue Dec 14 10:36:30 2010
@@ -5,12 +5,19 @@
 
   <modelVersion>4.0.0</modelVersion>
 
+  <!--<parent>-->
+    <!--<artifactId>ace-reactor</artifactId>-->
+    <!--<groupId>org.apache.ace</groupId>-->
+    <!--<version>0.8.0-SNAPSHOT</version>-->
+  <!--</parent>-->
+
   <parent>
-    <artifactId>ace-reactor</artifactId>
-    <groupId>org.apache.ace</groupId>
-    <version>0.8.0-SNAPSHOT</version>
+      <groupId>org.apache.ace</groupId>
+      <artifactId>ace-pom</artifactId>
+      <version>0.8.0-SNAPSHOT</version>
+      <relativePath>../pom/</relativePath>
   </parent>
-
+  
   <artifactId>ace-launcher</artifactId>
   <!--<packaging>pom</packaging>-->
 

Modified: incubator/ace/trunk/ace-launcher/src/main/java/org/apache/ace/launcher/Main.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-launcher/src/main/java/org/apache/ace/launcher/Main.java?rev=1049027&r1=1049026&r2=1049027&view=diff
==============================================================================
--- incubator/ace/trunk/ace-launcher/src/main/java/org/apache/ace/launcher/Main.java (original)
+++ incubator/ace/trunk/ace-launcher/src/main/java/org/apache/ace/launcher/Main.java Tue Dec
14 10:36:30 2010
@@ -22,11 +22,21 @@ package org.apache.ace.launcher;
 import org.apache.ace.managementagent.Activator;
 import org.osgi.framework.launch.FrameworkFactory;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
+/**
+ * A simple launcher, that launches the embedded Felix together with a management agent.
It accepts the following
+ * command line arguments,
+ * <ul>
+ * <li><tt>--fwOption=key=value</tt> framework options to be passed to
the launched framework. This argument can be used
+ * multiple times.</li>
+ * </ul>
+ * <br>
+ * Furthermore, it inherits all system properties that the self-containted Management Agent
accepts. 
+ *
+ */
 public class Main {
     public static void main(String[] args) throws Exception {
         FrameworkFactory factory = (FrameworkFactory) Class.forName("org.apache.felix.framework.FrameworkFactory").newInstance();
@@ -35,7 +45,20 @@ public class Main {
         activators.add(new Activator());
         Map frameworkProperties = new HashMap();
         frameworkProperties.put("felix.systembundle.activators", activators);
+        frameworkProperties.putAll(findFrameworkProperties(args));
 
         factory.newFramework(frameworkProperties).start();
     }
+
+    static Map findFrameworkProperties(String[] args) {
+        Pattern pattern = Pattern.compile("--(\\w*)=([.\\w]*)=(.*)");
+        Map result = new HashMap();
+        for (String arg : args) {
+            Matcher m = pattern.matcher(arg);
+            if (m.matches() && m.group(1).equals("fwOption")) {
+                result.put(m.group(2), m.group(3));
+            }
+        }
+        return result;
+    }
 }

Added: incubator/ace/trunk/ace-launcher/src/test/java/org/apache/ace/launcher/FindFrameworkPropertiesTest.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-launcher/src/test/java/org/apache/ace/launcher/FindFrameworkPropertiesTest.java?rev=1049027&view=auto
==============================================================================
--- incubator/ace/trunk/ace-launcher/src/test/java/org/apache/ace/launcher/FindFrameworkPropertiesTest.java
(added)
+++ incubator/ace/trunk/ace-launcher/src/test/java/org/apache/ace/launcher/FindFrameworkPropertiesTest.java
Tue Dec 14 10:36:30 2010
@@ -0,0 +1,73 @@
+/*
+ * 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.ace.launcher;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import static junit.framework.Assert.assertEquals;
+
+@RunWith(Parameterized.class)
+public class FindFrameworkPropertiesTest {
+    private final String[] m_args;
+    private final Map<String, String> m_expected;
+
+    @Parameters
+    public static Collection<Object[]> data() {
+        return Arrays.asList(new Object[][] {
+                { new String[] {"--fwOption=something=true"}, map("something", "true") },
+                { new String[] {"--fwOption=something=true", "--fwOption=somethingElse=false"},
map("something", "true", "somethingElse", "false") },
+                { new String[] {"--fwOption=something=true", "--fwOption=something=false"},
map("something", "false") },
+                { new String[] {"--fwOption=something=true=false"}, map("something", "true=false")
},
+                { new String[] {"--fwOption=some.thing=true"}, map("some.thing", "true")
},
+                { new String[] {"--fwOption=nothing"}, map() }
+        });
+    }
+
+    public FindFrameworkPropertiesTest(String[] args, Map<String, String> expected)
{
+        m_args = args;
+        m_expected = expected;
+    }
+
+    @Test
+    public void test() {
+        assertEquals(m_expected, Main.findFrameworkProperties(m_args));
+    }
+
+    /**
+     * Helper method to create a literal map
+     */
+    private static <T> Map<T, T> map(T... values) {
+        Map<T, T> result = new HashMap<T, T>();
+
+        for (int i = 0; i < values.length; i += 2) {
+            result.put(values[i], values[i+1]);
+        }
+
+        return result;
+    }
+}



Mime
View raw message