Skip to content

Instantly share code, notes, and snippets.

@snjeza
Created December 19, 2017 15:41
Show Gist options
  • Save snjeza/3ef56919f6b482657075a95761646032 to your computer and use it in GitHub Desktop.
Save snjeza/3ef56919f6b482657075a95761646032 to your computer and use it in GitHub Desktop.
JDK9 tests
diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/TestVMType.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/TestVMType.java
index 41f3e32..3dac885 100644
--- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/TestVMType.java
+++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/TestVMType.java
@@ -14,8 +14,6 @@ import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
@@ -26,26 +24,24 @@ import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.URIUtil;
+import org.eclipse.jdt.internal.launching.StandardVMType;
import org.eclipse.jdt.launching.AbstractVMInstall;
import org.eclipse.jdt.launching.AbstractVMInstallType;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.IVMInstallType;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.launching.LibraryLocation;
+import org.eclipse.jdt.launching.VMStandin;
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager;
import org.osgi.framework.Bundle;
-
public class TestVMType extends AbstractVMInstallType {
private static final String VMTYPE_ID = "org.eclipse.jdt.ls.core.internal.TestVMType";
+ private static final String VMTYPE_ID_JDK9 = "org.eclipse.jdt.ls.core.internal.TestVMType.jdk9";
private static final String RTSTUBS18_JAR = "rtstubs18.jar";
private static final String FAKE_JDK = "/fakejdk";
- private static final Map<String, String> JAVA_HOMES = new HashMap<>();
- static {
- JAVA_HOMES.put("9", System.getProperty("java9.home"));
- }
public static void setTestJREAsDefault() throws CoreException {
IVMInstallType vmInstallType = JavaRuntime.getVMInstallType(VMTYPE_ID);
@@ -61,20 +57,28 @@ public class TestVMType extends AbstractVMInstallType {
for (IExecutionEnvironment environment : environments) {
IVMInstall[] compatibleVMs = environment.getCompatibleVMs();
for (IVMInstall compatibleVM : compatibleVMs) {
- if (VMTYPE_ID.equals(compatibleVM.getVMInstallType().getId()) && compatibleVM.getVMInstallType().findVMInstall(compatibleVM.getId()) != null && !compatibleVM.equals(environment.getDefaultVM())
- // Fugly way to ensure the lowest VM version is set:
- && (environment.getDefaultVM() == null || compatibleVM.getId().compareTo(environment.getDefaultVM().getId()) < 0)) {
+ if (VMTYPE_ID.equals(compatibleVM.getVMInstallType().getId()) && compatibleVM.getVMInstallType().findVMInstall(compatibleVM.getId()) != null && !compatibleVM.equals(environment.getDefaultVM())) {
environment.setDefaultVM(compatibleVM);
}
}
}
+ String java9Home = System.getProperty("java9.home");
+ if (java9Home != null) {
+ File location = new File(java9Home);
+ if (location.isDirectory()) {
+ String vmName = "JavaSE-9";
+ IVMInstallType installType = JavaRuntime.getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE);
+ String vmId = VMTYPE_ID + "-9";
+ VMStandin vm = new VMStandin(installType, vmId);
+ vm.setName(vmName);
+ vm.setInstallLocation(location);
+ vm.convertToRealVM();
+ }
+ }
}
public TestVMType() {
createVMInstall("1.8");
- if (JAVA_HOMES.get("9") != null) {
- createVMInstall("9");
- }
}
@Override
@@ -122,25 +126,17 @@ public class TestVMType extends AbstractVMInstallType {
*/
@Override
protected IVMInstall doCreateVMInstall(String id) {
- String javaHome = JAVA_HOMES.get(id);
- File javaHomeDir = TestVMType.getInstallLocation();
- if (javaHome != null) {
- javaHomeDir = new File(javaHome);
- if (!javaHomeDir.isDirectory() || !javaHomeDir.canRead()) {
- throw new IllegalArgumentException(javaHome + " is not an accessible JDK location!");
- }
- }
- return new TestVMInstall(this, id, javaHomeDir);
+ return new TestVMInstall(this, id);
}
}
class TestVMInstall extends AbstractVMInstall {
- public TestVMInstall(IVMInstallType type, String id, File installLocation) {
+ public TestVMInstall(IVMInstallType type, String id) {
super(type, id);
setNotify(false);
- setInstallLocation(installLocation);
+ setInstallLocation(TestVMType.getInstallLocation());
}
@Override
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment