diff --git a/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/provisioning/ProvisionedEquinoxInstallation.java b/sisu-osgi/sisu-equinox-launching/src/main/java/org/eclipse/sisu/equinox/launching/ProvisionedEquinoxInstallation.java similarity index 91% rename from tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/provisioning/ProvisionedEquinoxInstallation.java rename to sisu-osgi/sisu-equinox-launching/src/main/java/org/eclipse/sisu/equinox/launching/ProvisionedEquinoxInstallation.java index 934f48f3bc..1ad3576d94 100644 --- a/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/provisioning/ProvisionedEquinoxInstallation.java +++ b/sisu-osgi/sisu-equinox-launching/src/main/java/org/eclipse/sisu/equinox/launching/ProvisionedEquinoxInstallation.java @@ -10,12 +10,10 @@ * Contributors: * Mickael Istria (Red Hat Inc.) - 386988 Support for provisioned applications ******************************************************************************/ -package org.eclipse.tycho.surefire.provisioning; +package org.eclipse.sisu.equinox.launching; import java.io.File; -import org.eclipse.sisu.equinox.launching.EquinoxInstallation; -import org.eclipse.sisu.equinox.launching.EquinoxInstallationDescription; import org.eclipse.sisu.equinox.launching.internal.EquinoxInstallationLaunchConfiguration; /** @@ -33,7 +31,7 @@ public class ProvisionedEquinoxInstallation implements EquinoxInstallation { public ProvisionedEquinoxInstallation(File location) { this.location = location; - description = new ProvisionedInstallationDescription(location, null); + description = new ProvisionedInstallationDescription(location); } @Override diff --git a/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/provisioning/ProvisionedInstallationDescription.java b/sisu-osgi/sisu-equinox-launching/src/main/java/org/eclipse/sisu/equinox/launching/ProvisionedInstallationDescription.java similarity index 77% rename from tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/provisioning/ProvisionedInstallationDescription.java rename to sisu-osgi/sisu-equinox-launching/src/main/java/org/eclipse/sisu/equinox/launching/ProvisionedInstallationDescription.java index ca8df0d362..7ebd4de566 100644 --- a/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/provisioning/ProvisionedInstallationDescription.java +++ b/sisu-osgi/sisu-equinox-launching/src/main/java/org/eclipse/sisu/equinox/launching/ProvisionedInstallationDescription.java @@ -10,23 +10,22 @@ * Contributors: * Mickael Istria (Red Hat Inc.) - 386988 Support for provisioned applications ******************************************************************************/ -package org.eclipse.tycho.surefire.provisioning; +package org.eclipse.sisu.equinox.launching; import java.io.File; import java.io.FileFilter; +import java.io.IOException; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.jar.JarFile; import org.eclipse.osgi.internal.framework.EquinoxContainer; -import org.eclipse.sisu.equinox.launching.BundleReference; -import org.eclipse.sisu.equinox.launching.BundleStartLevel; -import org.eclipse.sisu.equinox.launching.EquinoxInstallationDescription; import org.eclipse.tycho.ArtifactKey; import org.eclipse.tycho.ArtifactType; import org.eclipse.tycho.DefaultArtifactKey; -import org.eclipse.tycho.core.osgitools.BundleReader; +import org.osgi.framework.Constants; /** * A "read-only" equinox installation (no bundles can be added, nothing configured). All @@ -36,11 +35,9 @@ public class ProvisionedInstallationDescription implements EquinoxInstallationDe private File location; private BundleReference systemBundleDescriptor; - private BundleReader bundleReader; - ProvisionedInstallationDescription(File location, BundleReader bundleReader) { + ProvisionedInstallationDescription(File location) { this.location = location; - this.bundleReader = bundleReader; } @Override @@ -61,27 +58,31 @@ public BundleReference getSystemBundle() { } else { systemBundle = systemBundles[0]; } - String version = bundleReader.loadManifest(systemBundle).getBundleVersion(); - ArtifactKey systemBundleKey = new DefaultArtifactKey(ArtifactType.TYPE_ECLIPSE_PLUGIN, EquinoxContainer.NAME, - version); - systemBundleDescriptor = new BundleReference() { - - @Override - public String getVersion() { - return systemBundleKey.getVersion(); - } - - @Override - public File getLocation() { - return systemBundle; - } - - @Override - public String getId() { - return systemBundleKey.getId(); - } - }; - return systemBundleDescriptor; + try (JarFile jarFile = new JarFile(systemBundle)) { + String version = jarFile.getManifest().getMainAttributes().getValue(Constants.BUNDLE_VERSION); + ArtifactKey systemBundleKey = new DefaultArtifactKey(ArtifactType.TYPE_ECLIPSE_PLUGIN, + EquinoxContainer.NAME, version); + systemBundleDescriptor = new BundleReference() { + + @Override + public String getVersion() { + return systemBundleKey.getVersion(); + } + + @Override + public File getLocation() { + return systemBundle; + } + + @Override + public String getId() { + return systemBundleKey.getId(); + } + }; + return systemBundleDescriptor; + } catch (IOException e) { + throw new IllegalArgumentException("Can't read system bundle " + systemBundle.getAbsolutePath()); + } } @Override diff --git a/sisu-osgi/sisu-equinox-launching/src/main/java/org/eclipse/sisu/equinox/launching/internal/DefaultEquinoxLauncher.java b/sisu-osgi/sisu-equinox-launching/src/main/java/org/eclipse/sisu/equinox/launching/internal/DefaultEquinoxLauncher.java index a53261c229..8444f513c0 100644 --- a/sisu-osgi/sisu-equinox-launching/src/main/java/org/eclipse/sisu/equinox/launching/internal/DefaultEquinoxLauncher.java +++ b/sisu-osgi/sisu-equinox-launching/src/main/java/org/eclipse/sisu/equinox/launching/internal/DefaultEquinoxLauncher.java @@ -14,7 +14,9 @@ import java.io.File; import java.io.IOException; +import java.util.Arrays; import java.util.Map; +import java.util.stream.Collectors; import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.DefaultExecutor; @@ -64,7 +66,7 @@ public int execute(LaunchConfiguration configuration, int forkedProcessTimeoutIn executor.setWatchdog(watchdog); } - log.info("Command line:\n\t" + cli.toString()); + log.info("Command line: " + Arrays.stream(cli.toStrings()).collect(Collectors.joining(" "))); // best effort to avoid orphaned child process executor.setProcessDestroyer(new ShutdownHookProcessDestroyer()); diff --git a/tycho-eclipse-plugin/src/main/java/org/eclipse/tycho/eclipserun/EclipseRunMojo.java b/tycho-eclipse-plugin/src/main/java/org/eclipse/tycho/eclipserun/EclipseRunMojo.java index c694169d93..77866b40dc 100644 --- a/tycho-eclipse-plugin/src/main/java/org/eclipse/tycho/eclipserun/EclipseRunMojo.java +++ b/tycho-eclipse-plugin/src/main/java/org/eclipse/tycho/eclipserun/EclipseRunMojo.java @@ -43,6 +43,7 @@ import org.eclipse.sisu.equinox.launching.EquinoxInstallationFactory; import org.eclipse.sisu.equinox.launching.EquinoxLauncher; import org.eclipse.sisu.equinox.launching.LaunchConfiguration; +import org.eclipse.sisu.equinox.launching.ProvisionedEquinoxInstallation; import org.eclipse.sisu.equinox.launching.internal.EquinoxLaunchConfiguration; import org.eclipse.tycho.ArtifactType; import org.eclipse.tycho.ExecutionEnvironmentConfiguration; @@ -84,6 +85,13 @@ public class EclipseRunMojo extends AbstractMojo { @Parameter(defaultValue = "${project.build.directory}/eclipserun-work") private File work; + /** + * Allows to use a prebuild installation to perform the run instead of one + * assembled by Tycho + */ + @Parameter + private File installation; + /** * Whether the workspace should be cleared before running eclipse. *

@@ -139,7 +147,7 @@ public class EclipseRunMojo extends AbstractMojo { * </repositories> * */ - @Parameter(required = true) + @Parameter private List repositories; @Parameter(property = "session", readonly = true, required = true) @@ -282,7 +290,7 @@ public EclipseRunMojo(File work, boolean clearWorkspaceBeforeLaunch, MavenProjec List applicationArgs, int forkedProcessTimeoutInSeconds, Map environmentVariables, EquinoxInstallationFactory installationFactory, EquinoxLauncher launcher, ToolchainProvider toolchainProvider, P2ResolverFactory resolverFactory, Logger logger, - ToolchainManager toolchainManager, TargetPlatformFactory platformFactory) { + ToolchainManager toolchainManager, TargetPlatformFactory platformFactory, File installation) { this.work = work; this.clearWorkspaceBeforeLaunch = clearWorkspaceBeforeLaunch; this.project = project; @@ -303,6 +311,7 @@ public EclipseRunMojo(File work, boolean clearWorkspaceBeforeLaunch, MavenProjec this.logger = logger; this.toolchainManager = toolchainManager; this.platformFactory = platformFactory; + this.installation = installation; } @Override @@ -312,8 +321,12 @@ public void execute() throws MojoExecutionException, MojoFailureException { return; } EquinoxInstallation installation; - synchronized (CREATE_LOCK) { - installation = createEclipseInstallation(); + if (this.installation != null) { + installation = new ProvisionedEquinoxInstallation(this.installation); + } else { + synchronized (CREATE_LOCK) { + installation = createEclipseInstallation(); + } } runEclipse(installation); } @@ -339,8 +352,11 @@ private EquinoxInstallation createEclipseInstallation() throws MojoFailureExcept TargetPlatformConfigurationStub tpConfiguration = new TargetPlatformConfigurationStub(); // we want to resolve from remote repos only tpConfiguration.setIgnoreLocalArtifacts(true); - for (Repository repository : repositories) { - tpConfiguration.addP2Repository(new MavenRepositoryLocation(repository.getId(), repository.getLocation())); + if (repositories != null) { + for (Repository repository : repositories) { + tpConfiguration + .addP2Repository(new MavenRepositoryLocation(repository.getId(), repository.getLocation())); + } } ExecutionEnvironmentConfiguration eeConfiguration = new ExecutionEnvironmentConfigurationImpl(logger, false, toolchainManager, session); @@ -386,7 +402,7 @@ public void runEclipse(EquinoxInstallation runtime) throws MojoExecutionExceptio getLog().info("Expected Eclipse log file: " + expectedLog.getCanonicalPath()); int returnCode = launcher.execute(cli, forkedProcessTimeoutInSeconds); if (returnCode != 0) { - throw new MojoExecutionException("Error while executing platform: return code=" + returnCode + throw new MojoExecutionException("Error while executing eclipse: return code=" + returnCode + ", see content of " + expectedLog + "for more details."); } } diff --git a/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/provisioning/ProvisionedInstallationBuilder.java b/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/provisioning/ProvisionedInstallationBuilder.java index 5d79a3bda3..63958d18aa 100644 --- a/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/provisioning/ProvisionedInstallationBuilder.java +++ b/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/provisioning/ProvisionedInstallationBuilder.java @@ -22,6 +22,7 @@ import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.FileUtils; import org.eclipse.sisu.equinox.launching.EquinoxInstallation; +import org.eclipse.sisu.equinox.launching.ProvisionedEquinoxInstallation; import org.eclipse.tycho.PlatformPropertiesUtils; import org.eclipse.tycho.TargetEnvironment; import org.eclipse.tycho.p2.tools.director.shared.DirectorCommandException;