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

Refresh the output folders after build tasks #1493

Merged
merged 2 commits into from
Jun 12, 2024
Merged
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 @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -55,8 +58,43 @@ protected IProject[] build(int kind, Map<String, String> args, IProgressMonitor
throw new CoreException(new Status(IStatus.ERROR, ImporterPlugin.PLUGIN_ID,
IResourceStatus.BUILD_FAILED, "Build Failed.", null));
}
this.refreshOutputs(monitor);
}
}
return null;
}

/**
* Trigger <code>.refreshLocal()</code> 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();
if (output != null) {
output = output.removeFirstSegments(1);
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);
}
}
}
}
Loading