From 606a087f9d2e84af82b9c3679c553cd941aa8089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sat, 25 Nov 2023 08:14:38 +0100 Subject: [PATCH] Support multi-environment install for p2installed test runtime For some rare cases it is usefull to provision an install with multiple environments. This adds a new option installAllEnvironments to support this. --- .../surefire/AbstractEclipseTestMojo.java | 27 ++++++++++++++++--- .../ProvisionedInstallationBuilder.java | 23 +++++++++++++--- 2 files changed, 43 insertions(+), 7 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 a9947e645e..93274ac480 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 @@ -304,6 +304,12 @@ public abstract class AbstractEclipseTestMojo extends AbstractTestMojo { @Parameter private BundleStartLevel defaultStartLevel; + /** + * If {@link #testRuntime} is p2Installed installs all configured environments + */ + @Parameter + private boolean installAllEnvironments; + /** * Flaky tests will re-run until they pass or the number of reruns has been exhausted. See * surefire documentation for details. @@ -641,9 +647,24 @@ private EquinoxInstallation createProvisionedInstallation() throws MojoExecution installationBuilder.setWorkingDir(workingDir); installationBuilder.setDestination(work); List list = getTestTargetEnvironments(); - TargetEnvironment env = list.get(0); - getLog().info("Provisioning with environment " + env + "..."); - return installationBuilder.install(env); + TargetEnvironment testEnvironment = list.get(0); + if (installAllEnvironments) { + TargetPlatformConfiguration configuration = projectManager.getTargetPlatformConfiguration(project); + List targetEnvironments = configuration.getEnvironments(); + EquinoxInstallation installation = null; + for (TargetEnvironment targetEnvironment : targetEnvironments) { + getLog().info("Provisioning with environment " + targetEnvironment + "..."); + installationBuilder.setProfileName(targetEnvironment.toString()); + EquinoxInstallation current = installationBuilder.install(targetEnvironment); + if (targetEnvironment == testEnvironment) { + installation = current; + } + } + return installation; + } else { + getLog().info("Provisioning with environment " + testEnvironment + "..."); + return installationBuilder.install(testEnvironment); + } } 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 20b5b902aa..5d79a3bda3 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 @@ -139,14 +139,29 @@ private void executeDirector(TargetEnvironment env) 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/"); - } + if (PlatformPropertiesUtils.OS_MACOSX.equals(env.getOs()) && !hasRequiredMacLayout(effectiveDestination)) { + return new File(effectiveDestination, "Eclipse.app/Contents/Eclipse/"); } return effectiveDestination; } + private static boolean hasRequiredMacLayout(File folder) { + //TODO if we do not have this exact layout then director fails with: + //The framework persistent data location (/work/MacOS/configuration) is not the same as the framework configuration location /work/Contents/Eclipse/configuration) + //maybe we can simply configure the "persistent data location" to point to the expected one? + //or the "configuration location" must be configured and look like /work/Contents//configuration ? + //the actual values seem even depend on if this is an empty folder where one installs or an existing one + //e.g. if one installs multiple env Equinox finds the launcher and then set the location different... + if ("Eclipse".equals(folder.getName())) { + File folder2 = folder.getParentFile(); + if (folder2 != null && "Contents".equals(folder2.getName())) { + File parent = folder2.getParentFile(); + return parent != null && parent.getName().endsWith(".app"); + } + } + return false; + } + private void validate() { assertNotNull(workingDir, "workingDir"); assertNotNull(effectiveDestination, "destination");