Skip to content

Commit

Permalink
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 12, 2023
1 parent ef83550 commit b912137
Show file tree
Hide file tree
Showing 5 changed files with 59 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 @@ -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;
Expand Down Expand Up @@ -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());
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 Expand Up @@ -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.");
}
}
Expand Down
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 b912137

Please sign in to comment.