Skip to content

Commit a4274fb

Browse files
author
Daniel Ekelund
committed
feat: support --print-graph as dverbose
1 parent 13557c5 commit a4274fb

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

lib/index.ts

+18-7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export function debug(...messages: string[]) {
3131
}
3232

3333
export interface MavenOptions extends legacyPlugin.BaseInspectOptions {
34+
'print-graph'?: boolean;
3435
scanAllUnmanaged?: boolean;
3536
allProjects?: boolean;
3637
mavenAggregateProject?: boolean;
@@ -112,7 +113,7 @@ export async function inspect(
112113
throw new Error('Could not find file or directory ' + targetPath);
113114
}
114115
if (!options) {
115-
options = { dev: false, scanAllUnmanaged: false };
116+
options = { dev: false, scanAllUnmanaged: false, 'print-graph': false };
116117
}
117118

118119
if (targetPath && isArchive(targetPath)) {
@@ -159,13 +160,17 @@ export async function inspect(
159160
const mavenCommand = getCommand(root, targetFile);
160161
const mvnWorkingDirectory = findWrapper(mavenCommand, root, targetPath);
161162
const args = options.args || [];
163+
162164
const verboseEnabled =
163-
args.includes('-Dverbose') || args.includes('-Dverbose=true');
165+
args.includes('-Dverbose') ||
166+
args.includes('-Dverbose=true') ||
167+
!!options['print-graph'];
168+
164169
const mvnArgs = buildArgs(
165170
root,
166171
mvnWorkingDirectory,
167172
targetFile,
168-
options.args,
173+
args,
169174
options.mavenAggregateProject,
170175
verboseEnabled,
171176
);
@@ -214,8 +219,8 @@ export async function inspect(
214219
export function buildArgs(
215220
rootPath: string,
216221
executionPath: string,
217-
targetFile?: string,
218-
mavenArgs?: string[] | undefined,
222+
targetFile: string | undefined,
223+
mavenArgs: string[],
219224
mavenAggregateProject = false,
220225
verboseEnabled = false,
221226
) {
@@ -255,9 +260,15 @@ export function buildArgs(
255260
}
256261
}
257262

258-
if (mavenArgs) {
259-
args = args.concat(mavenArgs);
263+
if (
264+
verboseEnabled &&
265+
!mavenArgs.includes('-Dverbose') &&
266+
!mavenArgs.includes('-Dverbose=true')
267+
) {
268+
args = args.concat('-Dverbose');
260269
}
261270

271+
args = args.concat(mavenArgs);
272+
262273
return args;
263274
}

tests/jest/system/dverbose-flag.spec.ts

+21
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,24 @@ test('inspect on dverbose-project pom using -Dverbose', async () => {
2828
},
2929
20000,
3030
);
31+
32+
test('inspect on dverbose-project pom using --print-graph', async () => {
33+
let result: Record<string, any> = await plugin.inspect(
34+
'.',
35+
path.join(testProjectPath, 'pom.xml'),
36+
{
37+
'print-graph': true
38+
},
39+
);
40+
41+
const expectedJSON = await readFixtureJSON(
42+
'dverbose-project',
43+
'expected-dverbose-dep-graph.json',
44+
);
45+
const expectedDepGraph = depGraphLib.createFromJSON(expectedJSON).toJSON();
46+
result = result.scannedProjects[0].depGraph?.toJSON();
47+
48+
expect(result).toEqual(expectedDepGraph);
49+
},
50+
20000,
51+
);

0 commit comments

Comments
 (0)