[MNG-6843] Parallel build fails due to missing JAR artifacts in compilePath

Signed-off-by: rfscholte <rfscholte@apache.org>
This commit is contained in:
Falko Modler 2021-06-25 19:28:40 +02:00 committed by rfscholte
parent 6bed162a65
commit 73e00ed85d
1 changed files with 31 additions and 25 deletions

View File

@ -111,10 +111,6 @@ public class MavenProject
private Set<Artifact> resolvedArtifacts;
private ArtifactFilter artifactFilter;
private Set<Artifact> artifacts;
private Artifact parentArtifact;
private Set<Artifact> pluginArtifacts;
@ -151,8 +147,8 @@ public class MavenProject
private Artifact artifact;
// calculated.
private Map<String, Artifact> artifactMap;
private final ThreadLocal<ArtifactsHolder> threadLocalArtifactsHolder =
ThreadLocal.withInitial( ArtifactsHolder::new );
private Model originalModel;
@ -695,10 +691,11 @@ public class MavenProject
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;
}
/**
@ -711,34 +708,36 @@ public class MavenProject
*/
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 )
@ -1428,8 +1427,9 @@ public class MavenProject
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;
}
/**
@ -1442,9 +1442,10 @@ public class MavenProject
*/
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;
}
/**
@ -1839,7 +1840,6 @@ public class MavenProject
{
reportArtifactMap = ArtifactUtils.artifactMapByVersionlessId( getReportArtifacts() );
}
return reportArtifactMap;
}
@ -1864,7 +1864,6 @@ public class MavenProject
{
extensionArtifactMap = ArtifactUtils.artifactMapByVersionlessId( getExtensionArtifacts() );
}
return extensionArtifactMap;
}
@ -1986,4 +1985,11 @@ public class MavenProject
{
this.projectBuilderConfiguration = projectBuildingRequest;
}
private static class ArtifactsHolder
{
private ArtifactFilter artifactFilter;
private Set<Artifact> artifacts;
private Map<String, Artifact> artifactMap;
}
}