Skip to content

Commit 3a7436f

Browse files
committed
Manually setup openjdk8 as default vm if it exists
1 parent aab731b commit 3a7436f

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/EclipseUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.eclipse.jdt.core.IJavaProject;
3636
import org.eclipse.jdt.core.JavaCore;
3737
import org.eclipse.jdt.core.JavaModelException;
38+
import org.eclipse.jdt.launching.JavaRuntime;
3839
import org.junit.Assert;
3940

4041
import net.sourceforge.pmd.Rule;
@@ -233,7 +234,7 @@ public static void addJavaNature(final IProject project) throws CoreException {
233234
javaProject
234235
.setRawClasspath(
235236
new IClasspathEntry[] { JavaCore.newSourceEntry(sourceFolder.getFullPath()),
236-
JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER")) },
237+
JavaRuntime.getDefaultJREContainerEntry() },
237238
null);
238239

239240
Hashtable<String, String> javaOptions = JavaCore.getOptions();

net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/internal/TestActivator.java

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44

55
package net.sourceforge.pmd.eclipse.internal;
66

7+
import java.io.File;
8+
import java.io.IOException;
9+
10+
import org.eclipse.core.runtime.CoreException;
711
import org.eclipse.core.runtime.IStatus;
812
import 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;
916
import org.eclipse.ui.plugin.AbstractUIPlugin;
1017
import org.slf4j.LoggerFactory;
1118

19+
import net.sourceforge.pmd.eclipse.WaitingMonitor;
1220
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
1321

1422
import 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

Comments
 (0)