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 <[email protected]>
  • Loading branch information
goneall committed Mar 11, 2024
1 parent b725783 commit fbada9e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/spdx/maven/CreateSpdxMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
Expand Down Expand Up @@ -98,7 +97,8 @@
*/
@Mojo( name = "createSPDX",
defaultPhase = LifecyclePhase.VERIFY,
requiresOnline = true )
requiresOnline = true,
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 fbada9e

Please sign in to comment.