/*
 * Copyright 2013 Harald Wellmann.
 *
 * Licensed 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.ops4j.pax.cdi.test.karaf;

import static org.ops4j.pax.exam.CoreOptions.composite;
import static org.ops4j.pax.exam.CoreOptions.maven;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;

import java.io.File;

import org.ops4j.pax.cdi.api.Info;
import org.ops4j.pax.exam.ConfigurationManager;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.karaf.options.KarafDistributionOption;
import org.ops4j.pax.exam.options.MavenArtifactUrlReference;
import org.ops4j.pax.exam.options.MavenUrlReference;

/**
 * Default configuration for native container regression tests, overriding the default test system
 * configuration.
 * <p>
 * We do not need the Remote Bundle Context for Native Container, and we prefer unified logging with
 * logback.
 * <p>
 * To override the standard options, you need to set the configuration property
 * {@code pax.exam.system = default}.
 * 
 * @author Harald Wellmann
 * @since Dec 2011
 */
public class RegressionConfiguration {
    public static final MavenUrlReference PAX_CDI_FEATURES = maven().groupId("org.ops4j.pax.cdi")
        .artifactId("pax-cdi-features").type("xml").classifier("features").version(Info.getPaxCdiVersion());
    
    public static final Option SAMPLE1 = mavenBundle().groupId("org.ops4j.pax.cdi.samples")
        .artifactId("pax-cdi-sample1").versionAsInProject();
    
    public static final Option SAMPLE1_WEB = mavenBundle().groupId("org.ops4j.pax.cdi.samples")
        .artifactId("pax-cdi-sample1-web").versionAsInProject();

    public static Option regressionDefaults() {
        return regressionDefaults("target/exam");        
    }

    public static Option regressionDefaults(String unpackDir) {
        return composite(

            karafDistributionConfiguration().frameworkUrl(mvnKarafDist()).karafVersion(karafVersion())
                .unpackDirectory(unpackDirFile(unpackDir)).useDeployFolder(false),                
 
            KarafDistributionOption.keepRuntimeFolder()
            /*
            when(isEquinox()).useOptions(                
                editConfigurationFilePut(CustomProperties.KARAF_FRAMEWORK, "equinox"),
                propagateSystemProperty("pax.exam.framework"),
                systemProperty("osgi.console").value("6666"),
                systemProperty("osgi.console.enable.builtin").value("true"))*/
            );
    }

    private static File unpackDirFile(String unpackDir) {
        return unpackDir == null ? null : new File(unpackDir);
    }

    public static boolean isEquinox() {
        return "equinox".equals(System.getProperty("pax.exam.framework"));
    }

    public static boolean isFelix() {
        return "felix".equals(System.getProperty("pax.exam.framework"));
    }
    
    public static MavenArtifactUrlReference mvnKarafDist() {
        return maven().groupId("org.apache.karaf")
            .artifactId("apache-karaf").type("tar.gz").version(karafVersion());
    }
    
    public static String karafVersion() {
        ConfigurationManager cm = new ConfigurationManager();
        String karafVersion = cm.getProperty("pax.exam.karaf.version", "3.0.0-SNAPSHOT");
        return karafVersion;
    }
}

@@ -800,16 +800,384 @@
 Bundle;%0A
+import static org.ops4j.pax.exam.CoreOptions.propagateSystemProperty;%0Aimport static org.ops4j.pax.exam.CoreOptions.systemProperty;%0Aimport static org.ops4j.pax.exam.CoreOptions.when;%0Aimport static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole;%0Aimport static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;%0A
 import s
@@ -1271,16 +1271,16 @@
 ration;%0A
-
 %0Aimport 
@@ -1468,32 +1468,98 @@
 ributionOption;%0A
+import org.ops4j.pax.exam.karaf.options.configs.CustomProperties;%0A
 import org.ops4j
@@ -1661,428 +1661,8 @@
 e;%0A%0A
-/**%0A * Default configuration for native container regression tests, overriding the default test system%0A * configuration.%0A * %3Cp%3E%0A * We do not need the Remote Bundle Context for Native Container, and we prefer unified logging with%0A * logback.%0A * %3Cp%3E%0A * To override the standard options, you need to set the configuration property%0A * %7B@code pax.exam.system = default%7D.%0A * %0A * @author Harald Wellmann%0A * @since Dec 2011%0A */%0A
 publ
@@ -2636,16 +2636,69 @@
      %0A %0A
+            configureConsole().ignoreLocalConsole(),%0A
         
@@ -2744,16 +2744,17 @@
 Folder()
+,
 %0A       
@@ -2758,18 +2758,16 @@
         
-/*
 %0A       
@@ -3105,18 +3105,16 @@
 %22true%22))
-*/
 %0A       
@@ -3803,24 +3803,24 @@
 nManager();%0A
+
         Stri
@@ -3888,17 +3888,8 @@
 .0.0
--SNAPSHOT
 %22);%0A

Upgrade to Karaf 3.0.0