Skip to content

Commit

Permalink
Prepare for Doxia 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-o committed Mar 20, 2023
1 parent 0fbd7fd commit f2990e4
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 70 deletions.
50 changes: 12 additions & 38 deletions pom.xml
Expand Up @@ -30,7 +30,7 @@ under the License.
</parent>

<artifactId>maven-pmd-plugin</artifactId>
<version>3.21.0-SNAPSHOT</version>
<version>4.0.0-M1-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<name>Apache Maven PMD Plugin</name>
Expand Down Expand Up @@ -86,15 +86,14 @@ under the License.

<properties>
<mavenVersion>3.2.5</mavenVersion>
<doxiaVersion>1.12.0</doxiaVersion>
<doxiaSitetoolsVersion>1.11.1</doxiaSitetoolsVersion>
<doxiaVersion>2.0.0-M5</doxiaVersion>
<javaVersion>8</javaVersion><!-- Because PMD 6.35.0+ requires Java 8 -->
<pmdVersion>6.55.0</pmdVersion>
<slf4jVersion>1.7.36</slf4jVersion>
<aetherVersion>1.0.0.v20140518</aetherVersion>
<sitePluginVersion>3.12.1</sitePluginVersion>
<projectInfoReportsPluginVersion>3.4.1</projectInfoReportsPluginVersion>
<jxrPluginVersion>3.3.0</jxrPluginVersion>
<sitePluginVersion>4.0.0-M5</sitePluginVersion>
<projectInfoReportsPluginVersion>4.0.0-M1-SNAPSHOT</projectInfoReportsPluginVersion>
<jxrPluginVersion>4.0.0-M1-SNAPSHOT</jxrPluginVersion>
<project.build.outputTimestamp>2023-01-06T22:00:33Z</project.build.outputTimestamp>
</properties>

Expand All @@ -118,6 +117,12 @@ under the License.
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
Expand Down Expand Up @@ -191,43 +196,12 @@ under the License.
<artifactId>doxia-sink-api</artifactId>
<version>${doxiaVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-decoration-model</artifactId>
<version>${doxiaSitetoolsVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-site-renderer</artifactId>
<version>${doxiaSitetoolsVersion}</version>
<!--
Note: doxia-site-renderer needs to be defined AFTER pmd:
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.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-impl</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-shared-utils</artifactId>
<version>3.3.4</version>
<version>4.0.0-M4</version>
</dependency>

<!-- plexus -->
Expand Down
Expand Up @@ -245,12 +245,6 @@ public abstract class AbstractPmdReport
// Read-only parameters
// ----------------------------------------------------------------------

/**
* The projects in the reactor for aggregation report.
*/
@Parameter( property = "reactorProjects", readonly = true )
protected List<MavenProject> reactorProjects;

/**
* The current build session instance. This is used for
* toolchain manager API calls and for dependency resolver API calls.
Expand All @@ -264,15 +258,17 @@ public abstract class AbstractPmdReport
/** The files that are being analyzed. */
protected Map<File, PmdFileInfo> filesToProcess;

/**
* {@inheritDoc}
*/
@Override
protected MavenProject getProject()
{
return project;
}

protected List<MavenProject> getReactorProjects()
{
return reactorProjects;
}

protected String constructXRefLocation( boolean test )
{
String location = null;
Expand Down
Expand Up @@ -165,7 +165,7 @@ public void generate( List<Duplication> duplications )
String code = duplication.getCodefragment();

sink.table();
sink.tableRows( null, false );
sink.tableRows();
sink.tableRow();
sink.tableHeaderCell();
sink.text( bundle.getString( "report.cpd.column.file" ) );
Expand Down
Expand Up @@ -166,7 +166,7 @@ private void startFileSection( int level, String currentFilename, PmdFileInfo fi
sink.sectionTitle_( level );

sink.table();
sink.tableRows( null, false );
sink.tableRows();
sink.tableRow();
sink.tableHeaderCell();
sink.text( bundle.getString( "report.pmd.column.rule" ) );
Expand Down Expand Up @@ -408,7 +408,7 @@ public int compare( SuppressedViolation o1, SuppressedViolation o2 )
} );

sink.table();
sink.tableRows( null, false );
sink.tableRows();
sink.tableRow();
sink.tableHeaderCell();
sink.text( bundle.getString( "report.pmd.suppressedViolations.column.filename" ) );
Expand Down Expand Up @@ -475,7 +475,7 @@ public int compare( ProcessingError e1, ProcessingError e2 )
sink.sectionTitle1_();

sink.table();
sink.tableRows( null, false );
sink.tableRows();
sink.tableRow();
sink.tableHeaderCell();
sink.text( bundle.getString( "report.pmd.processingErrors.column.filename" ) );
Expand Down
Expand Up @@ -22,6 +22,8 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Collections;
import java.util.List;
import java.util.Locale;

import org.apache.maven.plugin.LegacySupport;
Expand Down Expand Up @@ -121,8 +123,12 @@ protected AbstractPmdReport createReportMojo( String goal, File pluginXmlFile )
(DefaultRepositorySystemSession) legacySupport.getRepositorySession();
repoSession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repoSession, new LocalRepository( artifactStubFactory.getWorkingDir() ) ) );

List<MavenProject> reactorProjects = mojo.getReactorProjects() != null ? mojo.getReactorProjects() : Collections.emptyList();

setVariableValueToObject( mojo, "session", legacySupport.getSession() );
setVariableValueToObject( mojo, "reactorProjects", reactorProjects );
setVariableValueToObject( mojo, "remoteRepositories", mojo.getProject().getRemoteArtifactRepositories() );
setVariableValueToObject( mojo, "siteDirectory", new File( mojo.getProject().getBasedir(), "src/site" ) );
return mojo;
}

Expand Down
2 changes: 0 additions & 2 deletions src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java
Expand Up @@ -23,7 +23,6 @@
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Locale;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
Expand All @@ -47,7 +46,6 @@ protected void setUp()
throws Exception
{
super.setUp();
Locale.setDefault( Locale.ENGLISH );
FileUtils.deleteDirectory( new File( getBasedir(), "target/test/unit" ) );
}

Expand Down
8 changes: 3 additions & 5 deletions src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
Expand Up @@ -26,7 +26,6 @@
import java.net.ServerSocket;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Locale;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -55,7 +54,6 @@ protected void setUp()
throws Exception
{
super.setUp();
Locale.setDefault( Locale.ENGLISH );
FileUtils.deleteDirectory( new File( getBasedir(), "target/test/unit" ) );
}

Expand Down Expand Up @@ -93,9 +91,9 @@ public void testDefaultConfiguration()
assertTrue( str.contains( "pmd_rules_java_bestpractices.html#unusedprivatefield\">UnusedPrivateField</a>" ) );

// there should be the section Violations By Priority
assertTrue( str.contains( "Violations By Priority</h2>" ) );
assertTrue( str.contains( "Priority 3</h3>" ) );
assertTrue( str.contains( "Priority 4</h3>" ) );
assertTrue( str.contains( "Violations By Priority</h1>" ) );
assertTrue( str.contains( "Priority 3</h2>" ) );
assertTrue( str.contains( "Priority 4</h2>" ) );
// the file App.java is mentioned 3 times: in prio 3, in prio 4 and in the files section
assertEquals( 3, StringUtils.countMatches( str, "def/configuration/App.java" ) );

Expand Down
Expand Up @@ -51,7 +51,7 @@ public CustomConfigurationMavenProjectStub()
{
model =
pomReader.read( new FileReader( new File( getBasedir()
+ "/src/test/resources/unit/custom-configuration/custom-configuration-plugin-config.xml" ) ) );
+ "/" + getPOM() ) ) );
setModel( model );
}
catch ( Exception e )
Expand All @@ -72,15 +72,15 @@ public CustomConfigurationMavenProjectStub()

Build build = new Build();
build.setFinalName( model.getBuild().getFinalName() );
build.setDirectory( getBasedir() + "/target/test/unit/custom-configuration/target" );
build.setSourceDirectory( getBasedir() + "/src/test/resources/unit/custom-configuration" );
build.setDirectory( getBasedir() + "/target" );
build.setSourceDirectory( getBasedir().getAbsolutePath() );
setBuild( build );

setReportPlugins( model.getReporting().getPlugins() );

String basedir = getBasedir().getAbsolutePath();
List<String> compileSourceRoots = new ArrayList<>();
compileSourceRoots.add( basedir + "/src/test/resources/unit/custom-configuration/custom/configuration" );
compileSourceRoots.add( basedir + "/custom/configuration" );
setCompileSourceRoots( compileSourceRoots );

Artifact artifact = new PmdPluginArtifactStub( getGroupId(), getArtifactId(), getVersion(), getPackaging() );
Expand Down Expand Up @@ -116,4 +116,14 @@ public List<ReportPlugin> getReportPlugins()
return reportPlugins;
}

@Override
public File getBasedir() {
return new File( super.getBasedir() + "/custom-configuration" );
}

@Override
protected String getPOM() {
return "custom-configuration-plugin-config.xml";
}

}
Expand Up @@ -48,7 +48,7 @@ public DefaultConfigurationMavenProjectStub()
Model model = null;

try ( FileReader reader = new FileReader( new File( getBasedir()
+ "/src/test/resources/unit/default-configuration/default-configuration-plugin-config.xml" ) ) )
+ "/" + getPOM() ) ) )
{
model = pomReader.read( reader );
setModel( model );
Expand All @@ -72,16 +72,16 @@ public DefaultConfigurationMavenProjectStub()
Build build = new Build();
build.setFinalName( model.getBuild()
.getFinalName() );
build.setDirectory( getBasedir() + "/target/test/unit/default-configuration/target" );
build.setSourceDirectory( getBasedir() + "/src/test/resources/unit/default-configuration" );
build.setDirectory( getBasedir() + "/target" );
build.setSourceDirectory( getBasedir().getAbsolutePath() );
setBuild( build );

setReportPlugins( model.getReporting()
.getPlugins() );

String basedir = getBasedir().getAbsolutePath();
List<String> compileSourceRoots = new ArrayList<>();
compileSourceRoots.add( basedir + "/src/test/resources/unit/default-configuration/def/configuration" );
compileSourceRoots.add( basedir + "/def/configuration" );
setCompileSourceRoots( compileSourceRoots );

File file = new File( getBasedir().getAbsolutePath() + "/pom.xml" );
Expand Down Expand Up @@ -118,4 +118,14 @@ public Build getBuild()
{
return build;
}

@Override
public File getBasedir() {
return new File( super.getBasedir() + "/default-configuration" );
}

@Override
protected String getPOM() {
return "default-configuration-plugin-config.xml";
}
}
Expand Up @@ -48,7 +48,7 @@ public InvalidFormatMavenProjectStub()
{
model =
pomReader.read( new FileReader( new File( getBasedir()
+ "/src/test/resources/unit/invalid-format/invalid-format-plugin-config.xml" ) ) );
+ "/" + getPOM() ) ) );
setModel( model );
}
catch ( Exception e )
Expand All @@ -69,13 +69,13 @@ public InvalidFormatMavenProjectStub()

Build build = new Build();
build.setFinalName( model.getBuild().getFinalName() );
build.setDirectory( getBasedir() + "/target/test/unit/invalid-format/target" );
build.setSourceDirectory( getBasedir() + "/src/test/resources/unit/invalid-format" );
build.setDirectory( getBasedir() + "/target" );
build.setSourceDirectory( getBasedir().getAbsolutePath() );
setBuild( build );

String basedir = getBasedir().getAbsolutePath();
List<String> compileSourceRoots = new ArrayList<>();
compileSourceRoots.add( basedir + "/src/test/resources/unit/invalid-format/invalid/format" );
compileSourceRoots.add( basedir + "/invalid/format" );
setCompileSourceRoots( compileSourceRoots );

Artifact artifact = new PmdPluginArtifactStub( getGroupId(), getArtifactId(), getVersion(), getPackaging() );
Expand All @@ -100,4 +100,14 @@ public Build getBuild()
return build;
}

@Override
public File getBasedir() {
return new File( super.getBasedir() + "/invalid-format" );
}

@Override
protected String getPOM() {
return "invalid-format-plugin-config.xml";
}

}
Expand Up @@ -19,6 +19,7 @@
* under the License.
*/

import java.io.File;
import java.util.Collections;
import java.util.List;

Expand All @@ -31,6 +32,23 @@
public abstract class PmdProjectStub
extends MavenProjectStub
{
/**
* @return the POM file name
*/
protected abstract String getPOM();

@Override
public File getBasedir()
{
return new File( super.getBasedir() + "/src/test/resources/unit/" );
}

@Override
public File getFile()
{
return new File( getBasedir(), getPOM() );
}

@Override
public List<ArtifactRepository> getRemoteArtifactRepositories()
{
Expand Down

0 comments on commit f2990e4

Please sign in to comment.