diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/director/shared/DirectorRuntime.java b/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/director/shared/DirectorRuntime.java index 307d0b876f..a92fcf57f8 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/director/shared/DirectorRuntime.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/director/shared/DirectorRuntime.java @@ -17,6 +17,7 @@ import java.util.Map; import org.eclipse.tycho.DependencySeed; +import org.eclipse.tycho.PlatformPropertiesUtils; import org.eclipse.tycho.TargetEnvironment; /** @@ -59,4 +60,35 @@ public interface Command { * director runtime. */ public Command newInstallCommand(); + + /** + * Computes the destination of a director install based on a target environment + * + * @param baseLocation + * @param env + * @return + */ + public static File getDestination(File baseLocation, TargetEnvironment env) { + if (PlatformPropertiesUtils.OS_MACOSX.equals(env.getOs()) && !hasRequiredMacLayout(baseLocation)) { + return new File(baseLocation, "Eclipse.app/Contents/Eclipse/"); + } + return baseLocation; + } + + 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; + } } diff --git a/tycho-its/projects/surefire.p2InstalledRuntime/example-product/pom.xml b/tycho-its/projects/surefire.p2InstalledRuntime/example-product/pom.xml index bac2234569..ccf91c8473 100644 --- a/tycho-its/projects/surefire.p2InstalledRuntime/example-product/pom.xml +++ b/tycho-its/projects/surefire.p2InstalledRuntime/example-product/pom.xml @@ -26,6 +26,14 @@ + + org.eclipse.tycho + tycho-p2-repository-plugin + ${tycho-version} + + true + + org.eclipse.tycho tycho-p2-director-plugin diff --git a/tycho-its/projects/surefire.p2InstalledRuntime/extProductTestDirector/META-INF/MANIFEST.MF b/tycho-its/projects/surefire.p2InstalledRuntime/extProductTestDirector/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..0a321b3440 --- /dev/null +++ b/tycho-its/projects/surefire.p2InstalledRuntime/extProductTestDirector/META-INF/MANIFEST.MF @@ -0,0 +1,7 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-SymbolicName: spir.extProductTest +Bundle-Version: 1.0.0 +Require-Bundle: org.junit, + org.eclipse.core.runtime +Bundle-RequiredExecutionEnvironment: JavaSE-11 diff --git a/tycho-its/projects/surefire.p2InstalledRuntime/extProductTestDirector/build.properties b/tycho-its/projects/surefire.p2InstalledRuntime/extProductTestDirector/build.properties new file mode 100644 index 0000000000..34d2e4d2da --- /dev/null +++ b/tycho-its/projects/surefire.p2InstalledRuntime/extProductTestDirector/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/tycho-its/projects/surefire.p2InstalledRuntime/extProductTestDirector/pom.xml b/tycho-its/projects/surefire.p2InstalledRuntime/extProductTestDirector/pom.xml new file mode 100644 index 0000000000..ccd58ee8be --- /dev/null +++ b/tycho-its/projects/surefire.p2InstalledRuntime/extProductTestDirector/pom.xml @@ -0,0 +1,87 @@ + + + + + + 4.0.0 + + + tycho-its-project.surefire.p2InstalledRuntime + provisionedApplicationParent + 1.0.0 + + + spir.extProductTest + eclipse-test-plugin + + + + ${target-platform} + ${project.build.directory}/sdk-product + SDKProfile + + + + + test-repo + ${other.p2.repo.url} + p2 + + + + + + + org.eclipse.tycho + tycho-surefire-plugin + ${tycho-version} + + p2Installed + spir.example-product + ${sdkWorkDir} + ${sdkProfile} + + + + + org.eclipse.tycho + tycho-p2-director-plugin + ${tycho-version} + + ${sdkWorkDir} + ${sdkProfile} + true + + + + install-sdk + + director + + pre-integration-test + + file:${project.basedir}/../example-product/target/repository + + + spir.example-product + + + + + + + + + + diff --git a/tycho-its/projects/surefire.p2InstalledRuntime/extProductTestDirector/src/testProvisioning/RootFileTest.java b/tycho-its/projects/surefire.p2InstalledRuntime/extProductTestDirector/src/testProvisioning/RootFileTest.java new file mode 100644 index 0000000000..81bba71254 --- /dev/null +++ b/tycho-its/projects/surefire.p2InstalledRuntime/extProductTestDirector/src/testProvisioning/RootFileTest.java @@ -0,0 +1,19 @@ +package testProvisioning; + +import java.io.File; + +import junit.framework.TestCase; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.Platform; + +public class RootFileTest extends TestCase { + + public void testIsProvisionedInstallation() throws Exception { + File eclipseInstallationRoot = new File(FileLocator.toFileURL( + Platform.getInstallLocation().getURL()).getPath()); + File rootFile = new File(eclipseInstallationRoot, "README.txt"); + assertTrue(rootFile + " does not exist - installation was not provisioned by p2", rootFile.isFile()); + } + +} diff --git a/tycho-its/projects/surefire.p2InstalledRuntime/pom.xml b/tycho-its/projects/surefire.p2InstalledRuntime/pom.xml index b8521b747a..1d01ccbe92 100644 --- a/tycho-its/projects/surefire.p2InstalledRuntime/pom.xml +++ b/tycho-its/projects/surefire.p2InstalledRuntime/pom.xml @@ -60,5 +60,12 @@ extProductTest + + + useProvisionedProductDirector + + extProductTestDirector + + diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/surefire/P2InstalledTestRuntimeTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/surefire/P2InstalledTestRuntimeTest.java index dc73417158..1d5f1f994f 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/surefire/P2InstalledTestRuntimeTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/surefire/P2InstalledTestRuntimeTest.java @@ -41,6 +41,16 @@ public void testRunTestOnProvisionedApp() throws Exception { verifier.verifyErrorFreeLog(); } + @Test + public void testRunTestOnProvisionedDirector() throws Exception { + Verifier verifier = getVerifier("surefire.p2InstalledRuntime"); + verifier.addCliOption("-PuseProvisionedProductDirector"); + verifier.addCliOption("-DproductClassifier=" + getProductClassifier()); + verifier.executeGoals(List.of("clean", "integration-test")); + verifier.verifyErrorFreeLog(); + verifier.verifyTextInLog("Tests run: 1"); + } + @Test public void testDifferentHarnessVersions() throws Exception { Verifier verifier = getVerifier("surefire.p2InstalledRuntime", false); diff --git a/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/p2/director/DirectorMojo.java b/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/p2/director/DirectorMojo.java index 71a2cb459a..1104f5b457 100644 --- a/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/p2/director/DirectorMojo.java +++ b/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/p2/director/DirectorMojo.java @@ -37,9 +37,11 @@ import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.equinox.p2.core.IProvisioningAgentProvider; import org.eclipse.equinox.p2.core.ProvisionException; +import org.eclipse.tycho.TargetEnvironment; import org.eclipse.tycho.TychoConstants; import org.eclipse.tycho.p2.CommandLineArguments; import org.eclipse.tycho.p2.resolver.BundlePublisher; +import org.eclipse.tycho.p2.tools.director.shared.DirectorRuntime; import org.eclipse.tycho.p2tools.TychoDirectorApplication; /** @@ -349,7 +351,8 @@ public class DirectorMojo extends AbstractMojo { @Override public void execute() throws MojoExecutionException, MojoFailureException { CommandLineArguments args = new CommandLineArguments(); - args.addNonNull("-destination", destination); + args.addNonNull("-destination", + DirectorRuntime.getDestination(destination, TargetEnvironment.getRunningEnvironment())); args.addNonNull("-metadatarepository", metadatarepositories); args.addNonNull("-artifactrepository", artifactrepositories); args.addNonNull("-repository", getRepositories()); 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 63958d18aa..448556f714 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 @@ -23,7 +23,6 @@ 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; import org.eclipse.tycho.p2.tools.director.shared.DirectorRuntime; @@ -100,7 +99,7 @@ public EquinoxInstallation install(TargetEnvironment main) throws Exception { validate(); publishPlainBundleJars(); executeDirector(main); - return new ProvisionedEquinoxInstallation(getFinalDestination(main)); + return new ProvisionedEquinoxInstallation(DirectorRuntime.getDestination(effectiveDestination, main)); } private void publishPlainBundleJars() throws Exception { @@ -127,7 +126,7 @@ private void executeDirector(TargetEnvironment env) throws MojoFailureException for (String iu : ius) { command.addUnitToInstall(iu); } - command.setDestination(getFinalDestination(env)); + command.setDestination(DirectorRuntime.getDestination(effectiveDestination, env)); command.setProfileName(profileName); command.setInstallFeatures(installFeatures); command.setEnvironment(env); @@ -139,30 +138,6 @@ private void executeDirector(TargetEnvironment env) throws MojoFailureException } } - private File getFinalDestination(TargetEnvironment env) { - 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");