summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorEvgeny Mandrikov2011-06-28 17:19:34 (EDT)
committer jsievers2011-09-23 05:20:09 (EDT)
commit41815deaac0a000512e9f5a28a06aa2051961e53 (patch)
tree0ca53309a7f5271bccd339c6c2a84a9fc330404d
parent092a2f99f4e22da3c373c42f52d151420e877605 (diff)
downloadorg.eclipse.tycho-41815deaac0a000512e9f5a28a06aa2051961e53.zip
org.eclipse.tycho-41815deaac0a000512e9f5a28a06aa2051961e53.tar.gz
org.eclipse.tycho-41815deaac0a000512e9f5a28a06aa2051961e53.tar.bz2
Use Maven Toolchains in tycho-surefire-plugin
-rw-r--r--tycho-embedder-api/src/main/java/org/eclipse/tycho/launching/LaunchConfiguration.java2
-rw-r--r--tycho-equinox-launching/src/main/java/org/eclipse/tycho/equinox/launching/internal/DefaultEquinoxLauncher.java10
-rw-r--r--tycho-equinox-launching/src/main/java/org/eclipse/tycho/equinox/launching/internal/EquinoxLaunchConfiguration.java10
-rw-r--r--tycho-its/projects/toolchains/META-INF/MANIFEST.MF8
-rw-r--r--tycho-its/projects/toolchains/build.properties4
-rw-r--r--tycho-its/projects/toolchains/fake-jdk-home/.keep0
-rw-r--r--tycho-its/projects/toolchains/pom.xml40
-rw-r--r--tycho-its/projects/toolchains/src/tycho/its/Test.java9
-rw-r--r--tycho-its/projects/toolchains/toolchains.xml13
-rw-r--r--tycho-its/src/test/java/org/eclipse/tycho/test/toolchains/JavaToolchainInSurefireTest.java18
-rw-r--r--tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/TestMojo.java21
11 files changed, 132 insertions, 3 deletions
diff --git a/tycho-embedder-api/src/main/java/org/eclipse/tycho/launching/LaunchConfiguration.java b/tycho-embedder-api/src/main/java/org/eclipse/tycho/launching/LaunchConfiguration.java
index 5a15846..f10f44a 100644
--- a/tycho-embedder-api/src/main/java/org/eclipse/tycho/launching/LaunchConfiguration.java
+++ b/tycho-embedder-api/src/main/java/org/eclipse/tycho/launching/LaunchConfiguration.java
@@ -16,6 +16,8 @@ import java.util.Map;
public interface LaunchConfiguration {
public Map<String, String> getEnvironment();
+ public String getJvmExecutable();
+
public File getWorkingDirectory();
public String[] getProgramArguments();
diff --git a/tycho-equinox-launching/src/main/java/org/eclipse/tycho/equinox/launching/internal/DefaultEquinoxLauncher.java b/tycho-equinox-launching/src/main/java/org/eclipse/tycho/equinox/launching/internal/DefaultEquinoxLauncher.java
index f023e70..d1a5714 100644
--- a/tycho-equinox-launching/src/main/java/org/eclipse/tycho/equinox/launching/internal/DefaultEquinoxLauncher.java
+++ b/tycho-equinox-launching/src/main/java/org/eclipse/tycho/equinox/launching/internal/DefaultEquinoxLauncher.java
@@ -34,9 +34,13 @@ public class DefaultEquinoxLauncher implements EquinoxLauncher {
throws EquinoxLaunchingException {
Commandline cli = new Commandline();
- String executable = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
- if (File.separatorChar == '\\') {
- executable = executable + ".exe";
+ String executable = configuration.getJvmExecutable();
+ if (executable == null || "".equals(executable)) {
+ // use the same JVM as the one used to run Maven (the "java.home" one)
+ executable = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
+ if (File.separatorChar == '\\') {
+ executable = executable + ".exe";
+ }
}
cli.setExecutable(executable);
diff --git a/tycho-equinox-launching/src/main/java/org/eclipse/tycho/equinox/launching/internal/EquinoxLaunchConfiguration.java b/tycho-equinox-launching/src/main/java/org/eclipse/tycho/equinox/launching/internal/EquinoxLaunchConfiguration.java
index 7ba818e..d8e232a 100644
--- a/tycho-equinox-launching/src/main/java/org/eclipse/tycho/equinox/launching/internal/EquinoxLaunchConfiguration.java
+++ b/tycho-equinox-launching/src/main/java/org/eclipse/tycho/equinox/launching/internal/EquinoxLaunchConfiguration.java
@@ -21,6 +21,8 @@ import org.eclipse.tycho.equinox.launching.EquinoxInstallation;
import org.eclipse.tycho.launching.LaunchConfiguration;
public class EquinoxLaunchConfiguration implements LaunchConfiguration {
+ private String jvmExecutable;
+
private File workingDirectory;
private final Map<String, String> env = new LinkedHashMap<String, String>();
@@ -43,6 +45,14 @@ public class EquinoxLaunchConfiguration implements LaunchConfiguration {
return env;
}
+ public void setJvmExecutable(String jvmExecutable) {
+ this.jvmExecutable = jvmExecutable;
+ }
+
+ public String getJvmExecutable() {
+ return jvmExecutable;
+ }
+
public void setWorkingDirectory(File workingDirectory) {
this.workingDirectory = workingDirectory;
}
diff --git a/tycho-its/projects/toolchains/META-INF/MANIFEST.MF b/tycho-its/projects/toolchains/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..cf0dccd
--- /dev/null
+++ b/tycho-its/projects/toolchains/META-INF/MANIFEST.MF
@@ -0,0 +1,8 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: toolchains
+Bundle-SymbolicName: toolchains
+Bundle-Version: 0.0.1.qualifier
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Require-Bundle: org.junit,
+ org.eclipse.core.runtime
diff --git a/tycho-its/projects/toolchains/build.properties b/tycho-its/projects/toolchains/build.properties
new file mode 100644
index 0000000..34d2e4d
--- /dev/null
+++ b/tycho-its/projects/toolchains/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/tycho-its/projects/toolchains/fake-jdk-home/.keep b/tycho-its/projects/toolchains/fake-jdk-home/.keep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tycho-its/projects/toolchains/fake-jdk-home/.keep
diff --git a/tycho-its/projects/toolchains/pom.xml b/tycho-its/projects/toolchains/pom.xml
new file mode 100644
index 0000000..12c472a
--- /dev/null
+++ b/tycho-its/projects/toolchains/pom.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>toolchains</groupId>
+ <artifactId>test</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+
+ <packaging>eclipse-test-plugin</packaging>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-maven-plugin</artifactId>
+ <version>${tycho-version}</version>
+ <extensions>true</extensions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-toolchains-plugin</artifactId>
+ <version>1.0</version>
+ <executions>
+ <execution>
+ <phase>validate</phase>
+ <goals>
+ <goal>toolchain</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <toolchains>
+ <vendor>fake</vendor>
+ </toolchains>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/tycho-its/projects/toolchains/src/tycho/its/Test.java b/tycho-its/projects/toolchains/src/tycho/its/Test.java
new file mode 100644
index 0000000..ab7a7d6
--- /dev/null
+++ b/tycho-its/projects/toolchains/src/tycho/its/Test.java
@@ -0,0 +1,9 @@
+package tycho.its;
+
+import junit.framework.TestCase;
+
+public class Test extends TestCase
+{
+ public void test() throws Exception {
+ }
+}
diff --git a/tycho-its/projects/toolchains/toolchains.xml b/tycho-its/projects/toolchains/toolchains.xml
new file mode 100644
index 0000000..c9b724a
--- /dev/null
+++ b/tycho-its/projects/toolchains/toolchains.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF8"?>
+<toolchains>
+ <toolchain>
+ <type>jdk</type>
+ <provides>
+ <id>default</id>
+ <vendor>fake</vendor>
+ </provides>
+ <configuration>
+ <jdkHome>fake-jdk-home</jdkHome>
+ </configuration>
+ </toolchain>
+</toolchains>
diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/toolchains/JavaToolchainInSurefireTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/toolchains/JavaToolchainInSurefireTest.java
new file mode 100644
index 0000000..a31d04f
--- /dev/null
+++ b/tycho-its/src/test/java/org/eclipse/tycho/test/toolchains/JavaToolchainInSurefireTest.java
@@ -0,0 +1,18 @@
+package org.eclipse.tycho.test.toolchains;
+
+import org.apache.maven.it.Verifier;
+import org.eclipse.tycho.test.AbstractTychoIntegrationTest;
+import org.junit.Test;
+
+import java.io.File;
+
+public class JavaToolchainInSurefireTest extends AbstractTychoIntegrationTest {
+ @Test
+ public void test() throws Exception {
+ Verifier verifier = getVerifier("/toolchains");
+ File toolchains = new File(verifier.getBasedir() + "/toolchains.xml");
+ verifier.getCliOptions().add("--toolchains " + toolchains.getCanonicalPath());
+ verifier.executeGoal("integration-test");
+ verifier.verifyTextInLog("Toolchain in tycho-surefire-plugin: JDK[fake-jdk-home]");
+ }
+}
diff --git a/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/TestMojo.java b/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/TestMojo.java
index 7bfe7d0..a57aa4c 100644
--- a/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/TestMojo.java
+++ b/tycho-surefire/tycho-surefire-plugin/src/main/java/org/eclipse/tycho/surefire/TestMojo.java
@@ -38,6 +38,8 @@ import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.repository.RepositorySystem;
+import org.apache.maven.toolchain.Toolchain;
+import org.apache.maven.toolchain.ToolchainManager;
import org.codehaus.plexus.util.FileUtils;
import org.eclipse.tycho.ArtifactDescriptor;
import org.eclipse.tycho.ArtifactKey;
@@ -322,6 +324,9 @@ public class TestMojo extends AbstractMojo implements LaunchConfigurationFactory
*/
private OsgiBundleProject osgiBundle;
+ /** @component */
+ private ToolchainManager toolchainManager;
+
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip || skipExec) {
getLog().info("Skipping tests");
@@ -558,9 +563,25 @@ public class TestMojo extends AbstractMojo implements LaunchConfigurationFactory
return result == 0;
}
+ private Toolchain getToolchain() {
+ Toolchain tc = null;
+ if (toolchainManager != null) {
+ tc = toolchainManager.getToolchainFromBuildContext("jdk", session);
+ }
+ return tc;
+ }
+
LaunchConfiguration createCommandLine(EquinoxInstallation testRuntime, File workspace) throws MalformedURLException {
EquinoxLaunchConfiguration cli = new EquinoxLaunchConfiguration(testRuntime);
+ String executable = null;
+ Toolchain tc = getToolchain();
+ if (tc != null) {
+ getLog().info("Toolchain in tycho-surefire-plugin: " + tc);
+ executable = tc.findTool("java");
+ }
+ cli.setJvmExecutable(executable);
+
cli.setWorkingDirectory(project.getBasedir());
if (debugPort > 0) {