Skip to content

Commit

Permalink
[logging] Plugin is to chatty when verbose turned off, make info logs…
Browse files Browse the repository at this point in the history
… debug if verbose is turned off
  • Loading branch information
hazendaz committed May 29, 2024
1 parent 55135fc commit b4fd51d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/it/makeAggregateBom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
<groupId>org.cyclonedx</groupId>
<artifactId>cyclonedx-maven-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<verbose>true</verbose>
</configuration>
<!-- intentionally use default configuration -->
<executions>
<execution>
Expand Down
20 changes: 16 additions & 4 deletions src/main/java/org/cyclonedx/maven/BaseCycloneDxMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public abstract class BaseCycloneDxMojo extends AbstractMojo {
*/
@SuppressWarnings("CanBeFinal")
@Parameter(property = "cyclonedx.verbose", defaultValue = "false", required = false)
private boolean verbose = false;
protected boolean verbose = false;

/**
* Timestamp for reproducible output archive entries, either formatted as ISO 8601
Expand Down Expand Up @@ -361,7 +361,11 @@ private Property newProperty(String name, String value) {

private void generateBom(String analysis, Metadata metadata, List<Component> components, List<Dependency> dependencies) throws MojoExecutionException {
try {
getLog().info(String.format(MESSAGE_CREATING_BOM, schemaVersion, components.size()));
if (verbose) {
getLog().info(String.format(MESSAGE_CREATING_BOM, schemaVersion, components.size()));
} else {
getLog().debug(String.format(MESSAGE_CREATING_BOM, schemaVersion, components.size()));
}
final Bom bom = new Bom();
bom.setComponents(components);

Expand Down Expand Up @@ -447,15 +451,23 @@ private void saveBom(Bom bom) throws ParserConfigurationException, IOException,
private void saveBomToFile(String bomString, String extension, Parser bomParser) throws IOException, MojoExecutionException {
final File bomFile = new File(outputDirectory, outputName + "." + extension);

getLog().info(String.format(MESSAGE_WRITING_BOM, extension.toUpperCase(), bomFile.getAbsolutePath()));
if (verbose) {
getLog().info(String.format(MESSAGE_WRITING_BOM, extension.toUpperCase(), bomFile.getAbsolutePath()));
} else {
getLog().debug(String.format(MESSAGE_WRITING_BOM, extension.toUpperCase(), bomFile.getAbsolutePath()));
}
FileUtils.write(bomFile, bomString, StandardCharsets.UTF_8, false);

if (!bomParser.isValid(bomFile, schemaVersion())) {
throw new MojoExecutionException(MESSAGE_VALIDATION_FAILURE);
}

if (!skipAttach) {
getLog().info(String.format(MESSAGE_ATTACHING_BOM, project.getArtifactId(), project.getVersion(), extension));
if (verbose) {
getLog().info(String.format(MESSAGE_ATTACHING_BOM, project.getArtifactId(), project.getVersion(), extension));
} else {
getLog().debug(String.format(MESSAGE_ATTACHING_BOM, project.getArtifactId(), project.getVersion(), extension));
}
mavenProjectHelper.attachArtifact(project, extension, "cyclonedx", bomFile);
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/cyclonedx/maven/CycloneDxMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ protected String getSkipReason() {
}

protected String extractComponentsAndDependencies(final Set<String> topLevelComponents, final Map<String, Component> components, final Map<String, Dependency> dependencies) throws MojoExecutionException {
getLog().info(MESSAGE_RESOLVING_DEPS);
if (verbose) {
getLog().info(MESSAGE_RESOLVING_DEPS);
} else {
getLog().debug(MESSAGE_RESOLVING_DEPS);
}

final BomDependencies bomDependencies = extractBOMDependencies(getProject());
final Map<String, Dependency> projectDependencies = bomDependencies.getDependencies();
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/org/cyclonedx/maven/CycloneDxPackageMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,21 @@ protected boolean shouldInclude(MavenProject mavenProject) {
}

protected String extractComponentsAndDependencies(Set<String> topLevelComponents, Map<String, Component> components, Map<String, Dependency> dependencies) throws MojoExecutionException {
getLog().info(MESSAGE_RESOLVING_DEPS);
if (verbose) {
getLog().info(MESSAGE_RESOLVING_DEPS);
} else {
getLog().debug(MESSAGE_RESOLVING_DEPS);
}

for (final MavenProject mavenProject : reactorProjects) {
if (!shouldInclude(mavenProject)) {
continue;
}
getLog().info("Analyzing " + mavenProject.getArtifactId());
if (verbose) {
getLog().info("Analyzing " + mavenProject.getArtifactId());
} else {
getLog().debug("Analyzing " + mavenProject.getArtifactId());
}

final BomDependencies bomDependencies = extractBOMDependencies(mavenProject);
final Map<String, Dependency> projectDependencies = bomDependencies.getDependencies();
Expand Down

0 comments on commit b4fd51d

Please sign in to comment.