Skip to content

Commit

Permalink
(doc) small code cleanup from ide suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
slachiewicz committed Sep 8, 2022
1 parent 500569d commit bde012c
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ public void reportMissedCriteria( Logger logger )
report = true;
}

if ( report )
if ( report && logger.isDebugEnabled() )
{
logger.debug( "The following scope filters were not used: " + buffer.toString() );
logger.debug( "The following scope filters were not used: " + buffer );
}
}
}
Expand All @@ -244,34 +244,8 @@ public void reportMissedCriteria( Logger logger )
*/
public boolean hasMissedCriteria()
{
boolean report = false;

if ( !nullScopeHit )
{
report = true;
}
if ( !compileScopeHit )
{
report = true;
}
if ( !runtimeScopeHit )
{
report = true;
}
if ( !testScopeHit )
{
report = true;
}
if ( !providedScopeHit )
{
report = true;
}
if ( !systemScopeHit )
{
report = true;
}

return report;
return !nullScopeHit || !compileScopeHit || !runtimeScopeHit || !testScopeHit || !providedScopeHit
|| !systemScopeHit;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.ArrayList;
import java.util.Collection;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter;
Expand Down Expand Up @@ -86,40 +85,36 @@ public void setActTransitivelyPattern( boolean actTransitivelyPattern )
@Override
public ArtifactFilter transform( final ScopeFilter scopeFilter )
{
return new ArtifactFilter()
return artifact ->
{
@Override
public boolean include( Artifact artifact )
if ( artifact.getScope() == null )
{
if ( artifact.getScope() == null )
{
return includeNullScope;
}

boolean isIncluded;
return includeNullScope;
}

if ( scopeFilter.getIncluded() != null )
{
isIncluded = scopeFilter.getIncluded().contains( artifact.getScope() );
}
else
{
isIncluded = true;
}
boolean isIncluded;

boolean isExcluded;
if ( scopeFilter.getIncluded() != null )
{
isIncluded = scopeFilter.getIncluded().contains( artifact.getScope() );
}
else
{
isIncluded = true;
}

if ( scopeFilter.getExcluded() != null )
{
isExcluded = scopeFilter.getExcluded().contains( artifact.getScope() );
}
else
{
isExcluded = false;
}
boolean isExcluded;

return isIncluded && !isExcluded;
if ( scopeFilter.getExcluded() != null )
{
isExcluded = scopeFilter.getExcluded().contains( artifact.getScope() );
}
else
{
isExcluded = false;
}

return isIncluded && !isExcluded;
};
}

Expand Down Expand Up @@ -155,20 +150,16 @@ public ArtifactFilter transform( OrFilter orFilter )
filters.add( subFilter.transform( this ) );
}

return new ArtifactFilter()
return artifact ->
{
@Override
public boolean include( Artifact artifact )
for ( ArtifactFilter filter : filters )
{
for ( ArtifactFilter filter : filters )
if ( filter.include( artifact ) )
{
if ( filter.include( artifact ) )
{
return true;
}
return true;
}
return false;
}
return false;
};
}

Expand All @@ -190,13 +181,6 @@ public ArtifactFilter transform( PatternInclusionsFilter patternInclusionsFilter
@Override
public ArtifactFilter transform( final AbstractFilter filter )
{
return new ArtifactFilter()
{
@Override
public boolean include( Artifact artifact )
{
return filter.accept( new ArtifactIncludeNode( artifact ), null );
}
};
return artifact -> filter.accept( new ArtifactIncludeNode( artifact ), null );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.apache.maven.shared.artifact.filter.resolve.ScopeFilter;
import org.apache.maven.shared.artifact.filter.resolve.TransformableFilter;
import org.eclipse.aether.graph.DependencyFilter;
import org.eclipse.aether.graph.DependencyNode;
import org.eclipse.aether.util.filter.AndDependencyFilter;
import org.eclipse.aether.util.filter.ExclusionsDependencyFilter;
import org.eclipse.aether.util.filter.OrDependencyFilter;
Expand Down Expand Up @@ -128,16 +127,12 @@ public DependencyFilter transform( PatternInclusionsFilter filter )
@Override
public DependencyFilter transform( final AbstractFilter filter )
{
return new DependencyFilter()
return ( node, parents ) ->
{
@Override
public boolean accept( DependencyNode node, List<DependencyNode> parents )
{
requireNonNull( node, "node cannot be null" );
requireNonNull( parents, "parents cannot be null" );
requireNonNull( node, "node cannot be null" );
requireNonNull( parents, "parents cannot be null" );

return filter.accept( new EclipseAetherNode( node ), null );
}
return filter.accept( new EclipseAetherNode( node ), null );
};
}

Expand All @@ -156,28 +151,22 @@ private DependencyFilter newAdvancedPatternInclusionFilter( Collection<String> i

final String classifier = matcher.group( 2 );

DependencyFilter classifierFilter = new DependencyFilter()
filters.add( new AndDependencyFilter( patternFilter, ( node, parents ) ->
{
@Override
public boolean accept( DependencyNode node, List<DependencyNode> parents )
requireNonNull( node, "node cannot be null" );
requireNonNull( parents, "parents cannot be null" );

String nodeClassifier = node.getArtifact().getClassifier();

if ( nodeClassifier == null )
{
requireNonNull( node, "node cannot be null" );
requireNonNull( parents, "parents cannot be null" );

String nodeClassifier = node.getArtifact().getClassifier();

if ( nodeClassifier == null )
{
return false;
}
else
{
return "*".equals( classifier ) || nodeClassifier.matches( classifier );
}
return false;
}
};

filters.add( new AndDependencyFilter( patternFilter, classifierFilter ) );
else
{
return "*".equals( classifier ) || nodeClassifier.matches( classifier );
}
} ) );
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ public void testShouldIncludeTransitiveDependencyWhenWildcardMatchesButDoesntMat
when( artifact2.getArtifactId() ).thenReturn( otherArtifact );
when( artifact2.getType() ).thenReturn( otherType );
when( artifact2.getBaseVersion() ).thenReturn( "version" );
when( artifact2.getDependencyTrail() ).thenReturn( Collections.<String> emptyList() );
when( artifact2.getDependencyTrail() ).thenReturn( Collections.emptyList() );

final ArtifactFilter filter = createFilter( patterns, true );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Warmup(iterations = 3, time = 3, timeUnit = TimeUnit.SECONDS)
@Warmup(iterations = 3, time = 3 )
public class PatternFilterPerfTest {

@State(Scope.Benchmark)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.apache.maven.shared.artifact.filter.resolve.PatternExclusionsFilter;
import org.apache.maven.shared.artifact.filter.resolve.PatternInclusionsFilter;
import org.apache.maven.shared.artifact.filter.resolve.ScopeFilter;
import org.apache.maven.shared.artifact.filter.resolve.TransformableFilter;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -95,9 +94,9 @@ public void testTransformExclusionsFilter()
public void testTransformOrFilter()
throws Exception
{
OrFilter filter =
new OrFilter( Arrays.<TransformableFilter>asList( ScopeFilter.including( "compile" ),
ScopeFilter.including( "test" ) ) );
OrFilter filter = new OrFilter( Arrays.asList(
ScopeFilter.including( "compile" ),
ScopeFilter.including( "test" ) ) );

ArtifactFilter dependencyFilter = filter.transform( transformer );

Expand Down

0 comments on commit bde012c

Please sign in to comment.