Skip to content

Commit

Permalink
feat: extract gradle sub-project count
Browse files Browse the repository at this point in the history
  • Loading branch information
lili2311 committed Nov 1, 2019
1 parent 343ae0f commit 781a516
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/cli/commands/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,11 @@ async function monitor(...args0: MethodArgs): Promise<any> {
}),
);
} else {
if (
!options['gradle-sub-project'] &&
inspectResult.plugin.meta &&
inspectResult.plugin.meta.allSubProjectNames &&
inspectResult.plugin.meta.allSubProjectNames.length > 1
) {
advertiseSubprojectsCount =
inspectResult.plugin.meta.allSubProjectNames.length;
if (packageManager === 'gradle') {
advertiseSubprojectsCount = getSubProjectCountForGradle(
inspectResult,
options['gradle-sub-project'],
);
}
perProjectResult = [inspectResult];
}
Expand Down Expand Up @@ -272,12 +269,26 @@ async function monitor(...args0: MethodArgs): Promise<any> {
throw new Error(output);
}

function getSubProjectCountForGradle(
inspectResult,
calledForSingleSubProject,
): number | null {
if (
!calledForSingleSubProject &&
inspectResult.plugin.meta &&
inspectResult.plugin.meta.allSubProjectNames &&
inspectResult.plugin.meta.allSubProjectNames.length > 1
) {
return inspectResult.plugin.meta.allSubProjectNames.length;
}

return null;
}

async function validateMonitorPath(path, isDocker) {
const exists = await fs.exists(path);
if (!exists && !isDocker) {
throw new Error(
'"' + path + '" is not a valid path for "snyk monitor"',
);
throw new Error('"' + path + '" is not a valid path for "snyk monitor"');
}
}

Expand Down

0 comments on commit 781a516

Please sign in to comment.