From 2d28713aabbf267f35789ac12a00ffca51dc3611 Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Mon, 3 Jun 2024 11:01:50 +0800 Subject: [PATCH 1/2] Refresh the output folders after build tasks Signed-off-by: Sheng Chen --- .../importer/builder/BuildServerBuilder.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/builder/BuildServerBuilder.java b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/builder/BuildServerBuilder.java index d00122e2c..0d4112cff 100644 --- a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/builder/BuildServerBuilder.java +++ b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/builder/BuildServerBuilder.java @@ -5,6 +5,7 @@ import java.util.Objects; import java.util.stream.Collectors; +import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResourceStatus; import org.eclipse.core.resources.IncrementalProjectBuilder; @@ -13,6 +14,8 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin; import org.eclipse.jdt.ls.core.internal.ProjectUtils; import org.eclipse.jdt.ls.core.internal.preferences.Preferences; @@ -55,8 +58,42 @@ protected IProject[] build(int kind, Map args, IProgressMonitor throw new CoreException(new Status(IStatus.ERROR, ImporterPlugin.PLUGIN_ID, IResourceStatus.BUILD_FAILED, "Build Failed.", null)); } + this.refreshOutputs(monitor); } } return null; } + + /** + * Trigger .refreshLocal() to all the output folders of the project. + * This is to make sure the changes made by the build server are reflected in the workspace. + */ + private void refreshOutputs(IProgressMonitor monitor) throws CoreException { + IJavaProject javaProject = ProjectUtils.getJavaProject(this.getProject()); + if (javaProject == null) { + return; + } + + boolean needRefreshDefaultOutput = false; + for (IClasspathEntry cp : javaProject.getRawClasspath()) { + if (cp.getEntryKind() != IClasspathEntry.CPE_SOURCE) { + continue; + } + + IPath output = cp.getOutputLocation().removeFirstSegments(1); + if (output != null) { + javaProject.getProject().getFolder(output).refreshLocal(IProject.DEPTH_INFINITE, monitor); + } else { + needRefreshDefaultOutput = true; + } + } + + if (needRefreshDefaultOutput) { + IPath relativeOutputPath = javaProject.getOutputLocation().removeFirstSegments(1); + IFolder defaultOutput = javaProject.getProject().getFolder(relativeOutputPath); + if (defaultOutput.exists()) { + defaultOutput.refreshLocal(IProject.DEPTH_INFINITE, monitor); + } + } + } } From e847b3f97fac7703bde2c604484de2a96da34b92 Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Wed, 12 Jun 2024 13:26:30 +0800 Subject: [PATCH 2/2] Add null check --- .../gradle/bs/importer/builder/BuildServerBuilder.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/builder/BuildServerBuilder.java b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/builder/BuildServerBuilder.java index 0d4112cff..09255eacf 100644 --- a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/builder/BuildServerBuilder.java +++ b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/builder/BuildServerBuilder.java @@ -80,8 +80,9 @@ private void refreshOutputs(IProgressMonitor monitor) throws CoreException { continue; } - IPath output = cp.getOutputLocation().removeFirstSegments(1); + IPath output = cp.getOutputLocation(); if (output != null) { + output = output.removeFirstSegments(1); javaProject.getProject().getFolder(output).refreshLocal(IProject.DEPTH_INFINITE, monitor); } else { needRefreshDefaultOutput = true;