From 46d4a802b713ff2a21c18f04f26c8760a3c70309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Fri, 24 Nov 2023 16:46:30 +0100 Subject: [PATCH] Select best matching target environment for p2install 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. --- .../surefire/AbstractEclipseTestMojo.java | 16 +++++--------- .../ProvisionedInstallationBuilder.java | 22 ++++++++++++++----- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/AbstractEclipseTestMojo.java b/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/AbstractEclipseTestMojo.java index f066418d79..8644c466fc 100644 --- a/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/AbstractEclipseTestMojo.java +++ b/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/AbstractEclipseTestMojo.java @@ -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 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); } 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 5b207f99b8..0b48b4c615 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.tycho.PlatformPropertiesUtils; import org.eclipse.tycho.TargetEnvironment; import org.eclipse.tycho.core.osgitools.BundleReader; import org.eclipse.tycho.p2.tools.director.shared.DirectorCommandException; @@ -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 { @@ -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(); @@ -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");