From 8898877dacbec59f7eb5c9b154e29ba3da48485a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Tue, 12 Dec 2023 09:22:45 +0100 Subject: [PATCH] Support using a provisioned install for eclipse-run mojo Currently Tycho always assembles the eclipse installation used by the eclipse run mojo but in some cases it is more useful to run an existing application. This now adds support to use an already assembled eclipse installation. --- .../ProvisionedEquinoxInstallation.java | 6 +- .../ProvisionedInstallationDescription.java | 59 ++++++++++--------- .../tycho/eclipserun/EclipseRunMojo.java | 24 ++++++-- .../ProvisionedInstallationBuilder.java | 1 + 4 files changed, 53 insertions(+), 37 deletions(-) rename {tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/provisioning => sisu-osgi/sisu-equinox-launching/src/main/java/org/eclipse/sisu/equinox/launching}/ProvisionedEquinoxInstallation.java (91%) rename {tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/provisioning => sisu-osgi/sisu-equinox-launching/src/main/java/org/eclipse/sisu/equinox/launching}/ProvisionedInstallationDescription.java (77%) 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/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..5864300038 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); } @@ -336,6 +349,9 @@ private void addDefaultDependencies(P2Resolver resolver) { } private EquinoxInstallation createEclipseInstallation() throws MojoFailureException { + if (repositories == null || repositories.isEmpty()) { + throw new MojoFailureException("At least one repository must be specified!"); + } TargetPlatformConfigurationStub tpConfiguration = new TargetPlatformConfigurationStub(); // we want to resolve from remote repos only tpConfiguration.setIgnoreLocalArtifacts(true); 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;