Skip to content

Commit

Permalink
[MPMD-349] Upgrade Maven Reporting API to 3.1.1/Maven Reporting Impl …
Browse files Browse the repository at this point in the history
…to 3.2.0

This closes #84
  • Loading branch information
michael-o committed Aug 12, 2022
1 parent 1740f00 commit 8c71996
Show file tree
Hide file tree
Showing 61 changed files with 575 additions and 645 deletions.
57 changes: 48 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ under the License.
<javaVersion>8</javaVersion><!-- Because PMD 6.35.0+ requires Java 8 -->
<pmdVersion>6.48.0</pmdVersion>
<slf4jVersion>1.7.36</slf4jVersion>
<sitePluginVersion>3.12.0</sitePluginVersion>
<projectInfoReportsPluginVersion>3.3.0</projectInfoReportsPluginVersion>
<aetherVersion>1.0.0.v20140518</aetherVersion>
<sitePluginVersion>3.12.1</sitePluginVersion>
<projectInfoReportsPluginVersion>3.4.1</projectInfoReportsPluginVersion>
<project.build.outputTimestamp>2022-05-31T17:37:31Z</project.build.outputTimestamp>
</properties>

Expand Down Expand Up @@ -203,18 +204,24 @@ under the License.
doxia-site-renderer requires transitively dom4j 1.1 which provides a very old version of jaxen (same jar).
PMD requires a newer version of jaxen, which is not compatible.
-->
<exclusions>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- shared -->
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-api</artifactId>
<version>3.1.0</version>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-impl</artifactId>
<version>3.1.0</version>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
Expand Down Expand Up @@ -243,11 +250,43 @@ under the License.
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<!-- that's a very old version, but it's the newest one that brings in
a old guava version, that is compatible with maven 3.1.1.
maven 3.1.1 uses guava 11, wiremock 1.49 uses guava 13.0.1
-->
<version>1.49</version>
<version>1.58</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-api</artifactId>
<version>${aetherVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-impl</artifactId>
<version>${aetherVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-connector-basic</artifactId>
<version>${aetherVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-wagon</artifactId>
<version>${aetherVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http-lightweight</artifactId>
<version>3.5.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion src/it/MPMD-270-325-JDK11/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ under the License.
<failurePriority>4</failurePriority>
<printFailingErrors>true</printFailingErrors>
<targetJdk>${java.version}</targetJdk>
<sourceEncoding>UTF-8</sourceEncoding>
<inputEncoding>UTF-8</inputEncoding>
<minimumTokens>100</minimumTokens>
</configuration>
<executions>
Expand Down
2 changes: 1 addition & 1 deletion src/it/MPMD-280-JDK12/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ under the License.
<failurePriority>4</failurePriority>
<printFailingErrors>true</printFailingErrors>
<targetJdk>${java.version}</targetJdk>
<sourceEncoding>UTF-8</sourceEncoding>
<inputEncoding>UTF-8</inputEncoding>
<minimumTokens>100</minimumTokens>
</configuration>
<executions>
Expand Down
2 changes: 1 addition & 1 deletion src/it/MPMD-289-format-html-check/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ under the License.
<skip>false</skip>
<failOnViolation>true</failOnViolation>
<failurePriority>4</failurePriority>
<sourceEncoding>UTF-8</sourceEncoding>
<inputEncoding>UTF-8</inputEncoding>
<minimumTokens>100</minimumTokens>
<skipEmptyReport>false</skipEmptyReport>
<format>html</format>
Expand Down
2 changes: 1 addition & 1 deletion src/it/MPMD-295-JDK13/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ under the License.
<failurePriority>4</failurePriority>
<printFailingErrors>true</printFailingErrors>
<targetJdk>${java.version}</targetJdk>
<sourceEncoding>UTF-8</sourceEncoding>
<inputEncoding>UTF-8</inputEncoding>
<minimumTokens>100</minimumTokens>
</configuration>
<executions>
Expand Down
2 changes: 1 addition & 1 deletion src/it/MPMD-302-JDK14/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ under the License.
<failurePriority>4</failurePriority>
<printFailingErrors>true</printFailingErrors>
<targetJdk>${java.version}</targetJdk>
<sourceEncoding>UTF-8</sourceEncoding>
<inputEncoding>UTF-8</inputEncoding>
<minimumTokens>100</minimumTokens>
</configuration>
<executions>
Expand Down
2 changes: 1 addition & 1 deletion src/it/MPMD-302-JDK15/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ under the License.
<failurePriority>4</failurePriority>
<printFailingErrors>true</printFailingErrors>
<targetJdk>${java.version}</targetJdk>
<sourceEncoding>UTF-8</sourceEncoding>
<inputEncoding>UTF-8</inputEncoding>
<minimumTokens>100</minimumTokens>
</configuration>
<executions>
Expand Down
2 changes: 1 addition & 1 deletion src/it/MPMD-304-toolchain-support/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ under the License.
<failOnViolation>false</failOnViolation>
<printFailingErrors>true</printFailingErrors>
<targetJdk>${java.version}</targetJdk>
<sourceEncoding>UTF-8</sourceEncoding>
<inputEncoding>UTF-8</inputEncoding>
<minimumTokens>10</minimumTokens>
</configuration>
<executions>
Expand Down
2 changes: 1 addition & 1 deletion src/it/MPMD-312-JDK16/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ under the License.
<failurePriority>4</failurePriority>
<printFailingErrors>true</printFailingErrors>
<targetJdk>${java.version}</targetJdk>
<sourceEncoding>UTF-8</sourceEncoding>
<inputEncoding>UTF-8</inputEncoding>
<minimumTokens>100</minimumTokens>
</configuration>
<executions>
Expand Down
2 changes: 1 addition & 1 deletion src/it/MPMD-312-JDK17/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ under the License.
<failurePriority>4</failurePriority>
<printFailingErrors>true</printFailingErrors>
<targetJdk>${java.version}</targetJdk>
<sourceEncoding>UTF-8</sourceEncoding>
<inputEncoding>UTF-8</inputEncoding>
<minimumTokens>100</minimumTokens>
</configuration>
<executions>
Expand Down
2 changes: 1 addition & 1 deletion src/it/MPMD-332-JDK18/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ under the License.
<failurePriority>4</failurePriority>
<printFailingErrors>true</printFailingErrors>
<targetJdk>${java.version}</targetJdk>
<sourceEncoding>UTF-8</sourceEncoding>
<inputEncoding>UTF-8</inputEncoding>
<minimumTokens>100</minimumTokens>
</configuration>
<executions>
Expand Down
2 changes: 1 addition & 1 deletion src/it/MPMD-348-JDK19/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ under the License.
<failurePriority>4</failurePriority>
<printFailingErrors>true</printFailingErrors>
<targetJdk>${java.version}</targetJdk>
<sourceEncoding>UTF-8</sourceEncoding>
<inputEncoding>UTF-8</inputEncoding>
<minimumTokens>100</minimumTokens>
</configuration>
<executions>
Expand Down
2 changes: 1 addition & 1 deletion src/it/empty-rulesets/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ under the License.
<failOnViolation>true</failOnViolation>
<failurePriority>4</failurePriority>
<targetJdk>1.7</targetJdk>
<sourceEncoding>UTF-8</sourceEncoding>
<inputEncoding>UTF-8</inputEncoding>
<minimumTokens>100</minimumTokens>
<excludes>
<exclude>**/*Bean.java</exclude>
Expand Down
2 changes: 1 addition & 1 deletion src/it/mpmd-168-empty-report/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ under the License.
<configuration>
<verbose>true</verbose>
<minimumTokens>25</minimumTokens>
<sourceEncoding>UTF-8</sourceEncoding>
<inputEncoding>UTF-8</inputEncoding>
<failOnViolation>false</failOnViolation> <!-- force execution of both goals, will be checked with verify-script -->
<skipPmdError>false</skipPmdError>
<!-- <skipEmptyReport>false</skipEmptyReport> skipEmptyReport is false by default since 3.13.0 -->
Expand Down
2 changes: 1 addition & 1 deletion src/it/mpmd-168/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ under the License.
<configuration>
<verbose>true</verbose>
<minimumTokens>25</minimumTokens>
<sourceEncoding>UTF-8</sourceEncoding>
<inputEncoding>UTF-8</inputEncoding>
<failOnViolation>false</failOnViolation> <!-- force execution of both goals, will be checked with verify-script -->
<skipPmdError>false</skipPmdError>
<skipEmptyReport>true</skipEmptyReport>
Expand Down
67 changes: 2 additions & 65 deletions src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import org.apache.maven.toolchain.ToolchainManager;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.PathTool;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;

import net.sourceforge.pmd.PMDVersion;
Expand All @@ -73,14 +72,6 @@ public abstract class AbstractPmdReport
@Parameter( property = "project.build.directory", required = true )
protected File targetDirectory;

/**
* The output directory for the final HTML report. Note that this parameter is only evaluated if the goal is run
* directly from the command line or during the default lifecycle. If the goal is run indirectly as part of a site
* generation, the output directory configured in the Maven Site Plugin is used instead.
*/
@Parameter( property = "project.reporting.outputDirectory", required = true )
protected File outputDirectory;

/**
* Set the output format type, in addition to the HTML report. Must be one of: "none", "csv", "xml", "txt" or the
* full class name of the PMD renderer to use. See the net.sourceforge.pmd.renderers package javadoc for available
Expand Down Expand Up @@ -172,22 +163,6 @@ public abstract class AbstractPmdReport
@Deprecated
protected boolean aggregate;

/**
* The file encoding to use when reading the Java sources.
*
* @since 2.3
*/
@Parameter( property = "encoding", defaultValue = "${project.build.sourceEncoding}" )
private String sourceEncoding;

/**
* The file encoding when writing non-HTML reports.
*
* @since 2.5
*/
@Parameter( property = "outputEncoding", defaultValue = "${project.reporting.outputEncoding}" )
private String outputEncoding;

/**
* Whether to include the xml files generated by PMD/CPD in the site.
*
Expand Down Expand Up @@ -271,12 +246,6 @@ public abstract class AbstractPmdReport
// Read-only parameters
// ----------------------------------------------------------------------

/**
* The project to analyse.
*/
@Parameter( defaultValue = "${project}", readonly = true, required = true )
protected MavenProject project;

/**
* The projects in the reactor for aggregation report.
*/
Expand All @@ -290,12 +259,6 @@ public abstract class AbstractPmdReport
@Parameter( defaultValue = "${session}", required = true, readonly = true )
protected MavenSession session;

/**
* Site rendering component for generating the HTML report.
*/
@Component
private Renderer siteRenderer;

@Component
private ToolchainManager toolchainManager;

Expand Down Expand Up @@ -588,32 +551,6 @@ public boolean canGenerateReport()
return true;
}

/**
* {@inheritDoc}
*/
@Override
protected String getOutputDirectory()
{
return outputDirectory.getAbsolutePath();
}

protected String getSourceEncoding()
{
return sourceEncoding;
}

/**
* Gets the effective reporting output files encoding.
*
* @return The effective reporting output file encoding, never <code>null</code>.
* @since 2.5
*/
@Override
protected String getOutputEncoding()
{
return ( outputEncoding != null ) ? outputEncoding : ReaderFactory.UTF_8;
}

protected String determineCurrentRootLogLevel()
{
String logLevel = System.getProperty( "org.slf4j.simpleLogger.defaultLogLevel" );
Expand Down Expand Up @@ -694,9 +631,9 @@ protected Collection<MavenProject> getAggregatedProjects()

/**
* Recursively add the modules of the aggregatedProject to the set of aggregatedModules.
*
*
* @param aggregatedProject the project being aggregated
* @param reactorProjectsMap map of (still) available reactor projects
* @param reactorProjectsMap map of (still) available reactor projects
* @throws MavenReportException if any
*/
private Set<MavenProject> modulesForAggregatedProject( MavenProject aggregatedProject,
Expand Down
36 changes: 8 additions & 28 deletions src/main/java/org/apache/maven/plugins/pmd/CpdReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,36 +134,16 @@ public String getDescription( Locale locale )
public void executeReport( Locale locale )
throws MavenReportException
{
ClassLoader origLoader = Thread.currentThread().getContextClassLoader();
try
{
execute( locale );
Thread.currentThread().setContextClassLoader( this.getClass().getClassLoader() );

generateMavenSiteReport( locale );
}
finally
{
if ( getSink() != null )
{
getSink().close();
}
}
}

private void execute( Locale locale )
throws MavenReportException
{
if ( !skip && canGenerateReport() )
{
ClassLoader origLoader = Thread.currentThread().getContextClassLoader();
try
{
Thread.currentThread().setContextClassLoader( this.getClass().getClassLoader() );

generateMavenSiteReport( locale );
}
finally
{
Thread.currentThread().setContextClassLoader( origLoader );
}

Thread.currentThread().setContextClassLoader( origLoader );
}
}

Expand Down Expand Up @@ -257,7 +237,7 @@ private void executeCpd()
}
catch ( UnsupportedEncodingException e )
{
throw new MavenReportException( "Encoding '" + getSourceEncoding() + "' is not supported.", e );
throw new MavenReportException( "Encoding '" + getInputEncoding() + "' is not supported.", e );
}
catch ( IOException e )
{
Expand All @@ -276,10 +256,10 @@ private String determineEncoding( boolean showWarn )
throws UnsupportedEncodingException
{
String encoding = WriterFactory.FILE_ENCODING;
if ( StringUtils.isNotEmpty( getSourceEncoding() ) )
if ( StringUtils.isNotEmpty( getInputEncoding() ) )
{

encoding = getSourceEncoding();
encoding = getInputEncoding();
// test encoding as CPD will convert exception into a RuntimeException
WriterFactory.newWriter( new ByteArrayOutputStream(), encoding );

Expand Down

0 comments on commit 8c71996

Please sign in to comment.