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.
  • Loading branch information
laeubi committed Nov 24, 2023
1 parent a6dfcba commit 46d4a80
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 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
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.tycho.PlatformPropertiesUtils;
import org.eclipse.tycho.TargetEnvironment;
import org.eclipse.tycho.core.osgitools.BundleReader;
import org.eclipse.tycho.p2.tools.director.shared.DirectorCommandException;
Expand Down Expand Up @@ -97,11 +98,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), bundleReader);
}

private void publishPlainBundleJars() throws Exception {
Expand All @@ -121,17 +122,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 +141,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

0 comments on commit 46d4a80

Please sign in to comment.