@@ -88,53 +88,53 @@ export function clearDataSavedInGlobalState(context: vscode.ExtensionContext) {
8888 */
8989export async function checkSiblingFilesInTargetOrBuildParent ( filePath : string ) : Promise < boolean > {
9090
91- try {
92- let currentDir = path . dirname ( filePath ) ; // Start with the directory of the provided file
93-
94- // Traverse upwards through the directories
95- while ( currentDir !== path . parse ( currentDir ) . root ) {
96- let targetDir : string | undefined ;
97- let siblingFilePath : string | undefined ;
98-
99- // Determine the file type to look for (either pom.xml or build.gradle)
100- if ( filePath . endsWith ( 'pom.xml' ) ) {
101- targetDir = 'target' ; // For Maven projects, look for target directory
102- siblingFilePath = path . join ( currentDir , targetDir , 'pom.xml' ) ;
103- } else if ( filePath . endsWith ( 'build.gradle' ) || filePath . endsWith ( 'settings.gradle' ) ) {
104- targetDir = 'build' ; // For Gradle projects, look for build directory
105- siblingFilePath = path . join ( currentDir , targetDir , 'build.gradle' ) ;
106- } else {
107- console . log ( "Invalid file type. Only 'pom.xml' or 'build.gradle' are supported." ) ;
108- return false ;
109- }
110-
111- // Ensure that targetDir and siblingFilePath are assigned before proceeding
112- if ( ! targetDir || ! siblingFilePath ) {
113- console . error ( "Error: targetDir or siblingFilePath not properly assigned." ) ;
114- return false ;
115- }
116-
117- // Check if the target/build directory exists
118- const currentTargetDir = path . join ( currentDir , targetDir ) ;
119- if ( fs . existsSync ( currentTargetDir ) && fs . statSync ( currentTargetDir ) . isDirectory ( ) ) {
120-
121- // Check if the expected sibling file (pom.xml or build.gradle) exists
122- if ( fs . existsSync ( siblingFilePath ) && fs . statSync ( siblingFilePath ) . isFile ( ) ) {
123- console . log ( `Found sibling ${ filePath . endsWith ( 'pom.xml' ) ? 'pom.xml' : 'build.gradle' } in directory: ${ currentTargetDir } ` ) ;
124- return true ; // Found the sibling file, return true to indicate file should be ignored
125- }
126- }
127-
128- // Move up to the parent directory
129- currentDir = path . dirname ( currentDir ) ;
130- }
131-
132- // If no sibling file was found and we reached the root, return false to allow refresh
133- console . log ( "Reached project root, no sibling file found. Allowing refresh." ) ;
134- return false ;
135- } catch ( err ) {
136- console . error ( 'Error during directory traversal:' , err ) ;
137- return false ;
138- }
91+ try {
92+ let currentDir = path . dirname ( filePath ) ; // Start with the directory of the provided file
93+
94+ // Traverse upwards through the directories
95+ while ( currentDir !== path . parse ( currentDir ) . root ) {
96+ let targetDir : string | undefined ;
97+ let siblingFilePath : string | undefined ;
98+
99+ // Determine the file type to look for (either pom.xml or build.gradle)
100+ if ( filePath . endsWith ( 'pom.xml' ) ) {
101+ targetDir = 'target' ; // For Maven projects, look for target directory
102+ siblingFilePath = path . join ( currentDir , targetDir , 'pom.xml' ) ;
103+ } else if ( filePath . endsWith ( 'build.gradle' ) || filePath . endsWith ( 'settings.gradle' ) ) {
104+ targetDir = 'build' ; // For Gradle projects, look for build directory
105+ siblingFilePath = path . join ( currentDir , targetDir , 'build.gradle' ) ;
106+ } else {
107+ console . log ( "Invalid file type. Only 'pom.xml' or 'build.gradle' are supported." ) ;
108+ return false ;
109+ }
110+
111+ // Ensure that targetDir and siblingFilePath are assigned before proceeding
112+ if ( ! targetDir || ! siblingFilePath ) {
113+ console . error ( "Error: targetDir or siblingFilePath not properly assigned." ) ;
114+ return false ;
115+ }
116+
117+ // Check if the target/build directory exists
118+ const currentTargetDir = path . join ( currentDir , targetDir ) ;
119+ if ( fs . existsSync ( currentTargetDir ) && fs . statSync ( currentTargetDir ) . isDirectory ( ) ) {
120+
121+ // Check if the expected sibling file (pom.xml or build.gradle) exists
122+ if ( fs . existsSync ( siblingFilePath ) && fs . statSync ( siblingFilePath ) . isFile ( ) ) {
123+ console . log ( `Found sibling ${ filePath . endsWith ( 'pom.xml' ) ? 'pom.xml' : 'build.gradle' } in directory: ${ currentTargetDir } ` ) ;
124+ return true ; // Found the sibling file, return true to indicate file should be ignored
125+ }
126+ }
127+
128+ // Move up to the parent directory
129+ currentDir = path . dirname ( currentDir ) ;
130+ }
131+
132+ // If no sibling file was found and we reached the root, return false to allow refresh
133+ console . log ( "Reached project root, no sibling file found. Allowing refresh." ) ;
134+ return false ;
135+ } catch ( err ) {
136+ console . error ( 'Error during directory traversal:' , err ) ;
137+ return false ;
138+ }
139139}
140140
0 commit comments