Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Threadsafe mojos #474

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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 );
Expand Down
Expand Up @@ -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
{
Expand Down
Expand Up @@ -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
{
Expand Down
Expand Up @@ -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
{
Expand Down
Expand Up @@ -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
{
Expand Down
Expand Up @@ -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
{
Expand Down
Expand Up @@ -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
{

Expand Down
Expand Up @@ -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
{
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -101,7 +102,12 @@ public class DefaultThirdPartyHelper
/**
* Cache of dependencies (as maven project) loaded.
*/
private static SortedMap<String, MavenProject> artifactCache;
private static final class ArtifactCacheHolder
{
private ArtifactCacheHolder() {}

private static final SortedMap<String, MavenProject> artifactCache = new ConcurrentSkipListMap<>();
}

/**
* Constructor of the helper.
Expand Down Expand Up @@ -136,11 +142,7 @@ public DefaultThirdPartyHelper( MavenProject project, String encoding, boolean v
*/
public SortedMap<String, MavenProject> getArtifactCache()
{
if ( artifactCache == null )
{
artifactCache = new TreeMap<>();
}
return artifactCache;
return ArtifactCacheHolder.artifactCache;
}

/**
Expand Down
20 changes: 6 additions & 14 deletions src/main/java/org/codehaus/mojo/license/spdx/SpdxLicenseList.java
Expand Up @@ -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;
Expand Down