Search in sources :

Example 1 with EquinoxInstallationDescription

use of org.eclipse.sisu.equinox.launching.EquinoxInstallationDescription 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 EquinoxInstallationDescription

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

the class P2ApplicationLauncher method execute.

public int execute(int forkedProcessTimeoutInSeconds) {
    try {
        File installationFolder = newTemporaryFolder();
        try {
            final EquinoxInstallationDescription description = new DefaultEquinoxInstallationDescription();
            runtimeLocator.locateRuntime(new EquinoxRuntimeDescription() {

                @Override
                public void addPlatformProperty(String property, String value) {
                    description.addPlatformProperty(property, value);
                }

                @Override
                public void addInstallation(File location) {
                    for (File file : new File(location, "plugins").listFiles()) {
                        P2ApplicationLauncher.this.addBundle(description, file);
                    }
                }

                @Override
                public void addExtraSystemPackage(String systemPackages) {
                }

                @Override
                public void addBundle(File location) {
                    P2ApplicationLauncher.this.addBundle(description, location);
                }

                @Override
                public void addBundleStartLevel(String id, int level, boolean autostart) {
                    description.addBundleStartLevel(new BundleStartLevel(id, level, autostart));
                }
            });
            EquinoxInstallation installation = installationFactory.createInstallation(description, installationFolder);
            EquinoxLaunchConfiguration launchConfiguration = new EquinoxLaunchConfiguration(installation);
            launchConfiguration.setWorkingDirectory(workingDirectory);
            launchConfiguration.addProgramArguments("-configuration", installation.getConfigurationLocation().getAbsolutePath());
            if (logger.isDebugEnabled()) {
                launchConfiguration.addProgramArguments("-debug", "-consoleLog");
                launchConfiguration.addProgramArguments("-console");
            }
            // application and application arguments
            launchConfiguration.addProgramArguments("-nosplash", "-application", applicationName);
            launchConfiguration.addProgramArguments(args.toArray(new String[args.size()]));
            return launcher.execute(launchConfiguration, forkedProcessTimeoutInSeconds);
        } finally {
            try {
                FileUtils.deleteDirectory(installationFolder);
            } catch (IOException e) {
                // this may happen if child process did not close all file handles
                logger.warn("Failed to delete temp folder " + installationFolder);
            }
        }
    } catch (Exception e) {
        // TODO better exception?
        throw new RuntimeException(e);
    }
}
Also used : BundleStartLevel(org.eclipse.sisu.equinox.launching.BundleStartLevel) IOException(java.io.IOException) EquinoxInstallation(org.eclipse.sisu.equinox.launching.EquinoxInstallation) IOException(java.io.IOException) EquinoxInstallationDescription(org.eclipse.sisu.equinox.launching.EquinoxInstallationDescription) DefaultEquinoxInstallationDescription(org.eclipse.sisu.equinox.launching.DefaultEquinoxInstallationDescription) EquinoxRuntimeDescription(org.eclipse.sisu.equinox.embedder.EquinoxRuntimeLocator.EquinoxRuntimeDescription) DefaultEquinoxInstallationDescription(org.eclipse.sisu.equinox.launching.DefaultEquinoxInstallationDescription) File(java.io.File)

Aggregations

File (java.io.File)2 BundleStartLevel (org.eclipse.sisu.equinox.launching.BundleStartLevel)2 DefaultEquinoxInstallationDescription (org.eclipse.sisu.equinox.launching.DefaultEquinoxInstallationDescription)2 EquinoxInstallationDescription (org.eclipse.sisu.equinox.launching.EquinoxInstallationDescription)2 IOException (java.io.IOException)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 ArtifactDescriptor (org.eclipse.tycho.ArtifactDescriptor)1 ArtifactKey (org.eclipse.tycho.ArtifactKey)1 ReactorProject (org.eclipse.tycho.ReactorProject)1 DependencyArtifacts (org.eclipse.tycho.artifacts.DependencyArtifacts)1 DependencyResolver (org.eclipse.tycho.core.DependencyResolver)1 DependencyResolverConfiguration (org.eclipse.tycho.core.DependencyResolverConfiguration)1 DefaultReactorProject (org.eclipse.tycho.core.osgitools.DefaultReactorProject)1 DevBundleInfo (org.eclipse.tycho.dev.DevBundleInfo)1 TestFrameworkProvider (org.eclipse.tycho.surefire.provider.spi.TestFrameworkProvider)1