From 55f31a8b3ea3ce566cff390adaea47bed629c972 Mon Sep 17 00:00:00 2001 From: Snjezana Peco Date: Wed, 14 Aug 2024 02:11:52 +0200 Subject: [PATCH] Enable m2e toolchains.xml --- .../managers/GradleProjectImporter.java | 7 ++++--- .../core/internal/managers/GradleUtils.java | 2 +- .../JavaLanguageServerTestPlugin.java | 21 +++++++++++++++++-- .../AbstractProjectsManagerBasedTest.java | 18 ++++++++++++++++ 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/GradleProjectImporter.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/GradleProjectImporter.java index 927f2315bf..b846668164 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/GradleProjectImporter.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/GradleProjectImporter.java @@ -500,9 +500,10 @@ public static BuildConfiguration getBuildConfiguration(Path rootFolder, boolean File javaHome = getJavaHome(preferences); File gradleUserHome = getGradleUserHomeFile(); List 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 gradleJvmArguments = preferences.getGradleJvmArguments(); diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/GradleUtils.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/GradleUtils.java index 76c8245e88..c5c7a67cb9 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/GradleUtils.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/managers/GradleUtils.java @@ -318,7 +318,7 @@ public static File getJdkToLaunchDaemon(String highestJavaVersion) { return null; } - Map jdks = getAllVmInstalls();; + Map jdks = getAllVmInstalls(); Entry selected = null; for (Entry jdk : jdks.entrySet()) { String javaVersion = jdk.getKey(); diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/JavaLanguageServerTestPlugin.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/JavaLanguageServerTestPlugin.java index e04e55c252..313f0c3a0e 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/JavaLanguageServerTestPlugin.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/JavaLanguageServerTestPlugin.java @@ -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 @@ -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(); diff --git a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/AbstractProjectsManagerBasedTest.java b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/AbstractProjectsManagerBasedTest.java index 3f025cab18..493c29462b 100644 --- a/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/AbstractProjectsManagerBasedTest.java +++ b/org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/managers/AbstractProjectsManagerBasedTest.java @@ -83,8 +83,10 @@ import org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager; import org.eclipse.jdt.ls.core.internal.preferences.Preferences; import org.eclipse.jdt.ls.core.internal.preferences.StandardPreferenceManager; +import org.eclipse.m2e.jdt.LookupJDKToolchainsJob; import org.junit.After; import org.junit.Before; +import org.junit.BeforeClass; import org.mockito.Mock; import org.mockito.Mockito; @@ -132,6 +134,22 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl } }); + @BeforeClass + public static void initJVMs() { + Job[] jobs = Job.getJobManager().find(null); + for (Job job : jobs) { + if (job instanceof LookupJDKToolchainsJob) { + try { + // 10 minutes + job.join(600000, new NullProgressMonitor()); + } catch (OperationCanceledException | InterruptedException e) { + JavaLanguageServerPlugin.logException(e); + } + } + } + CorePlugin.publishedGradleVersions().getVersions(); + } + @Before public void initProjectManager() throws Exception { clientRequests.clear();