Skip to content

Commit

Permalink
fix: Infer the project root before launching build server (#1433)
Browse files Browse the repository at this point in the history
- If the build files do not exist at the root folder, use the out most
  folder containing the build files as the root for build server.

Signed-off-by: Sheng Chen <[email protected]>
  • Loading branch information
jdneo authored Oct 18, 2023
1 parent 4083079 commit 6462613
Showing 1 changed file with 22 additions and 1 deletion.
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

0 comments on commit 6462613

Please sign in to comment.