Skip to content

Commit

Permalink
Merge pull request #280 from CycloneDX/verbose
Browse files Browse the repository at this point in the history
document and test verbose
  • Loading branch information
hboutemy committed Feb 15, 2023
2 parents 38dca23 + 1dfb33a commit 4436ada
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Default Values
<outputReactorProjects>true</outputReactorProjects>
<outputFormat>all</outputFormat>
<outputName>bom</outputName>
<verbose>true</verbose><!-- = ${cyclonedx.verbose} -->
</configuration>
</plugin>
</plugins>
Expand Down
1 change: 1 addition & 0 deletions src/it/makeBom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<cyclonedx.verbose>false</cyclonedx.verbose><!-- override default plugin value, user still can override with CLI -Dcyclonedx.verbose -->
</properties>

<dependencies>
Expand Down
2 changes: 2 additions & 0 deletions src/it/makeBom/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ File bomAggregateFileJson = new File(basedir, "target/bom-makeAggregateBom.json"

assert bomAggregateFileXml.exists()
assert bomAggregateFileJson.exists()

assert ! new File(basedir, "build.log").text.contains('[INFO] CycloneDX: Parameters')
2 changes: 0 additions & 2 deletions src/test/java/org/cyclonedx/maven/BundleDependencyTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.cyclonedx.maven;

import static io.takari.maven.testing.TestResources.assertFilesPresent;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down
50 changes: 50 additions & 0 deletions src/test/java/org/cyclonedx/maven/VerboseTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.cyclonedx.maven;

import java.io.File;

import org.junit.Test;
import org.junit.runner.RunWith;

import io.takari.maven.testing.executor.MavenRuntime.MavenRuntimeBuilder;
import io.takari.maven.testing.executor.MavenVersions;
import io.takari.maven.testing.executor.junit.MavenJUnitTestRunner;

/**
* test for https://github.com/CycloneDX/cyclonedx-maven-plugin/issues/280
* how to switch verbosity off by default, but let the user activate with CLI parameter
*/
@RunWith(MavenJUnitTestRunner.class)
@MavenVersions({"3.6.3"})
public class VerboseTest extends BaseMavenVerifier {

public VerboseTest(MavenRuntimeBuilder runtimeBuilder) throws Exception {
super(runtimeBuilder);
}

@Test
public void testVerboseOffByDefault() throws Exception {
File projDir = resources.getBasedir("verbose");

verifier
.forProject(projDir)
.withCliOption("-Dcurrent.version=" + getCurrentVersion()) // inject cyclonedx-maven-plugin version
.withCliOption("-B")
.execute("verify")
.assertErrorFreeLog()
.assertNoLogText("[INFO] CycloneDX: Parameters"); // check no verbose output by default given property defined in pom.xml
}

@Test
public void testVerboseWithCli() throws Exception {
File projDir = resources.getBasedir("verbose");

verifier
.forProject(projDir)
.withCliOption("-Dcurrent.version=" + getCurrentVersion()) // inject cyclonedx-maven-plugin version
.withCliOption("-B")
.withCliOption("-Dcyclonedx.verbose") // activate verbose with CLI parameter
.execute("verify")
.assertErrorFreeLog()
.assertLogText("[INFO] CycloneDX: Parameters"); // check goal verbose output
}
}
52 changes: 52 additions & 0 deletions src/test/resources/verbose/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>issue-280</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>

<name>Issue-280: make verbose off by default, that can be overridden on CLI</name>

<licenses>
<license>
<name>Apache-2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<cyclonedx.verbose>false</cyclonedx.verbose><!-- use the plugin-provided cyclonedx.verbose property to override default -->
</properties>

<build>
<plugins>
<plugin>
<groupId>org.cyclonedx</groupId>
<artifactId>cyclonedx-maven-plugin</artifactId>
<version>${current.version}</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>makeBom</goal>
</goals>
</execution>
</executions>
<configuration>
<outputFormat>json</outputFormat>
<!-- <verbose>false</verbose> do not inject a fixed value in the plugin configuration: it could not be overridden with CLI -->
</configuration>
</plugin>
</plugins>
</build>

</project>

0 comments on commit 4436ada

Please sign in to comment.