Skip to content

Commit

Permalink
Make the Mojo threadsafe
Browse files Browse the repository at this point in the history
Fixes #161

Signed-off-by: Gary O'Neall <gary@sourceauditor.com>
  • Loading branch information
goneall committed Mar 11, 2024
1 parent 322336c commit 53df41e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/main/java/org/spdx/maven/CreateSpdxMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
*/
@Mojo( name = "createSPDX",
defaultPhase = LifecyclePhase.VERIFY,
requiresDependencyResolution = ResolutionScope.TEST )
requiresDependencyResolution = ResolutionScope.TEST,
threadSafe = true )
public class CreateSpdxMojo extends AbstractMojo
{
public static final String INCLUDE_ALL = "**/*";
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/org/spdx/maven/utils/MavenToSpdxLicenseMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public class MavenToSpdxLicenseMapper
private static final String LISTED_LICENSE_JSON_URL = SPDX_LICENSE_URL_PREFIX + "licenses.json";
private static final String LISTED_LICENSE_JSON_PATH = "resources/licenses.json";

static MavenToSpdxLicenseMapper instance;
static volatile MavenToSpdxLicenseMapper instance;
private static Object instanceMutex = new Object();
private Map<String, String> urlStringToSpdxLicenseId;

private MavenToSpdxLicenseMapper() throws LicenseMapperException
Expand Down Expand Up @@ -101,11 +102,19 @@ private MavenToSpdxLicenseMapper() throws LicenseMapperException

public static MavenToSpdxLicenseMapper getInstance() throws LicenseMapperException
{
if ( instance == null )
MavenToSpdxLicenseMapper result = instance;
if ( result == null )
{
instance = new MavenToSpdxLicenseMapper();
synchronized ( instanceMutex )
{
result = instance;
if ( result == null )
{
instance = result = new MavenToSpdxLicenseMapper();
}
}
}
return instance;
return result;
}

/**
Expand Down

0 comments on commit 53df41e

Please sign in to comment.