CPD Results

The following document contains the results of PMD's CPD 6.42.0.

Duplications

File Line
org/apache/maven/shared/dependency/graph/internal/maven30/VerboseJavaScopeSelector.java 34
org/apache/maven/shared/dependency/graph/internal/maven31/VerboseJavaScopeSelector.java 35
public class VerboseJavaScopeSelector extends ScopeSelector
{
    public static final String REDUCED_SCOPE = "REDUCED_SCOPE";
    
    private final ScopeSelector scopeSelector = new JavaScopeSelector();

    @Override
    public void selectScope( ConflictContext context )
        throws RepositoryException
    {
        scopeSelector.selectScope( context );
        
        context.getItems().stream()
            .flatMap( i -> i.getScopes().stream() )
            .distinct()
            .max( new ScopeComparator() )
            .filter( s -> s != context.getScope() )
            .ifPresent( s -> context.getWinner().getNode().setData( REDUCED_SCOPE, s ) );
    }
    
    static class ScopeComparator implements Comparator<String>
    {
        List<String> orderedScopes = Arrays.asList( "compile", "runtime", "provided", "test" );

        @Override
        public int compare( String lhs, String rhs )
        {
            return orderedScopes.indexOf( rhs ) - orderedScopes.indexOf( lhs );
        }
    }    
}
File Line
org/apache/maven/shared/dependency/graph/internal/Maven31DependencyCollectorBuilder.java 248
org/apache/maven/shared/dependency/graph/internal/Maven3DependencyCollectorBuilder.java 254
String premanagedScope = DependencyManagerUtils.getPremanagedScope( node );

        Boolean optional = null;
        if ( node.getDependency() != null )
        {
            optional = node.getDependency().isOptional();
        }
        
        List<org.apache.maven.model.Exclusion> exclusions = null;
        if ( node.getDependency() != null )
        {
            exclusions = new ArrayList<>( node.getDependency().getExclusions().size() );
            for ( Exclusion exclusion : node.getDependency().getExclusions() )
            {
                org.apache.maven.model.Exclusion modelExclusion = new org.apache.maven.model.Exclusion();
                modelExclusion.setGroupId( exclusion.getGroupId() );
                modelExclusion.setArtifactId( exclusion.getArtifactId() );
                exclusions.add( modelExclusion );
            }
        }

        org.eclipse.aether.graph.DependencyNode winner =
File Line
org/apache/maven/shared/dependency/graph/internal/Maven31DependencyCollectorBuilder.java 287
org/apache/maven/shared/dependency/graph/internal/Maven31DependencyGraphBuilder.java 172
exclusions, data );

        List<DependencyNode> nodes = new ArrayList<>( node.getChildren().size() );
        for ( org.eclipse.aether.graph.DependencyNode child : node.getChildren() )
        {
            Artifact childArtifact = getDependencyArtifact( child.getDependency() );

            if ( ( filter == null ) || filter.include( childArtifact ) )
            {
                nodes.add( buildDependencyNode( current, child, childArtifact, filter ) );
            }
        }

        current.setChildren( Collections.unmodifiableList( nodes ) );

        return current;
    }

    private String getVersionSelectedFromRange( VersionConstraint constraint )
    {
        if ( ( constraint == null ) || ( constraint.getVersion() != null ) )
        {
            return null;
        }

        return constraint.getRange().toString();
    }
}
File Line
org/apache/maven/shared/dependency/graph/internal/Maven3DependencyCollectorBuilder.java 293
org/apache/maven/shared/dependency/graph/internal/Maven3DependencyGraphBuilder.java 118
data );

        List<DependencyNode> nodes = new ArrayList<>( node.getChildren().size() );
        for ( org.sonatype.aether.graph.DependencyNode child : node.getChildren() )
        {
            Artifact childArtifact = getDependencyArtifact( child.getDependency() );

            if ( ( filter == null ) || filter.include( childArtifact ) )
            {
                nodes.add( buildDependencyNode( current, child, childArtifact, filter ) );
            }
        }

        current.setChildren( Collections.unmodifiableList( nodes ) );

        return current;
    }

    private String getVersionSelectedFromRange( VersionConstraint constraint )
    {
        if ( ( constraint == null ) || ( constraint.getVersion() != null ) || ( constraint.getRanges().isEmpty() ) )
File Line
org/apache/maven/shared/dependency/graph/internal/Maven31DependencyCollectorBuilder.java 290
org/apache/maven/shared/dependency/graph/internal/Maven31DependencyGraphBuilder.java 175
org/apache/maven/shared/dependency/graph/internal/Maven3DependencyGraphBuilder.java 121
for ( org.eclipse.aether.graph.DependencyNode child : node.getChildren() )
        {
            Artifact childArtifact = getDependencyArtifact( child.getDependency() );

            if ( ( filter == null ) || filter.include( childArtifact ) )
            {
                nodes.add( buildDependencyNode( current, child, childArtifact, filter ) );
            }
        }

        current.setChildren( Collections.unmodifiableList( nodes ) );

        return current;
    }

    private String getVersionSelectedFromRange( VersionConstraint constraint )
    {
        if ( ( constraint == null ) || ( constraint.getVersion() != null ) )
        {
            return null;
        }
File Line
org/apache/maven/shared/dependency/graph/internal/maven30/Maven3DirectScopeDependencySelector.java 85
org/apache/maven/shared/dependency/graph/internal/maven31/Maven31DirectScopeDependencySelector.java 85
return new Maven3DirectScopeDependencySelector( scope, depth + 1 );
    }

    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        result = prime * result + depth;
        result = prime * result + ( ( scope == null ) ? 0 : scope.hashCode() );
        return result;
    }

    @Override
    public boolean equals( Object obj )
    {
        if ( this == obj )
        {
            return true;
        }
        if ( obj == null )
        {
            return false;
        }
        if ( getClass() != obj.getClass() )
        {
            return false;
        }
File Line
org/apache/maven/shared/dependency/graph/internal/Maven31DependencyCollectorBuilder.java 256
org/apache/maven/shared/dependency/graph/internal/Maven31DependencyGraphBuilder.java 156
org/apache/maven/shared/dependency/graph/internal/Maven3DependencyCollectorBuilder.java 262
List<org.apache.maven.model.Exclusion> exclusions = null;
        if ( node.getDependency() != null )
        {
            exclusions = new ArrayList<>( node.getDependency().getExclusions().size() );
            for ( Exclusion exclusion : node.getDependency().getExclusions() )
            {
                org.apache.maven.model.Exclusion modelExclusion = new org.apache.maven.model.Exclusion();
                modelExclusion.setGroupId( exclusion.getGroupId() );
                modelExclusion.setArtifactId( exclusion.getArtifactId() );
                exclusions.add( modelExclusion );
            }
        }