Skip to content

Commit

Permalink
feat: add logging for configurations in scope for artifact resolution…
Browse files Browse the repository at this point in the history
… and dependency graph

Signed-off-by: Gordon <gordon_rousselle@hotmail.com>
  • Loading branch information
gordonrousselle authored and skhokhlov committed Feb 4, 2025
1 parent 955c785 commit a03550a
Showing 1 changed file with 40 additions and 9 deletions.
49 changes: 40 additions & 9 deletions src/main/java/org/cyclonedx/gradle/SbomGraphProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.cyclonedx.gradle.model.SbomComponent;
Expand Down Expand Up @@ -116,7 +117,15 @@ private Stream<Map<SbomComponentId, SbomComponent>> traverseProject(final Projec
final DependencyGraphTraverser traverser =
new DependencyGraphTraverser(project.getLogger(), getArtifacts(), mavenLookup, task);

return Arrays.stream(project.getConfigurations().toArray(CONFIG_TYPE))
final Configuration[] configs = project.getConfigurations().toArray(CONFIG_TYPE);
this.project
.getLogger()
.info(
"For project {} following configurations are in scope to build the dependency graph: {}",
project.getName(),
summarize(configs, Configuration::getName));

return Arrays.stream(configs)
.filter(configuration -> shouldIncludeConfiguration(configuration)
&& !shouldSkipConfiguration(configuration)
&& configuration.isCanBeResolved())
Expand All @@ -127,23 +136,45 @@ private Stream<Map<SbomComponentId, SbomComponent>> traverseProject(final Projec
private Map<ComponentIdentifier, File> getArtifacts() {
return Stream.concat(Stream.of(project), project.getSubprojects().stream())
.filter(project -> !shouldSkipProject(project))
.flatMap(project -> Arrays.stream(project.getConfigurations().toArray(CONFIG_TYPE)))
.flatMap(project -> {
final Configuration[] configs = project.getConfigurations().toArray(CONFIG_TYPE);
this.project
.getLogger()
.info(
"For project {} following configurations are in scope to resolve artifacts: {}",
project.getName(),
summarize(configs, Configuration::getName));
return Arrays.stream(configs);
})
.filter(configuration -> shouldIncludeConfiguration(configuration)
&& !shouldSkipConfiguration(configuration)
&& configuration.isCanBeResolved())
.flatMap(config -> Arrays.stream(config.getIncoming()
.artifactView(view -> {
view.lenient(true);
})
.getArtifacts()
.getArtifacts()
.toArray(ARTIFACT_TYPE)))
.flatMap(config -> {
final ResolvedArtifactResult[] resolvedArtifacts = config.getIncoming()
.artifactView(view -> {
view.lenient(true);
})
.getArtifacts()
.getArtifacts()
.toArray(ARTIFACT_TYPE);
this.project
.getLogger()
.debug(
"For project {} following artifacts have been resolved: {}",
project.getName(),
summarize(resolvedArtifacts, v -> v.getId().getDisplayName()));
return Arrays.stream(resolvedArtifacts);
})
.collect(Collectors.toMap(
artifact -> artifact.getId().getComponentIdentifier(),
ResolvedArtifactResult::getFile,
(v1, v2) -> v1));
}

private <T> String summarize(T[] data, final Function<T, String> extractor) {
return Arrays.stream(data).map(extractor).collect(Collectors.joining(","));
}

private boolean shouldSkipConfiguration(final Configuration configuration) {
return task.getSkipConfigs().get().stream().anyMatch(configuration.getName()::matches);
}
Expand Down

0 comments on commit a03550a

Please sign in to comment.