[MNG-6633] - Reduce memory usage of excludes

ExcludesArtifactFilter was highly inefficient.
It took the group and artifact ID of an Exclusion, concatenated them into
a new String, which was kept in memory for the whole duration
of the build and then compared that String against the concatenation
of group and artifact ID of each incoming artifact, adding more
CPU cycles than necessary.

Instead we now just wrap the existing Exclusion object and check its
groupId and artifactId against the artifact to tell whether it should
be excluded.

The old class is kept around for binary compatibility, but is now unused.

Closes #243
This commit is contained in:
Stefan Oehme 2019-04-29 15:31:34 +02:00 committed by Sylwester Lachiewicz
parent ff8c5c8706
commit 790dc0f2b7
3 changed files with 34 additions and 20 deletions

View File

@ -0,0 +1,30 @@
package org.apache.maven.artifact.resolver.filter;
import java.util.List;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Exclusion;
public class ExclusionArtifactFilter implements ArtifactFilter
{
private final List<Exclusion> exclusions;
public ExclusionArtifactFilter( List<Exclusion> exclusions )
{
this.exclusions = exclusions;
}
@Override
public boolean include( Artifact artifact )
{
for ( Exclusion exclusion : exclusions )
{
if ( exclusion.getGroupId().equals( artifact.getGroupId() )
&& exclusion.getArtifactId().equals( artifact.getArtifactId() ) )
{
return false;
}
}
return true;
}
}

View File

@ -44,12 +44,11 @@ import org.apache.maven.artifact.repository.MavenArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout2;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ExclusionArtifactFilter;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Exclusion;
import org.apache.maven.model.Plugin;
import org.apache.maven.repository.Proxy;
import org.apache.maven.repository.RepositorySystem;
@ -116,14 +115,7 @@ public class MavenRepositorySystem
if ( !d.getExclusions().isEmpty() )
{
List<String> exclusions = new ArrayList<>();
for ( Exclusion exclusion : d.getExclusions() )
{
exclusions.add( exclusion.getGroupId() + ':' + exclusion.getArtifactId() );
}
artifact.setDependencyFilter( new ExcludesArtifactFilter( exclusions ) );
artifact.setDependencyFilter( new ExclusionArtifactFilter( d.getExclusions() ) );
}
return artifact;

View File

@ -47,7 +47,7 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException;
import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ExclusionArtifactFilter;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
@ -55,7 +55,6 @@ import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.Exclusion;
import org.apache.maven.model.Relocation;
import org.apache.maven.model.building.ModelBuildingException;
import org.apache.maven.model.building.ModelBuildingRequest;
@ -394,14 +393,7 @@ public class MavenMetadataSource
if ( !dependency.getExclusions().isEmpty() )
{
List<String> exclusions = new ArrayList<>();
for ( Exclusion e : dependency.getExclusions() )
{
exclusions.add( e.getGroupId() + ':' + e.getArtifactId() );
}
effectiveFilter = new ExcludesArtifactFilter( exclusions );
effectiveFilter = new ExclusionArtifactFilter( dependency.getExclusions() );
if ( inheritedFilter != null )
{