Search in sources :

Example 1 with BundleStartLevel

use of org.eclipse.sisu.equinox.launching.BundleStartLevel in project tycho by eclipse.

the class TestMojo method createEclipseInstallation.

private EquinoxInstallation createEclipseInstallation() throws MojoExecutionException {
    DependencyResolver platformResolver = dependencyResolverLocator.lookupDependencyResolver(project);
    final List<Dependency> extraDependencies = getExtraDependencies();
    List<ReactorProject> reactorProjects = getReactorProjects();
    final DependencyResolverConfiguration resolverConfiguration = new DependencyResolverConfiguration() {

        @Override
        public OptionalResolutionAction getOptionalResolutionAction() {
            return OptionalResolutionAction.IGNORE;
        }

        @Override
        public List<Dependency> getExtraRequirements() {
            return extraDependencies;
        }
    };
    DependencyArtifacts testRuntimeArtifacts = platformResolver.resolveDependencies(session, project, null, reactorProjects, resolverConfiguration);
    if (testRuntimeArtifacts == null) {
        throw new MojoExecutionException("Cannot determinate build target platform location -- not executing tests");
    }
    work.mkdirs();
    EquinoxInstallationDescription testRuntime = new DefaultEquinoxInstallationDescription();
    testRuntime.setDefaultBundleStartLevel(defaultStartLevel);
    testRuntime.addBundlesToExplode(getBundlesToExplode());
    testRuntime.addFrameworkExtensions(getFrameworkExtensions());
    if (bundleStartLevel != null) {
        for (BundleStartLevel level : bundleStartLevel) {
            testRuntime.addBundleStartLevel(level);
        }
    }
    TestFrameworkProvider provider = providerHelper.selectProvider(getProjectType().getClasspath(project), getMergedProviderProperties(), providerHint);
    createSurefireProperties(provider);
    for (ArtifactDescriptor artifact : testRuntimeArtifacts.getArtifacts(ArtifactType.TYPE_ECLIPSE_PLUGIN)) {
        // note that this project is added as directory structure rooted at project basedir.
        // project classes and test-classes are added via dev.properties file (see #createDevProperties())
        // all other projects are added as bundle jars.
        ReactorProject otherProject = artifact.getMavenProject();
        if (otherProject != null) {
            if (otherProject.sameProject(project)) {
                testRuntime.addBundle(artifact.getKey(), project.getBasedir());
                continue;
            }
            File file = otherProject.getArtifact(artifact.getClassifier());
            if (file != null) {
                testRuntime.addBundle(artifact.getKey(), file);
                continue;
            }
        }
        testRuntime.addBundle(artifact);
    }
    Set<Artifact> testFrameworkBundles = providerHelper.filterTestFrameworkBundles(provider, pluginArtifacts);
    for (Artifact artifact : testFrameworkBundles) {
        DevBundleInfo devInfo = workspaceState.getBundleInfo(session, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), project.getPluginArtifactRepositories());
        if (devInfo != null) {
            testRuntime.addBundle(devInfo.getArtifactKey(), devInfo.getLocation(), true);
            testRuntime.addDevEntries(devInfo.getSymbolicName(), devInfo.getDevEntries());
        } else {
            File bundleLocation = artifact.getFile();
            ArtifactKey bundleArtifactKey = getBundleArtifactKey(bundleLocation);
            testRuntime.addBundle(bundleArtifactKey, bundleLocation, true);
        }
    }
    testRuntime.addDevEntries(getTestBundleSymbolicName(), getBuildOutputDirectories());
    reportsDirectory.mkdirs();
    return installationFactory.createInstallation(testRuntime, work);
}
Also used : DependencyArtifacts(org.eclipse.tycho.artifacts.DependencyArtifacts) BundleStartLevel(org.eclipse.sisu.equinox.launching.BundleStartLevel) ArtifactKey(org.eclipse.tycho.ArtifactKey) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ReactorProject(org.eclipse.tycho.ReactorProject) DefaultReactorProject(org.eclipse.tycho.core.osgitools.DefaultReactorProject) Dependency(org.apache.maven.model.Dependency) DependencyResolverConfiguration(org.eclipse.tycho.core.DependencyResolverConfiguration) Artifact(org.apache.maven.artifact.Artifact) DependencyResolver(org.eclipse.tycho.core.DependencyResolver) EquinoxInstallationDescription(org.eclipse.sisu.equinox.launching.EquinoxInstallationDescription) DefaultEquinoxInstallationDescription(org.eclipse.sisu.equinox.launching.DefaultEquinoxInstallationDescription) ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor) DevBundleInfo(org.eclipse.tycho.dev.DevBundleInfo) DefaultEquinoxInstallationDescription(org.eclipse.sisu.equinox.launching.DefaultEquinoxInstallationDescription) TestFrameworkProvider(org.eclipse.tycho.surefire.provider.spi.TestFrameworkProvider) File(java.io.File)

Example 2 with BundleStartLevel

use of org.eclipse.sisu.equinox.launching.BundleStartLevel in project tycho by eclipse.

the class DefaultEquinoxInstallationFactory method createInstallation.

@Override
public EquinoxInstallation createInstallation(EquinoxInstallationDescription description, File location) {
    Set<String> bundlesToExplode = description.getBundlesToExplode();
    List<File> frameworkExtensions = description.getFrameworkExtensions();
    Map<String, BundleStartLevel> startLevel = description.getBundleStartLevel();
    BundleStartLevel defaultBundleStartLevel = description.getDefaultBundleStartLevel();
    if (defaultBundleStartLevel == null) {
        defaultBundleStartLevel = new BundleStartLevel(null, 4, false);
    }
    Map<ArtifactKey, File> effective = new LinkedHashMap<>();
    for (ArtifactDescriptor artifact : description.getBundles()) {
        ArtifactKey key = artifact.getKey();
        File file = artifact.getLocation();
        OsgiManifest mf = manifestReader.loadManifest(file);
        boolean directoryShape = bundlesToExplode.contains(key.getId()) || mf.isDirectoryShape();
        if (!file.isDirectory() && directoryShape) {
            String filename = key.getId() + "_" + key.getVersion();
            File unpacked = new File(location, "plugins/" + filename);
            unpacked.mkdirs();
            unpack(file, unpacked);
            effective.put(key, unpacked);
        } else {
            effective.put(key, file);
        }
    }
    try {
        location.mkdirs();
        Properties p = new Properties();
        p.putAll(description.getPlatformProperties());
        String newOsgiBundles = toOsgiBundles(effective, startLevel, defaultBundleStartLevel);
        p.setProperty("osgi.bundles", newOsgiBundles);
        // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=234069
        p.setProperty("osgi.bundlefile.limit", "100");
        // @see SimpleConfiguratorConstants#PROP_KEY_EXCLUSIVE_INSTALLATION
        // p.setProperty("org.eclipse.equinox.simpleconfigurator.exclusiveInstallation", "false");
        p.setProperty("osgi.install.area", "file:" + location.getAbsolutePath().replace('\\', '/'));
        p.setProperty("osgi.configuration.cascaded", "false");
        p.setProperty("osgi.framework", "org.eclipse.osgi");
        p.setProperty("osgi.bundles.defaultStartLevel", String.valueOf(defaultBundleStartLevel.getLevel()));
        // fix osgi.framework
        String url = p.getProperty("osgi.framework");
        if (url != null) {
            File file;
            ArtifactDescriptor desc = description.getBundle(url, null);
            if (desc != null) {
                url = "file:" + desc.getLocation().getAbsolutePath().replace('\\', '/');
            } else if (url.startsWith("file:")) {
                String path = url.substring("file:".length());
                file = new File(path);
                if (!file.isAbsolute()) {
                    file = new File(location, path);
                }
                url = "file:" + file.getAbsolutePath().replace('\\', '/');
            }
        }
        if (url != null) {
            p.setProperty("osgi.framework", url);
        }
        if (!frameworkExtensions.isEmpty()) {
            // see osgi.framework.extensions at http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Fruntime-options.html
            Collection<String> bundleNames = unpackFrameworkExtensions(location, frameworkExtensions);
            p.setProperty("osgi.framework", copySystemBundle(description, location));
            p.setProperty("osgi.framework.extensions", StringUtils.join(bundleNames.iterator(), ","));
        }
        if (!description.getDevEntries().isEmpty()) {
            p.put("osgi.dev", createDevProperties(location, description.getDevEntries()));
        }
        File configIni = new File(location, TychoConstants.CONFIG_INI_PATH);
        File configurationLocation = configIni.getParentFile();
        configurationLocation.mkdirs();
        FileOutputStream fos = new FileOutputStream(configIni);
        try {
            p.store(fos, null);
        } finally {
            fos.close();
        }
        return new DefaultEquinoxInstallation(description, location, configurationLocation);
    } catch (IOException e) {
        throw new RuntimeException("Exception creating test eclipse runtime", e);
    }
}
Also used : BundleStartLevel(org.eclipse.sisu.equinox.launching.BundleStartLevel) ArtifactKey(org.eclipse.tycho.ArtifactKey) IOException(java.io.IOException) Properties(java.util.Properties) LinkedHashMap(java.util.LinkedHashMap) ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor) FileOutputStream(java.io.FileOutputStream) OsgiManifest(org.eclipse.tycho.core.osgitools.OsgiManifest) File(java.io.File)

Example 3 with BundleStartLevel

use of org.eclipse.sisu.equinox.launching.BundleStartLevel in project tycho by eclipse.

the class DefaultEquinoxInstallationFactory method toOsgiBundles.

protected String toOsgiBundles(Map<ArtifactKey, File> bundles, Map<String, BundleStartLevel> startLevel, BundleStartLevel defaultStartLevel) throws IOException {
    log.debug("Installation OSGI bundles:");
    StringBuilder result = new StringBuilder();
    for (Map.Entry<ArtifactKey, File> entry : bundles.entrySet()) {
        BundleStartLevel level = startLevel.get(entry.getKey().getId());
        if (level != null && level.getLevel() == -1) {
            // system bundle
            continue;
        }
        if (result.length() > 0) {
            result.append(",");
        }
        StringBuilder line = new StringBuilder();
        line.append(appendAbsolutePath(entry.getValue()));
        if (level != null) {
            line.append('@');
            if (level.getLevel() > 0) {
                line.append(level.getLevel());
            }
            if (level.isAutoStart()) {
                if (line.charAt(line.length() - 1) == '@') {
                    line.append("start");
                } else {
                    line.append(":start");
                }
            }
        } else {
            if (defaultStartLevel.isAutoStart()) {
                line.append("@start");
            }
        }
        log.debug("\t" + line);
        result.append(line.toString());
    }
    return result.toString();
}
Also used : BundleStartLevel(org.eclipse.sisu.equinox.launching.BundleStartLevel) ArtifactKey(org.eclipse.tycho.ArtifactKey) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) File(java.io.File)

Example 4 with BundleStartLevel

use of org.eclipse.sisu.equinox.launching.BundleStartLevel in project tycho by eclipse.

the class DefaultEquinoxInstallationFactoryTest method testExplicitlyConfiguredStartLevelAndAutoStart.

@Test
public void testExplicitlyConfiguredStartLevelAndAutoStart() throws IOException {
    instDesc.addBundleStartLevel(new BundleStartLevel("org.example.bundle1", 6, true));
    List<String> config = splitAtComma(subject.toOsgiBundles(bundles, instDesc.getBundleStartLevel(), defaultLevel));
    assertThat(config, hasItem("reference:file:absolute/path/to/bundle1@6:start"));
}
Also used : BundleStartLevel(org.eclipse.sisu.equinox.launching.BundleStartLevel) Test(org.junit.Test)

Example 5 with BundleStartLevel

use of org.eclipse.sisu.equinox.launching.BundleStartLevel in project tycho by eclipse.

the class DefaultEquinoxInstallationFactoryTest method testDefaultAutoStartIsSet.

@Test
public void testDefaultAutoStartIsSet() throws Exception {
    defaultLevel = new BundleStartLevel(null, 7, true);
    List<String> config = splitAtComma(subject.toOsgiBundles(bundles, instDesc.getBundleStartLevel(), defaultLevel));
    assertThat(config, hasItem("reference:file:absolute/path/to/bundle2@start"));
}
Also used : BundleStartLevel(org.eclipse.sisu.equinox.launching.BundleStartLevel) Test(org.junit.Test)

Aggregations

BundleStartLevel (org.eclipse.sisu.equinox.launching.BundleStartLevel)9 File (java.io.File)4 Test (org.junit.Test)4 DefaultEquinoxInstallationDescription (org.eclipse.sisu.equinox.launching.DefaultEquinoxInstallationDescription)3 ArtifactKey (org.eclipse.tycho.ArtifactKey)3 IOException (java.io.IOException)2 LinkedHashMap (java.util.LinkedHashMap)2 EquinoxInstallationDescription (org.eclipse.sisu.equinox.launching.EquinoxInstallationDescription)2 ArtifactDescriptor (org.eclipse.tycho.ArtifactDescriptor)2 FileOutputStream (java.io.FileOutputStream)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Artifact (org.apache.maven.artifact.Artifact)1 Dependency (org.apache.maven.model.Dependency)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 EquinoxRuntimeDescription (org.eclipse.sisu.equinox.embedder.EquinoxRuntimeLocator.EquinoxRuntimeDescription)1 EquinoxInstallation (org.eclipse.sisu.equinox.launching.EquinoxInstallation)1 DefaultArtifactKey (org.eclipse.tycho.DefaultArtifactKey)1 ReactorProject (org.eclipse.tycho.ReactorProject)1 DependencyArtifacts (org.eclipse.tycho.artifacts.DependencyArtifacts)1