Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance initialization of gradle projects #3357

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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);
Expand All @@ -195,6 +210,14 @@ 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) {
return INITIALIZE_AFTER_JOB.equals(family);
}

};
initializeAfterLoad.setPriority(Job.SHORT);
initializeAfterLoad.schedule();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -97,15 +91,7 @@ public InitHandler(ProjectsManager manager, PreferenceManager preferenceManager,

@Override
public Map<?, ?> handleInitializationOptions(InitializeParams param) {
// 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 {
Expand Down Expand Up @@ -313,14 +299,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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Loading