Search in sources :

Example 6 with CPD

use of net.sourceforge.pmd.cpd.CPD in project pmd-eclipse-plugin by pmd.

the class DetectCutAndPasteCmd method newCPD.

private CPD newCPD() {
    CPDConfiguration config = new CPDConfiguration();
    config.setMinimumTileSize(minTileSize);
    config.setLanguage(language);
    config.setEncoding(System.getProperty("file.encoding"));
    return new CPD(config);
}
Also used : CPDConfiguration(net.sourceforge.pmd.cpd.CPDConfiguration) CPD(net.sourceforge.pmd.cpd.CPD)

Example 7 with CPD

use of net.sourceforge.pmd.cpd.CPD in project pmd-eclipse-plugin by pmd.

the class DetectCutAndPasteCmd method detectCutAndPaste.

/**
 * Run the cut and paste detector. At first all files have to be added to
 * the cpd. Then the CPD can be executed.
 *
 * @param files
 *            List of files to be checked.
 * @return the CPD itself for retrieving the matches.
 * @throws CoreException
 */
private CPD detectCutAndPaste(final List<File> files) {
    LOG.debug("Searching for project files");
    final CPD cpd = newCPD();
    subTask("Collecting files for CPD");
    final Iterator<File> fileIterator = files.iterator();
    while (fileIterator.hasNext() && !isCanceled()) {
        final File file = fileIterator.next();
        try {
            cpd.add(file);
            worked(1);
        } catch (IOException e) {
            LOG.warn("IOException when adding file " + file.getName() + " to CPD. Continuing.", e);
        }
    }
    if (!isCanceled()) {
        subTask("Performing CPD");
        LOG.debug("Performing CPD");
        cpd.go();
        worked(getStepCount());
    }
    return cpd;
}
Also used : CPD(net.sourceforge.pmd.cpd.CPD) IOException(java.io.IOException) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Aggregations

CPD (net.sourceforge.pmd.cpd.CPD)7 File (java.io.File)6 CPDConfiguration (net.sourceforge.pmd.cpd.CPDConfiguration)5 JavaLanguage (net.sourceforge.pmd.cpd.JavaLanguage)4 IOException (java.io.IOException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 EcmascriptLanguage (net.sourceforge.pmd.cpd.EcmascriptLanguage)2 JSPLanguage (net.sourceforge.pmd.cpd.JSPLanguage)2 Language (net.sourceforge.pmd.cpd.Language)2 Mark (net.sourceforge.pmd.cpd.Mark)2 Match (net.sourceforge.pmd.cpd.Match)2 SourceCode (net.sourceforge.pmd.cpd.SourceCode)2 TokenEntry (net.sourceforge.pmd.cpd.TokenEntry)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 MavenReportException (org.apache.maven.reporting.MavenReportException)2 IFile (org.eclipse.core.resources.IFile)2 Document (org.w3c.dom.Document)2