Skip to content

Commit db2a35b

Browse files
Bananeweizenhboutemy
authored andcommitted
Make log output more easy to understand by sorting dependencies
Sort the log output for excluded artifacts as well as not depended upon artifacts. That makes comparing multiple builds much easier than reading the "randomly sorted" looking output (it's not really random, but driven by the dependency order). Signed-off-by: Michael Keppler <[email protected]>
1 parent 6429094 commit db2a35b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/main/java/org/cyclonedx/maven/CycloneDxAggregateMojo.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.cyclonedx.model.Component;
2828
import org.cyclonedx.model.Dependency;
2929

30+
import java.util.ArrayList;
3031
import java.util.Arrays;
3132
import java.util.List;
3233
import java.util.Map;
@@ -117,9 +118,10 @@ protected String extractComponentsAndDependencies(final Set<String> topLevelComp
117118
// root project: analyze and aggregate all the modules
118119
getLog().info((reactorProjects.size() <= 1) ? MESSAGE_RESOLVING_DEPS : MESSAGE_RESOLVING_AGGREGATED_DEPS);
119120

121+
final List<String> excludedProjects = new ArrayList<>();
120122
for (final MavenProject mavenProject : reactorProjects) {
121123
if (shouldExclude(mavenProject)) {
122-
getLog().info("Excluding " + mavenProject.getArtifactId());
124+
excludedProjects.add(mavenProject.getArtifactId());
123125
continue;
124126
}
125127

@@ -135,6 +137,8 @@ protected String extractComponentsAndDependencies(final Set<String> topLevelComp
135137
projectDependencies.forEach(dependencies::putIfAbsent);
136138
}
137139

140+
excludedProjects.stream().sorted(String.CASE_INSENSITIVE_ORDER).forEach(excluded -> getLog().info("Excluding " + excluded));
141+
138142
addMavenProjectsAsParentDependencies(reactorProjects, dependencies);
139143

140144
return "makeAggregateBom";

src/main/java/org/cyclonedx/maven/DefaultProjectDependenciesConverter.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@
4040
import org.slf4j.LoggerFactory;
4141

4242
import java.lang.reflect.Field;
43+
import java.util.ArrayList;
4344
import java.util.Arrays;
4445
import java.util.HashSet;
4546
import java.util.Iterator;
4647
import java.util.LinkedHashMap;
48+
import java.util.List;
4749
import java.util.Map;
4850
import java.util.Set;
4951

@@ -242,6 +244,7 @@ public void cleanupBomDependencies(Metadata metadata, Map<String, Component> com
242244

243245
// Check all BOM components have an associated BOM dependency
244246

247+
final List<String> notDepended = new ArrayList<>();
245248
for (Iterator<Map.Entry<String, Component>> it = components.entrySet().iterator(); it.hasNext(); ) {
246249
Map.Entry<String, Component> entry = it.next();
247250
if (!dependencies.containsKey(entry.getKey())) {
@@ -250,10 +253,12 @@ public void cleanupBomDependencies(Metadata metadata, Map<String, Component> com
250253
}
251254
it.remove();
252255
} else if (!dependsOns.contains(entry.getKey())) {
253-
logger.warn("BOM dependency listed but is not depended upon: " + entry.getKey());
256+
notDepended.add(entry.getKey());
254257
}
255258
}
256259

260+
notDepended.stream().sorted(String.CASE_INSENSITIVE_ORDER).forEach(dependency -> logger.warn("BOM dependency listed but is not depended upon: " + dependency));
261+
257262
// include BOM main component
258263
Component main = metadata.getComponent();
259264
final String mainBomRef = main.getBomRef();

0 commit comments

Comments
 (0)