Skip to content

Commit

Permalink
[backport] Support using a provisioned install for eclipse-run mojo
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
laeubi committed Dec 13, 2023
1 parent f0537d5 commit fbfca8b
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand 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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
* <p>
Expand Down Expand Up @@ -139,7 +147,7 @@ public class EclipseRunMojo extends AbstractMojo {
* &lt;/repositories&gt;
* </pre>
*/
@Parameter(required = true)
@Parameter
private List<Repository> repositories;

@Parameter(property = "session", readonly = true, required = true)
Expand Down Expand Up @@ -282,7 +290,7 @@ public EclipseRunMojo(File work, boolean clearWorkspaceBeforeLaunch, MavenProjec
List<String> applicationArgs, int forkedProcessTimeoutInSeconds, Map<String, String> 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;
Expand All @@ -303,6 +311,7 @@ public EclipseRunMojo(File work, boolean clearWorkspaceBeforeLaunch, MavenProjec
this.logger = logger;
this.toolchainManager = toolchainManager;
this.platformFactory = platformFactory;
this.installation = installation;
}

@Override
Expand All @@ -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);
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public EclipseRunMojo(File work, boolean clearWorkspaceBeforeLaunch, MavenProjec
List<String> applicationArgs, int forkedProcessTimeoutInSeconds, Map<String, String> environmentVariables,
EquinoxInstallationFactory installationFactory, EquinoxLauncher launcher,
ToolchainProvider toolchainProvider, P2ResolverFactory resolverFactory, Logger logger,
ToolchainManager toolchainManager, TargetPlatformFactory platformFactory) {
ToolchainManager toolchainManager, TargetPlatformFactory platformFactory, File installation) {
super(work, clearWorkspaceBeforeLaunch, project, dependencies, addDefaultDependencies, executionEnvironment,
repositories, session, jvmArgs, skip, applicationArgs, forkedProcessTimeoutInSeconds,
environmentVariables, installationFactory, launcher, toolchainProvider, resolverFactory, logger,
toolchainManager, platformFactory);
toolchainManager, platformFactory, installation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fbfca8b

Please sign in to comment.