Skip to content

Commit

Permalink
fix: handle projects with wrappers that have whitespaces in the direc…
Browse files Browse the repository at this point in the history
…tory names (#66)
  • Loading branch information
kyegupov authored May 8, 2019
1 parent bd1f293 commit 6f90fe9
Show file tree
Hide file tree
Showing 11 changed files with 10 additions and 9 deletions.
9 changes: 5 additions & 4 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,18 +333,19 @@ ${chalk.red.bold(mainErrorMessage)}`;
}

function getCommand(root, targetFile) {
const isWin = /^win/.test(os.platform());
const wrapperScript = isWin ? 'gradlew.bat' : './gradlew';
const isWinLocal = /^win/.test(os.platform()); // local check, can be stubbed in tests
const quotLocal = isWinLocal ? '"' : '\'';
const wrapperScript = isWinLocal ? 'gradlew.bat' : './gradlew';
// try to find a sibling wrapper script first
let pathToWrapper = path.resolve(
root, path.dirname(targetFile), wrapperScript);
if (fs.existsSync(pathToWrapper)) {
return pathToWrapper;
return quotLocal + pathToWrapper + quotLocal;
}
// now try to find a wrapper in the root
pathToWrapper = path.resolve(root, wrapperScript);
if (fs.existsSync(pathToWrapper)) {
return pathToWrapper;
return quotLocal + pathToWrapper + quotLocal;
}
return 'gradle';
}
Expand Down
4 changes: 2 additions & 2 deletions test/system/darwin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test('darwin with wrapper', async (t) => {
t.fail('Expected failure');
} catch {
const cmd = (subProcess.execute as SinonStub).getCall(0).args[0];
const expectedCmd = path.join(rootWithWrapper, 'gradlew');
const expectedCmd = "'" + path.join(rootWithWrapper, 'gradlew') + "'";
t.same(cmd, expectedCmd, 'invokes wrapper script');
}
});
Expand All @@ -46,7 +46,7 @@ test('darwin with wrapper in root', async (t) => {
t.fail('Expected failure');
} catch {
const cmd = (subProcess.execute as SinonStub).getCall(0).args[0];
const expectedCmd = path.join(subWithWrapper, 'gradlew');
const expectedCmd = "'" + path.join(subWithWrapper, "gradlew") + "'";
t.same(cmd, expectedCmd, 'invokes wrapper script');
}
});
Expand Down
2 changes: 1 addition & 1 deletion test/system/multi-module.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ test('multi-project: only sub-project has deps, none returned for main', async (

test('multi-project: using gradle via wrapper', async (t) => {
const result = await inspect('.',
path.join(fixtureDir('multi-project-gradle-wrapper'), 'build.gradle'));
path.join(fixtureDir('multi-project gradle wrapper'), 'build.gradle'));
t.match(result.package.name, '.',
'returned project name is not sub-project');
t.deepEqual(result.plugin.meta!.allDepRootNames, ['root-proj', 'subproj']);
Expand Down
4 changes: 2 additions & 2 deletions test/system/windows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('windows with wrapper in root', async (t) => {
t.fail('Expected failure');
} catch {
const cmd = (subProcess.execute as SinonStub).getCall(0).args[0];
const expectedCmd = path.join(subWithWrapper, 'gradlew.bat');
const expectedCmd = '"' + path.join(subWithWrapper, 'gradlew.bat') + '"';
t.same(cmd, expectedCmd, 'invokes wrapper bat');
}
});
Expand All @@ -33,7 +33,7 @@ test('windows with wrapper', async (t) => {
t.fail('Expected failure');
} catch {
const cmd = (subProcess.execute as SinonStub).getCall(0).args[0];
const expectedCmd = path.join(rootWithWrapper, 'gradlew.bat');
const expectedCmd = '"' + path.join(rootWithWrapper, 'gradlew.bat') + '"';
t.same(cmd, expectedCmd, 'invokes wrapper bat');
}
});
Expand Down

0 comments on commit 6f90fe9

Please sign in to comment.