44
55package net .sourceforge .pmd .eclipse .internal ;
66
7+ import java .io .File ;
8+ import java .io .IOException ;
9+
10+ import org .eclipse .core .runtime .CoreException ;
711import org .eclipse .core .runtime .IStatus ;
812import org .eclipse .core .runtime .Status ;
13+ import org .eclipse .jdt .launching .IVMInstall ;
14+ import org .eclipse .jdt .launching .IVMInstallType ;
15+ import org .eclipse .jdt .launching .JavaRuntime ;
916import org .eclipse .ui .plugin .AbstractUIPlugin ;
1017import org .slf4j .LoggerFactory ;
1118
19+ import net .sourceforge .pmd .eclipse .WaitingMonitor ;
1220import net .sourceforge .pmd .eclipse .plugin .PMDPlugin ;
1321
1422import ch .qos .logback .classic .Level ;
@@ -26,7 +34,37 @@ public TestActivator() {
2634 } else {
2735 mainPlugin .getLog ().log (new Status (IStatus .WARNING , PMDPlugin .PLUGIN_ID , "Couldn't setup logging for tests." ));
2836 }
29-
30- }
3137
38+ // Setup a default JVM. This is especially required for mac osx on github actions,
39+ // as there is no default JVM detected automatically.
40+ // This is not done via the following extension, in order to check for the existence of openjdk8Path:
41+ /*
42+ <extension
43+ point="org.eclipse.jdt.launching.vmInstalls">
44+ <vmInstall
45+ home="${env_var:HOME}/openjdk8"
46+ id="net.sourceforge.pmd.eclipse.plugin.test.openjdk8"
47+ name="openjdk8"
48+ vmInstallType="org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType">
49+ </vmInstall>
50+ </extension>
51+ */
52+ File openjdk8Path = new File (System .getProperty ("user.home" ), "openjdk8" );
53+ if (openjdk8Path .exists ()) {
54+ try {
55+ openjdk8Path = openjdk8Path .getCanonicalFile ();
56+ IVMInstallType vmInstallType = JavaRuntime .getVMInstallType ("org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType" );
57+ IVMInstall vm = vmInstallType .createVMInstall ("net.sourceforge.pmd.eclipse.plugin.test.openjdk8" );
58+ vm .setInstallLocation (openjdk8Path );
59+ vm .setName ("openjdk8" );
60+ WaitingMonitor monitor = new WaitingMonitor ();
61+ JavaRuntime .setDefaultVMInstall (vm , monitor );
62+ monitor .await ();
63+ } catch (IOException | CoreException | InterruptedException e ) {
64+ mainPlugin .getLog ().log (new Status (IStatus .ERROR , PMDPlugin .PLUGIN_ID ,
65+ "Error setting up default JVM " + openjdk8Path , e ));
66+ Thread .currentThread ().interrupt ();
67+ }
68+ }
69+ }
3270}
0 commit comments