Skip to content

Commit

Permalink
[MNG-6843] Parallel build fails due to missing JAR artifacts in compi…
Browse files Browse the repository at this point in the history
…lePath

Signed-off-by: rfscholte <rfscholte@apache.org>
(cherry picked from commit 73e00ed)

This closes #482
  • Loading branch information
famod authored and michael-o committed Jun 26, 2021
1 parent 42c99b4 commit 76d5f0d
Showing 1 changed file with 36 additions and 31 deletions.
67 changes: 36 additions & 31 deletions maven-core/src/main/java/org/apache/maven/project/MavenProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,9 @@
public class MavenProject
implements Cloneable
{

private static final Logger LOGGER = LoggerFactory.getLogger( MavenProject.class );

public static final String EMPTY_PROJECT_GROUP_ID = "unknown";

public static final String EMPTY_PROJECT_ARTIFACT_ID = "empty-project";

public static final String EMPTY_PROJECT_VERSION = "0";

private Model model;
Expand All @@ -111,10 +107,6 @@ public class MavenProject

private Set<Artifact> resolvedArtifacts;

private ArtifactFilter artifactFilter;

private Set<Artifact> artifacts;

private Artifact parentArtifact;

private Set<Artifact> pluginArtifacts;
Expand Down Expand Up @@ -151,8 +143,13 @@ public class MavenProject

private Artifact artifact;

// calculated.
private Map<String, Artifact> artifactMap;
private final ThreadLocal<ArtifactsHolder> threadLocalArtifactsHolder = new ThreadLocal()
{
protected ArtifactsHolder initialValue()
{
return new ArtifactsHolder();
}
};

private Model originalModel;

Expand Down Expand Up @@ -185,11 +182,9 @@ public class MavenProject
public MavenProject()
{
Model model = new Model();

model.setGroupId( EMPTY_PROJECT_GROUP_ID );
model.setArtifactId( EMPTY_PROJECT_ARTIFACT_ID );
model.setVersion( EMPTY_PROJECT_VERSION );

setModel( model );
}

Expand Down Expand Up @@ -695,10 +690,11 @@ public void addLicense( License license )

public void setArtifacts( Set<Artifact> artifacts )
{
this.artifacts = artifacts;
ArtifactsHolder artifactsHolder = threadLocalArtifactsHolder.get();
artifactsHolder.artifacts = artifacts;

// flush the calculated artifactMap
artifactMap = null;
artifactsHolder.artifactMap = null;
}

/**
Expand All @@ -711,34 +707,36 @@ public void setArtifacts( Set<Artifact> artifacts )
*/
public Set<Artifact> getArtifacts()
{
if ( artifacts == null )
ArtifactsHolder artifactsHolder = threadLocalArtifactsHolder.get();
if ( artifactsHolder.artifacts == null )
{
if ( artifactFilter == null || resolvedArtifacts == null )
if ( artifactsHolder.artifactFilter == null || resolvedArtifacts == null )
{
artifacts = new LinkedHashSet<>();
artifactsHolder.artifacts = new LinkedHashSet<>();
}
else
{
artifacts = new LinkedHashSet<>( resolvedArtifacts.size() * 2 );
artifactsHolder.artifacts = new LinkedHashSet<>( resolvedArtifacts.size() * 2 );
for ( Artifact artifact : resolvedArtifacts )
{
if ( artifactFilter.include( artifact ) )
if ( artifactsHolder.artifactFilter.include( artifact ) )
{
artifacts.add( artifact );
artifactsHolder.artifacts.add( artifact );
}
}
}
}
return artifacts;
return artifactsHolder.artifacts;
}

public Map<String, Artifact> getArtifactMap()
{
if ( artifactMap == null )
ArtifactsHolder artifactsHolder = threadLocalArtifactsHolder.get();
if ( artifactsHolder.artifactMap == null )
{
artifactMap = ArtifactUtils.artifactMapByVersionlessId( getArtifacts() );
artifactsHolder.artifactMap = ArtifactUtils.artifactMapByVersionlessId( getArtifacts() );
}
return artifactMap;
return artifactsHolder.artifactMap;
}

public void setPluginArtifacts( Set<Artifact> pluginArtifacts )
Expand Down Expand Up @@ -1433,8 +1431,9 @@ public DependencyFilter getExtensionDependencyFilter()
public void setResolvedArtifacts( Set<Artifact> artifacts )
{
this.resolvedArtifacts = ( artifacts != null ) ? artifacts : Collections.<Artifact>emptySet();
this.artifacts = null;
this.artifactMap = null;
ArtifactsHolder artifactsHolder = threadLocalArtifactsHolder.get();
artifactsHolder.artifacts = null;
artifactsHolder.artifactMap = null;
}

/**
Expand All @@ -1447,9 +1446,10 @@ public void setResolvedArtifacts( Set<Artifact> artifacts )
*/
public void setArtifactFilter( ArtifactFilter artifactFilter )
{
this.artifactFilter = artifactFilter;
this.artifacts = null;
this.artifactMap = null;
ArtifactsHolder artifactsHolder = threadLocalArtifactsHolder.get();
artifactsHolder.artifactFilter = artifactFilter;
artifactsHolder.artifacts = null;
artifactsHolder.artifactMap = null;
}

/**
Expand Down Expand Up @@ -1844,7 +1844,6 @@ public Map<String, Artifact> getReportArtifactMap()
{
reportArtifactMap = ArtifactUtils.artifactMapByVersionlessId( getReportArtifacts() );
}

return reportArtifactMap;
}

Expand All @@ -1869,7 +1868,6 @@ public Map<String, Artifact> getExtensionArtifactMap()
{
extensionArtifactMap = ArtifactUtils.artifactMapByVersionlessId( getExtensionArtifacts() );
}

return extensionArtifactMap;
}

Expand Down Expand Up @@ -1991,4 +1989,11 @@ public void setProjectBuildingRequest( ProjectBuildingRequest projectBuildingReq
{
this.projectBuilderConfiguration = projectBuildingRequest;
}

private static class ArtifactsHolder
{
private ArtifactFilter artifactFilter;
private Set<Artifact> artifacts;
private Map<String, Artifact> artifactMap;
}
}

0 comments on commit 76d5f0d

Please sign in to comment.