Search in sources :

Example 1 with JSPLanguage

use of net.sourceforge.pmd.cpd.JSPLanguage in project maven-plugins by apache.

the class CpdReport method executeCpd.

private void executeCpd() throws MavenReportException {
    if (cpd != null) {
        // CPD has already been run
        getLog().debug("CPD has already been run - skipping redundant execution.");
        return;
    }
    Properties p = new Properties();
    if (ignoreLiterals) {
        p.setProperty(JavaTokenizer.IGNORE_LITERALS, "true");
    }
    if (ignoreIdentifiers) {
        p.setProperty(JavaTokenizer.IGNORE_IDENTIFIERS, "true");
    }
    try {
        if (filesToProcess == null) {
            filesToProcess = getFilesToProcess();
        }
        try {
            excludeDuplicationsFromFile.loadExcludeFromFailuresData(excludeFromFailureFile);
        } catch (MojoExecutionException e) {
            throw new MavenReportException("Error loading exclusions", e);
        }
        String encoding = determineEncoding(!filesToProcess.isEmpty());
        Language cpdLanguage;
        if ("java".equals(language) || null == language) {
            cpdLanguage = new JavaLanguage(p);
        } else if ("javascript".equals(language)) {
            cpdLanguage = new EcmascriptLanguage();
        } else if ("jsp".equals(language)) {
            cpdLanguage = new JSPLanguage();
        } else {
            cpdLanguage = LanguageFactory.createLanguage(language, p);
        }
        CPDConfiguration cpdConfiguration = new CPDConfiguration();
        cpdConfiguration.setMinimumTileSize(minimumTokens);
        cpdConfiguration.setLanguage(cpdLanguage);
        cpdConfiguration.setSourceEncoding(encoding);
        cpd = new CPD(cpdConfiguration);
        for (File file : filesToProcess.keySet()) {
            cpd.add(file);
        }
    } catch (UnsupportedEncodingException e) {
        throw new MavenReportException("Encoding '" + getSourceEncoding() + "' is not supported.", e);
    } catch (IOException e) {
        throw new MavenReportException(e.getMessage(), e);
    }
    getLog().debug("Executing CPD...");
    cpd.go();
    getLog().debug("CPD finished.");
    // so the "check" goals can check for violations
    if (isXml()) {
        writeNonHtml(cpd);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) JSPLanguage(net.sourceforge.pmd.cpd.JSPLanguage) CPDConfiguration(net.sourceforge.pmd.cpd.CPDConfiguration) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) Properties(java.util.Properties) JavaLanguage(net.sourceforge.pmd.cpd.JavaLanguage) EcmascriptLanguage(net.sourceforge.pmd.cpd.EcmascriptLanguage) JSPLanguage(net.sourceforge.pmd.cpd.JSPLanguage) Language(net.sourceforge.pmd.cpd.Language) JavaLanguage(net.sourceforge.pmd.cpd.JavaLanguage) CPD(net.sourceforge.pmd.cpd.CPD) EcmascriptLanguage(net.sourceforge.pmd.cpd.EcmascriptLanguage) File(java.io.File) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 2 with JSPLanguage

use of net.sourceforge.pmd.cpd.JSPLanguage in project maven-plugins by apache.

the class CpdReport method executeCpd.

private void executeCpd() throws MavenReportException {
    if (cpd != null) {
        // CPD has already been run
        getLog().debug("CPD has already been run - skipping redundant execution.");
        return;
    }
    Properties p = new Properties();
    if (ignoreLiterals) {
        p.setProperty(JavaTokenizer.IGNORE_LITERALS, "true");
    }
    if (ignoreIdentifiers) {
        p.setProperty(JavaTokenizer.IGNORE_IDENTIFIERS, "true");
    }
    try {
        if (filesToProcess == null) {
            filesToProcess = getFilesToProcess();
        }
        try {
            excludeDuplicationsFromFile.loadExcludeFromFailuresData(excludeFromFailureFile);
        } catch (MojoExecutionException e) {
            throw new MavenReportException("Error loading exclusions", e);
        }
        String encoding = determineEncoding(!filesToProcess.isEmpty());
        Language cpdLanguage;
        if ("java".equals(language) || null == language) {
            cpdLanguage = new JavaLanguage(p);
        } else if ("javascript".equals(language)) {
            cpdLanguage = new EcmascriptLanguage();
        } else if ("jsp".equals(language)) {
            cpdLanguage = new JSPLanguage();
        } else {
            cpdLanguage = LanguageFactory.createLanguage(language, p);
        }
        CPDConfiguration cpdConfiguration = new CPDConfiguration();
        cpdConfiguration.setMinimumTileSize(minimumTokens);
        cpdConfiguration.setLanguage(cpdLanguage);
        cpdConfiguration.setSourceEncoding(encoding);
        cpd = new CPD(cpdConfiguration);
        for (File file : filesToProcess.keySet()) {
            cpd.add(file);
        }
    } catch (UnsupportedEncodingException e) {
        throw new MavenReportException("Encoding '" + getSourceEncoding() + "' is not supported.", e);
    } catch (IOException e) {
        throw new MavenReportException(e.getMessage(), e);
    }
    getLog().debug("Executing CPD...");
    cpd.go();
    getLog().debug("CPD finished.");
    // so the "check" goals can check for violations
    if (isXml()) {
        writeNonHtml(cpd);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) JSPLanguage(net.sourceforge.pmd.cpd.JSPLanguage) CPDConfiguration(net.sourceforge.pmd.cpd.CPDConfiguration) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) Properties(java.util.Properties) JavaLanguage(net.sourceforge.pmd.cpd.JavaLanguage) EcmascriptLanguage(net.sourceforge.pmd.cpd.EcmascriptLanguage) JSPLanguage(net.sourceforge.pmd.cpd.JSPLanguage) Language(net.sourceforge.pmd.cpd.Language) JavaLanguage(net.sourceforge.pmd.cpd.JavaLanguage) CPD(net.sourceforge.pmd.cpd.CPD) EcmascriptLanguage(net.sourceforge.pmd.cpd.EcmascriptLanguage) File(java.io.File) MavenReportException(org.apache.maven.reporting.MavenReportException)

Aggregations

File (java.io.File)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Properties (java.util.Properties)2 CPD (net.sourceforge.pmd.cpd.CPD)2 CPDConfiguration (net.sourceforge.pmd.cpd.CPDConfiguration)2 EcmascriptLanguage (net.sourceforge.pmd.cpd.EcmascriptLanguage)2 JSPLanguage (net.sourceforge.pmd.cpd.JSPLanguage)2 JavaLanguage (net.sourceforge.pmd.cpd.JavaLanguage)2 Language (net.sourceforge.pmd.cpd.Language)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 MavenReportException (org.apache.maven.reporting.MavenReportException)2