From b74ca37d11b77163962e5e490de6099a85e01beb Mon Sep 17 00:00:00 2001 From: JoshwinThomasIBM Date: Thu, 2 Jan 2025 18:13:21 +0530 Subject: [PATCH 1/6] Restricting the refresh for any changes in the build or target directory --- src/extension.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index 07a0a9bb..a208e4ac 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -183,7 +183,7 @@ export function deactivate(): Promise { * @param projectProvider Liberty Dev projects */ export function registerFileWatcher(projectProvider: ProjectProvider): void { - const watcher: vscode.FileSystemWatcher = vscode.workspace.createFileSystemWatcher("{**/pom.xml,**/build.gradle,**/settings.gradle,**/src/main/liberty/config/server.xml}"); + const watcher: vscode.FileSystemWatcher = vscode.workspace.createFileSystemWatcher("{**/pom.xml,**/build.gradle,**/settings.gradle,**/src/main/liberty/config/server.xml,!**/target/**,!**/build/**}"); watcher.onDidCreate(async () => { projectProvider.refresh(); }); From bcebc272682fef6e57d249d12ac62dd8924bce3a Mon Sep 17 00:00:00 2001 From: JoshwinThomasIBM Date: Fri, 3 Jan 2025 09:33:36 +0530 Subject: [PATCH 2/6] excluding target and build folders for pom and build.gradle scans --- package.json | 4 ++-- src/liberty/libertyProject.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 4ca69f55..fe108a4d 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,8 @@ "theme": "dark" }, "activationEvents": [ - "workspaceContains:**/pom.xml", - "workspaceContains:**/build.gradle", + "workspaceContains:**/!(target|build)/**/pom.xml", + "workspaceContains:**/!(target|build)/**/build.gradle", "onCommand:liberty.dev.start", "onCommand:liberty.dev.stop", "onCommand:liberty.dev.custom", diff --git a/src/liberty/libertyProject.ts b/src/liberty/libertyProject.ts index 6672977b..936381c8 100644 --- a/src/liberty/libertyProject.ts +++ b/src/liberty/libertyProject.ts @@ -86,8 +86,8 @@ export class ProjectProvider implements vscode.TreeDataProvider * */ public async getListOfMavenAndGradleFolders(path: string): Promise{ let uris: string[] = []; - const pomPattern = new vscode.RelativePattern(path, "**/pom.xml"); - const gradlePattern = new vscode.RelativePattern(path, "**/build.gradle"); + const pomPattern = new vscode.RelativePattern(path, "**/!(target|build)/**/pom.xml"); + const gradlePattern = new vscode.RelativePattern(path, "**/!(target|build)/**/build.gradle"); let paths = (await vscode.workspace.findFiles(pomPattern, EXCLUDED_DIR_PATTERN)).map(uri => uri.fsPath); uris = uris.concat(paths); paths = (await vscode.workspace.findFiles(gradlePattern, EXCLUDED_DIR_PATTERN)).map(uri => uri.fsPath); @@ -410,8 +410,8 @@ export class ProjectProvider implements vscode.TreeDataProvider private async updateProjects(): Promise { // find all build files in the open workspace and find all the ones that are valid for dev-mode - const pomPaths = (await vscode.workspace.findFiles("**/pom.xml", EXCLUDED_DIR_PATTERN)).map(uri => uri.fsPath); - const gradlePaths = (await vscode.workspace.findFiles("**/build.gradle", EXCLUDED_DIR_PATTERN)).map(uri => uri.fsPath); + const pomPaths = (await vscode.workspace.findFiles("**/!(target|build)/**/pom.xml", EXCLUDED_DIR_PATTERN)).map(uri => uri.fsPath); + const gradlePaths = (await vscode.workspace.findFiles("**/!(target|build)/**/build.gradle", EXCLUDED_DIR_PATTERN)).map(uri => uri.fsPath); const validPoms: BuildFileImpl[] = await this.findValidPOMs(pomPaths); const validGradleBuilds: BuildFileImpl[] = await this.findValidGradleBuildFiles(gradlePaths); let serverXMLPaths: string[] = []; From b899512770391d97480d94295e5e9b19332257eb Mon Sep 17 00:00:00 2001 From: JoshwinThomasIBM Date: Fri, 3 Jan 2025 11:27:21 +0530 Subject: [PATCH 3/6] Added build folder to excluded directories --- src/definitions/constants.ts | 2 +- src/liberty/libertyProject.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/definitions/constants.ts b/src/definitions/constants.ts index 4c42c9d7..02d8ad15 100644 --- a/src/definitions/constants.ts +++ b/src/definitions/constants.ts @@ -32,7 +32,7 @@ export const COMMAND_AND_PROJECT_TYPE_MAP: { [command: string]: string[] } = { "gradle":[ LIBERTY_GRADLE_PROJECT, LIBERTY_GRADLE_PROJECT_CONTAINER], "liberty.dev.debug": [LIBERTY_MAVEN_PROJECT, LIBERTY_GRADLE_PROJECT, LIBERTY_MAVEN_PROJECT_CONTAINER, LIBERTY_GRADLE_PROJECT_CONTAINER], }; -export const EXCLUDED_DIR_PATTERN = "**/{bin,classes,target}/**"; +export const EXCLUDED_DIR_PATTERN = "**/{bin,classes,target,build}/**"; export const COMMAND_TITLES = new Map(); export const UNTITLED_WORKSPACE="Untitled (Workspace)"; COMMAND_TITLES.set(localize("hotkey.commands.title.refresh"), "liberty.explorer.refresh"); diff --git a/src/liberty/libertyProject.ts b/src/liberty/libertyProject.ts index 936381c8..6672977b 100644 --- a/src/liberty/libertyProject.ts +++ b/src/liberty/libertyProject.ts @@ -86,8 +86,8 @@ export class ProjectProvider implements vscode.TreeDataProvider * */ public async getListOfMavenAndGradleFolders(path: string): Promise{ let uris: string[] = []; - const pomPattern = new vscode.RelativePattern(path, "**/!(target|build)/**/pom.xml"); - const gradlePattern = new vscode.RelativePattern(path, "**/!(target|build)/**/build.gradle"); + const pomPattern = new vscode.RelativePattern(path, "**/pom.xml"); + const gradlePattern = new vscode.RelativePattern(path, "**/build.gradle"); let paths = (await vscode.workspace.findFiles(pomPattern, EXCLUDED_DIR_PATTERN)).map(uri => uri.fsPath); uris = uris.concat(paths); paths = (await vscode.workspace.findFiles(gradlePattern, EXCLUDED_DIR_PATTERN)).map(uri => uri.fsPath); @@ -410,8 +410,8 @@ export class ProjectProvider implements vscode.TreeDataProvider private async updateProjects(): Promise { // find all build files in the open workspace and find all the ones that are valid for dev-mode - const pomPaths = (await vscode.workspace.findFiles("**/!(target|build)/**/pom.xml", EXCLUDED_DIR_PATTERN)).map(uri => uri.fsPath); - const gradlePaths = (await vscode.workspace.findFiles("**/!(target|build)/**/build.gradle", EXCLUDED_DIR_PATTERN)).map(uri => uri.fsPath); + const pomPaths = (await vscode.workspace.findFiles("**/pom.xml", EXCLUDED_DIR_PATTERN)).map(uri => uri.fsPath); + const gradlePaths = (await vscode.workspace.findFiles("**/build.gradle", EXCLUDED_DIR_PATTERN)).map(uri => uri.fsPath); const validPoms: BuildFileImpl[] = await this.findValidPOMs(pomPaths); const validGradleBuilds: BuildFileImpl[] = await this.findValidGradleBuildFiles(gradlePaths); let serverXMLPaths: string[] = []; From f9b2bc08576ba86bac625205cca93b9035ee06e4 Mon Sep 17 00:00:00 2001 From: JoshwinThomasIBM Date: Fri, 3 Jan 2025 12:12:53 +0530 Subject: [PATCH 4/6] Added check to avoid refresh when there are changes in target or build folders --- src/extension.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index a208e4ac..708c4350 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -163,8 +163,13 @@ function registerCommands(context: ExtensionContext) { }) ); // Listens for any new folders are added to the workspace - context.subscriptions.push(vscode.workspace.onDidChangeWorkspaceFolders((event) => { - projectProvider.refresh(); + context.subscriptions.push(vscode.workspace.onDidChangeWorkspaceFolders((event) => { + const isTargetOrBuildFolderChanged = event.added.some(folder => + folder.uri.fsPath.includes('/target') || folder.uri.fsPath.includes('/build')) || + event.removed.some(folder => + folder.uri.fsPath.includes('/target') || folder.uri.fsPath.includes('/build')); + if (!isTargetOrBuildFolderChanged) + projectProvider.refresh(); })); } From 64fb495da00abde7fc7d51b4d9b4f244f8db2a61 Mon Sep 17 00:00:00 2001 From: JoshwinThomasIBM Date: Wed, 8 Jan 2025 10:15:29 +0530 Subject: [PATCH 5/6] Added check for build files in target or build directories --- package.json | 4 ++-- src/extension.ts | 31 ++++++++++++++++--------------- src/util/helperUtil.ts | 8 ++++++++ 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index fe108a4d..4ca69f55 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,8 @@ "theme": "dark" }, "activationEvents": [ - "workspaceContains:**/!(target|build)/**/pom.xml", - "workspaceContains:**/!(target|build)/**/build.gradle", + "workspaceContains:**/pom.xml", + "workspaceContains:**/build.gradle", "onCommand:liberty.dev.start", "onCommand:liberty.dev.stop", "onCommand:liberty.dev.custom", diff --git a/src/extension.ts b/src/extension.ts index 708c4350..613694b1 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -164,11 +164,6 @@ function registerCommands(context: ExtensionContext) { ); // Listens for any new folders are added to the workspace context.subscriptions.push(vscode.workspace.onDidChangeWorkspaceFolders((event) => { - const isTargetOrBuildFolderChanged = event.added.some(folder => - folder.uri.fsPath.includes('/target') || folder.uri.fsPath.includes('/build')) || - event.removed.some(folder => - folder.uri.fsPath.includes('/target') || folder.uri.fsPath.includes('/build')); - if (!isTargetOrBuildFolderChanged) projectProvider.refresh(); })); } @@ -188,16 +183,22 @@ export function deactivate(): Promise { * @param projectProvider Liberty Dev projects */ export function registerFileWatcher(projectProvider: ProjectProvider): void { - const watcher: vscode.FileSystemWatcher = vscode.workspace.createFileSystemWatcher("{**/pom.xml,**/build.gradle,**/settings.gradle,**/src/main/liberty/config/server.xml,!**/target/**,!**/build/**}"); - watcher.onDidCreate(async () => { - projectProvider.refresh(); - }); - watcher.onDidChange(async () => { - projectProvider.refresh(); - }); - watcher.onDidDelete(async () => { - projectProvider.refresh(); - }); + const watcher: vscode.FileSystemWatcher = vscode.workspace.createFileSystemWatcher("{**/pom.xml,**/build.gradle,**/settings.gradle,**/src/main/liberty/config/server.xml}"); + const isInTargetOrBuild = (uri: vscode.Uri) => { + return helperUtil.isInTargetOrBuild(uri.fsPath); + } + if (!isInTargetOrBuild) { + watcher.onDidCreate(async (uri) => { + projectProvider.refresh(); + }); + watcher.onDidChange(async (uri) => { + projectProvider.refresh(); + }); + watcher.onDidDelete(async (uri) => { + projectProvider.refresh(); + }); + } + } function startLangServer(context: ExtensionContext, requirements: RequirementsData, isLiberty: boolean) { diff --git a/src/util/helperUtil.ts b/src/util/helperUtil.ts index 277ed455..e3f5b584 100644 --- a/src/util/helperUtil.ts +++ b/src/util/helperUtil.ts @@ -79,4 +79,12 @@ export function clearDataSavedInGlobalState(context: vscode.ExtensionContext) { context.globalState.update('workspaceSaveInProgress', false); context.globalState.update('selectedProject', undefined); } +/** + * Method checks if the given file path is in target or build folders and returns a boolean + * @param filePath + * @returns + */ +export function isInTargetOrBuild(filePath: string): boolean { + return filePath.includes('/target/') || filePath.includes('/build/'); +} From 4d5102f350688b8183aaed3e512f6d958031939e Mon Sep 17 00:00:00 2001 From: JoshwinThomasIBM Date: Wed, 8 Jan 2025 16:06:53 +0530 Subject: [PATCH 6/6] code formatted --- src/extension.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 613694b1..95e91e44 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -162,9 +162,9 @@ function registerCommands(context: ExtensionContext) { devCommands.deleteTerminal(closedTerminal); }) ); - // Listens for any new folders are added to the workspace + // Listens for any new folders are added to the workspace context.subscriptions.push(vscode.workspace.onDidChangeWorkspaceFolders((event) => { - projectProvider.refresh(); + projectProvider.refresh(); })); }