You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2012/09/06 16:55:33 UTC

svn commit: r1381632 [1/3] - in /karaf/branches/karaf-2.3.x: ./ itests/ itests/dependencies/ itests/kittests/ itests/kittests/src/test/java/org/apache/karaf/kittests/ itests/tests/ itests/tests/src/test/java/org/apache/karaf/shell/itests/ itests/tests/...

Author: jbonofre
Date: Thu Sep  6 14:55:30 2012
New Revision: 1381632

URL: http://svn.apache.org/viewvc?rev=1381632&view=rev
Log:
[KARAF-1792] Add Karaf exam framework in Karaf 2.3.x branch

Added:
    karaf/branches/karaf-2.3.x/tooling/exam/
    karaf/branches/karaf-2.3.x/tooling/exam/container/
    karaf/branches/karaf-2.3.x/tooling/exam/container/NOTICE
      - copied, changed from r1380213, karaf/branches/karaf-2.3.x/itests/NOTICE
    karaf/branches/karaf-2.3.x/tooling/exam/container/pom.xml
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/Constants.java
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/ExamFeaturesFile.java
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/InternalKarafDistributionConfigurationOption.java
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/KarafPropertiesFile.java
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/KarafTestContainer.java
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/KarafTestContainerFactory.java
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/RMIRegistry.java
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/adaptions/
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/adaptions/KarafManipulator.java
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/adaptions/KarafManipulatorFactory.java
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/adaptions/KarafManipulatorStartingFrom220.java
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/runner/
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/runner/BaseScriptRunner.java
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/runner/CommandLineBuilder.java
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/runner/InternalRunner.java
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/runner/KarafJavaRunner.java
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/runner/NixRunner.java
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/runner/Runner.java
    karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/runner/WindowsRunner.java
    karaf/branches/karaf-2.3.x/tooling/exam/options/
    karaf/branches/karaf-2.3.x/tooling/exam/options/NOTICE
      - copied, changed from r1380213, karaf/branches/karaf-2.3.x/itests/NOTICE
    karaf/branches/karaf-2.3.x/tooling/exam/options/pom.xml
      - copied, changed from r1380213, karaf/branches/karaf-2.3.x/itests/dependencies/pom.xml
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/exam/
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/exam/options/
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/exam/options/ConfigurationPointer.java
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/exam/options/DoNotModifyLogOption.java
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/exam/options/ExamBundlesStartLevel.java
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/exam/options/KarafDistributionBaseConfigurationOption.java
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/exam/options/KarafDistributionConfigurationConsoleOption.java
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/exam/options/KarafDistributionConfigurationFileExtendOption.java
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/exam/options/KarafDistributionConfigurationFileOption.java
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/exam/options/KarafDistributionConfigurationFilePutOption.java
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/exam/options/KarafDistributionConfigurationFileReplacementOption.java
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/exam/options/KarafDistributionConfigurationOption.java
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/exam/options/KarafDistributionKitConfigurationOption.java
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/exam/options/KarafDistributionOption.java
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/exam/options/KarafExamSystemConfigurationOption.java
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/exam/options/KeepRuntimeFolderOption.java
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/exam/options/LogLevelOption.java
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/exam/options/configs/
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/exam/options/configs/CustomProperties.java
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/exam/options/configs/FeaturesCfg.java
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/exam/options/configs/JreProperties.java
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/exam/options/configs/LoggingCfg.java
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/exam/options/configs/ManagementCfg.java
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/exam/options/configs/SystemProperties.java
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/exam/options/configs/UsersProperties.java
    karaf/branches/karaf-2.3.x/tooling/exam/options/src/main/java/org/apache/karaf/tooling/exam/options/configs/WebCfg.java
    karaf/branches/karaf-2.3.x/tooling/exam/pom.xml
      - copied, changed from r1380213, karaf/branches/karaf-2.3.x/itests/pom.xml
Removed:
    karaf/branches/karaf-2.3.x/itests/NOTICE
    karaf/branches/karaf-2.3.x/itests/dependencies/pom.xml
    karaf/branches/karaf-2.3.x/itests/kittests/pom.xml
    karaf/branches/karaf-2.3.x/itests/kittests/src/test/java/org/apache/karaf/kittests/Helper.java
    karaf/branches/karaf-2.3.x/itests/kittests/src/test/java/org/apache/karaf/kittests/KitTest.java
    karaf/branches/karaf-2.3.x/itests/pom.xml
    karaf/branches/karaf-2.3.x/itests/tests/pom.xml
    karaf/branches/karaf-2.3.x/itests/tests/src/test/java/org/apache/karaf/shell/itests/CoreTest.java
    karaf/branches/karaf-2.3.x/itests/tests/src/test/java/org/apache/karaf/shell/itests/FeaturesTest.java
    karaf/branches/karaf-2.3.x/itests/tests/src/test/resources/log4j.properties
    karaf/branches/karaf-2.3.x/tooling/testing/pom.xml
    karaf/branches/karaf-2.3.x/tooling/testing/src/main/java/org/apache/karaf/testing/AbstractIntegrationTest.java
    karaf/branches/karaf-2.3.x/tooling/testing/src/main/java/org/apache/karaf/testing/HeaderParser.java
    karaf/branches/karaf-2.3.x/tooling/testing/src/main/java/org/apache/karaf/testing/Helper.java
Modified:
    karaf/branches/karaf-2.3.x/pom.xml
    karaf/branches/karaf-2.3.x/tooling/pom.xml

Modified: karaf/branches/karaf-2.3.x/pom.xml
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/pom.xml?rev=1381632&r1=1381631&r2=1381632&view=diff
==============================================================================
--- karaf/branches/karaf-2.3.x/pom.xml (original)
+++ karaf/branches/karaf-2.3.x/pom.xml Thu Sep  6 14:55:30 2012
@@ -48,7 +48,6 @@
         <module>exception</module>
         <module>assemblies</module>
         <module>demos</module>
-        <module>itests</module>
         <module>tooling</module>
         <module>archetypes</module>
         <module>diagnostic</module>
@@ -107,7 +106,9 @@
         <commons-beanutils.version>1.8.3</commons-beanutils.version>
         <commons-codec.version>1.6</commons-codec.version>
         <commons-collections.version>3.2.1</commons-collections.version>
+        <commons-compress.version>1.4.1</commons-compress.version>
         <commons-fileupload.version>1.2.2</commons-fileupload.version>
+        <commons-io.version>1.3.2</commons-io.version>
         <commons-lang.version>2.6</commons-lang.version>
         <icu4j.version>4.8.1.1</icu4j.version>
         <jasypt.bundle.version>1.9.0_1</jasypt.bundle.version>
@@ -153,7 +154,8 @@
         <maven.version>2.0.9</maven.version>
         <mina.version>2.0.4</mina.version>
         <osgi.version>4.3.0</osgi.version>
-        <pax.exam.version>1.2.4</pax.exam.version>
+        <pax.base.version>1.3.0</pax.base.version>
+        <pax.exam.version>2.4.0</pax.exam.version>
         <pax.logging.version>1.6.10</pax.logging.version>
         <pax.runner.version>1.7.6</pax.runner.version>
         <pax.url.version>1.3.5</pax.url.version>
@@ -795,6 +797,22 @@
                 <artifactId>slf4j-simple</artifactId>
                 <version>${slf4j.version}</version>
             </dependency>
+
+            <dependency>
+                <groupId>com.google.guava</groupId>
+                <artifactId>guava</artifactId>
+                <version>13.0.1</version>
+            </dependency>
+            <dependency>
+                <groupId>org.ops4j.base</groupId>
+                <artifactId>ops4j-base-lang</artifactId>
+                <version>${pax.base.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.ops4j.base</groupId>
+                <artifactId>ops4j-base-net</artifactId>
+                <version>${pax.base.version}</version>
+            </dependency>
             <dependency>
                 <groupId>org.ops4j.pax.logging</groupId>
                 <artifactId>pax-logging-api</artifactId>
@@ -873,19 +891,46 @@
             </dependency>
             <dependency>
                 <groupId>org.ops4j.pax.exam</groupId>
-                <artifactId>pax-exam-junit</artifactId>
+                <artifactId>pax-exam-container-remote</artifactId>
+                <version>${pax.exam.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.ops4j.pax.exam</groupId>
+                <artifactId>pax-exam-spi</artifactId>
+                <version>${pax.exam.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.ops4j.pax.exam</groupId>
+                <artifactId>pax-exam-invoker-junit</artifactId>
+                <version>${pax.exam.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.ops4j.pax.exam</groupId>
+                <artifactId>pax-exam-container-rbc</artifactId>
+                <version>${pax.exam.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.ops4j.pax.exam</groupId>
+                <artifactId>pax-exam-container-rbc-client</artifactId>
+                <version>${pax.exam.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.ops4j.pax.exam</groupId>
+                <artifactId>pax-exam-junit4</artifactId>
                 <version>${pax.exam.version}</version>
+                <scope>test</scope>
             </dependency>
             <dependency>
                 <groupId>org.ops4j.pax.exam</groupId>
-                <artifactId>pax-exam-container-default</artifactId>
+                <artifactId>pax-exam-extender-service</artifactId>
                 <version>${pax.exam.version}</version>
             </dependency>
             <dependency>
                 <groupId>org.ops4j.pax.exam</groupId>
-                <artifactId>pax-exam-junit-extender-impl</artifactId>
+                <artifactId>pax-exam-inject</artifactId>
                 <version>${pax.exam.version}</version>
             </dependency>
+
             <dependency>
                 <groupId>org.ops4j.pax.swissbox</groupId>
                 <artifactId>pax-swissbox-tinybundles</artifactId>
@@ -1042,6 +1087,16 @@
                 <version>${commons-collections.version}</version>
             </dependency>
             <dependency>
+                <groupId>org.apache.commons</groupId>
+                <artifactId>commons-compress</artifactId>
+                <version>${commons-compress.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.commons</groupId>
+                <artifactId>commons-io</artifactId>
+                <version>${commons-io.version}</version>
+            </dependency>
+            <dependency>
                 <groupId>commons-lang</groupId>
                 <artifactId>commons-lang</artifactId>
                 <version>${commons-lang.version}</version>

Copied: karaf/branches/karaf-2.3.x/tooling/exam/container/NOTICE (from r1380213, karaf/branches/karaf-2.3.x/itests/NOTICE)
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/tooling/exam/container/NOTICE?p2=karaf/branches/karaf-2.3.x/tooling/exam/container/NOTICE&p1=karaf/branches/karaf-2.3.x/itests/NOTICE&r1=1380213&r2=1381632&rev=1381632&view=diff
==============================================================================
    (empty)

Added: karaf/branches/karaf-2.3.x/tooling/exam/container/pom.xml
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/tooling/exam/container/pom.xml?rev=1381632&view=auto
==============================================================================
--- karaf/branches/karaf-2.3.x/tooling/exam/container/pom.xml (added)
+++ karaf/branches/karaf-2.3.x/tooling/exam/container/pom.xml Thu Sep  6 14:55:30 2012
@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <!--
+
+        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.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.karaf.tooling.exam</groupId>
+        <artifactId>exam</artifactId>
+        <version>2.3.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <groupId>org.apache.karaf.tooling.exam</groupId>
+    <artifactId>org.apache.karaf.tooling.exam.container</artifactId>
+    <packaging>jar</packaging>
+    <name>Apache Karaf :: Tooling :: Exam Testing Framework :: Container</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-extender-service</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-container-rbc</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-invoker-junit</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-container-remote</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-spi</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-container-rbc-client</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.base</groupId>
+            <artifactId>ops4j-base-lang</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.base</groupId>
+            <artifactId>ops4j-base-net</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-compress</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-io</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-inject</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.karaf.tooling.exam</groupId>
+            <artifactId>org.apache.karaf.tooling.exam.options</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <resources>
+            <resource>
+                <directory>src/main/resources</directory>
+                <filtering>true</filtering>
+            </resource>
+        </resources>
+    </build>
+
+</project>
\ No newline at end of file

Added: karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/Constants.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/Constants.java?rev=1381632&view=auto
==============================================================================
--- karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/Constants.java (added)
+++ karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/Constants.java Thu Sep  6 14:55:30 2012
@@ -0,0 +1,28 @@
+/*
+ * 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.karaf.tooling.exam.container.internal;
+
+public interface Constants {
+
+    static final String FEATURES_CFG_LOCATION = "/etc/org.apache.karaf.features.cfg";
+
+    static final int SYSTEM_BUNDLE = 0;
+
+    static final int DEFAULT_START_LEVEL = 5;
+
+}
\ No newline at end of file

Added: karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/ExamFeaturesFile.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/ExamFeaturesFile.java?rev=1381632&view=auto
==============================================================================
--- karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/ExamFeaturesFile.java (added)
+++ karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/ExamFeaturesFile.java Thu Sep  6 14:55:30 2012
@@ -0,0 +1,151 @@
+/*
+ * 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.karaf.tooling.exam.container.internal;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.apache.commons.io.FileUtils;
+import org.ops4j.pax.exam.Info;
+
+public class ExamFeaturesFile {
+
+    private String featuresXml;
+
+    public ExamFeaturesFile() {
+        this("", Constants.DEFAULT_START_LEVEL);
+    }
+
+    public ExamFeaturesFile(String featuresXml) {
+        this(featuresXml, Constants.DEFAULT_START_LEVEL);
+    }
+
+    public ExamFeaturesFile(String extension, int startLevel) {
+        featuresXml =
+                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+                        + "<features name=\"pax-exam-features-"
+                        + Info.getPaxExamVersion()
+                        + "\">\n"
+                        + "<feature name=\"exam\" version=\""
+                        + Info.getPaxExamVersion()
+                        + "\">\n"
+                        + extension + "\n"
+                        + "<bundle start-level='" + startLevel + "'>mvn:org.ops4j.base/ops4j-base-lang/"
+                        + Info.getOps4jBaseVersion()
+                        + "</bundle>\n"
+                        + "<bundle start-level='" + startLevel + "'>mvn:org.ops4j.base/ops4j-base-monitors/"
+                        + Info.getOps4jBaseVersion()
+                        + "</bundle>\n"
+                        + "<bundle start-level='" + startLevel + "'>mvn:org.ops4j.base/ops4j-base-net/"
+                        + Info.getOps4jBaseVersion()
+                        + "</bundle>\n"
+                        + "<bundle start-level='" + startLevel + "'>mvn:org.ops4j.base/ops4j-base-store/"
+                        + Info.getOps4jBaseVersion()
+                        + "</bundle>\n"
+                        + "<bundle start-level='" + startLevel + "'>mvn:org.ops4j.base/ops4j-base-io/"
+                        + Info.getOps4jBaseVersion()
+                        + "</bundle>\n"
+                        + "<bundle start-level='" + startLevel + "'>mvn:org.ops4j.base/ops4j-base-spi/"
+                        + Info.getOps4jBaseVersion()
+                        + "</bundle>\n"
+                        + "<bundle start-level='" + startLevel + "'>mvn:org.ops4j.base/ops4j-base-util-property/"
+                        + Info.getOps4jBaseVersion()
+                        + "</bundle>\n"
+                        + "<bundle start-level='" + startLevel + "'>mvn:org.ops4j.pax.swissbox/pax-swissbox-core/"
+                        + Info.getPaxSwissboxVersion()
+                        + "</bundle>\n"
+                        + "<bundle start-level='" + startLevel + "'>mvn:org.ops4j.pax.swissbox/pax-swissbox-extender/"
+                        + Info.getPaxSwissboxVersion()
+                        + "</bundle>\n"
+                        + "<bundle start-level='" + startLevel + "'>mvn:org.ops4j.pax.swissbox/pax-swissbox-lifecycle/"
+                        + Info.getPaxSwissboxVersion()
+                        + "</bundle>\n"
+                        + "<bundle start-level='" + startLevel + "'>mvn:org.ops4j.pax.swissbox/pax-swissbox-framework/"
+                        + Info.getPaxSwissboxVersion()
+                        + "</bundle>\n"
+                        + "<bundle start-level='" + startLevel + "'>mvn:org.ops4j.pax.exam/pax-exam/"
+                        + Info.getPaxExamVersion()
+                        + "</bundle>\n"
+                        + "<bundle start-level='" + startLevel + "'>mvn:org.ops4j.pax.exam/pax-exam-extender-service/"
+                        + Info.getPaxExamVersion()
+                        + "</bundle>\n"
+                        + "<bundle start-level='" + startLevel + "'>mvn:org.ops4j.pax.exam/pax-exam-container-rbc/"
+                        + Info.getPaxExamVersion()
+                        + "</bundle>\n"
+                        + "<bundle start-level='" + startLevel + "'>wrap:mvn:junit/junit/" + getJunitVersion()
+                        + "</bundle>\n"
+                        + "<bundle start-level='" + startLevel + "'>mvn:org.ops4j.pax.exam/pax-exam-invoker-junit/"
+                        + Info.getPaxExamVersion()
+                        + "</bundle>\n"
+                        + "<bundle start-level='" + startLevel
+                        + "'>mvn:org.apache.karaf.tooling.exam/org.apache.karaf.tooling.exam.options/"
+                        + getOptionsVersion()
+                        + "</bundle>\n"
+                        + "<bundle start-level='" + startLevel
+                        + "'>mvn:org.apache.geronimo.specs/geronimo-atinject_1.0_spec/" + getInjectionVersion()
+                        + "</bundle>\n"
+                        + "<bundle start-level='" + startLevel + "'>mvn:org.ops4j.pax.exam/pax-exam-inject/"
+                        + Info.getPaxExamVersion() + "</bundle>\n"
+                        + "</feature>\n"
+                        + "</features>";
+    }
+
+    private String getJunitVersion() {
+        return getNamedVersion("junit.version");
+    }
+
+    private String getInjectionVersion() {
+        return getNamedVersion("injection.version");
+    }
+
+    private String getOptionsVersion() {
+        return getNamedVersion("options.version");
+    }
+
+    private String getNamedVersion(String name) {
+        String optionsVersion = "";
+        try {
+            final InputStream is = ExamFeaturesFile.class.getClassLoader().getResourceAsStream(
+                    "META-INF/versions.properties"
+            );
+            if (is != null) {
+                final Properties properties = new Properties();
+                properties.load(is);
+                optionsVersion = properties.getProperty(name, "").trim();
+            }
+        } catch (Exception ignore) {
+            // use default versions
+        }
+        return optionsVersion;
+    }
+
+    public void writeToFile(File featuresXmlFile) throws IOException {
+        FileUtils.writeStringToFile(featuresXmlFile, featuresXml);
+    }
+
+    public void adaptDistributionToStartExam(File karafHome, File featuresXmlFile) throws IOException {
+        KarafPropertiesFile karafPropertiesFile = new KarafPropertiesFile(karafHome, Constants.FEATURES_CFG_LOCATION);
+        karafPropertiesFile.load();
+        String finalFilePath = ",file:" + featuresXmlFile.toString().replaceAll("\\\\", "/").replaceAll(" ", "%20");
+        karafPropertiesFile.extend("featuresRepositories", finalFilePath);
+        karafPropertiesFile.extend("featuresBoot", ",exam");
+        karafPropertiesFile.store();
+    }
+}

Added: karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/InternalKarafDistributionConfigurationOption.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/InternalKarafDistributionConfigurationOption.java?rev=1381632&view=auto
==============================================================================
--- karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/InternalKarafDistributionConfigurationOption.java (added)
+++ karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/InternalKarafDistributionConfigurationOption.java Thu Sep  6 14:55:30 2012
@@ -0,0 +1,93 @@
+/*
+ * 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.karaf.tooling.exam.container.internal;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.Properties;
+
+import org.apache.karaf.tooling.exam.options.KarafDistributionBaseConfigurationOption;
+import org.apache.karaf.tooling.exam.options.KarafDistributionConfigurationOption;
+
+/**
+ * Extends the {@link KarafDistributionConfigurationOption} to add functionality to store those values also in a
+ * distribution.info file in the distirbution.
+ */
+public class InternalKarafDistributionConfigurationOption extends KarafDistributionConfigurationOption {
+
+    private static final String NAME = "name";
+    private static final String KARAF_VERSION = "karafVersion";
+
+    private File distributionInfo;
+
+    public InternalKarafDistributionConfigurationOption(KarafDistributionBaseConfigurationOption distributionConfigurationOption, File distributionInfo) {
+        super(distributionConfigurationOption);
+        this.distributionInfo = distributionInfo;
+    }
+
+    @Override
+    public String getKarafVersion() {
+        String internalVersion = super.getKarafVersion();
+        if (internalVersion != null && internalVersion.length() != 0) {
+            return internalVersion;
+        }
+        if (!distributionInfo.exists()) {
+            throw new IllegalStateException(
+                    "Either distribution.info or the property itself has to define a karaf version.");
+        }
+        String retrieveProperty = retrieveProperty(KARAF_VERSION);
+        if (retrieveProperty == null || retrieveProperty.length() == 0) {
+            throw new IllegalStateException(
+                    "Either distribution.info or the property itself has to define a karaf version.");
+        }
+        return retrieveProperty;
+    }
+
+    @Override
+    public String getName() {
+        String internalName = super.getName();
+        if (internalName != null && internalName.length() != 0) {
+            return internalName;
+        }
+        if (!distributionInfo.exists()) {
+            throw new IllegalStateException(
+                    "Either distribution.info or the property itself has to define a name for the distribution..");
+        }
+        String retrieveProperty = retrieveProperty(NAME);
+        if (retrieveProperty == null || retrieveProperty.length() == 0) {
+            throw new IllegalStateException(
+                    "Either distribution.info or the property itself has to define a name for the distribution..");
+        }
+        return retrieveProperty;
+    }
+
+    private String retrieveProperty(String key) {
+        try {
+            FileInputStream fileInputStream = new FileInputStream(distributionInfo);
+            try {
+                Properties props = new Properties();
+                props.load(fileInputStream);
+                return props.getProperty(key);
+            } finally {
+                fileInputStream.close();
+            }
+        } catch (Exception e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+}
\ No newline at end of file

Added: karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/KarafPropertiesFile.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/KarafPropertiesFile.java?rev=1381632&view=auto
==============================================================================
--- karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/KarafPropertiesFile.java (added)
+++ karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/KarafPropertiesFile.java Thu Sep  6 14:55:30 2012
@@ -0,0 +1,76 @@
+/*
+ * 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.karaf.tooling.exam.container.internal;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+import org.apache.commons.io.FileUtils;
+
+public class KarafPropertiesFile {
+
+    private final Properties properties;
+    private final File propertyFile;
+
+    public KarafPropertiesFile(File karafHome, String location) {
+        if (location.startsWith("/")) {
+            propertyFile = new File(karafHome + location);
+        } else {
+            propertyFile = new File(karafHome + "/" + location);
+        }
+        properties = new Properties();
+    }
+
+    public void load() throws IOException {
+        if (!propertyFile.exists()) {
+            return;
+        }
+        properties.load(new FileInputStream(propertyFile));
+    }
+
+    public void put(String key, String value) {
+        properties.put(key, value);
+    }
+
+    public void extend(String key, String value) {
+        if (properties.get(key) == null) {
+            properties.put(key, value);
+            return;
+        }
+        properties.put(key, properties.get(key) + value);
+    }
+
+    public String get(String key) {
+        return properties.getProperty(key);
+    }
+
+    public void store() throws IOException {
+        properties.store(new FileOutputStream(propertyFile), "Modified by paxexam");
+    }
+
+    public void replace(File source) {
+        try {
+            FileUtils.copyFile(source, propertyFile);
+        } catch (IOException e) {
+            throw new IllegalStateException("It is required to replace propertyFile");
+        }
+    }
+
+}
\ No newline at end of file

Added: karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/KarafTestContainer.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/KarafTestContainer.java?rev=1381632&view=auto
==============================================================================
--- karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/KarafTestContainer.java (added)
+++ karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/KarafTestContainer.java Thu Sep  6 14:55:30 2012
@@ -0,0 +1,665 @@
+/*
+ * 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.karaf.tooling.exam.container.internal;
+
+import static org.apache.karaf.tooling.exam.options.KarafDistributionOption.editConfigurationFileExtend;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+import static org.ops4j.pax.exam.rbc.Constants.RMI_HOST_PROPERTY;
+import static org.ops4j.pax.exam.rbc.Constants.RMI_NAME_PROPERTY;
+import static org.ops4j.pax.exam.rbc.Constants.RMI_PORT_PROPERTY;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Properties;
+import java.util.Queue;
+import java.util.Set;
+import java.util.UUID;
+
+import org.apache.commons.compress.archivers.ArchiveEntry;
+import org.apache.commons.compress.archivers.ArchiveInputStream;
+import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
+import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
+import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.filefilter.WildcardFileFilter;
+import org.apache.karaf.tooling.exam.container.internal.adaptions.KarafManipulator;
+import org.apache.karaf.tooling.exam.container.internal.adaptions.KarafManipulatorFactory;
+import org.apache.karaf.tooling.exam.container.internal.runner.Runner;
+import org.apache.karaf.tooling.exam.options.DoNotModifyLogOption;
+import org.apache.karaf.tooling.exam.options.ExamBundlesStartLevel;
+import org.apache.karaf.tooling.exam.options.KarafDistributionBaseConfigurationOption;
+import org.apache.karaf.tooling.exam.options.KarafDistributionConfigurationConsoleOption;
+import org.apache.karaf.tooling.exam.options.KarafDistributionConfigurationFileExtendOption;
+import org.apache.karaf.tooling.exam.options.KarafDistributionConfigurationFileOption;
+import org.apache.karaf.tooling.exam.options.KarafDistributionConfigurationFilePutOption;
+import org.apache.karaf.tooling.exam.options.KarafDistributionConfigurationFileReplacementOption;
+import org.apache.karaf.tooling.exam.options.KarafExamSystemConfigurationOption;
+import org.apache.karaf.tooling.exam.options.KeepRuntimeFolderOption;
+import org.apache.karaf.tooling.exam.options.LogLevelOption;
+import org.apache.karaf.tooling.exam.options.configs.CustomProperties;
+import org.apache.karaf.tooling.exam.options.configs.FeaturesCfg;
+import org.ops4j.pax.exam.ExamSystem;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.RelativeTimeout;
+import org.ops4j.pax.exam.TestAddress;
+import org.ops4j.pax.exam.TestContainer;
+import org.ops4j.pax.exam.TimeoutException;
+import org.ops4j.pax.exam.container.remote.RBCRemoteTarget;
+import org.ops4j.pax.exam.options.BootClasspathLibraryOption;
+import org.ops4j.pax.exam.options.BootDelegationOption;
+import org.ops4j.pax.exam.options.ProvisionOption;
+import org.ops4j.pax.exam.options.ServerModeOption;
+import org.ops4j.pax.exam.options.SystemPackageOption;
+import org.ops4j.pax.exam.options.SystemPropertyOption;
+import org.ops4j.pax.exam.options.UrlReference;
+import org.ops4j.pax.exam.options.extra.FeaturesScannerProvisionOption;
+import org.ops4j.pax.exam.options.extra.VMOption;
+import org.ops4j.pax.exam.rbc.client.RemoteBundleContextClient;
+import org.osgi.framework.Bundle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+public class KarafTestContainer implements TestContainer {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(KarafTestContainer.class);
+
+    private static final String KARAF_TEST_CONTAINER = "KarafTestContainer.start";
+    private static final String EXAM_INVOKER_PROPERTY = "pax.exam.invoker";
+    private static final String EXAM_INJECT_PROPERTY = "pax.exam.inject";
+
+    private final Runner runner;
+    private final RMIRegistry registry;
+    private final ExamSystem system;
+    private KarafDistributionBaseConfigurationOption framework;
+    @SuppressWarnings("unused")
+    private KarafManipulator versionAdaptions;
+
+    private boolean deleteRuntime = true;
+    private boolean started = false;
+    private RBCRemoteTarget target;
+
+    private File targetFolder;
+
+    public KarafTestContainer(ExamSystem system, RMIRegistry registry,
+                              KarafDistributionBaseConfigurationOption framework, Runner runner) {
+        this.framework = framework;
+        this.registry = registry;
+        this.system = system;
+        this.runner = runner;
+    }
+
+    @Override
+    public synchronized TestContainer start() {
+        try {
+            String name = system.createID(KARAF_TEST_CONTAINER);
+
+            KarafExamSystemConfigurationOption[] internalConfigurationOptions =
+                    system.getOptions(KarafExamSystemConfigurationOption.class);
+            Option invokerConfiguration = systemProperty("pax.exam.invoker").value("junit");
+            if (internalConfigurationOptions != null && internalConfigurationOptions.length != 0) {
+                invokerConfiguration =
+                        systemProperty("pax.exam.invoker").value(internalConfigurationOptions[0].getInvoker());
+            }
+
+            ExamSystem subsystem = system.fork(
+                    options(
+                            systemProperty(RMI_HOST_PROPERTY).value(registry.getHost()),
+                            systemProperty(RMI_PORT_PROPERTY).value("" + registry.getPort()),
+                            systemProperty(RMI_NAME_PROPERTY).value(name),
+                            invokerConfiguration,
+                            systemProperty(EXAM_INJECT_PROPERTY).value("true"),
+                            editConfigurationFileExtend("etc/system.properties", "jline.shutdownhook", "true")
+                    ));
+            target = new RBCRemoteTarget(name, registry.getPort(), subsystem.getTimeout());
+
+            System.setProperty("java.protocol.handler.pkgs", "org.ops4j.pax.url");
+
+            URL sourceDistribution = new URL(framework.getFrameworkUrl());
+
+            KeepRuntimeFolderOption[] keepRuntimeFolder = subsystem.getOptions(KeepRuntimeFolderOption.class);
+            if (keepRuntimeFolder != null && keepRuntimeFolder.length != 0) {
+                deleteRuntime = false;
+            }
+
+            targetFolder = retrieveFinalTargetFolder(subsystem);
+            extractKarafDistribution(sourceDistribution, targetFolder);
+
+            File javaHome = new File(System.getProperty("java.home"));
+            File karafBase = searchKarafBase(targetFolder);
+            File distributionInfo = new File(karafBase + "/etc/distribution.info");
+            File karafBin = new File(karafBase + "/bin");
+            File featuresXmlFile = new File(targetFolder + "/examfeatures.xml");
+            File karafHome = karafBase;
+            File deploy = new File(karafBase + "/deploy");
+            String karafData = karafHome + "/data";
+
+            framework = new InternalKarafDistributionConfigurationOption(framework, distributionInfo);
+            versionAdaptions = KarafManipulatorFactory.createManipulator(framework.getKarafVersion());
+
+            ArrayList<String> javaOpts = Lists.newArrayList();
+            appendVmSettingsFromSystem(javaOpts, subsystem);
+            String[] javaEndorsedDirs =
+                    new String[]{ javaHome + "/jre/lib/endorsed", javaHome + "/lib/endorsed", karafHome + "/lib/endorsed" };
+            String[] javaExtDirs =
+                    new String[]{ javaHome + "/jre/lib/ext", javaHome + "/lib/ext", javaHome + "/lib/ext" };
+            String[] karafOpts = new String[]{};
+            ArrayList<String> opts =
+                    Lists.newArrayList("-Dkaraf.startLocalConsole=" + shouldLocalConsoleBeStarted(subsystem),
+                            "-Dkaraf.startRemoteShell=" + shouldRemoteShellBeStarted(subsystem));
+
+            String[] classPath = buildKarafClasspath(karafHome);
+            String main = "org.apache.karaf.main.Main";
+            String options = "";
+            String[] environment = new String[]{};
+            String[] fileEndings = new String[]{ "jar", "war", "zip", "kar", "xml" };
+
+            updateLogProperties(karafHome, subsystem);
+            updateUserSetProperties(karafHome, subsystem);
+            copyBootClasspathLibraries(karafHome, subsystem);
+            setupExamProperties(karafHome, subsystem);
+            makeScriptsInBinExec(karafBin);
+
+            int startLevel = Constants.DEFAULT_START_LEVEL;
+            ExamBundlesStartLevel examBundlesStartLevel = system.getSingleOption(ExamBundlesStartLevel.class);
+            if (examBundlesStartLevel != null) {
+                startLevel = examBundlesStartLevel.getStartLevel();
+            }
+
+            ExamFeaturesFile examFeaturesFile;
+            if (framework.isUseDeployFolder()) {
+                copyReferencedArtifactsToDeployFolder(deploy, subsystem, fileEndings);
+                examFeaturesFile = new ExamFeaturesFile("", startLevel);
+            } else {
+                StringBuilder extension = extractExtensionString(subsystem);
+                examFeaturesFile = new ExamFeaturesFile(extension.toString(), startLevel);
+            }
+            examFeaturesFile.writeToFile(featuresXmlFile);
+
+            examFeaturesFile.adaptDistributionToStartExam(karafHome, featuresXmlFile);
+
+            long startedAt = System.currentTimeMillis();
+
+            runner.exec(environment, karafBase, javaHome.toString(), javaOpts.toArray(new String[]{}),
+                    javaEndorsedDirs, javaExtDirs, karafHome.toString(), karafData, karafOpts,
+                    opts.toArray(new String[]{}), classPath, main, options);
+
+            LOGGER.debug("Test Container started in " + (System.currentTimeMillis() - startedAt) + " millis");
+            LOGGER.info("Wait for test container to finish its initialization " + subsystem.getTimeout());
+
+            if (subsystem.getOptions(ServerModeOption.class).length == 0) {
+                waitForState(org.apache.karaf.tooling.exam.container.internal.Constants.SYSTEM_BUNDLE,
+                        Bundle.ACTIVE, subsystem.getTimeout());
+            }
+            else {
+                LOGGER
+                        .info("System runs in Server Mode. Which means, no Test facility bundles available on target system.");
+            }
+
+            started = true;
+        } catch (IOException e) {
+            throw new RuntimeException("Problem starting container", e);
+        }
+        return this;
+    }
+
+    private void copyBootClasspathLibraries(File karafHome, ExamSystem subsystem) throws MalformedURLException,
+            IOException {
+        BootClasspathLibraryOption[] bootClasspathLibraryOptions =
+                subsystem.getOptions(BootClasspathLibraryOption.class);
+        for (BootClasspathLibraryOption bootClasspathLibraryOption : bootClasspathLibraryOptions) {
+            UrlReference libraryUrl = bootClasspathLibraryOption.getLibraryUrl();
+            FileUtils.copyURLToFile(
+                    new URL(libraryUrl.getURL()),
+                    createFileNameWithRandomPrefixFromUrlAtTarget(libraryUrl.getURL(), new File(karafHome + "/lib"),
+                            new String[]{ "jar" }));
+        }
+    }
+
+    @SuppressWarnings("rawtypes")
+    private StringBuilder extractExtensionString(ExamSystem subsystem) {
+        ProvisionOption[] provisionOptions = subsystem.getOptions(ProvisionOption.class);
+        StringBuilder extension = new StringBuilder();
+        for (ProvisionOption provisionOption : provisionOptions) {
+            if (provisionOption.getURL().startsWith("link") || provisionOption.getURL().startsWith("scan-features")) {
+                // well those we've already handled at another location...
+                continue;
+            }
+            extension.append("<bundle>").append(provisionOption.getURL()).append("</bundle>\n");
+        }
+        return extension;
+    }
+
+    private String shouldRemoteShellBeStarted(ExamSystem subsystem) {
+        KarafDistributionConfigurationConsoleOption[] consoleOptions =
+                subsystem.getOptions(KarafDistributionConfigurationConsoleOption.class);
+        if (consoleOptions == null) {
+            return "true";
+        }
+        for (KarafDistributionConfigurationConsoleOption consoleOption : consoleOptions) {
+            if (consoleOption.getStartRemoteShell() != null) {
+                return consoleOption.getStartRemoteShell() ? "true" : "false";
+            }
+        }
+        return "true";
+    }
+
+    private String shouldLocalConsoleBeStarted(ExamSystem subsystem) {
+        KarafDistributionConfigurationConsoleOption[] consoleOptions =
+                subsystem.getOptions(KarafDistributionConfigurationConsoleOption.class);
+        if (consoleOptions == null) {
+            return "true";
+        }
+        for (KarafDistributionConfigurationConsoleOption consoleOption : consoleOptions) {
+            if (consoleOption.getStartLocalConsole() != null) {
+                return consoleOption.getStartLocalConsole() ? "true" : "false";
+            }
+        }
+        return "true";
+    }
+
+    private void makeScriptsInBinExec(File karafBin) {
+        if (!karafBin.exists()) {
+            return;
+        }
+        File[] files = karafBin.listFiles();
+        for (File file : files) {
+            file.setExecutable(true);
+        }
+    }
+
+    private File retrieveFinalTargetFolder(ExamSystem subsystem) {
+        if (framework.getUnpackDirectory() == null) {
+            return subsystem.getConfigFolder();
+        } else {
+            File target = new File(framework.getUnpackDirectory() + "/" + UUID.randomUUID().toString());
+            target = transformToAbsolutePath(target);
+            target.mkdirs();
+            return target;
+        }
+    }
+
+    private File transformToAbsolutePath(File file) {
+        return new File(file.getAbsolutePath());
+    }
+
+    private void appendVmSettingsFromSystem(ArrayList<String> opts, ExamSystem subsystem) {
+        VMOption[] options = subsystem.getOptions(VMOption.class);
+        for (VMOption option : options) {
+            opts.add(option.getOption());
+        }
+    }
+
+    @SuppressWarnings("rawtypes")
+    private void copyReferencedArtifactsToDeployFolder(File deploy, ExamSystem subsystem, String[] fileEndings) {
+        ProvisionOption[] options = subsystem.getOptions(ProvisionOption.class);
+        for (ProvisionOption option : options) {
+            try {
+                FileUtils.copyURLToFile(new URL(option.getURL()),
+                        createFileNameWithRandomPrefixFromUrlAtTarget(option.getURL(), deploy, fileEndings));
+            } catch (Exception e) {
+                // well, this can happen...
+            }
+        }
+    }
+
+    private File createFileNameWithRandomPrefixFromUrlAtTarget(String url, File deploy, String[] fileEndings) {
+        String prefix = UUID.randomUUID().toString();
+        String realEnding = extractPossibleFileEndingIfMavenArtifact(url, fileEndings);
+        String fileName = new File(url).getName();
+        return new File(deploy + "/" + prefix + "_" + fileName + "." + realEnding);
+    }
+
+    private String extractPossibleFileEndingIfMavenArtifact(String url, String[] fileEndings) {
+        String realEnding = "jar";
+        for (String ending : fileEndings) {
+            if (url.indexOf("/" + ending + "/") > 0) {
+                realEnding = ending;
+                break;
+            }
+        }
+        return realEnding;
+    }
+
+    private void updateUserSetProperties(File karafHome, ExamSystem subsystem) throws IOException {
+        List<KarafDistributionConfigurationFileOption> options = Lists.newArrayList(
+                subsystem.getOptions(KarafDistributionConfigurationFileOption.class));
+        options.addAll(extractFileOptionsBasedOnFeaturesScannerOptions(subsystem));
+        options.addAll(configureBootDelegation(subsystem));
+        options.addAll(configureSystemBundles(subsystem));
+        HashMap<String, HashMap<String, List<KarafDistributionConfigurationFileOption>>> optionMap = Maps.newHashMap();
+        for (KarafDistributionConfigurationFileOption option : options) {
+            if (!optionMap.containsKey(option.getConfigurationFilePath())) {
+                optionMap.put(option.getConfigurationFilePath(),
+                        new HashMap<String, List<KarafDistributionConfigurationFileOption>>());
+            }
+            HashMap<String, List<KarafDistributionConfigurationFileOption>> optionEntries =
+                    optionMap.get(option.getConfigurationFilePath());
+            if (!optionEntries.containsKey(option.getKey())) {
+                optionEntries.put(option.getKey(), new ArrayList<KarafDistributionConfigurationFileOption>());
+            } else {
+                // if special file warn, replace and continue
+                if (!option.getConfigurationFilePath().equals(FeaturesCfg.FILE_PATH)) {
+                    LOGGER.warn("you're trying to add an additional value to a config file; you're current " +
+                            "value will be replaced.");
+                    optionEntries.put(option.getKey(), new ArrayList<KarafDistributionConfigurationFileOption>());
+                }
+            }
+            optionEntries.get(option.getKey()).add(option);
+        }
+        Set<String> configFiles = optionMap.keySet();
+        for (String configFile : configFiles) {
+
+            KarafPropertiesFile karafPropertiesFile = new KarafPropertiesFile(karafHome, configFile);
+            karafPropertiesFile.load();
+            Collection<List<KarafDistributionConfigurationFileOption>> optionsToApply =
+                    optionMap.get(configFile).values();
+            boolean store = true;
+            for (List<KarafDistributionConfigurationFileOption> optionListToApply : optionsToApply) {
+                for (KarafDistributionConfigurationFileOption optionToApply : optionListToApply) {
+                    if (optionToApply instanceof KarafDistributionConfigurationFilePutOption) {
+                        karafPropertiesFile.put(optionToApply.getKey(), optionToApply.getValue());
+                    } else if (optionToApply instanceof KarafDistributionConfigurationFileReplacementOption) {
+                        karafPropertiesFile
+                                .replace(((KarafDistributionConfigurationFileReplacementOption) optionToApply)
+                                        .getSource());
+                        store = false;
+                        break;
+                    } else {
+                        karafPropertiesFile.extend(optionToApply.getKey(), optionToApply.getValue());
+                    }
+                }
+                if (!store) {
+                    break;
+                }
+            }
+            if (store) {
+                karafPropertiesFile.store();
+            }
+        }
+    }
+
+    private Collection<? extends KarafDistributionConfigurationFileOption> configureSystemBundles(ExamSystem subsystem) {
+        SystemPackageOption[] systemPackageOptions = subsystem.getOptions(SystemPackageOption.class);
+        String systemPackageString = "";
+        for (SystemPackageOption systemPackageOption : systemPackageOptions) {
+            if (!systemPackageString.equals("")) {
+                systemPackageString += ",";
+            }
+            systemPackageString += systemPackageOption.getValue();
+        }
+        if (systemPackageString.equals("")) {
+            return Lists.newArrayList();
+        }
+        return Lists.newArrayList(new KarafDistributionConfigurationFileExtendOption(
+                CustomProperties.SYSTEM_PACKAGES_EXTRA, systemPackageString));
+    }
+
+    private Collection<? extends KarafDistributionConfigurationFileOption>
+    configureBootDelegation(ExamSystem subsystem) {
+        BootDelegationOption[] bootDelegationOptions = subsystem.getOptions(BootDelegationOption.class);
+        String bootDelegationString = "";
+        for (BootDelegationOption bootDelegationOption : bootDelegationOptions) {
+            bootDelegationString += ",";
+            bootDelegationString += bootDelegationOption.getValue();
+        }
+        return Lists.newArrayList(new KarafDistributionConfigurationFileExtendOption(CustomProperties.BOOTDELEGATION,
+                bootDelegationString));
+    }
+
+    private Collection<? extends KarafDistributionConfigurationFileOption>
+    extractFileOptionsBasedOnFeaturesScannerOptions(ExamSystem subsystem) {
+        ArrayList<KarafDistributionConfigurationFileOption> retVal = Lists.newArrayList();
+        FeaturesScannerProvisionOption[] features = subsystem.getOptions(FeaturesScannerProvisionOption.class);
+        for (FeaturesScannerProvisionOption feature : features) {
+            String fullFeatureUrl = feature.getURL();
+            String[] split = fullFeatureUrl.split("\\!/");
+            String url = split[0].replaceAll("scan-features:", "");
+            retVal.add(new KarafDistributionConfigurationFileExtendOption(FeaturesCfg.REPOSITORIES, "," + url));
+            retVal.add(new KarafDistributionConfigurationFileExtendOption(FeaturesCfg.BOOT, "," + split[1]));
+        }
+        return retVal;
+    }
+
+    private void setupExamProperties(File karafHome, ExamSystem system) throws IOException {
+        File customPropertiesFile = new File(karafHome + "/etc/system.properties");
+        SystemPropertyOption[] customProps = system.getOptions(SystemPropertyOption.class);
+        Properties karafPropertyFile = new Properties();
+        karafPropertyFile.load(new FileInputStream(customPropertiesFile));
+        for (SystemPropertyOption systemPropertyOption : customProps) {
+            karafPropertyFile.put(systemPropertyOption.getKey(), systemPropertyOption.getValue());
+        }
+        karafPropertyFile.store(new FileOutputStream(customPropertiesFile), "updated by pax-exam");
+    }
+
+    private void updateLogProperties(File karafHome, ExamSystem system) throws IOException {
+        DoNotModifyLogOption[] modifyLog = system.getOptions(DoNotModifyLogOption.class);
+        if (modifyLog != null && modifyLog.length != 0) {
+            LOGGER.info("Log file should not be modified by the test framework");
+            return;
+        }
+        String realLogLevel = retrieveRealLogLevel(system);
+        File customPropertiesFile = new File(karafHome + "/etc/org.ops4j.pax.logging.cfg");
+        Properties karafPropertyFile = new Properties();
+        karafPropertyFile.load(new FileInputStream(customPropertiesFile));
+        karafPropertyFile.put("log4j.rootLogger", realLogLevel + ", out, stdout, osgi:*");
+        karafPropertyFile.store(new FileOutputStream(customPropertiesFile), "updated by pax-exam");
+    }
+
+    private String retrieveRealLogLevel(ExamSystem system) {
+        LogLevelOption[] logLevelOptions = system.getOptions(LogLevelOption.class);
+        return logLevelOptions != null && logLevelOptions.length != 0 ? logLevelOptions[0].getLogLevel().toString()
+                : "WARN";
+    }
+
+    private String[] buildKarafClasspath(File karafHome) {
+        List<String> cp = new ArrayList<String>();
+        File[] jars = new File(karafHome + "/lib").listFiles((FileFilter) new WildcardFileFilter("*.jar"));
+        for (File jar : jars) {
+            cp.add(jar.toString());
+        }
+        return cp.toArray(new String[]{});
+    }
+
+    /**
+     * Since we might get quite deep use a simple breath first search algorithm
+     */
+    private File searchKarafBase(File targetFolder) {
+        Queue<File> searchNext = new LinkedList<File>();
+        searchNext.add(targetFolder);
+        while (!searchNext.isEmpty()) {
+            File head = searchNext.poll();
+            if (!head.isDirectory()) {
+                continue;
+            }
+            boolean system = false;
+            boolean etc = false;
+            for (File file : head.listFiles()) {
+                if (file.isDirectory() && file.getName().equals("system")) {
+                    system = true;
+                }
+                if (file.isDirectory() && file.getName().equals("etc")) {
+                    etc = true;
+                }
+            }
+            if (system && etc) {
+                return head;
+            }
+            searchNext.addAll(Arrays.asList(head.listFiles()));
+        }
+        throw new IllegalStateException("No karaf base dir found in extracted distribution.");
+    }
+
+    private void extractKarafDistribution(URL sourceDistribution, File targetFolder) throws IOException {
+        if (sourceDistribution.getProtocol().equals("file")) {
+            if (sourceDistribution.getFile().indexOf(".zip") > 0) {
+                extractZipDistribution(sourceDistribution, targetFolder);
+            } else if (sourceDistribution.getFile().indexOf(".tar.gz") > 0) {
+                extractTarGzDistribution(sourceDistribution, targetFolder);
+            }
+            else {
+                throw new IllegalStateException(
+                        "Unknow packaging of distribution; only zip or tar.gz could be handled.");
+            }
+            return;
+        }
+        if (sourceDistribution.toExternalForm().indexOf("/zip") > 0) {
+            extractZipDistribution(sourceDistribution, targetFolder);
+        } else if (sourceDistribution.toExternalForm().indexOf("/tar.gz") > 0) {
+            extractTarGzDistribution(sourceDistribution, targetFolder);
+        } else {
+            throw new IllegalStateException(
+                    "Unknow packaging of distribution; only zip or tar.gz could be handled.");
+        }
+    }
+
+    private void extractTarGzDistribution(URL sourceDistribution, File targetFolder) throws IOException,
+            FileNotFoundException {
+        File uncompressedFile = File.createTempFile("uncompressedTarGz-", ".tar");
+        extractGzArchive(sourceDistribution.openStream(), uncompressedFile);
+        extract(new TarArchiveInputStream(new FileInputStream(uncompressedFile)), targetFolder);
+        FileUtils.forceDelete(uncompressedFile);
+    }
+
+    private void extractZipDistribution(URL sourceDistribution, File targetFolder) throws IOException {
+        extract(new ZipArchiveInputStream(sourceDistribution.openStream()), targetFolder);
+    }
+
+    private void extractGzArchive(InputStream tarGz, File tar) throws IOException {
+        BufferedInputStream in = new BufferedInputStream(tarGz);
+        FileOutputStream out = new FileOutputStream(tar);
+        GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in);
+        final byte[] buffer = new byte[1000];
+        int n = 0;
+        while (-1 != (n = gzIn.read(buffer))) {
+            out.write(buffer, 0, n);
+        }
+        out.close();
+        gzIn.close();
+    }
+
+    private void extract(ArchiveInputStream is, File targetDir) throws IOException {
+        try {
+            if (targetDir.exists()) {
+                FileUtils.forceDelete(targetDir);
+            }
+            targetDir.mkdirs();
+            ArchiveEntry entry = is.getNextEntry();
+            while (entry != null) {
+                String name = entry.getName();
+                name = name.substring(name.indexOf("/") + 1);
+                File file = new File(targetDir, name);
+                if (entry.isDirectory()) {
+                    file.mkdirs();
+                } else {
+                    file.getParentFile().mkdirs();
+                    OutputStream os = new FileOutputStream(file);
+                    try {
+                        IOUtils.copy(is, os);
+                    } finally {
+                        IOUtils.closeQuietly(os);
+                    }
+                }
+                entry = is.getNextEntry();
+            }
+        } finally {
+            is.close();
+        }
+    }
+
+    @Override
+    public synchronized TestContainer stop() {
+        LOGGER.debug("Shutting down the test container (Pax Runner)");
+        try {
+            if (started) {
+                target.stop();
+                RemoteBundleContextClient remoteBundleContextClient = target.getClientRBC();
+                if (remoteBundleContextClient != null) {
+                    remoteBundleContextClient.stop();
+
+                }
+                if (runner != null) {
+                    runner.shutdown();
+                }
+            }
+            else {
+                throw new RuntimeException("Container never came up");
+            }
+        } finally {
+            started = false;
+            target = null;
+            if (deleteRuntime) {
+                system.clear();
+                try {
+                    FileUtils.forceDelete(targetFolder);
+                } catch (IOException e) {
+                    LOGGER.info("Can't remove runtime system; shedule it for exit of the jvm.");
+                    try {
+                        FileUtils.forceDeleteOnExit(targetFolder);
+                    } catch (IOException e1) {
+                        LOGGER.error("Well, this should simply not happen...");
+                    }
+                }
+            }
+        }
+        return this;
+    }
+
+    private void waitForState(final long bundleId, final int state, final RelativeTimeout timeout)
+            throws TimeoutException {
+        target.getClientRBC().waitForState(bundleId, state, timeout);
+    }
+
+    @Override
+    public synchronized void call(TestAddress address) {
+        target.call(address);
+    }
+
+    @Override
+    public synchronized long install(InputStream stream) {
+        return install("local", stream);
+    }
+
+    @Override
+    public synchronized long install(String location, InputStream stream) {
+        return target.install(location, stream);
+    }
+
+    @Override
+    public String toString() {
+        return "KarafTestContainer{" + framework.getFrameworkUrl() + "}";
+    }
+}

Added: karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/KarafTestContainerFactory.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/KarafTestContainerFactory.java?rev=1381632&view=auto
==============================================================================
--- karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/KarafTestContainerFactory.java (added)
+++ karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/KarafTestContainerFactory.java Thu Sep  6 14:55:30 2012
@@ -0,0 +1,81 @@
+/*
+ * 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.karaf.tooling.exam.container.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.karaf.tooling.exam.container.internal.runner.KarafJavaRunner;
+import org.apache.karaf.tooling.exam.container.internal.runner.NixRunner;
+import org.apache.karaf.tooling.exam.container.internal.runner.WindowsRunner;
+import org.apache.karaf.tooling.exam.options.KarafDistributionBaseConfigurationOption;
+import org.apache.karaf.tooling.exam.options.KarafDistributionConfigurationOption;
+import org.apache.karaf.tooling.exam.options.KarafDistributionKitConfigurationOption;
+import org.apache.karaf.tooling.exam.options.KarafDistributionKitConfigurationOption.Platform;
+import org.ops4j.pax.exam.ExamSystem;
+import org.ops4j.pax.exam.TestContainer;
+import org.ops4j.pax.exam.TestContainerFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class KarafTestContainerFactory implements TestContainerFactory {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(KarafTestContainer.class);
+    private static final int DEFAULTPORT = 21412;
+    private static final boolean IS_WINDOWS_OS = System.getProperty("os.name").toLowerCase().contains("windows");
+
+    private RMIRegistry m_rmiRegistry;
+
+    public KarafTestContainerFactory() {
+        m_rmiRegistry = new RMIRegistry(DEFAULTPORT, DEFAULTPORT + 1, DEFAULTPORT + 99).selectGracefully();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public TestContainer[] create(ExamSystem system)
+    {
+        List<TestContainer> containers = new ArrayList<TestContainer>();
+        KarafDistributionKitConfigurationOption[] kitOptions =
+                system.getOptions(KarafDistributionKitConfigurationOption.class);
+        for (KarafDistributionKitConfigurationOption kitOption : kitOptions) {
+            if (kitOption.getPlatform().equals(Platform.WINDOWS)) {
+                if (IS_WINDOWS_OS) {
+                    containers.add(new KarafTestContainer(system, m_rmiRegistry, kitOption, new WindowsRunner(kitOption
+                            .getMakeExec(), kitOption.getExec())));
+                    continue;
+                }
+                LOGGER.info("Ignore windows settings on non windows platforms");
+            } else {
+                if (!IS_WINDOWS_OS) {
+                    containers.add(new KarafTestContainer(system, m_rmiRegistry, kitOption, new NixRunner(kitOption
+                            .getMakeExec(), kitOption.getExec())));
+                    continue;
+                }
+                LOGGER.info("Ignore non windows settings on windows platforms");
+            }
+        }
+        KarafDistributionBaseConfigurationOption[] options =
+                system.getOptions(KarafDistributionConfigurationOption.class);
+        for (KarafDistributionBaseConfigurationOption testContainer : options) {
+            containers.add(new KarafTestContainer(system, m_rmiRegistry, testContainer, new KarafJavaRunner()));
+        }
+        return containers.toArray(new TestContainer[containers.size()]);
+    }
+
+}

Added: karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/RMIRegistry.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/RMIRegistry.java?rev=1381632&view=auto
==============================================================================
--- karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/RMIRegistry.java (added)
+++ karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/RMIRegistry.java Thu Sep  6 14:55:30 2012
@@ -0,0 +1,160 @@
+/*
+ * 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.karaf.tooling.exam.container.internal;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+
+import org.ops4j.net.FreePort;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Graceful RMI registry creation/reuse. Tries to reuse an existing one but is fine with creating one on another port.
+ */
+public class RMIRegistry {
+
+    private static final Logger LOG = LoggerFactory.getLogger(RMIRegistry.class);
+
+    @SuppressWarnings("unused")
+    private final Integer m_defaultPort;
+
+    private static final int UNSELECTED = -1;
+
+    final private String m_host;
+    private Integer m_port = UNSELECTED;
+    private Integer m_altMin;
+    private Integer m_altTo;
+    private static final int TREASURE = 30;
+
+    public RMIRegistry(Integer defaultPort, Integer alternativeRangeFrom, Integer alternativeRangeTo) {
+        try {
+            m_host = InetAddress.getLocalHost().getHostName();
+        } catch (UnknownHostException e) {
+            throw new IllegalStateException("Cannot select localhost. That usually not a good sign for networking..");
+        }
+        m_defaultPort = defaultPort;
+        m_altMin = alternativeRangeFrom;
+        m_altTo = alternativeRangeTo;
+    }
+
+    /**
+     * This will make sure a registry exists and is valid m_port. If its not available or does not work for some reason,
+     * it will select another port. This should really not happen usually. But it can.
+     *
+     * @return this for fluent API. Or IllegalStateException if a port has not been detected successfully.
+     */
+    public synchronized RMIRegistry selectGracefully() {
+        int alternativePort = new FreePort(m_altMin, m_altTo).getPort();
+        if ((m_port = select(alternativePort)) == UNSELECTED) {
+            throw new IllegalStateException("No port found for RMI at all. Even though " + alternativePort
+                    + " should have worked. Thats.. not. good. at. all.");
+        }
+        printTakenStatus();
+        return this;
+    }
+
+    private void printTakenStatus() {
+        int in_use = m_port - m_altMin + 1; // the one we just took
+        int max = m_altTo - m_altMin;
+        String info =
+                "Currently " + in_use + " out of " + max + " ports are in use. Port range is from " + m_altMin + " up to "
+                        + m_altTo;
+        if (in_use + TREASURE > max) {
+            LOG.warn("--------------");
+            LOG.warn("BEWARE !!! " + info);
+            LOG.warn("--------------");
+        }
+        else {
+            LOG.debug(info);
+        }
+    }
+
+    /**
+     * This contains basically two paths: 1. check if the given port already is valid rmi registry. Use that one if
+     * possible 2. make a new one at that port otherwise. Must also be validated.
+     *
+     * @param port to select.
+     *
+     * @return input port if successful or UNSELECTED
+     */
+    private Integer select(int port) {
+        if (reuseRegistry(port)) {
+            LOG.debug("Reuse Registry on " + port);
+            return port;
+        }
+        else if (createNewRegistry(port)) {
+            LOG.debug("Created Registry on " + port);
+            return port;
+        }
+        // fail
+        return UNSELECTED;
+    }
+
+    private boolean createNewRegistry(int port) {
+        try {
+            Registry registry = LocateRegistry.createRegistry(port);
+
+            return verifyRegistry(registry);
+
+        } catch (Exception e) {
+            // ignore
+        }
+        return false;
+    }
+
+    private boolean reuseRegistry(int port) {
+        Registry reg = null;
+        try {
+            reg = LocateRegistry.getRegistry(port);
+            return verifyRegistry(reg);
+
+        } catch (Exception e) {
+            // exception? then its not a fine registry.
+        }
+        return false;
+    }
+
+    private boolean verifyRegistry(Registry reg) {
+        if (reg != null) {
+            // test:
+            try {
+                String[] objectsRemote = reg.list();
+
+                for (String r : objectsRemote) {
+                    LOG.info("-- Remotely available already: " + r);
+                }
+                return true;
+
+            } catch (Exception ex) {
+                // exception? then its not a fine registry.
+            }
+        }
+        return false;
+    }
+
+    public String getHost() {
+        return m_host;
+    }
+
+    public int getPort() {
+        return m_port;
+    }
+
+}

Added: karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/adaptions/KarafManipulator.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/adaptions/KarafManipulator.java?rev=1381632&view=auto
==============================================================================
--- karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/adaptions/KarafManipulator.java (added)
+++ karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/adaptions/KarafManipulator.java Thu Sep  6 14:55:30 2012
@@ -0,0 +1,24 @@
+/*
+ * 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.karaf.tooling.exam.container.internal.adaptions;
+
+/**
+ * Core interface defining which functions need to be supported by which Karaf manipulators.
+ */
+public interface KarafManipulator {
+
+}

Added: karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/adaptions/KarafManipulatorFactory.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/adaptions/KarafManipulatorFactory.java?rev=1381632&view=auto
==============================================================================
--- karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/adaptions/KarafManipulatorFactory.java (added)
+++ karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/adaptions/KarafManipulatorFactory.java Thu Sep  6 14:55:30 2012
@@ -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.karaf.tooling.exam.container.internal.adaptions;
+
+import org.osgi.framework.Version;
+
+/**
+ * Factory returning the correct version of the manipulator depending on the added Karaf version.
+ */
+public final class KarafManipulatorFactory {
+
+    private KarafManipulatorFactory() {
+        // Not required for a final class
+    }
+
+    public static KarafManipulator createManipulator(String karafVersion) {
+        Version version = new Version(karafVersion.replaceFirst("-", "."));
+        if (version.getMajor() < 2 || version.getMajor() == 2 && version.getMinor() < 2) {
+            throw new IllegalArgumentException("Karaf versions < 2.2.0 are not supported");
+        }
+        return new KarafManipulatorStartingFrom220();
+    }
+
+}

Added: karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/adaptions/KarafManipulatorStartingFrom220.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/adaptions/KarafManipulatorStartingFrom220.java?rev=1381632&view=auto
==============================================================================
--- karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/adaptions/KarafManipulatorStartingFrom220.java (added)
+++ karaf/branches/karaf-2.3.x/tooling/exam/container/src/main/java/org/apache/karaf/tooling/exam/container/internal/adaptions/KarafManipulatorStartingFrom220.java Thu Sep  6 14:55:30 2012
@@ -0,0 +1,25 @@
+/*
+ * 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.karaf.tooling.exam.container.internal.adaptions;
+
+/**
+ * This manipulator is currently valid for all Karaf versions starting from 2.2.0 and above. In case that a higher
+ * version is not supported any more an additional manipulator will be added.
+ */
+public class KarafManipulatorStartingFrom220 implements KarafManipulator {
+
+}