From 847af344638db958c1a9c308b3824170722f6616 Mon Sep 17 00:00:00 2001 From: Jendrik Johannes Date: Mon, 14 Oct 2024 12:06:52 +0200 Subject: [PATCH 1/2] Discover Gradle builds by looking for setting.gradle(.kts) When the option 'gradle.nestedProjects: true' is set, the build roots are currently discovered by looking for the wrapper scripts. These however are completely optional for a build. But there is one thing each Gradle build definitely needs to have: A 'settings.gradle' or 'setting.gradle.kts' file. Gradle itself searches for these files to accept a folder as a Gradle build/project. This change proposes to check for these files instead of the gradlw scripts. A good project to test this with is https://github.com/microsoft/build-server-for-gradle which contains a lot of Gradle build in the 'testProjects' folder. Signed-off-by: Jendrik Johannes --- extension/src/stores/RootProjectsStore.ts | 2 +- extension/src/util/index.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/extension/src/stores/RootProjectsStore.ts b/extension/src/stores/RootProjectsStore.ts index f694e8b6e..2f07a6f89 100644 --- a/extension/src/stores/RootProjectsStore.ts +++ b/extension/src/stores/RootProjectsStore.ts @@ -7,7 +7,7 @@ import { RootProject } from "../rootProject/RootProject"; import { GRADLE_BUILD_FILE_NAMES } from "../constant"; async function getNestedRootProjectFolders(): Promise { - const matchingNestedWrapperFiles = await vscode.workspace.findFiles("**/{gradlew,gradlew.bat}"); + const matchingNestedWrapperFiles = await vscode.workspace.findFiles("**/{settings.gradle,settings.gradle.kts}"); return [...new Set(matchingNestedWrapperFiles.map((uri) => path.dirname(uri.fsPath)))]; } diff --git a/extension/src/util/index.ts b/extension/src/util/index.ts index 27d9ba0ef..cf05ca677 100644 --- a/extension/src/util/index.ts +++ b/extension/src/util/index.ts @@ -57,8 +57,8 @@ export function waitOnTcp(host: string, port: number): Promise { export function isGradleRootProject(rootProject: RootProject): boolean { return ( - fs.existsSync(path.join(rootProject.getProjectUri().fsPath, "gradlew")) || - fs.existsSync(path.join(rootProject.getProjectUri().fsPath, "gradlew.bat")) + fs.existsSync(path.join(rootProject.getProjectUri().fsPath, "settings.gradle")) || + fs.existsSync(path.join(rootProject.getProjectUri().fsPath, "settings.gradle.kts")) ); } From 915777724f953b0a24568f5fa0f3e8e07f20b8ca Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Thu, 24 Oct 2024 12:57:54 +0800 Subject: [PATCH 2/2] Try fixing test --- extension/src/test/testUtil.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extension/src/test/testUtil.ts b/extension/src/test/testUtil.ts index 45ca12f0e..be0f6c33b 100644 --- a/extension/src/test/testUtil.ts +++ b/extension/src/test/testUtil.ts @@ -86,13 +86,13 @@ export function stubWorkspaceFolders(workspaceFolders: vscode.WorkspaceFolder[]) const getWorkspaceFolderStub = sinon.stub(vscode.workspace, "getWorkspaceFolder"); const dirnameStub = sinon.stub(path, "dirname"); workspaceFolders.forEach((workspaceFolder) => { - existsSyncStub.withArgs(path.join(workspaceFolder.uri.fsPath, "gradlew")).returns(true); + existsSyncStub.withArgs(path.join(workspaceFolder.uri.fsPath, "settings.gradle")).returns(true); getWorkspaceFolderStub.withArgs(sinon.match.has("fsPath", workspaceFolder.uri.fsPath)).returns(workspaceFolder); dirnameStub.withArgs(workspaceFolder.uri.fsPath).returns(workspaceFolder.uri.fsPath); }); sinon .stub(vscode.workspace, "findFiles") - .withArgs("**/{gradlew,gradlew.bat}") + .withArgs("**/{settings.gradle,settings.gradle.kts}") .returns(Promise.resolve(workspaceFolders.map((folder) => folder.uri))); }