Search in sources :

Example 1 with DefaultCompositeOption

use of org.ops4j.pax.exam.options.DefaultCompositeOption in project sling by apache.

the class PaxExamUtilities method paxConfig.

public static Option[] paxConfig() {
    final File thisProjectsBundle = new File(System.getProperty("bundle.file.name", "BUNDLE_FILE_NOT_SET"));
    final String launchpadVersion = System.getProperty("sling.launchpad.version", "LAUNCHPAD_VERSION_NOT_SET");
    log.info("Sling launchpad version: {}", launchpadVersion);
    SlingPaxOptions.setIgnoredBundles("org.apache.sling.jcr.contentloader");
    try {
        return new DefaultCompositeOption(SlingPaxOptions.defaultLaunchpadOptions(launchpadVersion), provision(bundle(thisProjectsBundle.toURI().toString())), wrappedBundle(mavenBundle("org.apache.sling", "org.apache.sling.commons.testing").versionAsInProject()), wrappedBundle(mavenBundle("org.ops4j.pax.tinybundles", "tinybundles").versionAsInProject()), mavenBundle("org.apache.sling", "org.apache.sling.commons.johnzon").versionAsInProject(), mavenBundle("biz.aQute.bnd", "bndlib").versionAsInProject()).getOptions();
    } finally {
        SlingPaxOptions.setIgnoredBundles();
    }
}
Also used : File(java.io.File) DefaultCompositeOption(org.ops4j.pax.exam.options.DefaultCompositeOption)

Example 2 with DefaultCompositeOption

use of org.ops4j.pax.exam.options.DefaultCompositeOption in project sling by apache.

the class SlingPaxOptions method slingBundleList.

public static CompositeOption slingBundleList(String groupId, String artifactId, String version, String type, String classifier) {
    final DefaultCompositeOption result = new DefaultCompositeOption();
    final String paxUrl = new StringBuilder().append("mvn:").append(groupId).append("/").append(artifactId).append("/").append(version == null ? "" : version).append("/").append(type == null ? "" : type).append("/").append(classifier == null ? "" : classifier).toString();
    // TODO BundleList should take an InputStream - for now copy to a tmp file for parsing
    log.info("Getting bundle list {}", paxUrl);
    File tmp = null;
    final Collection<String> testRunModes = getTestRunModes();
    try {
        tmp = dumpMvnUrlToTmpFile(paxUrl);
        final BundleList list = BundleListUtils.readBundleList(tmp);
        int counter = 0;
        int ignored = 0;
        for (StartLevel s : list.getStartLevels()) {
            // Start level < 0 means bootstrap in our bundle lists
            final int startLevel = s.getStartLevel() < 0 ? 1 : s.getStartLevel();
            for (Bundle b : s.getBundles()) {
                if (ignore(b)) {
                    log.info("Bundle ignored due to setIgnoredBundles: {}", b);
                    ignored++;
                    continue;
                }
                counter++;
                // TODO need better fragment detection
                // (but pax exam should really detect that by itself?)
                final List<String> KNOWN_FRAGMENTS = new ArrayList<String>();
                KNOWN_FRAGMENTS.add("org.apache.sling.extensions.webconsolebranding");
                final boolean isFragment = b.getArtifactId().contains("fragment") || KNOWN_FRAGMENTS.contains(b.getArtifactId());
                // Ignore bundles with run modes that do not match ours 
                final String bundleRunModes = b.getRunModes();
                if (bundleRunModes != null && bundleRunModes.length() > 0) {
                    boolean active = false;
                    for (String m : bundleRunModes.split(",")) {
                        if (testRunModes.contains(m)) {
                            active = true;
                            break;
                        }
                    }
                    if (!active) {
                        log.info("Ignoring bundle {} as none of its run modes [{}] are active in this test run {}", new Object[] { b.getArtifactId(), bundleRunModes, testRunModes });
                        continue;
                    }
                }
                if (isFragment) {
                    result.add(mavenBundle(b.getGroupId(), b.getArtifactId(), b.getVersion()).noStart());
                } else if (startLevel == 0) {
                    result.add(mavenBundle(b.getGroupId(), b.getArtifactId(), b.getVersion()));
                } else {
                    result.add(mavenBundle(b.getGroupId(), b.getArtifactId(), b.getVersion()).startLevel(startLevel));
                }
                log.info("Bundle added: {}/{}/{}", new Object[] { b.getGroupId(), b.getArtifactId(), b.getVersion() });
            }
        }
        log.info("Got {} bundles ({} ignored) from {}", new Object[] { counter, ignored, paxUrl });
    } catch (Exception e) {
        throw new RuntimeException("Error getting bundle list " + paxUrl, e);
    } finally {
        if (tmp != null) {
            tmp.delete();
        }
    }
    return result;
}
Also used : BundleList(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList) CoreOptions.mavenBundle(org.ops4j.pax.exam.CoreOptions.mavenBundle) Bundle(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle) ArrayList(java.util.ArrayList) DefaultCompositeOption(org.ops4j.pax.exam.options.DefaultCompositeOption) IOException(java.io.IOException) StartLevel(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel) File(java.io.File)

Aggregations

File (java.io.File)2 DefaultCompositeOption (org.ops4j.pax.exam.options.DefaultCompositeOption)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Bundle (org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle)1 BundleList (org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList)1 StartLevel (org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel)1 CoreOptions.mavenBundle (org.ops4j.pax.exam.CoreOptions.mavenBundle)1