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: Infer the project root before launching build server #1433

Merged
merged 1 commit into from
Oct 18, 2023
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 @@ -93,11 +93,18 @@ public void importToWorkspace(IProgressMonitor monitor) throws OperationCanceled
IPath rootPath = ResourceUtils.filePathFromURI(rootFolder.toURI().toString());
BuildServerConnection buildServer = ImporterPlugin.getBuildServerConnection(rootPath);

// 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.
java.nio.file.Path inferredRoot = this.directories.stream()
.filter(directory -> directory.startsWith(rootFolder.toPath()))
.sorted((p1, p2) -> p1.getNameCount() - p2.getNameCount())
.findFirst()
.orElse(rootFolder.toPath());
InitializeBuildParams params = new InitializeBuildParams(
CLIENT_NAME,
CLIENT_VERSION,
BSP_VERSION,
rootFolder.toPath().toUri().toString(),
inferredRoot.toUri().toString(),
new BuildClientCapabilities(java.util.Collections.singletonList("java"))
);
BuildServerPreferences data = getBuildServerPreferences();
Expand Down Expand Up @@ -132,6 +139,20 @@ public void importToWorkspace(IProgressMonitor monitor) throws OperationCanceled
}
}

@Override
public boolean isResolved(File folder) throws OperationCanceledException, CoreException {
// TOOD: Once the upstream GradleProjectImporter has been updated to not import when
// the gradle project has already imported by other importers, we can modify this logic
// so that Maven importer can be involved for other projects.
for (IProject project : ProjectUtils.getAllProjects()) {
if (Utils.isGradleBuildServerProject(project) &&
project.getLocation().toPath().startsWith(folder.toPath())) {
return true;
}
}
return false;
}

@Override
public void reset() {
// do nothing
Expand Down
Loading