Skip to content

Commit

Permalink
Merge pull request #88 from spdx/issue69
Browse files Browse the repository at this point in the history
Add default file extension
  • Loading branch information
goneall committed Apr 10, 2023
2 parents 0ef4ed2 + 58043a5 commit 9aa6ff6
Showing 1 changed file with 31 additions and 26 deletions.
57 changes: 31 additions & 26 deletions src/main/java/org/spdx/maven/CreateSpdxMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;

/**
Expand Down Expand Up @@ -129,7 +130,7 @@ public class CreateSpdxMojo extends AbstractMojo
/**
* SPDX File name
*/
@Parameter( defaultValue = "${project.reporting.outputDirectory}/${project.groupId}_${project.artifactId}-${project.version}.spdx.json",
@Parameter( defaultValue = "${project.reporting.outputDirectory}/${project.groupId}_${project.artifactId}-${project.version}.spdx",
property = "spdxFileName",
required = true )
private File spdxFile;
Expand Down Expand Up @@ -394,31 +395,12 @@ public void execute() throws MojoExecutionException
}
if ( this.spdxFile == null )
{
throw ( new MojoExecutionException(
"No SPDX file referenced. " + "Specify a configuration parameter spdxFile to resolve." ) );
}
File outputDir = this.spdxFile.getParentFile();
if ( outputDir == null )
{
throw ( new MojoExecutionException(
"Invalid path for SPDX output file. " + "Specify a configuration parameter spdxFile with a valid directory path to resolve." ) );
}
if ( !outputDir.exists() )
{
outputDir.mkdirs();
}

if ( onlyUseLocalLicenses )
{
System.setProperty( "SPDXParser.OnlyUseLocalLicenses", "true" );
}
if ( defaultLicenseInformationInFile == null ) {
defaultLicenseInformationInFile = defaultFileConcludedLicense;
throw ( new MojoExecutionException("No SPDX file referenced. " +
"Specify a configuration parameter spdxFile to resolve." ) );
}
if ( this.outputFormat == null )
{
String spdxFileName = spdxFile.getName().toLowerCase();
if ( spdxFileName.endsWith( ".rdf.xml" ) )
if ( spdxFile.getName().toLowerCase().endsWith( ".rdf.xml" ) )
{
outputFormat = RDF_OUTPUT_FORMAT;
}
Expand All @@ -431,15 +413,38 @@ public void execute() throws MojoExecutionException
{
outputFormat = this.outputFormat.toUpperCase();
}

if ( !RDF_OUTPUT_FORMAT.equals( outputFormat ) && !JSON_OUTPUT_FORMAT.equals( outputFormat ))
{
this.getLog().warn( "Invalid SPDX output format: "+this.outputFormat+". Defaulting to JSON format." );
this.outputFormat = JSON_OUTPUT_FORMAT;
}

this.artifactType = RDF_OUTPUT_FORMAT.equals( this.outputFormat ) ? SPDX_RDF_ARTIFACT_TYPE : SPDX_JSON_ARTIFACT_TYPE;
this.getLog().info( "Creating SPDX File " + spdxFile.getPath() );
if (spdxFile.getName().endsWith( ".spdx" )) {
// add a default extension
String spdxFileType = Objects.equals(this.artifactType, SPDX_RDF_ARTIFACT_TYPE) ? ".rdf.xml" : ".json";
getLog().info( "spdx file type = "+spdxFileType );
spdxFile = new File( spdxFile.getAbsolutePath() + spdxFileType );
}
File outputDir = this.spdxFile.getParentFile();
if ( outputDir == null )
{
throw ( new MojoExecutionException(
"Invalid path for SPDX output file. " + "Specify a configuration parameter spdxFile with a valid directory path to resolve." ) );
}
if ( !outputDir.exists() )
{
outputDir.mkdirs();
}

if ( onlyUseLocalLicenses )
{
System.setProperty( "SPDXParser.OnlyUseLocalLicenses", "true" );
}
if ( defaultLicenseInformationInFile == null ) {
defaultLicenseInformationInFile = defaultFileConcludedLicense;
}

this.getLog().info( "Creating SPDX File " + spdxFile.getPath() );

SpdxDocumentBuilder builder;
try
Expand Down

0 comments on commit 9aa6ff6

Please sign in to comment.