Skip to content

Commit 634ad3b

Browse files
committed
fix: normalize manifest dir
Signed-off-by: Ruben Romero Montes <[email protected]>
1 parent 06f500e commit 634ad3b

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

src/providers/base_java.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -175,22 +175,33 @@ export default class Base_Java {
175175
* @returns {string|undefined}
176176
*/
177177
traverseForWrapper(startingManifest, repoRoot = undefined) {
178-
repoRoot = repoRoot || getGitRootDir(path.resolve(path.dirname(startingManifest))) || path.parse(path.resolve(startingManifest)).root
179-
180-
const wrapperName = this.localWrapper;
181-
const wrapperPath = path.join(path.resolve(path.dirname(startingManifest)), wrapperName);
178+
const normalizedManifest = this.normalizePath(startingManifest);
179+
const currentDir = this.normalizePath(path.dirname(normalizedManifest));
180+
repoRoot = repoRoot || getGitRootDir(currentDir) || path.parse(normalizedManifest).root;
181+
const wrapperPath = path.join(currentDir, this.localWrapper);
182182

183183
try {
184-
fs.accessSync(wrapperPath, fs.constants.X_OK)
185-
} catch(error) {
184+
fs.accessSync(wrapperPath, fs.constants.X_OK);
185+
return wrapperPath;
186+
}
187+
catch (error) {
186188
if (error.code === 'ENOENT') {
187-
if (path.resolve(path.dirname(startingManifest)) === repoRoot) {
188-
return undefined
189+
const rootDir = path.parse(currentDir).root;
190+
if (currentDir === repoRoot || currentDir === rootDir) {
191+
return undefined;
192+
}
193+
const parentDir = path.dirname(currentDir);
194+
if (parentDir === currentDir || parentDir === rootDir) {
195+
return undefined;
189196
}
190-
return this.traverseForWrapper(path.resolve(path.dirname(startingManifest)), repoRoot)
197+
return this.traverseForWrapper(path.join(parentDir, path.basename(normalizedManifest)), repoRoot);
191198
}
192-
throw new Error(`failure searching for ${this.localWrapper}`, {cause: error})
199+
throw new Error(`failure searching for ${this.localWrapper}`, { cause: error });
193200
}
194-
return wrapperPath
201+
}
202+
203+
normalizePath(thePath) {
204+
const normalized = path.resolve(thePath).normalize();
205+
return process.platform === 'win32' ? normalized.toLowerCase() : normalized;
195206
}
196207
}

src/providers/java_gradle.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,11 @@ export default class Java_gradle extends Base_java {
200200
#getProperties(manifestPath, opts) {
201201
let gradle = this.selectToolBinary(manifestPath, opts)
202202
try {
203-
let properties = this._invokeCommand(gradle, ['properties'], {cwd: path.dirname(manifestPath)})
204-
return properties.toString()
203+
const manifestDir = path.normalize(path.dirname(manifestPath));
204+
const commandResult = this._invokeCommand(gradle, ['properties'], {
205+
cwd: manifestDir
206+
})
207+
return commandResult.toString()
205208
} catch (error) {
206209
throw new Error(`Couldn't get properties of ${this._getManifestName()} file , Error message returned from gradle binary => ${EOL} ${error.message}`)
207210
}
@@ -243,7 +246,10 @@ export default class Java_gradle extends Base_java {
243246
#getDependencies(manifest, opts={}) {
244247
const gradle = this.selectToolBinary(manifest, opts)
245248
try {
246-
const commandResult = this._invokeCommand(gradle, ['dependencies'], {cwd: path.dirname(manifest)})
249+
const manifestDir = path.normalize(path.dirname(manifest));
250+
const commandResult = this._invokeCommand(gradle, ['dependencies'], {
251+
cwd: manifestDir
252+
})
247253
return commandResult.toString()
248254
} catch (error) {
249255
throw new Error(`Couldn't run gradle dependencies command, error message returned from gradle binary => ${EOL} ${error.message}`)

0 commit comments

Comments
 (0)