Skip to content

Commit

Permalink
Always pass in modelstore to expression parser
Browse files Browse the repository at this point in the history
Since we're not initializing or using the default model store, we need
to always pass in a model store to the license expression parser
methods.

Note that not using the default avoids a potential memory issue for long
running Maven scripts.
  • Loading branch information
goneall committed Jan 22, 2025
1 parent b5be6be commit 7f17183
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
20 changes: 16 additions & 4 deletions src/main/java/org/spdx/maven/utils/SpdxV2FileCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,20 @@ private SpdxFile convertToSpdxFile( File file, String outputFileName,
{
if ( fileSpdxLicenses.size() == 1 )
{
license = LicenseInfoFactory.parseSPDXLicenseStringCompatV2( fileSpdxLicenses.get( 0 ) );
license = LicenseInfoFactory.parseSPDXLicenseStringCompatV2( fileSpdxLicenses.get( 0 ),
spdxDoc.getModelStore(),
spdxDoc.getDocumentUri(),
spdxDoc.getCopyManager() );
}
else
{
Set<AnyLicenseInfo> licenseSet = new HashSet<>();
for ( String licenseExpression : fileSpdxLicenses )
{
licenseSet.add( LicenseInfoFactory.parseSPDXLicenseStringCompatV2( licenseExpression ) );
licenseSet.add( LicenseInfoFactory.parseSPDXLicenseStringCompatV2( licenseExpression,
spdxDoc.getModelStore(),
spdxDoc.getDocumentUri(),
spdxDoc.getCopyManager() ) );
}
license = spdxDoc.createConjunctiveLicenseSet( licenseSet );
}
Expand Down Expand Up @@ -336,8 +342,14 @@ else if ( !licenseComment.isEmpty() )
{
try
{
license = LicenseInfoFactory.parseSPDXLicenseStringCompatV2( defaultFileInformation.getDeclaredLicense() );
concludedLicense = LicenseInfoFactory.parseSPDXLicenseStringCompatV2( defaultFileInformation.getConcludedLicense() );
license = LicenseInfoFactory.parseSPDXLicenseStringCompatV2( defaultFileInformation.getDeclaredLicense(),
spdxDoc.getModelStore(),
spdxDoc.getDocumentUri(),
spdxDoc.getCopyManager() );
concludedLicense = LicenseInfoFactory.parseSPDXLicenseStringCompatV2( defaultFileInformation.getConcludedLicense(),
spdxDoc.getModelStore(),
spdxDoc.getDocumentUri(),
spdxDoc.getCopyManager() );
}
catch ( InvalidSPDXAnalysisException e )
{
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/org/spdx/maven/utils/SpdxV3FileCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,16 @@ private SpdxFile convertToSpdxFile( File file, String outputFileName,
{
if ( fileSpdxLicenses.size() == 1 )
{
license = LicenseInfoFactory.parseSPDXLicenseString( fileSpdxLicenses.get( 0 ) );
license = LicenseInfoFactory.parseSPDXLicenseString( fileSpdxLicenses.get( 0 ),
spdxDoc.getModelStore(), spdxDoc.getIdPrefix(), spdxDoc.getCopyManager(), customIdToUri );
}
else
{
Set<AnyLicenseInfo> licenseSet = new HashSet<>();
for ( String licenseExpression : fileSpdxLicenses )
{
licenseSet.add( LicenseInfoFactory.parseSPDXLicenseString( licenseExpression ) );
licenseSet.add( LicenseInfoFactory.parseSPDXLicenseString( licenseExpression,
spdxDoc.getModelStore(), spdxDoc.getIdPrefix(), spdxDoc.getCopyManager(), customIdToUri ) );
}
license = spdxDoc.createConjunctiveLicenseSet( spdxDoc.getIdPrefix() + spdxDoc.getModelStore().getNextId( IdType.SpdxId ) )
.addAllMember( licenseSet )
Expand Down Expand Up @@ -402,8 +404,10 @@ else if ( !licenseComment.isEmpty() )
{
try
{
license = LicenseInfoFactory.parseSPDXLicenseString( defaultFileInformation.getDeclaredLicense() );
concludedLicense = LicenseInfoFactory.parseSPDXLicenseString( defaultFileInformation.getConcludedLicense() );
license = LicenseInfoFactory.parseSPDXLicenseString( defaultFileInformation.getDeclaredLicense(),
spdxDoc.getModelStore(), spdxDoc.getIdPrefix(), spdxDoc.getCopyManager(), customIdToUri );
concludedLicense = LicenseInfoFactory.parseSPDXLicenseString( defaultFileInformation.getConcludedLicense(),
spdxDoc.getModelStore(), spdxDoc.getIdPrefix(), spdxDoc.getCopyManager(), customIdToUri );
}
catch ( InvalidSPDXAnalysisException e )
{
Expand Down

0 comments on commit 7f17183

Please sign in to comment.