diff --git a/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java b/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java index 1e5bec0d5..091bc3068 100644 --- a/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java @@ -67,7 +67,7 @@ */ // CHECKSTYLE_ON: LineLength @Mojo( name = "add-third-party", requiresDependencyResolution = ResolutionScope.TEST, - defaultPhase = LifecyclePhase.GENERATE_RESOURCES ) + defaultPhase = LifecyclePhase.GENERATE_RESOURCES, threadSafe = true ) public class AddThirdPartyMojo extends AbstractAddThirdPartyMojo implements MavenProjectDependenciesConfigurator { private static final Logger LOG = LoggerFactory.getLogger( AddThirdPartyMojo.class ); diff --git a/src/main/java/org/codehaus/mojo/license/AggregatorThirdPartyReportMojo.java b/src/main/java/org/codehaus/mojo/license/AggregatorThirdPartyReportMojo.java index dbbfa1223..208538043 100644 --- a/src/main/java/org/codehaus/mojo/license/AggregatorThirdPartyReportMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AggregatorThirdPartyReportMojo.java @@ -49,7 +49,8 @@ * @author Tony Chemit - dev@tchemit.fr * @since 1.10 */ -@Mojo( name = "aggregate-third-party-report", aggregator = true, requiresDependencyResolution = ResolutionScope.TEST ) +@Mojo( name = "aggregate-third-party-report", aggregator = true, + requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true ) public class AggregatorThirdPartyReportMojo extends AbstractThirdPartyReportMojo { diff --git a/src/main/java/org/codehaus/mojo/license/CommentStyleListMojo.java b/src/main/java/org/codehaus/mojo/license/CommentStyleListMojo.java index 1d9414104..7c21f8369 100644 --- a/src/main/java/org/codehaus/mojo/license/CommentStyleListMojo.java +++ b/src/main/java/org/codehaus/mojo/license/CommentStyleListMojo.java @@ -43,7 +43,7 @@ * @author tchemit dev@tchemit.fr * @since 1.0 */ -@Mojo( name = "comment-style-list", requiresProject = false, requiresDirectInvocation = true ) +@Mojo( name = "comment-style-list", requiresProject = false, requiresDirectInvocation = true, threadSafe = true ) public class CommentStyleListMojo extends AbstractLicenseMojo { diff --git a/src/main/java/org/codehaus/mojo/license/DownloadLicensesMojo.java b/src/main/java/org/codehaus/mojo/license/DownloadLicensesMojo.java index b0a6bebed..20929fde9 100644 --- a/src/main/java/org/codehaus/mojo/license/DownloadLicensesMojo.java +++ b/src/main/java/org/codehaus/mojo/license/DownloadLicensesMojo.java @@ -53,7 +53,7 @@ * @since 1.0 */ @Mojo( name = "download-licenses", requiresDependencyResolution = ResolutionScope.TEST, - defaultPhase = LifecyclePhase.PACKAGE ) + defaultPhase = LifecyclePhase.PACKAGE, threadSafe = true ) public class DownloadLicensesMojo extends AbstractDownloadLicensesMojo { diff --git a/src/main/java/org/codehaus/mojo/license/LicenseListMojo.java b/src/main/java/org/codehaus/mojo/license/LicenseListMojo.java index f5e2d6ab6..2d5c28359 100644 --- a/src/main/java/org/codehaus/mojo/license/LicenseListMojo.java +++ b/src/main/java/org/codehaus/mojo/license/LicenseListMojo.java @@ -42,7 +42,7 @@ * @author tchemit dev@tchemit.fr * @since 1.0 */ -@Mojo( name = "license-list", requiresProject = false, requiresDirectInvocation = true ) +@Mojo( name = "license-list", requiresProject = false, requiresDirectInvocation = true, threadSafe = true ) public class LicenseListMojo extends AbstractLicenseMojo { diff --git a/src/main/java/org/codehaus/mojo/license/LicensesXmlInsertVersionsMojo.java b/src/main/java/org/codehaus/mojo/license/LicensesXmlInsertVersionsMojo.java index fddcb50e9..7798b2ea5 100644 --- a/src/main/java/org/codehaus/mojo/license/LicensesXmlInsertVersionsMojo.java +++ b/src/main/java/org/codehaus/mojo/license/LicensesXmlInsertVersionsMojo.java @@ -52,7 +52,7 @@ * @since 1.19 */ @Mojo( name = "licenses-xml-insert-versions", requiresDependencyResolution = ResolutionScope.TEST, - defaultPhase = LifecyclePhase.PACKAGE ) + defaultPhase = LifecyclePhase.PACKAGE, threadSafe = true ) public class LicensesXmlInsertVersionsMojo extends AbstractLicensesXmlMojo { diff --git a/src/main/java/org/codehaus/mojo/license/ThirdPartyReportMojo.java b/src/main/java/org/codehaus/mojo/license/ThirdPartyReportMojo.java index 81f2cd4da..f4ad15d1f 100644 --- a/src/main/java/org/codehaus/mojo/license/ThirdPartyReportMojo.java +++ b/src/main/java/org/codehaus/mojo/license/ThirdPartyReportMojo.java @@ -41,7 +41,7 @@ * @author tchemit dev@tchemit.fr * @since 1.1 */ -@Mojo( name = "third-party-report", requiresDependencyResolution = ResolutionScope.TEST ) +@Mojo( name = "third-party-report", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true ) public class ThirdPartyReportMojo extends AbstractThirdPartyReportMojo { diff --git a/src/main/java/org/codehaus/mojo/license/UpdateProjectLicenseMojo.java b/src/main/java/org/codehaus/mojo/license/UpdateProjectLicenseMojo.java index 0390e20e2..ce162200d 100644 --- a/src/main/java/org/codehaus/mojo/license/UpdateProjectLicenseMojo.java +++ b/src/main/java/org/codehaus/mojo/license/UpdateProjectLicenseMojo.java @@ -43,7 +43,7 @@ * @author tchemit dev@tchemit.fr * @since 1.0 */ -@Mojo( name = "update-project-license", defaultPhase = LifecyclePhase.GENERATE_RESOURCES ) +@Mojo( name = "update-project-license", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, threadSafe = true ) public class UpdateProjectLicenseMojo extends AbstractLicenseNameMojo { diff --git a/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyHelper.java b/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyHelper.java index a0c5ec70b..bb60301ef 100644 --- a/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyHelper.java +++ b/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyHelper.java @@ -44,6 +44,7 @@ import java.util.SortedMap; import java.util.SortedSet; import java.util.TreeMap; +import java.util.concurrent.ConcurrentSkipListMap; import org.eclipse.aether.repository.RemoteRepository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -101,7 +102,12 @@ public class DefaultThirdPartyHelper /** * Cache of dependencies (as maven project) loaded. */ - private static SortedMap artifactCache; + private static final class ArtifactCacheHolder + { + private ArtifactCacheHolder() {} + + private static final SortedMap artifactCache = new ConcurrentSkipListMap<>(); + } /** * Constructor of the helper. @@ -136,11 +142,7 @@ public DefaultThirdPartyHelper( MavenProject project, String encoding, boolean v */ public SortedMap getArtifactCache() { - if ( artifactCache == null ) - { - artifactCache = new TreeMap<>(); - } - return artifactCache; + return ArtifactCacheHolder.artifactCache; } /** diff --git a/src/main/java/org/codehaus/mojo/license/spdx/SpdxLicenseList.java b/src/main/java/org/codehaus/mojo/license/spdx/SpdxLicenseList.java index d450057f9..e0504d454 100644 --- a/src/main/java/org/codehaus/mojo/license/spdx/SpdxLicenseList.java +++ b/src/main/java/org/codehaus/mojo/license/spdx/SpdxLicenseList.java @@ -42,23 +42,15 @@ */ public class SpdxLicenseList { - private static volatile SpdxLicenseList latest; - - private static final Object LOCK = new Object(); + private static final class LatestHolder + { + private LatestHolder() {} + private static final SpdxLicenseList latest = SpdxLicenseListData.createList(); + } public static SpdxLicenseList getLatest() { - if ( latest == null ) - { - synchronized ( LOCK ) - { - if ( latest == null ) - { - latest = SpdxLicenseListData.createList(); - } - } - } - return latest; + return LatestHolder.latest; } private final String licenseListVersion;