Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MPMD-375] Replace *ReportGenerators with a new *ReportRenderers #130

Merged
merged 1 commit into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ under the License.
<pmdVersion>6.55.0</pmdVersion>
<slf4jVersion>1.7.36</slf4jVersion>
<aetherVersion>1.0.0.v20140518</aetherVersion>
<doxiaVersion>1.12.0</doxiaVersion>
<compilerPluginVersion>3.11.0</compilerPluginVersion>
<sitePluginVersion>3.12.1</sitePluginVersion>
<projectInfoReportsPluginVersion>3.4.3</projectInfoReportsPluginVersion>
Expand Down Expand Up @@ -139,6 +140,12 @@ under the License.
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-common-artifact-filters</artifactId>
<version>3.3.2</version>
<exclusions>
<exclusion>
<groupId>org.sonatype.sisu</groupId>
<artifactId>sisu-inject-plexus</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
Expand Down Expand Up @@ -190,7 +197,24 @@ under the License.
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-sink-api</artifactId>
<version>1.12.0</version>
<version>${doxiaVersion}</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-core</artifactId>
<version>${doxiaVersion}</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
Expand All @@ -207,6 +231,14 @@ under the License.
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-api</artifactId>
</exclusion>
</exclusions>
</dependency>

Expand All @@ -227,6 +259,17 @@ under the License.
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-i18n</artifactId>
<version>1.0-beta-10</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-api</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- test -->
<dependency>
Expand All @@ -240,6 +283,12 @@ under the License.
<artifactId>maven-plugin-testing-harness</artifactId>
<version>3.3.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
Expand Down
41 changes: 23 additions & 18 deletions src/main/java/org/apache/maven/plugins/pmd/CpdReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@
import java.io.UnsupportedEncodingException;
import java.util.Locale;
import java.util.Properties;
import java.util.ResourceBundle;

import net.sourceforge.pmd.cpd.JavaTokenizer;
import net.sourceforge.pmd.cpd.renderer.CPDRenderer;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.pmd.exec.CpdExecutor;
import org.apache.maven.plugins.pmd.exec.CpdRequest;
import org.apache.maven.plugins.pmd.exec.CpdResult;
import org.apache.maven.reporting.MavenReportException;
import org.apache.maven.toolchain.Toolchain;
import org.codehaus.plexus.i18n.I18N;

/**
* Creates a report for PMD's Copy/Paste Detector (CPD) tool.
Expand Down Expand Up @@ -96,25 +97,36 @@ public class CpdReport extends AbstractPmdReport {
@Parameter(property = "cpd.ignoreAnnotations", defaultValue = "false")
private boolean ignoreAnnotations;

/**
* Internationalization component
*/
@Component
private I18N i18n;

/**
* Contains the result of the last CPD execution.
* It might be <code>null</code> which means, that CPD
* has not been executed yet.
*/
private CpdResult cpdResult;

/**
* {@inheritDoc}
*/
/** {@inheritDoc} */
public String getName(Locale locale) {
return getBundle(locale).getString("report.cpd.name");
return getI18nString(locale, "name");
}

/** {@inheritDoc} */
public String getDescription(Locale locale) {
return getI18nString(locale, "description");
}

/**
* {@inheritDoc}
* @param locale The locale
* @param key The key to search for
* @return The text appropriate for the locale.
*/
public String getDescription(Locale locale) {
return getBundle(locale).getString("report.cpd.description");
protected String getI18nString(Locale locale, String key) {
return i18n.getString("cpd-report", locale, "report.cpd." + key);
}

/**
Expand All @@ -126,7 +138,9 @@ public void executeReport(Locale locale) throws MavenReportException {
try {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());

generateMavenSiteReport(locale);
CpdReportRenderer r = new CpdReportRenderer(
getSink(), i18n, locale, filesToProcess, cpdResult.getDuplications(), isAggregator());
r.render();
} finally {
Thread.currentThread().setContextClassLoader(origLoader);
}
Expand Down Expand Up @@ -209,22 +223,13 @@ private void executeCpd() throws MavenReportException {
}
}

private void generateMavenSiteReport(Locale locale) {
CpdReportGenerator gen = new CpdReportGenerator(getSink(), filesToProcess, getBundle(locale), isAggregator());
gen.generate(cpdResult.getDuplications());
}

/**
* {@inheritDoc}
*/
public String getOutputName() {
return "cpd";
}

private static ResourceBundle getBundle(Locale locale) {
return ResourceBundle.getBundle("cpd-report", locale, CpdReport.class.getClassLoader());
}

/**
* Create and return the correct renderer for the output type.
*
Expand Down
Loading