Skip to content

Commit

Permalink
Merge pull request #177 from snyk/feat/support-print-graph-as-dverbose
Browse files Browse the repository at this point in the history
feat: support --print-graph as dverbose
  • Loading branch information
dekelund authored May 7, 2024
2 parents 13557c5 + a4274fb commit a62b0b4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
25 changes: 18 additions & 7 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function debug(...messages: string[]) {
}

export interface MavenOptions extends legacyPlugin.BaseInspectOptions {
'print-graph'?: boolean;
scanAllUnmanaged?: boolean;
allProjects?: boolean;
mavenAggregateProject?: boolean;
Expand Down Expand Up @@ -112,7 +113,7 @@ export async function inspect(
throw new Error('Could not find file or directory ' + targetPath);
}
if (!options) {
options = { dev: false, scanAllUnmanaged: false };
options = { dev: false, scanAllUnmanaged: false, 'print-graph': false };
}

if (targetPath && isArchive(targetPath)) {
Expand Down Expand Up @@ -159,13 +160,17 @@ export async function inspect(
const mavenCommand = getCommand(root, targetFile);
const mvnWorkingDirectory = findWrapper(mavenCommand, root, targetPath);
const args = options.args || [];

const verboseEnabled =
args.includes('-Dverbose') || args.includes('-Dverbose=true');
args.includes('-Dverbose') ||
args.includes('-Dverbose=true') ||
!!options['print-graph'];

const mvnArgs = buildArgs(
root,
mvnWorkingDirectory,
targetFile,
options.args,
args,
options.mavenAggregateProject,
verboseEnabled,
);
Expand Down Expand Up @@ -214,8 +219,8 @@ export async function inspect(
export function buildArgs(
rootPath: string,
executionPath: string,
targetFile?: string,
mavenArgs?: string[] | undefined,
targetFile: string | undefined,
mavenArgs: string[],
mavenAggregateProject = false,
verboseEnabled = false,
) {
Expand Down Expand Up @@ -255,9 +260,15 @@ export function buildArgs(
}
}

if (mavenArgs) {
args = args.concat(mavenArgs);
if (
verboseEnabled &&
!mavenArgs.includes('-Dverbose') &&
!mavenArgs.includes('-Dverbose=true')
) {
args = args.concat('-Dverbose');
}

args = args.concat(mavenArgs);

return args;
}
21 changes: 21 additions & 0 deletions tests/jest/system/dverbose-flag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,24 @@ test('inspect on dverbose-project pom using -Dverbose', async () => {
},
20000,
);

test('inspect on dverbose-project pom using --print-graph', async () => {
let result: Record<string, any> = await plugin.inspect(
'.',
path.join(testProjectPath, 'pom.xml'),
{
'print-graph': true
},
);

const expectedJSON = await readFixtureJSON(
'dverbose-project',
'expected-dverbose-dep-graph.json',
);
const expectedDepGraph = depGraphLib.createFromJSON(expectedJSON).toJSON();
result = result.scannedProjects[0].depGraph?.toJSON();

expect(result).toEqual(expectedDepGraph);
},
20000,
);

0 comments on commit a62b0b4

Please sign in to comment.