FELIX-2049: extend org.apache.felix.karaf.testing.Helper to emit a karaf-specific execution environmnent file for pax-runner

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@907997 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/karaf/assembly/src/main/filtered-resources/etc/config.properties b/karaf/assembly/src/main/filtered-resources/etc/config.properties
index a7716e5..d31b036 100644
--- a/karaf/assembly/src/main/filtered-resources/etc/config.properties
+++ b/karaf/assembly/src/main/filtered-resources/etc/config.properties
@@ -204,10 +204,7 @@
 #   - javax.transaction* is exported with a mandatory attribute 
 jre-1.6=, \
  javax.accessibility, \
- javax.activation, \
  javax.activity, \
- javax.annotation, \
- javax.annotation.processing, \
  javax.crypto, \
  javax.crypto.interfaces, \
  javax.crypto.spec, \
@@ -218,8 +215,6 @@
  javax.imageio.plugins.jpeg, \
  javax.imageio.spi, \
  javax.imageio.stream, \
- javax.jws, \
- javax.jws.soap, \
  javax.lang.model, \
  javax.lang.model.element, \
  javax.lang.model.type, \
@@ -284,12 +279,6 @@
  javax.tools, \
  javax.transaction; javax.transaction.xa; partial=true; mandatory:=partial, \
  javax.xml, \
- javax.xml.bind, \
- javax.xml.bind.annotation, \
- javax.xml.bind.annotation.adapters, \
- javax.xml.bind.attachment, \
- javax.xml.bind.helpers, \
- javax.xml.bind.util, \
  javax.xml.crypto, \
  javax.xml.crypto.dom, \
  javax.xml.crypto.dsig, \
@@ -299,22 +288,12 @@
  javax.xml.datatype, \
  javax.xml.namespace, \
  javax.xml.parsers, \
- javax.xml.soap, \
- javax.xml.stream, \
- javax.xml.stream.events, \
- javax.xml.stream.util, \
  javax.xml.transform, \
  javax.xml.transform.dom, \
  javax.xml.transform.sax, \
  javax.xml.transform.stax, \
  javax.xml.transform.stream, \
  javax.xml.validation, \
- javax.xml.ws, \
- javax.xml.ws.handler, \
- javax.xml.ws.handler.soap, \
- javax.xml.ws.http, \
- javax.xml.ws.soap, \
- javax.xml.ws.spi, \
  javax.xml.xpath, \
  org.ietf.jgss, \
  org.omg.CORBA, \
diff --git a/karaf/itests/src/test/java/org/apache/felix/karaf/shell/itests/CoreTest.java b/karaf/itests/src/test/java/org/apache/felix/karaf/shell/itests/CoreTest.java
index a0f7534..50377c2 100644
--- a/karaf/itests/src/test/java/org/apache/felix/karaf/shell/itests/CoreTest.java
+++ b/karaf/itests/src/test/java/org/apache/felix/karaf/shell/itests/CoreTest.java
@@ -34,6 +34,8 @@
 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
 import static org.ops4j.pax.exam.OptionUtils.combine;
 
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.workingDirectory;
+
 @RunWith(JUnit4TestRunner.class)
 public class CoreTest extends AbstractIntegrationTest {
 
@@ -109,9 +111,12 @@
     public static Option[] configuration() throws Exception {
         Option[] options = combine(
             // Default karaf environment
-            Helper.getDefaultOptions(),
-            // this is how you set the default log level when using pax logging (logProfile)
-            systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
+            Helper.getDefaultOptions(
+                // this is how you set the default log level when using pax logging (logProfile)
+                systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG")),
+
+            workingDirectory("target/paxrunner/core/"),
+
             // Test on both equinox and felix
             equinox(), felix()
         );
diff --git a/karaf/itests/src/test/java/org/apache/felix/karaf/shell/itests/FeaturesTest.java b/karaf/itests/src/test/java/org/apache/felix/karaf/shell/itests/FeaturesTest.java
index a3b29c0..2a6604c 100644
--- a/karaf/itests/src/test/java/org/apache/felix/karaf/shell/itests/FeaturesTest.java
+++ b/karaf/itests/src/test/java/org/apache/felix/karaf/shell/itests/FeaturesTest.java
@@ -35,6 +35,8 @@
 import static org.ops4j.pax.exam.OptionUtils.combine;
 import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.scanFeatures;
 
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.workingDirectory;
+
 @RunWith(JUnit4TestRunner.class)
 public class FeaturesTest extends AbstractIntegrationTest {
 
@@ -55,14 +57,18 @@
     public static Option[] configuration() throws Exception{
         return combine(
             // Default karaf environment
-            Helper.getDefaultOptions(),
-            // this is how you set the default log level when using pax logging (logProfile)
-            systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
+            Helper.getDefaultOptions(
+                // this is how you set the default log level when using pax logging (logProfile)
+                systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG")),
+
             // add two features
             scanFeatures(
                     maven().groupId("org.apache.felix.karaf").artifactId("apache-felix-karaf").type("xml").classifier("features").versionAsInProject(),
                     "obr", "wrapper"
             ),
+
+            workingDirectory("target/paxrunner/features/"),
+            
             // Test on both equinox and felix
             equinox(), felix()
         );
diff --git a/karaf/tooling/testing/src/main/java/org/apache/felix/karaf/testing/Helper.java b/karaf/tooling/testing/src/main/java/org/apache/felix/karaf/testing/Helper.java
index 1243eb9..5735481 100644
--- a/karaf/tooling/testing/src/main/java/org/apache/felix/karaf/testing/Helper.java
+++ b/karaf/tooling/testing/src/main/java/org/apache/felix/karaf/testing/Helper.java
@@ -32,10 +32,12 @@
 import org.ops4j.pax.exam.options.SystemPropertyOption;
 
 import static org.ops4j.pax.exam.CoreOptions.bootClasspathLibrary;
+import static org.ops4j.pax.exam.CoreOptions.bootDelegationPackages;
 import static org.ops4j.pax.exam.CoreOptions.frameworkStartLevel;
 import static org.ops4j.pax.exam.CoreOptions.maven;
 import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
 import static org.ops4j.pax.exam.OptionUtils.combine;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.rawPaxRunnerOption;
 
 /**
  * Helper class for setting up a pax-exam test environment for karaf.
@@ -105,11 +107,13 @@
      * Return an array of pax-exam options to correctly configure the osgi
      * framework for karaf.
      *
+     * @param sysOptions test-specific system property options
      * @return default pax-exam options for karaf osgi framework
      */
-    public static Option[] getDefaultConfigOptions() {
+    public static Option[] getDefaultConfigOptions(SystemPropertyOption... sysOptions) {
         return getDefaultConfigOptions(getDefaultSystemOptions(),
-                                       getResource("/org/apache/felix/karaf/testing/config.properties"));
+                                       getResource("/org/apache/felix/karaf/testing/config.properties"),
+                                       sysOptions);
     }
 
     /**
@@ -119,11 +123,13 @@
      *
      * @param sysProps karaf system properties
      * @param configProperties the URL to load the osgi framework properties from
+     * @param sysOptions test-specific system property options
      * @return pax-exam options for karaf osgi framework
      */
-    public static Option[] getDefaultConfigOptions(Properties sysProps, URL configProperties) {
+    public static Option[] getDefaultConfigOptions(Properties sysProps, URL configProperties, SystemPropertyOption... sysOptions) {
         // Load props
         Properties configProps = loadProperties(configProperties);
+
         // Set system props
         for (Enumeration e = sysProps.propertyNames(); e.hasMoreElements();) {
             String key = (String) e.nextElement();
@@ -134,17 +140,36 @@
             String name = (String) e.nextElement();
             configProps.setProperty(name, substVars(configProps.getProperty(name), name, null, configProps));
         }
-        // Transform to sys props options
+        // Transform system properties to VM options
         List<Option> options = new ArrayList<Option>();
+        String vmOptions = "-Dorg.ops4j.pax.exam.rbc.rmi.port=1099";
         for (Enumeration e = configProps.propertyNames(); e.hasMoreElements();) {
             String name = (String) e.nextElement();
             String value = configProps.getProperty(name);
-            value = value.replaceAll("\r", "").replaceAll("\n", "").replaceAll(" ", "");
-            options.add(new SystemPropertyOption(name).value(value));
+            value = align(value);
+            if ("org.osgi.framework.system.packages".equals(name)) {
+                String extra = align(configProps.getProperty("org.osgi.framework.system.packages.extra"));
+                vmOptions = vmOptions + " -D" + name + "=" + value + "," + extra;
+            } else if ("org.osgi.framework.bootdelegation".equals(name)) {
+                options.add(bootDelegationPackages(value));
+            } else {
+                vmOptions = vmOptions + " -D" + name + "=" + value;
+            }
         }
+
+        // add test-specific system properties
+        if (sysOptions != null) {
+            for (SystemPropertyOption sysOption : sysOptions) {
+                vmOptions = vmOptions + " -D" + sysOption.getKey() + "=" + sysOption.getValue();
+            }
+        }
+
         if (configProps.getProperty("org.osgi.framework.startlevel.beginning") != null) {
             options.add(frameworkStartLevel(Integer.parseInt(configProps.getProperty("org.osgi.framework.startlevel.beginning"))));
         }
+
+        options.add(rawPaxRunnerOption("--vmOptions", vmOptions));
+ 
         return options.toArray(new Option[options.size()]);
     }
 
@@ -188,6 +213,7 @@
             options.add(opt);
         }
         options.add(mavenBundle("org.apache.felix.karaf.tooling", "org.apache.felix.karaf.tooling.testing"));
+        options.add(wrappedBundle(maven("org.ops4j.pax.exam", "pax-exam-container-default")));
         // We need to add pax-exam-junit here when running with the ibm
         // jdk to avoid the following exception during the test run:
         // ClassNotFoundException: org.ops4j.pax.exam.junit.Configuration
@@ -203,7 +229,17 @@
      * @return an array of pax-exam options
      */
     public static Option[] getDefaultOptions() {
-        return combine(getDefaultConfigOptions(), getDefaultProvisioningOptions());
+        return getDefaultOptions(null);
+    }
+
+    /**
+     * Return an array of options for setting up a pax-exam test environment for karaf.
+     *
+     * @param sysOptions test-specific system property options
+     * @return an array of pax-exam options
+     */
+    public static Option[] getDefaultOptions(SystemPropertyOption... sysOptions) {
+        return combine(getDefaultConfigOptions(sysOptions), getDefaultProvisioningOptions());
     }
 
     /**
@@ -395,4 +431,9 @@
         }
     }
 
+
+    private static String align(String value) {
+        return value != null ? value.replaceAll("\r", "").replaceAll("\n", "").replaceAll(" ", "") : "";
+    }
+
 }
\ No newline at end of file