// Path: container/src/main/java/org/openengsb/labs/paxexam/karaf/container/internal/Constants.java
// 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;
// 
// }
// 
// Path: container/src/main/java/org/openengsb/labs/paxexam/karaf/container/internal/util/NormalisedMavenVersionAdapter.java
// public class NormalisedMavenVersionAdapter extends Version {
// 
//     private static final String VERSION_PATTERN = "[^0-9.]";
// 
//     public NormalisedMavenVersionAdapter(int major, int minor, int micro, String qualifier) {
//         super(major, minor, micro, qualifier);
//     }
// 
//     public NormalisedMavenVersionAdapter(int major, int minor, int micro) {
//         super(major, minor, micro);
//     }
// 
//     public NormalisedMavenVersionAdapter(String version) {
//         super(version.replace("_", ".").replaceAll(VERSION_PATTERN, ""));
//     }
// }


import org.openengsb.labs.paxexam.karaf.container.internal.Constants;
import org.openengsb.labs.paxexam.karaf.container.internal.util.NormalisedMavenVersionAdapter;
import org.ops4j.pax.exam.Info;
import org.osgi.framework.Version;
package org.openengsb.labs.paxexam.karaf.container.internal.examAdaptions;


/**
 * Factory to create a features.xml file meeting the currently used pax-exam version.
 */
public final class ExamFeaturesFileFactory {

    private ExamFeaturesFileFactory() {
        // Not required for a final class
    }

    public static ExamFeaturesFile createExamFeaturesFile() {
        return createExamFeaturesFile("", Constants.DEFAULT_START_LEVEL);
    }

    public static ExamFeaturesFile createExamFeaturesFile(String featuresXml) {
        return createExamFeaturesFile(featuresXml, Constants.DEFAULT_START_LEVEL);
    }

    public static ExamFeaturesFile createExamFeaturesFile(String extension, int startLevel) {
        Version examVersion = retrieveVersion();
        if (examVersion.getMajor() < 2) {
            throw new IllegalStateException("Exam versions < 2.0 are not supported");
        }
        if (examVersion.getMajor() == 2 && examVersion.getMinor() < 4) {
            return new ExamFeaturesFile23(extension, startLevel);
        }
        return new ExamFeaturesFile24(extension, startLevel);
    }

    private static Version retrieveVersion() {
// Path: container/src/main/java/org/openengsb/labs/paxexam/karaf/container/internal/Constants.java
// 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;
// 
// }
// 
// Path: container/src/main/java/org/openengsb/labs/paxexam/karaf/container/internal/util/NormalisedMavenVersionAdapter.java
// public class NormalisedMavenVersionAdapter extends Version {
// 
//     private static final String VERSION_PATTERN = "[^0-9.]";
// 
//     public NormalisedMavenVersionAdapter(int major, int minor, int micro, String qualifier) {
//         super(major, minor, micro, qualifier);
//     }
// 
//     public NormalisedMavenVersionAdapter(int major, int minor, int micro) {
//         super(major, minor, micro);
//     }
// 
//     public NormalisedMavenVersionAdapter(String version) {
//         super(version.replace("_", ".").replaceAll(VERSION_PATTERN, ""));
//     }
// }


// Path: container/src/main/java/org/openengsb/labs/paxexam/karaf/container/internal/examAdaptions/ExamFeaturesFileFactory.java
import org.openengsb.labs.paxexam.karaf.container.internal.Constants;
import org.openengsb.labs.paxexam.karaf.container.internal.util.NormalisedMavenVersionAdapter;
import org.ops4j.pax.exam.Info;
import org.osgi.framework.Version;

package org.openengsb.labs.paxexam.karaf.container.internal.examAdaptions;


/**
 * Factory to create a features.xml file meeting the currently used pax-exam version.
 */
public final class ExamFeaturesFileFactory {

    private ExamFeaturesFileFactory() {
        // Not required for a final class
    }

    public static ExamFeaturesFile createExamFeaturesFile() {
        return createExamFeaturesFile("", Constants.DEFAULT_START_LEVEL);
    }

    public static ExamFeaturesFile createExamFeaturesFile(String featuresXml) {
        return createExamFeaturesFile(featuresXml, Constants.DEFAULT_START_LEVEL);
    }

    public static ExamFeaturesFile createExamFeaturesFile(String extension, int startLevel) {
        Version examVersion = retrieveVersion();
        if (examVersion.getMajor() < 2) {
            throw new IllegalStateException("Exam versions < 2.0 are not supported");
        }
        if (examVersion.getMajor() == 2 && examVersion.getMinor() < 4) {
            return new ExamFeaturesFile23(extension, startLevel);
        }
        return new ExamFeaturesFile24(extension, startLevel);
    }

    private static Version retrieveVersion() {
        return new NormalisedMavenVersionAdapter(Info.getPaxExamVersion());