Skip to content

Commit

Permalink
Merge pull request #171 from snyk/feat/support-unpruned-flag
Browse files Browse the repository at this point in the history
feat: support unpruned flag from CLI
  • Loading branch information
orsagie committed Mar 21, 2024
2 parents b2912b8 + 87307aa commit cb21c33
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/index.ts
Expand Up @@ -34,6 +34,7 @@ export interface MavenOptions extends legacyPlugin.BaseInspectOptions {
scanAllUnmanaged?: boolean;
allProjects?: boolean;
mavenAggregateProject?: boolean;
unpruned?: boolean;
}

export function getCommand(root: string, targetFile: string | undefined) {
Expand Down Expand Up @@ -158,9 +159,7 @@ 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');
const verboseEnabled = handleVerbose(options);
const mvnArgs = buildArgs(
root,
mvnWorkingDirectory,
Expand Down Expand Up @@ -261,3 +260,14 @@ export function buildArgs(

return args;
}

function handleVerbose(options): boolean {
const args = options.args || [];
const verboseFlag =
args.includes('-Dverbose') || args.includes('-Dverbose=true');
if (options.unpruned && !verboseFlag) {
args.push('-Dverbose');
options.args = args;
}
return verboseFlag || options.unpruned;
}
24 changes: 24 additions & 0 deletions tests/tap/system/plugin.test.ts
Expand Up @@ -408,3 +408,27 @@ test('inspect on verbose-project pom using -Dverbose', async (t) => {
'returns expected dep-graph',
);
});

test('inspect on test-project pom using --unpruned', async (t) => {
const result = await plugin.inspect(
'.',
path.join(testProjectPath, 'pom.xml'),
{
unpruned: true,
},
);
if (!legacyPlugin.isMultiResult(result)) {
return t.fail('expected multi inspect result');
}
t.equal(result.scannedProjects.length, 1, 'returns 1 scanned project');
const expectedJSON = await readFixtureJSON(
'test-project',
'expected-verbose-dep-graph.json',
);
const expectedDepGraph = depGraphLib.createFromJSON(expectedJSON);
t.same(
result.scannedProjects[0].depGraph?.toJSON(),
expectedDepGraph.toJSON(),
'returns expected dep-graph',
);
});

0 comments on commit cb21c33

Please sign in to comment.