Skip to content

Commit

Permalink
feat: Implement onWillUpdate() in GradleBuildServerBuildSupport (#1405)
Browse files Browse the repository at this point in the history
Signed-off-by: Sheng Chen <[email protected]>
  • Loading branch information
jdneo authored Nov 13, 2023
1 parent 1a8013d commit 2fed172
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
Expand Down Expand Up @@ -126,6 +128,20 @@ public boolean applies(IProject project) {
return Utils.isGradleBuildServerProject(project);
}

public void onWillUpdate(Collection<IProject> projects, IProgressMonitor monitor) throws CoreException {
Set<IPath> roots = new HashSet<>();
for (IProject project : projects) {
IPath rootPath = ProjectUtils.findBelongedWorkspaceRoot(project.getLocation());
if (rootPath != null) {
roots.add(rootPath);
}
}
for (IPath rootPath : roots) {
BuildServerConnection connection = ImporterPlugin.getBuildServerConnection(rootPath);
connection.workspaceReload().join();
}
}

@Override
public void update(IProject project, boolean force, IProgressMonitor monitor) throws CoreException {
if (!applies(project)) {
Expand All @@ -139,10 +155,8 @@ public void update(IProject project, boolean force, IProgressMonitor monitor) th
JavaLanguageServerPlugin.logError("Cannot find workspace root for project: " + project.getName());
return;
}
BuildServerConnection buildServer = ImporterPlugin.getBuildServerConnection(rootPath);
buildServer.workspaceReload().join();

Map<URI, List<BuildTarget>> buildTargetMap = Utils.getBuildTargetsMappedByProjectPath(buildServer);
BuildServerConnection connection = ImporterPlugin.getBuildServerConnection(rootPath);
Map<URI, List<BuildTarget>> buildTargetMap = Utils.getBuildTargetsMappedByProjectPath(connection);
for (URI uri : buildTargetMap.keySet()) {
IProject projectFromUri = ProjectUtils.getProjectFromUri(uri.toString());
if (projectFromUri == null || !Utils.isGradleBuildServerProject(projectFromUri)) {
Expand Down

0 comments on commit 2fed172

Please sign in to comment.