Fork me on GitHub

CPD Results

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

Duplications

File Line
org/codehaus/mojo/versions/reporting/AbstractVersionsReportRenderer.java 293
org/codehaus/mojo/versions/reporting/PropertyUpdatesReportRenderer.java 180
protected void renderDependencyDetailTable( Dependency artifact, ArtifactVersions details, boolean includeScope )
    {
        ArtifactVersion[] allUpdates = allUpdatesCache.get( details, empty() );
        boolean upToDate = allUpdates == null || allUpdates.length == 0;

        final SinkEventAttributes headerAttributes = new SinkEventAttributeSet();
        headerAttributes.addAttribute( SinkEventAttributes.WIDTH, "70%" );
        final SinkEventAttributes cellAttributes = new SinkEventAttributeSet();
        headerAttributes.addAttribute( SinkEventAttributes.WIDTH, "30%" );
        sink.table();
        sink.tableRows( new int[] { Sink.JUSTIFY_RIGHT, Sink.JUSTIFY_LEFT }, false );
        sink.tableRow();
        sink.tableHeaderCell( headerAttributes );
        sink.text( getText( "report.status" ) );
        sink.tableHeaderCell_();
        sink.tableCell( cellAttributes );
        if ( newestUpdateCache.get( details, of( SUBINCREMENTAL ) ) != null )
        {
            renderWarningIcon();
            sink.nonBreakingSpace();
            sink.text( getText( "report.otherUpdatesAvailable" ) );
        }
        else if ( newestUpdateCache.get( details, of( INCREMENTAL ) ) != null )
        {
            renderWarningIcon();
            sink.nonBreakingSpace();
            sink.text( getText( "report.incrementalUpdatesAvailable" ) );
        }
        else if ( newestUpdateCache.get( details, of( MINOR ) ) != null )
        {
            renderWarningIcon();
            sink.nonBreakingSpace();
            sink.text( getText( "report.minorUpdatesAvailable" ) );
        }
        else if ( newestUpdateCache.get( details, of( MAJOR ) ) != null )
        {
            renderWarningIcon();
            sink.nonBreakingSpace();
            sink.text( getText( "report.majorUpdatesAvailable" ) );
        }
        else
        {
            renderSuccessIcon();
            sink.nonBreakingSpace();
            sink.text( getText( "report.noUpdatesAvailable" ) );
        }
        sink.tableCell_();
        sink.tableRow_();
        sink.tableRow();
        sink.tableHeaderCell( headerAttributes );
        sink.text( getText( "report.groupId" ) );
File Line
org/codehaus/mojo/versions/DisplayPluginUpdatesMojo.java 218
org/codehaus/mojo/versions/DisplayPluginUpdatesMojo.java 884
ModifiedPomXMLEventReader pom = newModifiedPomXER( buf, superPom.toString() );

                            Pattern pathRegex = Pattern.compile( "/project(/profiles/profile)?"
                                                                     + "((/build(/pluginManagement)?)|(/reporting))"
                                                                     + "/plugins/plugin" );
                            Stack<StackState> pathStack = new Stack<>();
                            StackState curState = null;
                            while ( pom.hasNext() )
                            {
                                XMLEvent event = pom.nextEvent();
                                if ( event.isStartDocument() )
                                {
                                    curState = new StackState( "" );
                                    pathStack.clear();
                                }
                                else if ( event.isStartElement() )
                                {
                                    String elementName = event.asStartElement().getName().getLocalPart();
                                    if ( curState != null && pathRegex.matcher( curState.path ).matches() )
                                    {
                                        if ( "groupId".equals( elementName ) )
                                        {
                                            curState.groupId = pom.getElementText().trim();
                                            continue;
                                        }
                                        else if ( "artifactId".equals( elementName ) )
                                        {
                                            curState.artifactId = pom.getElementText().trim();
                                            continue;

                                        }
                                        else if ( "version".equals( elementName ) )
                                        {
                                            curState.version = pom.getElementText().trim();
                                            continue;
                                        }
                                    }

                                    pathStack.push( curState );
                                    curState = new StackState( curState.path + "/" + elementName );
                                }
                                else if ( event.isEndElement() )
                                {
                                    if ( curState != null && pathRegex.matcher( curState.path ).matches() )
                                    {
                                        if ( curState.artifactId != null )
File Line
org/codehaus/mojo/versions/reporting/AbstractVersionsReportRenderer.java 250
org/codehaus/mojo/versions/reporting/PropertyUpdatesReportRenderer.java 137
sink.text( artifact.getType() );
        sink.tableCell_();

        sink.tableCell();
        if ( newestUpdateCache.get( details, of( SUBINCREMENTAL ) ) != null )
        {
            safeBold();
            sink.text( newestUpdateCache.get( details, of( SUBINCREMENTAL ) ).toString() );
            safeBold_();
        }
        sink.tableCell_();

        sink.tableCell();
        if ( newestUpdateCache.get( details, of( INCREMENTAL ) ) != null )
        {
            safeBold();
            sink.text( newestUpdateCache.get( details, of( INCREMENTAL ) ).toString() );
            safeBold_();
        }
        sink.tableCell_();

        sink.tableCell();
        if ( newestUpdateCache.get( details, of( MINOR ) ) != null )
        {
            safeBold();
            sink.text( newestUpdateCache.get( details, of( MINOR ) ).toString() );
            safeBold_();
        }
        sink.tableCell_();

        sink.tableCell();
        if ( newestUpdateCache.get( details, of( MAJOR ) ) != null )
        {
            safeBold();
            sink.text( newestUpdateCache.get( details, of( MAJOR ) ).toString() );
            safeBold_();
        }
        sink.tableCell_();

        sink.tableRow_();
    }

    @SuppressWarnings( "checkstyle:MethodLength" )
    protected void renderDependencyDetailTable( Dependency artifact, ArtifactVersions details, boolean includeScope )
File Line
org/codehaus/mojo/versions/reporting/AbstractVersionsReportRenderer.java 251
org/codehaus/mojo/versions/reporting/PluginUpdatesReportRenderer.java 181
org/codehaus/mojo/versions/reporting/PropertyUpdatesReportRenderer.java 138
sink.tableCell_();

        sink.tableCell();
        if ( newestUpdateCache.get( details, of( SUBINCREMENTAL ) ) != null )
        {
            safeBold();
            sink.text( newestUpdateCache.get( details, of( SUBINCREMENTAL ) ).toString() );
            safeBold_();
        }
        sink.tableCell_();

        sink.tableCell();
        if ( newestUpdateCache.get( details, of( INCREMENTAL ) ) != null )
        {
            safeBold();
            sink.text( newestUpdateCache.get( details, of( INCREMENTAL ) ).toString() );
            safeBold_();
        }
        sink.tableCell_();

        sink.tableCell();
        if ( newestUpdateCache.get( details, of( MINOR ) ) != null )
        {
            safeBold();
            sink.text( newestUpdateCache.get( details, of( MINOR ) ).toString() );
            safeBold_();
        }
        sink.tableCell_();

        sink.tableCell();
        if ( newestUpdateCache.get( details, of( MAJOR ) ) != null )
        {
            safeBold();
            sink.text( newestUpdateCache.get( details, of( MAJOR ) ).toString() );
            safeBold_();
        }
        sink.tableCell_();

        sink.tableRow_();
File Line
org/codehaus/mojo/versions/xml/DependencyUpdatesXmlReportRenderer.java 121
org/codehaus/mojo/versions/xml/PluginUpdatesXmlReportRenderer.java 123
new DependencyInfo()
        {{
            setGroupId( e.getKey().getGroupId() );
            setArtifactId( e.getKey().getArtifactId() );
            setCurrentVersion( e.getKey().getVersion() );
            setScope( e.getKey().getScope() );
            setType( e.getKey().getType() );
            setClassifier( e.getKey().getClassifier() );

            ofNullable( e.getValue().getNewestUpdate( empty() ) )
                    .map( ArtifactVersion::toString ).ifPresent( this::setLastVersion );

            setSection( e.getValue(), INCREMENTAL, this::setIncrementals );
            setSection( e.getValue(), MINOR, this::setMinors );
            setSection( e.getValue(), MAJOR, this::setMajors );

            setStatus( getLastVersion() == null
                    ? "no new available"
                    : getIncrementals() != null
                    ? "incremental available"
                    : getMinors() != null
                    ? "minor available"
                    : "major available" );
        }} ).collect( Collectors.toList() );
    }
}
File Line
org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java 184
org/codehaus/mojo/versions/UseNextSnapshotsMojo.java 170
ArtifactVersions versions = getHelper().lookupArtifactVersions( artifact, false );
                final VersionComparator versionComparator = versions.getVersionComparator();
                final DefaultArtifactVersion lowerBound = new DefaultArtifactVersion( version );
                if ( unchangedSegment.isPresent()
                        && unchangedSegment.get().value() >= versionComparator.getSegmentCount( lowerBound ) )
                {
                    getLog().info( "Ignoring " + toString( dep ) + " as the version number is too short" );
                    continue;
                }
                ArtifactVersion upperBound = unchangedSegment
                        .map( s ->
                                (ArtifactVersion) new BoundArtifactVersion( lowerBound, Segment.of( s.value() + 1 ) ) )
                        .orElse( null );

                getLog().info( "Upper bound: " + ( upperBound == null ? "none" : upperBound.toString() ) );
                Restriction restriction = new Restriction( lowerBound, false, upperBound, false );
                ArtifactVersion[] newer = versions.getVersions( restriction, true );
                getLog().debug( "Candidate versions " + Arrays.asList( newer ) );
File Line
org/codehaus/mojo/versions/api/PropertyVersions.java 436
org/codehaus/mojo/versions/api/PropertyVersionsBuilder.java 226
{
        public int compare( ArtifactVersion v1, ArtifactVersion v2 )
        {
            return innerCompare( v1, v2 );
        }

        private int innerCompare( ArtifactVersion v1, ArtifactVersion v2 )
        {
            if ( !isAssociated() )
            {
                throw new IllegalStateException( "Cannot compare versions for a property with no associations" );
            }
            VersionComparator[] comparators = lookupComparators();
            assert comparators.length >= 1 : "we have at least one association => at least one comparator";
            int result = comparators[0].compare( v1, v2 );
            for ( int i = 1; i < comparators.length; i++ )
            {
                int alt = comparators[i].compare( v1, v2 );
                if ( result != alt && ( result >= 0 && alt < 0 ) || ( result <= 0 && alt > 0 ) )
                {
                    throw new IllegalStateException(
                        "Property " + name + " is associated with multiple artifacts"
                            + " and these artifacts use different version sorting rules and these rules are effectively"
                            + " incompatible for the two of versions being compared.\nFirst rule says compare(\""
                            + v1
                            + "\", \"" + v2 + "\") = " + result
                            + "\nSecond rule says compare(\"" + v1 + "\", \"" + v2
                            + "\") = " + alt );
                }
            }
            return result;
        }
File Line
org/codehaus/mojo/versions/api/PomHelper.java 1166
org/codehaus/mojo/versions/api/PomHelper.java 1222
for ( Plugin plugin : plugins )
        {
            String version = plugin.getVersion();
            if ( version != null && version.contains( "${" ) && version.indexOf( '}' ) != -1 )
            {
                version = StringUtils.deleteWhitespace( version );
                for ( PropertyVersionsBuilder property : result.values() )
                {
                    // any of these could be defined by a property
                    final String propertyRef = "${" + property.getName() + "}";
                    if ( version.contains( propertyRef ) )
                    {
                        String groupId = plugin.getGroupId();
                        if ( groupId == null || groupId.trim().length() == 0 )
                        {
                            // group Id has a special default
                            groupId = APACHE_MAVEN_PLUGINS_GROUPID;
                        }
                        else
                        {
                            groupId = (String) expressionEvaluator.evaluate( groupId );
                        }
                        String artifactId = plugin.getArtifactId();
                        if ( artifactId == null || artifactId.trim().length() == 0 )
                        {
                            // malformed pom
                            continue;
                        }
                        else
                        {
                            artifactId = (String) expressionEvaluator.evaluate( artifactId );
                        }
                        // might as well capture the current value
                        String evaluatedVersion = (String) expressionEvaluator.evaluate( plugin.getVersion() );
File Line
org/codehaus/mojo/versions/reporting/AbstractVersionsReportRenderer.java 389
org/codehaus/mojo/versions/reporting/PluginUpdatesReportRenderer.java 331
sink.text( artifact.getType() );
        sink.tableCell_();
        sink.tableRow_();
        if ( !upToDate )
        {
            sink.tableRow();
            sink.tableHeaderCell( headerAttributes );
            sink.text( getText( "report.updateVersions" ) );
            sink.tableHeaderCell_();
            sink.tableCell( cellAttributes );
            for ( int i = 0; i < allUpdates.length; i++ )
            {
                if ( i > 0 )
                {
                    sink.lineBreak();
                }
                String label = getLabel( allUpdates[i], details );
                if ( label != null )
                {
                    safeBold();
                }
                sink.text( allUpdates[i].toString() );
                if ( label != null )
                {
                    safeBold_();
                    sink.nonBreakingSpace();
                    safeItalic();
                    sink.text( label );
                    safeItalic_();
                }
            }
            sink.tableCell_();
            sink.tableRow_();
        }
        sink.tableRows_();
        sink.table_();
    }
File Line
org/codehaus/mojo/versions/api/PomHelper.java 1050
org/codehaus/mojo/versions/api/PomHelper.java 1116
if ( profile.getDependencyManagement() != null )
                {
                    addDependencyAssocations( helper, expressionEvaluator, propertiesMap,
                            profile.getDependencyManagement().getDependencies(), false );
                }
                addDependencyAssocations( helper, expressionEvaluator, propertiesMap,
                        profile.getDependencies(),
                        false );
                if ( profile.getBuild() != null )
                {
                    if ( profile.getBuild().getPluginManagement() != null )
                    {
                        addPluginAssociations( helper, expressionEvaluator, propertiesMap,
                                profile.getBuild().getPluginManagement().getPlugins() );
                    }
                    addPluginAssociations( helper, expressionEvaluator, propertiesMap,
                            profile.getBuild().getPlugins() );
                }
                if ( profile.getReporting() != null )
                {
                    addReportPluginAssociations( helper, expressionEvaluator, propertiesMap,
                            profile.getReporting().getPlugins() );
                }
            }
File Line
org/codehaus/mojo/versions/api/PomHelper.java 658
org/codehaus/mojo/versions/api/PomHelper.java 904
+ "((/groupId)|(/artifactId)|(/version))" );

        pom.rewind();

        while ( pom.hasNext() )
        {
            XMLEvent event = pom.nextEvent();
            if ( event.isStartElement() )
            {
                stack.push( path );
                final String elementName = event.asStartElement().getName().getLocalPart();
                path = path + "/" + elementName;

                if ( matchScopeRegex.matcher( path ).matches() )
                {
                    // we're in a new match scope
                    // reset any previous partial matches
                    inMatchScope = true;
                    pom.clearMark( 0 );
                    pom.clearMark( 1 );

                    haveGroupId = false;
                    haveArtifactId = false;
                    haveOldVersion = false;
                }
                else if ( inMatchScope && matchTargetRegex.matcher( path ).matches() )
                {
                    if ( "groupId".equals( elementName ) )
                    {
                        haveGroupId = groupId.equals( evaluate( pom.getElementText().trim(), implicitProperties ) );
File Line
org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java 151
org/codehaus/mojo/versions/UseNextSnapshotsMojo.java 138
private void useLatestSnapshots( ModifiedPomXMLEventReader pom, Collection<Dependency> dependencies )
        throws XMLStreamException, MojoExecutionException, ArtifactMetadataRetrievalException
    {
        Optional<Segment> unchangedSegment = SegmentUtils.determineUnchangedSegment( allowMajorUpdates,
                allowMinorUpdates, allowIncrementalUpdates, getLog() );

        for ( Dependency dep : dependencies )
        {
            if ( isExcludeReactor() && isProducedByReactor( dep ) )
            {
                getLog().info( "Ignoring reactor dependency: " + toString( dep ) );
                continue;
            }

            if ( isHandledByProperty( dep ) )
            {
                getLog().debug( "Ignoring dependency with property as version: " + toString( dep ) );
                continue;
            }

            String version = dep.getVersion();
            Matcher versionMatcher = matchSnapshotRegex.matcher( version );
            if ( !versionMatcher.matches() )
            {
                getLog().debug( "Looking for latest snapshot of " + toString( dep ) );
File Line
org/codehaus/mojo/versions/api/PomHelper.java 416
org/codehaus/mojo/versions/api/PomHelper.java 466
final Pattern matchScopeRegex = Pattern.compile( "/project/version" );

        pom.rewind();

        while ( pom.hasNext() )
        {
            XMLEvent event = pom.nextEvent();
            if ( event.isStartElement() )
            {
                stack.push( path );
                path = path + "/" + event.asStartElement().getName().getLocalPart();

                if ( matchScopeRegex.matcher( path ).matches() )
                {
                    pom.mark( 0 );
                }
            }
            if ( event.isEndElement() )
            {
                if ( matchScopeRegex.matcher( path ).matches() )
                {
                    pom.mark( 1 );
                    if ( pom.hasMark( 0 ) && pom.hasMark( 1 ) )
                    {
File Line
org/codehaus/mojo/versions/LockSnapshotsMojo.java 100
org/codehaus/mojo/versions/UnlockSnapshotsMojo.java 100
private void lockSnapshots( ModifiedPomXMLEventReader pom, Collection<Dependency> dependencies )
        throws XMLStreamException, MojoExecutionException
    {
        for ( Dependency dep : dependencies )
        {
            if ( isExcludeReactor() && isProducedByReactor( dep ) )
            {
                getLog().info( "Ignoring reactor dependency: " + toString( dep ) );
                continue;
            }

            if ( isHandledByProperty( dep ) )
            {
                getLog().debug( "Ignoring dependency with property as version: " + toString( dep ) );
                continue;
            }

            if ( !isIncluded( this.toArtifact( dep ) ) )
            {
                continue;
            }

            String version = dep.getVersion();
            Matcher versionMatcher = matchSnapshotRegex.matcher( version );
            if ( versionMatcher.find() && versionMatcher.end() == version.length() )
            {
                String lockedVersion = resolveSnapshotVersion( dep );
File Line
org/codehaus/mojo/versions/UseLatestReleasesMojo.java 154
org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java 151
org/codehaus/mojo/versions/UseNextSnapshotsMojo.java 138
private void useLatestReleases( ModifiedPomXMLEventReader pom, Collection<Dependency> dependencies )
        throws XMLStreamException, MojoExecutionException, ArtifactMetadataRetrievalException
    {
        Optional<Segment> unchangedSegment = SegmentUtils.determineUnchangedSegment( allowMajorUpdates,
                allowMinorUpdates, allowIncrementalUpdates, getLog() );

        for ( Dependency dep : dependencies )
        {
            if ( isExcludeReactor() && isProducedByReactor( dep ) )
            {
                getLog().info( "Ignoring reactor dependency: " + toString( dep ) );
                continue;
            }

            if ( isHandledByProperty( dep ) )
            {
                getLog().debug( "Ignoring dependency with property as version: " + toString( dep ) );
                continue;
            }

            String version = dep.getVersion();
            Matcher versionMatcher = matchSnapshotRegex.matcher( version );
            if ( !versionMatcher.matches() )
            {
File Line
org/codehaus/mojo/versions/reporting/OverviewStats.java 69
org/codehaus/mojo/versions/reporting/PluginOverviewStats.java 66
OverviewStats stats = new OverviewStats();
        updates.forEach( details ->
        {
            if ( getNewestUpdate( cache, details, of( SUBINCREMENTAL ) ) != null )
            {
                stats.incrementAny();
            }
            else if ( getNewestUpdate( cache, details, of( INCREMENTAL ) ) != null )
            {
                stats.incrementIncremental();
            }
            else if ( getNewestUpdate( cache, details, of( MINOR ) ) != null )
            {
                stats.incrementMinor();
            }
            else if ( getNewestUpdate( cache, details, of( MAJOR ) ) != null )
            {
                stats.incrementMajor();
            }
            else
            {
                stats.incrementUpToDate();
            }
File Line
org/codehaus/mojo/versions/reporting/AbstractVersionsReportRenderer.java 295
org/codehaus/mojo/versions/reporting/PluginUpdatesReportRenderer.java 264
org/codehaus/mojo/versions/reporting/PropertyUpdatesReportRenderer.java 182
ArtifactVersion[] allUpdates = allUpdatesCache.get( details, empty() );
        boolean upToDate = allUpdates == null || allUpdates.length == 0;

        final SinkEventAttributes headerAttributes = new SinkEventAttributeSet();
        headerAttributes.addAttribute( SinkEventAttributes.WIDTH, "70%" );
        final SinkEventAttributes cellAttributes = new SinkEventAttributeSet();
        headerAttributes.addAttribute( SinkEventAttributes.WIDTH, "30%" );
        sink.table();
        sink.tableRows( new int[] { Sink.JUSTIFY_RIGHT, Sink.JUSTIFY_LEFT }, false );
        sink.tableRow();
        sink.tableHeaderCell( headerAttributes );
        sink.text( getText( "report.status" ) );
        sink.tableHeaderCell_();
        sink.tableCell( cellAttributes );
        if ( newestUpdateCache.get( details, of( SUBINCREMENTAL ) ) != null )
File Line
org/codehaus/mojo/versions/UseLatestReleasesMojo.java 154
org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java 151
org/codehaus/mojo/versions/UseLatestVersionsMojo.java 165
org/codehaus/mojo/versions/UseNextSnapshotsMojo.java 138
private void useLatestReleases( ModifiedPomXMLEventReader pom, Collection<Dependency> dependencies )
        throws XMLStreamException, MojoExecutionException, ArtifactMetadataRetrievalException
    {
        Optional<Segment> unchangedSegment = SegmentUtils.determineUnchangedSegment( allowMajorUpdates,
                allowMinorUpdates, allowIncrementalUpdates, getLog() );

        for ( Dependency dep : dependencies )
        {
            if ( isExcludeReactor() && isProducedByReactor( dep ) )
            {
                getLog().info( "Ignoring reactor dependency: " + toString( dep ) );
                continue;
            }

            if ( isHandledByProperty( dep ) )
            {
                getLog().debug( "Ignoring dependency with property as version: " + toString( dep ) );
                continue;
            }

            String version = dep.getVersion();