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

fix - Fallback to Buildship when multiple gradle projects in same level #1574

Merged
merged 1 commit into from
Aug 9, 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 @@ -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
Loading