Skip to content

Commit

Permalink
Select best matching target environment for p2install
Browse files Browse the repository at this point in the history
Currently a p2 provisioned install always use the running target to
provision what is also the best option most of the time. In case where
there is no matching one this can lead to failing installs.

This now allows to specify the environments and shows a warning if the
running one does not has any match.

(cherry picked from commit 3f41779)
  • Loading branch information
laeubi committed Nov 25, 2023
1 parent caca76a commit ada0802
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -639,17 +639,11 @@ private EquinoxInstallation createProvisionedInstallation() throws MojoExecution
File workingDir = new File(project.getBuild().getDirectory(), "p2temp");
workingDir.mkdirs();
installationBuilder.setWorkingDir(workingDir);
TargetEnvironment runningEnvironment = TargetEnvironment.getRunningEnvironment();
if (PlatformPropertiesUtils.OS_MACOSX.equals(runningEnvironment.getOs())) {
if (work.getName().endsWith(".app")) {
installationBuilder.setDestination(work);
} else {
installationBuilder.setDestination(new File(work, "Eclipse.app/Contents/Eclipse/"));
}
} else {
installationBuilder.setDestination(work);
}
return installationBuilder.install();
installationBuilder.setDestination(work);
List<TargetEnvironment> list = getTestTargetEnvironments();
TargetEnvironment env = list.get(0);
getLog().info("Provisioning with environment " + env + "...");
return installationBuilder.install(env);
} catch (Exception ex) {
throw new MojoExecutionException(ex.getMessage(), ex);
}
Expand Down Expand Up @@ -1054,7 +1048,7 @@ private EquinoxLaunchConfiguration createCommandLine(EquinoxInstallation testRun
addProgramArgs(cli, "-data", osgiDataDirectory.getAbsolutePath(), //
"-install", testRuntime.getLocation().getAbsolutePath(), //
"-configuration", testRuntime.getConfigurationLocation().getAbsolutePath(), //
"-application", getTestApplication(testRuntime.getInstallationDescription()), //
"-application", getTestApplication(), //
"-testproperties", surefireProperties.getAbsolutePath());
if (application != null) {
cli.addProgramArguments("-testApplication", application);
Expand Down Expand Up @@ -1122,7 +1116,7 @@ String[] splitArgLine(String argLine) throws MojoExecutionException {
}
}

private String getTestApplication(EquinoxInstallationDescription testRuntime) {
private String getTestApplication() {
if (useUIHarness) {
return "org.eclipse.tycho.surefire.osgibooter.uitest";
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.eclipse.sisu.equinox.launching.EquinoxInstallation;
import org.eclipse.sisu.equinox.launching.EquinoxInstallationDescription;
import org.eclipse.sisu.equinox.launching.internal.EquinoxInstallationLaunchConfiguration;
import org.eclipse.tycho.core.osgitools.BundleReader;

/**
* This class provides an implementation of an {@link EquinoxInstallation} which represents an RCP
Expand All @@ -32,9 +31,9 @@ public class ProvisionedEquinoxInstallation implements EquinoxInstallation {
private File configurationLocation;
private EquinoxInstallationDescription description;

public ProvisionedEquinoxInstallation(File location, BundleReader bundleReader) {
public ProvisionedEquinoxInstallation(File location) {
this.location = location;
description = new ProvisionedInstallationDescription(location, bundleReader);
description = new ProvisionedInstallationDescription(location, null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.FileUtils;
import org.eclipse.sisu.equinox.launching.EquinoxInstallation;
import org.eclipse.tycho.PlatformPropertiesUtils;
import org.eclipse.tycho.TargetEnvironment;
import org.eclipse.tycho.core.osgitools.BundleReader;
import org.eclipse.tycho.p2.tools.director.shared.DirectorCommandException;
import org.eclipse.tycho.p2.tools.director.shared.DirectorRuntime;

public class ProvisionedInstallationBuilder {

private Logger log;
private BundleReader bundleReader;
private DirectorRuntime directorRuntime;

private List<URI> metadataRepos = new ArrayList<>();
Expand All @@ -48,9 +47,8 @@ public void setWorkingDir(File workingDir) {
this.workingDir = workingDir;
}

public ProvisionedInstallationBuilder(BundleReader bundleReader, DirectorRuntime directorRuntime, Logger log) {
public ProvisionedInstallationBuilder(DirectorRuntime directorRuntime, Logger log) {
this.log = log;
this.bundleReader = bundleReader;
this.directorRuntime = directorRuntime;
this.bundlesPublisher = new BundlesPublisher(log);
}
Expand Down Expand Up @@ -97,11 +95,11 @@ public void setInstallFeatures(boolean installFeatures) {
this.installFeatures = installFeatures;
}

public EquinoxInstallation install() throws Exception {
public EquinoxInstallation install(TargetEnvironment main) throws Exception {
validate();
publishPlainBundleJars();
executeDirector();
return new ProvisionedEquinoxInstallation(effectiveDestination, bundleReader);
executeDirector(main);
return new ProvisionedEquinoxInstallation(getFinalDestination(main));
}

private void publishPlainBundleJars() throws Exception {
Expand All @@ -121,17 +119,17 @@ private void publishPlainBundleJars() throws Exception {
artifactRepos.add(bundlesRepoURI);
}

private void executeDirector() throws MojoFailureException {
private void executeDirector(TargetEnvironment env) throws MojoFailureException {
DirectorRuntime.Command command = directorRuntime.newInstallCommand();
command.addMetadataSources(metadataRepos);
command.addArtifactSources(artifactRepos);
for (String iu : ius) {
command.addUnitToInstall(iu);
}
command.setDestination(effectiveDestination);
command.setDestination(getFinalDestination(env));
command.setProfileName(profileName);
command.setInstallFeatures(installFeatures);
command.setEnvironment(TargetEnvironment.getRunningEnvironment());
command.setEnvironment(env);
log.info("Installing IUs " + ius + " to " + effectiveDestination);
try {
command.execute();
Expand All @@ -140,6 +138,15 @@ private void executeDirector() throws MojoFailureException {
}
}

private File getFinalDestination(TargetEnvironment env) {
if (PlatformPropertiesUtils.OS_MACOSX.equals(env.getOs())) {
if (!effectiveDestination.getName().endsWith(".app")) {
return new File(effectiveDestination, "Eclipse.app/Contents/Eclipse/");
}
}
return effectiveDestination;
}

private void validate() {
assertNotNull(workingDir, "workingDir");
assertNotNull(effectiveDestination, "destination");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,19 @@
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
import org.eclipse.tycho.core.osgitools.BundleReader;
import org.eclipse.tycho.p2.tools.director.shared.DirectorRuntime;

@Component(role = ProvisionedInstallationBuilderFactory.class)
public class ProvisionedInstallationBuilderFactory {

@Requirement
private BundleReader bundleReader;

@Requirement
private DirectorRuntime directorRuntime;

@Requirement
private Logger logger;

public ProvisionedInstallationBuilder createInstallationBuilder() {
return new ProvisionedInstallationBuilder(bundleReader, directorRuntime, logger);
return new ProvisionedInstallationBuilder(directorRuntime, logger);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ProvisionedInstallationBuilderTest {

@Test
public void setDestination_LayoutNormal() throws Exception {
ProvisionedInstallationBuilder builder = new ProvisionedInstallationBuilder(null, null, null);
ProvisionedInstallationBuilder builder = new ProvisionedInstallationBuilder(null, null);

File work = tempDir.newFolder("work");
builder.setDestination(work);
Expand All @@ -36,7 +36,7 @@ public void setDestination_LayoutNormal() throws Exception {

@Test
public void setDestination_LayoutMacOS() throws Exception {
ProvisionedInstallationBuilder builder = new ProvisionedInstallationBuilder(null, null, null);
ProvisionedInstallationBuilder builder = new ProvisionedInstallationBuilder(null, null);

File work = tempDir.newFolder("work.app");
builder.setDestination(work);
Expand Down

0 comments on commit ada0802

Please sign in to comment.