Search in sources :

Example 6 with BundleStartLevel

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

Example 7 with BundleStartLevel

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

the class DefaultEquinoxInstallationFactoryTest method setup.

@Before
public void setup() {
    bundles = new HashMap<>();
    bundles.put(new DefaultArtifactKey("eclipse-plugin", "org.example.bundle1", "1.0"), mockFile("absolute/path/to/bundle1"));
    bundles.put(new DefaultArtifactKey("eclipse-plugin", "org.example.bundle2", "1.0"), mockFile("absolute/path/to/bundle2"));
    instDesc = new DefaultEquinoxInstallationDescription();
    defaultLevel = new BundleStartLevel(null, 7, false);
    subject = new DefaultEquinoxInstallationFactory(mock(Logger.class));
}
Also used : BundleStartLevel(org.eclipse.sisu.equinox.launching.BundleStartLevel) DefaultEquinoxInstallationDescription(org.eclipse.sisu.equinox.launching.DefaultEquinoxInstallationDescription) DefaultArtifactKey(org.eclipse.tycho.DefaultArtifactKey) Before(org.junit.Before)

Example 8 with BundleStartLevel

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

the class DefaultEquinoxInstallationFactoryTest method testExplicitlyConfiguredStartLevel.

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

Example 9 with BundleStartLevel

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

the class DefaultEquinoxInstallationFactoryTest method testExplicitlyConfiguredAutoStart.

@Test
public void testExplicitlyConfiguredAutoStart() throws Exception {
    // level attribute omitted
    instDesc.addBundleStartLevel(new BundleStartLevel("org.example.bundle1", 0, true));
    List<String> config = splitAtComma(subject.toOsgiBundles(bundles, instDesc.getBundleStartLevel(), defaultLevel));
    // implicitly use default start level
    assertThat(config, hasItem("reference:file:absolute/path/to/bundle1@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