Skip to content

Commit

Permalink
add outputDirectory parameter
Browse files Browse the repository at this point in the history
Signed-off-by: Hervé Boutemy <hboutemy@apache.org>
  • Loading branch information
hboutemy committed Feb 14, 2023
1 parent 4797e8c commit 59afb05
Show file tree
Hide file tree
Showing 2 changed files with 11 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>
<outputDirectory>${project.build.directory}</outpuDirectory><!-- usually target, if not redefined in pom.xml -->
</configuration>
</plugin>
</plugins>
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/org/cyclonedx/maven/BaseCycloneDxMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,21 @@ public abstract class BaseCycloneDxMojo extends AbstractMojo {
private String outputFormat;

/**
* The CycloneDX output file name (without extension) that should be generated (in {@code target/} directory).
* The CycloneDX output file name (without extension) that should be generated (in {@code outputDirectory} directory).
*
* @since 2.2.0
*/
@Parameter(property = "outputName", defaultValue = "bom", required = false)
private String outputName;

/**
* The output directory where to store generated CycloneDX output files.
*
* @since 2.7.5
*/
@Parameter(defaultValue = "${project.build.directory}", required = false)
private File outputDirectory;

/**
* Should the resulting BOM contain a unique serial number?
*
Expand Down Expand Up @@ -315,7 +323,7 @@ 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(project.getBasedir(), "target/" + outputName + "." + extension);
final File bomFile = new File(outputDirectory, outputName + "." + extension);

getLog().info(String.format(MESSAGE_WRITING_BOM, extension.toUpperCase(), bomFile.getAbsolutePath()));
FileUtils.write(bomFile, bomString, StandardCharsets.UTF_8, false);
Expand Down

0 comments on commit 59afb05

Please sign in to comment.