Skip to content

Commit

Permalink
Enable m2e toolchains.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
snjeza committed Aug 15, 2024
1 parent 949a9a2 commit f4e7b2c
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ public static void waitForDownloadSourcesJobs(int maxTimeMillis) {
waitForJobs(DownloadSourcesJobMatcher.INSTANCE, maxTimeMillis);
}

public static void waitForLookupJDKToolchainsJob(int maxTimeMillis) {
waitForJobs(LookupJDKToolchainsJobMatcher.INSTANCE, maxTimeMillis);
}

public static void waitForJobs(IJobMatcher matcher, int maxWaitMillis) {
final long limit = System.currentTimeMillis() + maxWaitMillis;
while(true) {
Expand Down Expand Up @@ -354,4 +358,13 @@ public boolean matches(Job job) {

}

static class LookupJDKToolchainsJobMatcher implements IJobMatcher {
public static final IJobMatcher INSTANCE = new LookupJDKToolchainsJobMatcher();

@Override
public boolean matches(Job job) {
return ("org.eclipse.m2e.jdt.LookupJDKToolchainsJob".equals(job.getClass().getName()));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,10 @@ public static BuildConfiguration getBuildConfiguration(Path rootFolder, boolean
File javaHome = getJavaHome(preferences);
File gradleUserHome = getGradleUserHomeFile();
List<String> gradleArguments = new ArrayList<>();
if (noDaemon) {
gradleArguments.add("--no-daemon");
}
// https://github.com/microsoft/vscode-gradle/issues/1519
//if (noDaemon) {
// gradleArguments.add("--no-daemon");
//}
gradleArguments.addAll(getGradleInitScriptArgs());
gradleArguments.addAll(preferences.getGradleArguments());
List<String> gradleJvmArguments = preferences.getGradleJvmArguments();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public static File getJdkToLaunchDaemon(String highestJavaVersion) {
return null;
}

Map<String, File> jdks = getAllVmInstalls();;
Map<String, File> jdks = getAllVmInstalls();
Entry<String, File> selected = null;
for (Entry<String, File> jdk : jdks.entrySet()) {
String javaVersion = jdk.getKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@
*******************************************************************************/
package org.eclipse.jdt.ls.core.internal;

import static org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin.logException;

import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceDescription;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.m2e.jdt.MavenJdtPlugin;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;

/**
* @author snjeza
Expand All @@ -38,8 +43,20 @@ public class JavaLanguageServerTestPlugin implements BundleActivator {
*/
@Override
public void start(BundleContext context) throws Exception {
IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(MavenJdtPlugin.PLUGIN_ID);
prefs.put(PREFERENCE_LOOKUP_JVM_IN_TOOLCHAINS, Boolean.FALSE.toString());
// https://github.com/eclipse-jdtls/eclipse.jdt.ls/pull/3238
if ("false".equals(System.getProperty(PREFERENCE_LOOKUP_JVM_IN_TOOLCHAINS, "true"))) {
IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(MavenJdtPlugin.PLUGIN_ID);
prefs.put(PREFERENCE_LOOKUP_JVM_IN_TOOLCHAINS, Boolean.FALSE.toString());
}
try {
long start = System.currentTimeMillis();
String symbolicName = MavenJdtPlugin.PLUGIN_ID;
JavaLanguageServerPlugin.debugTrace("Starting " + symbolicName);
Platform.getBundle(symbolicName).start(Bundle.START_TRANSIENT);
JavaLanguageServerPlugin.logInfo("Started " + symbolicName + " " + (System.currentTimeMillis() - start) + "ms");
} catch (BundleException e) {
logException(e.getMessage(), e);
}
TestVMType.setTestJREAsDefault("17");
JavaCore.initializeAfterLoad(new NullProgressMonitor());
IWorkspace workspace = ResourcesPlugin.getWorkspace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

Expand All @@ -27,14 +25,11 @@
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
import org.eclipse.jdt.ls.core.internal.JDTUtils;
import org.eclipse.jdt.ls.core.internal.JVMConfigurator;
import org.eclipse.jdt.ls.core.internal.JobHelpers;
import org.eclipse.jdt.ls.core.internal.ResourceUtils;
import org.eclipse.jdt.ls.core.internal.RuntimeEnvironment;
import org.eclipse.jdt.ls.core.internal.TestVMType;
import org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest;
import org.eclipse.jdt.ls.core.internal.preferences.Preferences;
import org.hamcrest.core.IsNull;
import org.junit.After;
import org.junit.Assume;
Expand All @@ -43,7 +38,6 @@
public class JavaFXTest extends AbstractProjectsManagerBasedTest {

private static final String VERSION_1_8 = "1.8";
private static final String JAVA8FX_HOME = "java8fx.home";
private static final String JAVA_SE_8 = "JavaSE-1.8";
private static final String JAVA_SE_17 = "JavaSE-17";

Expand All @@ -53,29 +47,37 @@ public class JavaFXTest extends AbstractProjectsManagerBasedTest {
*/
@Test
public void testJavaFX() throws Exception {
String jdkFXHome = System.getProperty(JAVA8FX_HOME);
Assume.assumeThat("No java8fx.home path set, skipping test", jdkFXHome, IsNull.notNullValue());

IVMInstall defaultJRE = JavaRuntime.getDefaultVMInstall();

String name = "java8fx";
IProject project = null;
try {
// Create JavaFX runtime
Preferences prefs = createJavaFXRuntimePrefs(jdkFXHome);
JVMConfigurator.configureJVMs(prefs);
JobHelpers.waitForJobsToComplete();

IExecutionEnvironment java8env = JVMConfigurator.getExecutionEnvironment(JAVA_SE_8);
IVMInstall java8vm = null;
IVMInstall java8DefaultVm = null;
if (java8env != null) {
java8DefaultVm = java8env.getDefaultVM();
IVMInstall[] compatibleVms = java8env.getCompatibleVMs();
for (IVMInstall vm : compatibleVms) {
if (vm.getVMInstallType().getName().startsWith("TestVMInstall-")) {
continue;
}
if (java8env.isStrictlyCompatible(vm)) {
java8vm = vm;
java8env.setDefaultVM(java8vm);
break;
}
}
}
Assume.assumeThat("JavaSE-1.8 VM is not found, skipping test", java8vm, IsNull.notNullValue());
// Import JavaFX project and checks it compiles without errors
JavaRuntime.setDefaultVMInstall(java8vm, monitor, true);
importProjects("eclipse/" + name);
project = getProject(name);
assertNoErrors(project);

// Delete JavaFX runtime, project should fail to compile
IVMInstall vm = JVMConfigurator.findVM(new File(jdkFXHome), null);
vm.getVMInstallType().disposeVMInstall(vm.getId());
TestVMType.setTestJREAsDefault(VERSION_1_8);
JDTUtils.setCompatibleVMs(VERSION_1_8);
JavaRuntime.setDefaultVMInstall(defaultJRE, monitor, true);
if (java8env != null) {
java8env.setDefaultVM(java8DefaultVm);
}
JobHelpers.waitForJobsToComplete();
List<IMarker> errors = ResourceUtils.getErrorMarkers(project);
assertNotEquals(0, errors.size());
Expand All @@ -94,15 +96,7 @@ public void testJavaFX() throws Exception {
@After
public void cleanUp() throws Exception {
super.cleanUp();
String jdkFXHome = System.getProperty(JAVA8FX_HOME);
if (jdkFXHome != null && !jdkFXHome.isBlank()) {
IVMInstall vm = JVMConfigurator.findVM(new File(jdkFXHome), null);
if (vm != null) {
vm.getVMInstallType().disposeVMInstall(vm.getId());
}
}
TestVMType.setTestJREAsDefault("17");
JDTUtils.setCompatibleVMs(VERSION_1_8);
// Copied from org.eclipse.jdt.core.tests.model.ClasspathInitializerTests.tearDown()
// Cleanup caches
JavaModelManager manager = JavaModelManager.getJavaModelManager();
Expand All @@ -111,15 +105,4 @@ public void cleanUp() throws Exception {
JobHelpers.waitForJobsToComplete();
}

private Preferences createJavaFXRuntimePrefs(String path) {
Preferences prefs = new Preferences();
RuntimeEnvironment runtime = new RuntimeEnvironment();
runtime.setPath(path);
runtime.setName(JAVA_SE_8);
runtime.setDefault(true);
assertTrue(runtime.isValid());
prefs.setRuntimes(Collections.singleton(runtime));
return prefs;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import org.eclipse.jdt.ls.core.internal.preferences.StandardPreferenceManager;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.mockito.Mock;
import org.mockito.Mockito;

Expand Down Expand Up @@ -132,6 +133,12 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
}
});

@BeforeClass
public static void initJVMs() {
JobHelpers.waitForLookupJDKToolchainsJob(600000);
CorePlugin.publishedGradleVersions().getVersions();
}

@Before
public void initProjectManager() throws Exception {
clientRequests.clear();
Expand Down

0 comments on commit f4e7b2c

Please sign in to comment.