Skip to content

Commit

Permalink
fix - Fallback to Buildship when multiple gradle projects in same lev…
Browse files Browse the repository at this point in the history
…el (#1574)
  • Loading branch information
jdneo authored Aug 9, 2024
1 parent 93e6886 commit 57d4a77
Showing 1 changed file with 35 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.CompletionException;
import java.util.stream.Collectors;

import org.eclipse.core.internal.resources.Project;
import org.eclipse.core.internal.resources.ProjectDescription;
Expand Down Expand Up @@ -150,13 +151,6 @@ public boolean applies(Collection<IPath> projectConfigurations, IProgressMonitor

@Override
public void importToWorkspace(IProgressMonitor monitor) throws OperationCanceledException, CoreException {
IPath rootPath = ResourceUtils.filePathFromURI(rootFolder.toURI().toString());
BuildServerConnection buildServer = ImporterPlugin.getBuildServerConnection(rootPath, true);
if (buildServer == null) {
JavaLanguageServerPlugin.logError("Reach the maximum number of attempts to connect to the build server, use BuildShip instead");
this.isResolved = false;
return;
}
// for all the path in this.directories, find the out most directory which belongs
// to rootFolder and use that directory as the root folder for the build server.
// TODO: consider the following folder structure
Expand All @@ -166,11 +160,42 @@ public void importToWorkspace(IProgressMonitor monitor) throws OperationCanceled
// |-- sub3
// if user partially selects sub1 and sub2, we should still use ROOT as the root folder
// and only import sub1 and sub2 as projects.
java.nio.file.Path inferredRoot = this.directories.stream()
java.nio.file.Path inferredRoot = null;
List<java.nio.file.Path> sortedDirectories = this.directories.stream()
.filter(directory -> directory.startsWith(rootFolder.toPath()))
.sorted((p1, p2) -> p1.getNameCount() - p2.getNameCount())
.findFirst()
.orElse(rootFolder.toPath());
.collect(Collectors.toList());
if (sortedDirectories.isEmpty()) {
inferredRoot = null; // theoretically this should not happen
} else if (sortedDirectories.size() == 1) {
inferredRoot = sortedDirectories.get(0);
} else {
if (sortedDirectories.get(0).getNameCount() == sortedDirectories.get(1).getNameCount()) {
// if there are multiple directories with the same name count, we can't determine
// the root folder for the build server.
Telemetry telemetry = new Telemetry("unableToDetermineRootFolder", "true");
Utils.sendTelemetry(JavaLanguageServerPlugin.getProjectsManager().getConnection(),
telemetry);
inferredRoot = null;
} else {
inferredRoot = sortedDirectories.get(0);
}
}

if (inferredRoot == null) {
JavaLanguageServerPlugin.logError("Failed to determine the root folder for the build server, use BuildShip instead");
this.isResolved = false;
return;
}

IPath rootPath = ResourceUtils.filePathFromURI(rootFolder.toURI().toString());
BuildServerConnection buildServer = ImporterPlugin.getBuildServerConnection(rootPath, true);
if (buildServer == null) {
JavaLanguageServerPlugin.logError("Reach the maximum number of attempts to connect to the build server, use BuildShip instead");
this.isResolved = false;
return;
}

InitializeBuildParams params = new InitializeBuildParams(
CLIENT_NAME,
ImporterPlugin.getBundleVersion(),
Expand Down

0 comments on commit 57d4a77

Please sign in to comment.