Skip to content

Commit

Permalink
[Gradle] Added the possibility to completely exclude modules from the…
Browse files Browse the repository at this point in the history
… scan (fix for issue #1413) (#1418)

Added the possibility to completely exclude modules from the scan (fix for issue #1413)

Signed-off-by: Roland Asmann <roland.asmann@gmail.com>
  • Loading branch information
malice00 authored Oct 14, 2024
1 parent e9f714d commit 41cca69
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
3 changes: 2 additions & 1 deletion docs/ENV.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ The following environment variables are available to configure the bom generatio
| GRADLE_DEPENDENCY_TASK | By default cdxgen use the task "dependencies" to collect packages. Set to override the task name. |
| GRADLE_INCLUDED_BUILDS | Comma-separated list of 'includedBuilds' modules that should be scanned on top of all the modules of your projects. Since includedBuilds can't be found automatically, they have to be listed here. Use gradle-conventions (include the ':'-prefix) for the names. |
| GRADLE_RESOLVE_FROM_NODE | If some of your gradle modules are included from node (eg when using expo or react-native), set this to true to use the npm-packages as your dependencies. The big advantage of this, is that the generated purls will be of actually known components (eg in OSS Index) instead of generic names for the packages. |
| GRADLE_SKIP_MODULES | Comma-separated list of modules to skip during the "dependencies" task. This can be useful if you have modules that would fail the gradle build, eg when they do not have dependencies in the given configuration. Use "root" if the top most module should be skipped, use their gradle-name (so WITH leading ":") for all others. |
| GRADLE_SKIP_MODULE_DEPENDENCIES | Comma-separated list of modules to skip during the "dependencies" task. This can be useful if you have modules that would fail the gradle build, eg when they do not have dependencies in the given configuration. Use "root" if the top most module should be skipped, use their gradle-name (so WITH leading ":") for all others. |
| GRADLE_SKIP_MODULES | Comma-separated list of modules to skip for both "properties" and "dependencies" task. Use the gradle-name (so WITH leading ":"). NOTICE: when using this, neither the configured ID (group, name & version) nor the dependencies of these modules will be available! |
| SBT_CACHE_DIR | Specify sbt cache directory. Useful for class name resolving |
| FETCH_LICENSE | Set this variable to `true` or `1` to fetch license information from the registry. npm and golang |
| SEARCH_MAVEN_ORG | If maven metadata is missing in jar file, a search is performed on search.maven.org. Set to `false` or `0` to disable search. (defaults to `true`) |
Expand Down
24 changes: 18 additions & 6 deletions lib/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1684,29 +1684,36 @@ export async function createJavaBom(path, options) {
parentComponent = rootGradleModule;
// Get the sub-project properties and set the root dependencies
if (allProjectsStr?.length) {
const modulesToSkip = process.env.GRADLE_SKIP_MODULES
? process.env.GRADLE_SKIP_MODULES.split(",")
: [];

const parallelPropTaskOut = executeParallelGradleProperties(
gradleRootPath,
allProjectsStr,
allProjectsStr.filter((module) => !modulesToSkip.includes(module)),
);
const splitPropTaskOut = splitOutputByGradleProjects(
parallelPropTaskOut,
["properties"],
);

for (const [key, propTaskOut] of splitPropTaskOut.entries()) {
const retMap = parseGradleProperties(propTaskOut, key);
for (const subProject of allProjectsStr) {
const retMap = parseGradleProperties(
splitPropTaskOut.get(subProject),
subProject,
);
const rootSubProject = retMap.rootProject;
if (rootSubProject) {
const rootSubProjectObj = await buildObjectForGradleModule(
rootSubProject,
rootSubProject === "root" ? subProject : rootSubProject,
retMap.metadata,
);
if (!allProjectsAddedPurls.includes(rootSubProjectObj["purl"])) {
allProjects.push(rootSubProjectObj);
rootDependsOn.push(rootSubProjectObj["bom-ref"]);
allProjectsAddedPurls.push(rootSubProjectObj["purl"]);
}
gradleModules.set(key, rootSubProjectObj);
gradleModules.set(subProject, rootSubProjectObj);
}
}
// Bug #317 fix
Expand All @@ -1733,9 +1740,14 @@ export async function createJavaBom(path, options) {
: "dependencies";

const gradleSubCommands = [];
const modulesToSkip = process.env.GRADLE_SKIP_MODULES
let modulesToSkip = process.env.GRADLE_SKIP_MODULES
? process.env.GRADLE_SKIP_MODULES.split(",")
: [];
if (process.env.GRADLE_SKIP_MODULE_DEPENDENCIES) {
modulesToSkip = modulesToSkip.concat(
process.env.GRADLE_SKIP_MODULE_DEPENDENCIES.split(","),
);
}
if (!modulesToSkip.includes("root")) {
gradleSubCommands.push(gradleDepTask);
}
Expand Down
16 changes: 11 additions & 5 deletions lib/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2640,28 +2640,34 @@ export async function parseGradleDep(
let scope = undefined;
let profileName = undefined;
if (retMap?.projects) {
const modulesToSkip = process.env.GRADLE_SKIP_MODULES
? process.env.GRADLE_SKIP_MODULES.split(",")
: [];
const modulesToScan = retMap.projects.filter(
(module) => !gradleModules.has(module),
);
if (modulesToScan.length > 0) {
const parallelPropTaskOut = executeParallelGradleProperties(
gradleRootPath,
modulesToScan,
modulesToScan.filter((module) => !modulesToSkip.includes(module)),
);
const splitPropTaskOut = splitOutputByGradleProjects(
parallelPropTaskOut,
["properties"],
);

for (const [key, propTaskOut] of splitPropTaskOut.entries()) {
const propMap = parseGradleProperties(propTaskOut, key);
for (const module of modulesToScan) {
const propMap = parseGradleProperties(
splitPropTaskOut.get(module),
module,
);
const rootSubProject = propMap.rootProject;
if (rootSubProject) {
const rootSubProjectObj = await buildObjectForGradleModule(
rootSubProject,
rootSubProject === "root" ? module : rootSubProject,
propMap.metadata,
);
gradleModules.set(key, rootSubProjectObj);
gradleModules.set(module, rootSubProjectObj);
}
}
}
Expand Down

0 comments on commit 41cca69

Please sign in to comment.