diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JavaLanguageServerPlugin.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JavaLanguageServerPlugin.java index b2431ad5b8..eb085a98f8 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JavaLanguageServerPlugin.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/JavaLanguageServerPlugin.java @@ -27,6 +27,7 @@ import java.util.function.Function; import org.apache.commons.lang3.StringUtils; +import org.eclipse.buildship.core.internal.CorePlugin; import org.eclipse.core.internal.net.ProxySelector; import org.eclipse.core.net.proxy.IProxyData; import org.eclipse.core.net.proxy.IProxyService; @@ -52,6 +53,7 @@ import org.eclipse.jdt.ls.core.internal.JavaClientConnection.JavaLanguageClient; import org.eclipse.jdt.ls.core.internal.corext.template.java.JavaContextTypeRegistry; import org.eclipse.jdt.ls.core.internal.corext.template.java.JavaLanguageServerTemplateStore; +import org.eclipse.jdt.ls.core.internal.handlers.BundleUtils; import org.eclipse.jdt.ls.core.internal.handlers.CompletionContributionService; import org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer; import org.eclipse.jdt.ls.core.internal.handlers.LogHandler; @@ -68,6 +70,7 @@ import org.eclipse.jdt.ls.core.internal.syntaxserver.SyntaxProjectsManager; import org.eclipse.lsp4j.jsonrpc.Launcher; import org.eclipse.lsp4j.jsonrpc.MessageConsumer; +import org.eclipse.m2e.core.internal.IMavenConstants; import org.eclipse.text.templates.ContextTypeRegistry; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; @@ -78,6 +81,7 @@ public class JavaLanguageServerPlugin extends Plugin { + public static final String INITIALIZE_AFTER_JOB = "INITIALIZE_AFTER_JOB"; public static final String JDT_UI_PLUGIN = "org.eclipse.jdt.ui"; public static final String MANUAL = "Manual"; public static final String DIRECT = "Direct"; @@ -183,6 +187,17 @@ public void start(BundleContext bundleContext) throws Exception { @Override protected IStatus run(IProgressMonitor monitor) { try { + // load gradle plugin https://github.com/redhat-developer/vscode-java/issues/2088 + // start org.eclipse.buildship.core before JavaCore.initializeAfterLoad to avoid deadlock - https://github.com/redhat-developer/vscode-java/issues/3901 + // https://github.com/redhat-developer/vscode-java/issues/3184 + // start the m2e and buildship plugin before calling JavaCore.setOptions + // load maven plugin https://github.com/redhat-developer/vscode-java/issues/2088 + // https://github.com/redhat-developer/vscode-java/issues/3904 moved from InitHandler.handleInitializationOptions() + BundleUtils.startBundle(CorePlugin.PLUGIN_ID); + BundleUtils.startBundle(IMavenConstants.PLUGIN_ID); + long start = System.currentTimeMillis(); + JobHelpers.waitForProjectRegistryRefreshJob(); + JavaLanguageServerPlugin.logInfo("ProjectRegistryRefreshJob finished " + (System.currentTimeMillis() - start) + "ms"); JavaCore.initializeAfterLoad(monitor); } catch (CoreException e) { logException(e); @@ -195,6 +210,15 @@ protected IStatus run(IProgressMonitor monitor) { return Status.OK_STATUS; } + /* (non-Javadoc) + * @see org.eclipse.core.runtime.jobs.Job#belongsTo(java.lang.Object) + */ + @Override + public boolean belongsTo(Object family) { + // TODO Auto-generated method stub + return super.belongsTo(INITIALIZE_AFTER_JOB); + } + }; initializeAfterLoad.setPriority(Job.SHORT); initializeAfterLoad.schedule(); diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/BundleUtils.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/BundleUtils.java index 1e2f27e93c..a8cc465248 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/BundleUtils.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/BundleUtils.java @@ -14,6 +14,7 @@ package org.eclipse.jdt.ls.core.internal.handlers; import static java.lang.String.format; +import static org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin.logException; import java.io.File; import java.io.IOException; @@ -32,6 +33,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.jdt.ls.core.internal.IConstants; import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin; @@ -350,4 +352,15 @@ private static BundleInfo getBundleInfo(String bundleLocation) throws IOExceptio } return null; } + + public static void startBundle(String symbolicName) { + try { + long start = System.currentTimeMillis(); + 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); + } + } } diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/InitHandler.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/InitHandler.java index 492609895a..cd0145f887 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/InitHandler.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/InitHandler.java @@ -14,8 +14,6 @@ *******************************************************************************/ package org.eclipse.jdt.ls.core.internal.handlers; -import static org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin.logException; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -24,7 +22,6 @@ import java.util.Set; import java.util.stream.Collectors; -import org.eclipse.buildship.core.internal.CorePlugin; import org.eclipse.core.internal.resources.Workspace; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; @@ -33,8 +30,8 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubMonitor; import org.eclipse.core.runtime.jobs.Job; @@ -66,9 +63,6 @@ import org.eclipse.lsp4j.TextDocumentSyncOptions; import org.eclipse.lsp4j.WorkspaceFoldersOptions; import org.eclipse.lsp4j.WorkspaceServerCapabilities; -import org.eclipse.m2e.core.internal.IMavenConstants; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleException; /** * Handler for the VS Code extension initialization @@ -100,12 +94,7 @@ public InitHandler(ProjectsManager manager, PreferenceManager preferenceManager, // https://github.com/redhat-developer/vscode-java/issues/3184 // start the m2e and buildship plugin before calling JavaCore.setOptions // load maven plugin https://github.com/redhat-developer/vscode-java/issues/2088 - startBundle(IMavenConstants.PLUGIN_ID); - long start = System.currentTimeMillis(); - JobHelpers.waitForProjectRegistryRefreshJob(); - JavaLanguageServerPlugin.logInfo("ProjectRegistryRefreshJob finished " + (System.currentTimeMillis() - start) + "ms"); - // load gradle plugin https://github.com/redhat-developer/vscode-java/issues/2088 - startBundle(CorePlugin.PLUGIN_ID); + JobHelpers.waitForJobs(JavaLanguageServerPlugin.INITIALIZE_AFTER_JOB, new NullProgressMonitor()); Map initializationOptions = super.handleInitializationOptions(param); try { @@ -313,14 +302,4 @@ public boolean belongsTo(Object family) { job.schedule(); } - private void startBundle(String symbolicName) { - try { - long start = System.currentTimeMillis(); - 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); - } - } } 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 df641c7921..1c98261491 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 @@ -316,8 +316,19 @@ public void importToWorkspace(IProgressMonitor monitor) throws CoreException { } break; } - - GradleUtils.synchronizeAnnotationProcessingConfiguration(subMonitor); + // https://github.com/redhat-developer/vscode-java/issues/3904 + // skip synchronizeAnnotationProcessingConfiguration if not required + boolean shouldSynchronize = false; + for (Path directory : directoriesToImport) { + File location = directory.toFile(); + if (shouldSynchronize(location)) { + shouldSynchronize = true; + break; + } + } + if (shouldSynchronize) { + GradleUtils.synchronizeAnnotationProcessingConfiguration(subMonitor); + } eliminateBuildServerFootprint(monitor); subMonitor.done(); }