Skip to content

Commit

Permalink
Refresh the output folders after build tasks (#1493)
Browse files Browse the repository at this point in the history
Signed-off-by: Sheng Chen <[email protected]>
  • Loading branch information
jdneo authored Jun 12, 2024
1 parent 4e76ebc commit ffa87a3
Showing 1 changed file with 38 additions and 0 deletions.
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);
}
}
}
}

0 comments on commit ffa87a3

Please sign in to comment.