CPD Results

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

Duplications

FileLine
org/apache/maven/archetype/creator/FilesetArchetypeCreator.java853
org/apache/maven/archetype/creator/FilesetArchetypeCreator.java1074
    private void createModulePom( Model pom, String rootArtifactId, File archetypeFilesDirectory,
                                  Properties pomReversedProperties, File initialPomFile, boolean preserveCData,
                                  boolean keepParent )
        throws IOException
    {
        File outputFile = FileUtils.resolveFile( archetypeFilesDirectory, Constants.ARCHETYPE_POM );

        if ( preserveCData )
        {
            getLogger().debug( "Preserving CDATA parts of pom" );
            File inputFile = FileUtils.resolveFile( archetypeFilesDirectory, Constants.ARCHETYPE_POM + ".tmp" );

            FileUtils.copyFile( initialPomFile, inputFile );

            Reader in = null;
            Writer out = null;
            try
            {
                in = ReaderFactory.newXmlReader( inputFile );

                String initialcontent = IOUtil.toString( in );

                String content = getReversedContent( initialcontent, pomReversedProperties );

                outputFile.getParentFile().mkdirs();

                out = WriterFactory.newXmlWriter( outputFile );

                IOUtil.copy( content, out );
            }
            finally
            {
                IOUtil.close( in );
                IOUtil.close( out );
            }

            inputFile.delete();
        }
        else
        {
            if ( pom.getParent() != null )
FileLine
org/apache/maven/archetype/common/MavenJDOMWriter.java1792
org/apache/maven/archetype/common/MavenJDOMWriter.java2060
        updateBuildBase( value.getBuild(), "build", innerCount, root );
        findAndReplaceSimpleLists( innerCount, root, value.getModules(), "modules", "module" );
        iterateRepository( innerCount, root, value.getRepositories(), "repositories", "repository" );
        iterateRepository( innerCount, root, value.getPluginRepositories(), "pluginRepositories", "pluginRepository" );
        iterateDependency( innerCount, root, value.getDependencies(), "dependencies", "dependency" );
        findAndReplaceXpp3DOM( innerCount, root, "reports", (Xpp3Dom) value.getReports() );
        updateReporting( value.getReporting(), "reporting", innerCount, root );
        updateDependencyManagement( value.getDependencyManagement(), "dependencyManagement", innerCount, root );
        updateDistributionManagement( value.getDistributionManagement(), "distributionManagement", innerCount, root );
        findAndReplaceProperties( innerCount, root, "properties", value.getProperties() );
    } // -- void updateProfile(Profile, String, Counter, Element)

    /**
     * Method updateRelocation.
     *
     * @param value
     * @param element
     * @param counter
     * @param xmlTag
     */
    protected void updateRelocation( Relocation value, String xmlTag, Counter counter, Element element )
FileLine
org/apache/maven/archetype/common/MavenJDOMWriter.java1792
org/apache/maven/archetype/common/MavenJDOMWriter.java1818
            Counter innerCount = new Counter( counter.getDepth() + 1 );
            findAndReplaceSimpleLists( innerCount, root, value.getModules(), "modules", "module" );
            iterateRepository( innerCount, root, value.getRepositories(), "repositories", "repository" );
            iterateRepository( innerCount, root, value.getPluginRepositories(), "pluginRepositories",
                               "pluginRepository" );
            iterateDependency( innerCount, root, value.getDependencies(), "dependencies", "dependency" );
            findAndReplaceXpp3DOM( innerCount, root, "reports", (Xpp3Dom) value.getReports() );
            updateReporting( value.getReporting(), "reporting", innerCount, root );
            updateDependencyManagement( value.getDependencyManagement(), "dependencyManagement", innerCount, root );
            updateDistributionManagement( value.getDistributionManagement(), "distributionManagement", innerCount,
                                          root );
            findAndReplaceProperties( innerCount, root, "properties", value.getProperties() );
        }
FileLine
org/apache/maven/archetype/creator/FilesetArchetypeCreator.java629
org/apache/maven/archetype/creator/FilesetArchetypeCreator.java748
                    for ( Iterator<Plugin> plugins = profile.getBuild().getPluginManagement().getPlugins().iterator();
                        plugins.hasNext(); )
                    {
                        Plugin plugin = plugins.next();

                        if ( plugin.getArtifactId() != null && plugin.getArtifactId().indexOf( rootArtifactId ) >= 0 )
                        {
                            if ( plugin.getGroupId() != null )
                            {
                                plugin.setGroupId( StringUtils.replace( plugin.getGroupId(), groupId,
                                                                        "${" + Constants.GROUP_ID + "}" ) );
                            }

                            plugin.setArtifactId( StringUtils.replace( plugin.getArtifactId(), rootArtifactId,
                                                                       "${rootArtifactId}" ) );

                            if ( plugin.getVersion() != null )
                            {
                                plugin.setVersion( "${" + Constants.VERSION + "}" );
                            }
                        }
                    }
                }
FileLine
org/apache/maven/archetype/common/util/FileCharsetDetector.java58
org/apache/maven/archetype/common/util/FileCharsetDetector.java114
        BufferedInputStream imp = new BufferedInputStream( detectedStream );

        byte[] buf = new byte[1024];
        int len;
        boolean done = false;
        boolean isAscii = true;

        while ( ( len = imp.read( buf, 0, buf.length ) ) != -1 )
        {
            // Check if the stream is only ascii.
            if ( isAscii )
            {
                isAscii = det.isAscii( buf, len );
            }

            // DoIt if non-ascii and not done yet.
            if ( !isAscii && !done )
            {
                done = det.DoIt( buf, len, false );
                found = done;
            }
        }
        det.DataEnd();

        if ( !isFound() )
        {
            String[] prob = det.getProbableCharsets();

            if ( prob.length > 0 )
            {
                charset = prob[0];
            }
        }

        if ( isAscii )
        {
            charset = "ASCII";
        }
    }

    public String getCharset()
FileLine
org/apache/maven/archetype/creator/FilesetArchetypeCreator.java601
org/apache/maven/archetype/creator/FilesetArchetypeCreator.java629
            for ( Iterator<Plugin> plugins = pom.getBuild().getPluginManagement().getPlugins().iterator(); plugins.hasNext(); )
            {
                Plugin plugin = plugins.next();

                if ( plugin.getArtifactId() != null && plugin.getArtifactId().indexOf( rootArtifactId ) >= 0 )
                {
                    if ( plugin.getGroupId() != null )
                    {
                        plugin.setGroupId( StringUtils.replace( plugin.getGroupId(), groupId,
                                                                "${" + Constants.GROUP_ID + "}" ) );
                    }

                    plugin.setArtifactId( StringUtils.replace( plugin.getArtifactId(), rootArtifactId,
                                                               "${rootArtifactId}" ) );

                    if ( plugin.getVersion() != null )
                    {
                        plugin.setVersion( "${" + Constants.VERSION + "}" );
                    }
                }
            }
        }

        // rewrite Profiles
        if ( pom.getProfiles() != null )
FileLine
org/apache/maven/archetype/creator/FilesetArchetypeCreator.java601
org/apache/maven/archetype/creator/FilesetArchetypeCreator.java720
                    for ( Iterator<Plugin> plugins = profile.getBuild().getPlugins().iterator(); plugins.hasNext(); )
                    {
                        Plugin plugin = plugins.next();

                        if ( plugin.getArtifactId() != null && plugin.getArtifactId().indexOf( rootArtifactId ) >= 0 )
                        {
                            if ( plugin.getGroupId() != null )
                            {
                                plugin.setGroupId( StringUtils.replace( plugin.getGroupId(), groupId,
                                                                        "${" + Constants.GROUP_ID + "}" ) );
                            }

                            plugin.setArtifactId( StringUtils.replace( plugin.getArtifactId(), rootArtifactId,
                                                                       "${rootArtifactId}" ) );

                            if ( plugin.getVersion() != null )
                            {
                                plugin.setVersion( "${" + Constants.VERSION + "}" );
                            }
                        }
                    }
                }

                // rewrite PluginManagement
                if ( profile.getBuild() != null && profile.getBuild().getPluginManagement() != null
FileLine
org/apache/maven/archetype/creator/FilesetArchetypeCreator.java574
org/apache/maven/archetype/creator/FilesetArchetypeCreator.java692
                        profile.getDependencyManagement().getDependencies().iterator(); dependencies.hasNext(); )
                    {
                        Dependency dependency = dependencies.next();

                        if ( dependency.getArtifactId() != null
                            && dependency.getArtifactId().indexOf( rootArtifactId ) >= 0 )
                        {
                            if ( dependency.getGroupId() != null )
                            {
                                dependency.setGroupId( StringUtils.replace( dependency.getGroupId(), groupId,
                                                                            "${" + Constants.GROUP_ID + "}" ) );
                            }

                            dependency.setArtifactId( StringUtils.replace( dependency.getArtifactId(), rootArtifactId,
                                                                           "${rootArtifactId}" ) );

                            if ( dependency.getVersion() != null )
                            {
                                dependency.setVersion( "${" + Constants.VERSION + "}" );
                            }
                        }
                    }
                }

                // rewrite Plugins
                if ( profile.getBuild() != null && profile.getBuild().getPlugins() != null
FileLine
org/apache/maven/archetype/creator/FilesetArchetypeCreator.java547
org/apache/maven/archetype/creator/FilesetArchetypeCreator.java574
            for ( Iterator<Dependency> dependencies = pom.getDependencyManagement().getDependencies().iterator();
                dependencies.hasNext(); )
            {
                Dependency dependency = dependencies.next();

                if ( dependency.getArtifactId() != null && dependency.getArtifactId().indexOf( rootArtifactId ) >= 0 )
                {
                    if ( dependency.getGroupId() != null )
                    {
                        dependency.setGroupId( StringUtils.replace( dependency.getGroupId(), groupId,
                                                                    "${" + Constants.GROUP_ID + "}" ) );
                    }

                    dependency.setArtifactId( StringUtils.replace( dependency.getArtifactId(), rootArtifactId,
                                                                   "${rootArtifactId}" ) );

                    if ( dependency.getVersion() != null )
                    {
                        dependency.setVersion( "${" + Constants.VERSION + "}" );
                    }
                }
            }
        }

        // rewrite Plugins
        if ( pom.getBuild() != null && pom.getBuild().getPlugins() != null && !pom.getBuild().getPlugins().isEmpty() )
FileLine
org/apache/maven/archetype/creator/FilesetArchetypeCreator.java720
org/apache/maven/archetype/creator/FilesetArchetypeCreator.java748
                    for ( Iterator<Plugin> plugins = profile.getBuild().getPluginManagement().getPlugins().iterator();
                        plugins.hasNext(); )
                    {
                        Plugin plugin = plugins.next();

                        if ( plugin.getArtifactId() != null && plugin.getArtifactId().indexOf( rootArtifactId ) >= 0 )
                        {
                            if ( plugin.getGroupId() != null )
                            {
                                plugin.setGroupId( StringUtils.replace( plugin.getGroupId(), groupId,
                                                                        "${" + Constants.GROUP_ID + "}" ) );
                            }

                            plugin.setArtifactId( StringUtils.replace( plugin.getArtifactId(), rootArtifactId,
                                                                       "${rootArtifactId}" ) );

                            if ( plugin.getVersion() != null )
                            {
                                plugin.setVersion( "${" + Constants.VERSION + "}" );
                            }
                        }
                    }
                }
FileLine
org/apache/maven/archetype/creator/FilesetArchetypeCreator.java547
org/apache/maven/archetype/creator/FilesetArchetypeCreator.java692
                    for ( Iterator<Dependency> dependencies = profile.getDependencies().iterator(); dependencies.hasNext(); )
                    {
                        Dependency dependency = dependencies.next();

                        if ( dependency.getArtifactId() != null
                            && dependency.getArtifactId().indexOf( rootArtifactId ) >= 0 )
                        {
                            if ( dependency.getGroupId() != null )
                            {
                                dependency.setGroupId( StringUtils.replace( dependency.getGroupId(), groupId,
                                                                            "${" + Constants.GROUP_ID + "}" ) );
                            }

                            dependency.setArtifactId( StringUtils.replace( dependency.getArtifactId(), rootArtifactId,
                                                                           "${rootArtifactId}" ) );

                            if ( dependency.getVersion() != null )
                            {
                                dependency.setVersion( "${" + Constants.VERSION + "}" );
                            }
                        }
                    }
                }

                // rewrite DependencyManagement
                if ( profile.getDependencyManagement() != null
FileLine
org/apache/maven/archetype/common/MavenJDOMWriter.java1386
org/apache/maven/archetype/common/MavenJDOMWriter.java1412
            Counter innerCount = new Counter( counter.getDepth() + 1 );
            findAndReplaceSimpleElement( innerCount, root, "defaultGoal", value.getDefaultGoal(), null );
            iterateResource( innerCount, root, value.getResources(), "resources", "resource" );
            iterateResource( innerCount, root, value.getTestResources(), "testResources", "testResource" );
            findAndReplaceSimpleElement( innerCount, root, "directory", value.getDirectory(), null );
            findAndReplaceSimpleElement( innerCount, root, "finalName", value.getFinalName(), null );
            findAndReplaceSimpleLists( innerCount, root, value.getFilters(), "filters", "filter" );
            updatePluginManagement( value.getPluginManagement(), "pluginManagement", innerCount, root );
            iteratePlugin( innerCount, root, value.getPlugins(), "plugins", "plugin" );
        }
    } // -- void updateBuildBase(BuildBase, String, Counter, Element)

    /**
     * Method updateCiManagement.
     *
     * @param value
     * @param element
     * @param counter
     * @param xmlTag
     */
    protected void updateCiManagement( CiManagement value, String xmlTag, Counter counter, Element element )
FileLine
org/apache/maven/archetype/common/MavenJDOMWriter.java1477
org/apache/maven/archetype/common/MavenJDOMWriter.java1571
        findAndReplaceSimpleElement( innerCount, root, "id", value.getId(), null );
        findAndReplaceSimpleElement( innerCount, root, "name", value.getName(), null );
        findAndReplaceSimpleElement( innerCount, root, "email", value.getEmail(), null );
        findAndReplaceSimpleElement( innerCount, root, "url", value.getUrl(), null );
        findAndReplaceSimpleElement( innerCount, root, "organization", value.getOrganization(), null );
        findAndReplaceSimpleElement( innerCount, root, "organizationUrl", value.getOrganizationUrl(), null );
        findAndReplaceSimpleLists( innerCount, root, value.getRoles(), "roles", "role" );
        findAndReplaceSimpleElement( innerCount, root, "timezone", value.getTimezone(), null );
        findAndReplaceProperties( innerCount, root, "properties", value.getProperties() );
    } // -- void updateDeveloper(Developer, String, Counter, Element)

    /**
     * Method updateDistributionManagement.
     *
     * @param value
     * @param element
     * @param counter
     * @param xmlTag
     */
    protected void updateDistributionManagement( DistributionManagement value, String xmlTag, Counter counter,
FileLine
org/apache/maven/archetype/common/MavenJDOMWriter.java383
org/apache/maven/archetype/common/MavenJDOMWriter.java719
    protected void iterateResource( Counter counter, Element parent, java.util.Collection list,
                                    java.lang.String parentTag, java.lang.String childTag )
    {
        boolean shouldExist = ( list != null ) && ( list.size() > 0 );
        Element element = updateElement( counter, parent, parentTag, shouldExist );
        if ( shouldExist )
        {
            Iterator it = list.iterator();
            Iterator elIt = element.getChildren( childTag, element.getNamespace() ).iterator();
            if ( !elIt.hasNext() )
            {
                elIt = null;
            }

            Counter innerCount = new Counter( counter.getDepth() + 1 );
            while ( it.hasNext() )
            {
FileLine
org/apache/maven/archetype/common/util/XMLOutputter.java1579
org/apache/maven/archetype/common/util/XMLOutputter.java1665
                    break;
                default:
                    if ( strategy.shouldEscape( ch ) )
                    {
                        entity = "&#x" + Integer.toHexString( ch ) + ";";
                    }
                    else
                    {
                        entity = null;
                    }
                    break;
            }
            if ( buffer == null )
            {
                if ( entity != null )
                {
                    // An entity occurred, so we'll have to use StringBuffer
                    // (allocate room for it plus a few more entities).
                    buffer = new StringBuffer( str.length() + 20 );
                    // Copy previous skipped characters and fall through
                    // to pickup current character
                    buffer.append( str.substring( 0, i ) );
                    buffer.append( entity );
                }
            }
            else
            {
                if ( entity == null )
                {
                    buffer.append( ch );
                }
                else
                {
                    buffer.append( entity );
                }
            }
        }

        // If there were any entities, return the escaped characters
        // that we put in the StringBuffer. Otherwise, just return
        // the unmodified input string.
        return ( buffer == null ) ? str : buffer.toString();
    }

    /** Returns a copy of this XMLOutputter. */
    public Object clone()
FileLine
org/apache/maven/archetype/creator/FilesetArchetypeCreator.java793
org/apache/maven/archetype/creator/FilesetArchetypeCreator.java1282
                                 Properties reverseProperties, String defaultEncoding )
        throws IOException
    {
        String packageAsDirectory = StringUtils.replace( packageName, ".", File.separator );

        getLogger().debug( "Package as Directory: Package:" + packageName + "->" + packageAsDirectory );

        for ( String inputFileName : fileSetResources )
        {
            String outputFileName =
                packaged ? StringUtils.replace( inputFileName, packageAsDirectory + File.separator, "" )
                                : inputFileName;

            getLogger().debug( "InputFileName:" + inputFileName );
            getLogger().debug( "OutputFileName:" + outputFileName );

            File outputFile = new File( archetypeFilesDirectory, outputFileName );
            File inputFile = new File( basedir, inputFileName );