Skip to content
This repository was archived by the owner on Jan 9, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions lib/gradle-wrapper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'source-map-support/register';
import { execute } from './sub-process';
import * as path from 'path';
import * as fs from 'fs';
import { ClassPathGenerationError } from './errors';

export function getGradleCommandArgs(targetPath: string): string[] {
Expand All @@ -18,23 +17,13 @@ export function getGradleCommandArgs(targetPath: string): string[] {
return gradleArgs;
}

export function getGradleCommand(targetPath: string): string {
const pathToWrapper = path.resolve(targetPath || '', '.', 'gradlew');

if (fs.existsSync(pathToWrapper)) {
return pathToWrapper;
}

return 'gradle';
}

export async function getClassPathFromGradle(
targetPath: string,
gradlePath: string,
): Promise<string> {
const cmd = getGradleCommand(targetPath);
const args = getGradleCommandArgs(targetPath);
try {
const output = await execute(cmd, args, { cwd: targetPath });
const output = await execute(gradlePath, args, { cwd: targetPath });
return output.trim();
} catch (e) {
console.log(e);
Expand Down
5 changes: 4 additions & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ export async function getCallGraphMvn(

export async function getCallGraphGradle(
targetPath: string,
gradlePath = 'gradle',
timeout?: number,
): Promise<Graph> {
const [classPath, targets] = await Promise.all([
timeIt('getGradleClassPath', () => getClassPathFromGradle(targetPath)),
timeIt('getGradleClassPath', () =>
getClassPathFromGradle(targetPath, gradlePath),
),
timeIt('getEntrypoints', () => findBuildDirs(targetPath, 'gradle')),
]);

Expand Down
2 changes: 1 addition & 1 deletion test/integration/e2e-run_gradle.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as path from 'path';
import * as fs from '../../lib/promisified-fs-glob';
import * as os from 'os';
import { getCallGraphGradle } from '../../lib';

jest.setTimeout(60000);
Expand All @@ -15,6 +14,7 @@ test('callgraph for gradle is created', async () => {
__dirname,
...'../fixtures/java-reachability-playground'.split('/'),
),
'gradle',
);

// verify tempdir was created and file written
Expand Down