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

[MCHECKSTYLE-445] Upgrade to Doxia 2.0.0 Milestone Stack #114

Merged
merged 2 commits into from
Aug 19, 2024
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
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ under the License.
<resolverVersion>1.4.1</resolverVersion>
<checkstyleVersion>9.3</checkstyleVersion>
<slf4jVersion>1.7.36</slf4jVersion>
<doxiaVersion>1.11.1</doxiaVersion>
<doxiaSitetoolsVersion>1.11.1</doxiaSitetoolsVersion>
<sitePluginVersion>3.12.1</sitePluginVersion>
<jxrPluginVersion>3.3.0</jxrPluginVersion>
<doxiaVersion>2.0.0-M12</doxiaVersion>
<doxiaSitetoolsVersion>2.0.0-M19</doxiaSitetoolsVersion>
<sitePluginVersion>3.20.0</sitePluginVersion>
<jxrPluginVersion>3.4.0</jxrPluginVersion>
<project.build.outputTimestamp>2024-06-02T14:45:45Z</project.build.outputTimestamp>
</properties>

Expand Down Expand Up @@ -132,12 +132,12 @@ under the License.
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-api</artifactId>
<version>3.1.1</version>
<version>4.0.0-M12</version>
</dependency>
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-impl</artifactId>
<version>3.2.0</version>
<version>4.0.0-M15</version>
</dependency>

<!-- doxia -->
Expand Down
2 changes: 1 addition & 1 deletion src/it/MCHECKSTYLE-222-resources/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
* under the License.
*/

assert new File(basedir, 'target/site/checkstyle.html').exists();
assert new File(basedir, 'target/reports/checkstyle.html').exists();

return true;
2 changes: 1 addition & 1 deletion src/it/MCHECKSTYLE-222-testResources/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
* under the License.
*/

assert new File(basedir, 'target/site/checkstyle.html').exists();
assert new File(basedir, 'target/reports/checkstyle.html').exists();

return true;
4 changes: 2 additions & 2 deletions src/it/MCHECKSTYLE-338/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ assert buildLog.text.contains( 'EmptyLogging: EmptyLoggingCheck on file TestFals
assert !buildLog.text.contains( 'EmptyLogging: EmptyLoggingCheck on file TestTrue.java' )

// verify that the "checkstyle" goal does the same
site = new File( basedir, 'omitignoredmodules-false/target/site/checkstyle.html' )
site = new File( basedir, 'omitignoredmodules-false/target/reports/checkstyle.html' )
assert site.text.contains( 'EmptyLoggingCheck on file TestFalse.java' )
site = new File( basedir, 'omitignoredmodules-true/target/site/checkstyle.html' )
site = new File( basedir, 'omitignoredmodules-true/target/reports/checkstyle.html' )
assert !site.text.contains( 'EmptyLoggingCheck on file TestTrue.java' )
26 changes: 0 additions & 26 deletions src/it/MCHECKSTYLE-412/src/main/java/org/MyClass.java

This file was deleted.

8 changes: 4 additions & 4 deletions src/it/MCHECKSTYLE-99-custom-xref-test-location/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
* under the License.
*/

site = new File( basedir, 'target/site/checkstyle.html' )
assert site.exists();
assert site.text.contains( '<a href="./xref/com/example/App.html#L26">' )
assert site.text.contains( '<a href="./custom-xref-test-location/com/example/AppTest.html#L32">' )
report = new File( basedir, 'target/reports/checkstyle.html' )
assert report.exists();
assert report.text.contains( '<a href="./xref/com/example/App.html#L26">' )
assert report.text.contains( '<a href="./custom-xref-test-location/com/example/AppTest.html#L32">' )

return true;
8 changes: 4 additions & 4 deletions src/it/MCHECKSTYLE-99/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
* under the License.
*/

site = new File( basedir, 'target/site/checkstyle.html' )
assert site.exists();
assert site.text.contains( '<a href="./xref/com/example/App.html#L26">' )
assert site.text.contains( '<a href="./xref-test/com/example/AppTest.html#L32">' )
report = new File( basedir, 'target/reports/checkstyle.html' )
assert report.exists();
assert report.text.contains( '<a href="./xref/com/example/App.html#L26">' )
assert report.text.contains( '<a href="./xref-test/com/example/AppTest.html#L32">' )

return true;
2 changes: 1 addition & 1 deletion src/it/checkstyle-goal/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ assert new File( basedir, 'target/checkstyle-checker.xml' ).exists();
assert new File( basedir, 'target/checkstyle-header.txt' ).exists();
assert new File( basedir, 'target/checkstyle-result.xml' ).exists();

def html = new File( basedir, 'target/site/checkstyle.html' ).text;
def html = new File( basedir, 'target/reports/checkstyle.html' ).text;
assert html.contains( '<meta charset="UTF-8" />' );

return true;
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.OutputStream;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand All @@ -42,6 +43,7 @@
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginManagement;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.Reporting;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugins.annotations.Component;
Expand All @@ -50,6 +52,7 @@
import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorException;
import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorRequest;
import org.apache.maven.plugins.checkstyle.exec.CheckstyleResults;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.AbstractMavenReport;
import org.apache.maven.reporting.MavenReportException;
import org.codehaus.plexus.configuration.PlexusConfiguration;
Expand Down Expand Up @@ -345,24 +348,28 @@ public abstract class AbstractCheckstyleReport extends AbstractMavenReport {
private PluginDescriptor plugin;

/**
* Link the violation line numbers to the source xref. Will link
* automatically if Maven JXR plugin is being used.
* Link the violation line numbers to the (Test) Source XRef. Links will be created automatically if the JXR plugin is
* being used.
*
* @since 2.1
*/
@Parameter(property = "linkXRef", defaultValue = "true")
private boolean linkXRef;

/**
* Location of the Xrefs to link to.
* Location where Source XRef is generated for this project.
* <br>
* <strong>Default</strong>: {@link #getReportOutputDirectory()} + {@code /xref}
*/
@Parameter(defaultValue = "${project.reporting.outputDirectory}/xref")
@Parameter
private File xrefLocation;

/**
* Location of the XrefTests to link to.
* Location where Test Source XRef is generated for this project.
* <br>
* <strong>Default</strong>: {@link #getReportOutputDirectory()} + {@code /xref-test}
*/
@Parameter(defaultValue = "${project.reporting.outputDirectory}/xref-test")
@Parameter
private File xrefTestLocation;

/**
Expand Down Expand Up @@ -474,6 +481,53 @@ protected String getI18nString(Locale locale, String key) {
return i18n.getString("checkstyle-report", locale, "report.checkstyle." + key);
}

protected MavenProject getProject() {
return project;
}

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

protected String constructXrefLocation(boolean test, boolean haveResults) {
String location = null;
if (linkXRef) {
File xrefLocation = getXrefLocation(test);

String relativePath = PathTool.getRelativePath(
getReportOutputDirectory().getAbsolutePath(), xrefLocation.getAbsolutePath());
if (relativePath == null || relativePath.isEmpty()) {
relativePath = ".";
}
relativePath = relativePath + "/" + xrefLocation.getName();
if (xrefLocation.exists()) {
// XRef was already generated by manual execution of a lifecycle binding
location = relativePath;
} else {
// Not yet generated - check if the report is on its way
Reporting reporting = project.getModel().getReporting();
List<ReportPlugin> reportPlugins =
reporting != null ? reporting.getPlugins() : Collections.<ReportPlugin>emptyList();
for (ReportPlugin plugin : reportPlugins) {
String artifactId = plugin.getArtifactId();
if ("maven-jxr-plugin".equals(artifactId) || "jxr-maven-plugin".equals(artifactId)) {
location = relativePath;
}
}
}

if (location == null && haveResults) {
getLog().warn("Unable to locate" + (test ? " Test" : "") + " Source XRef to link to - DISABLED");
}
}
return location;
}

protected File getXrefLocation(boolean test) {
File location = test ? xrefTestLocation : xrefLocation;
return location != null ? location : new File(getReportOutputDirectory(), test ? "xref-test" : "xref");
}

/** {@inheritDoc} */
public void executeReport(Locale locale) throws MavenReportException {
checkDeprecatedParameterUsage(sourceDirectory, "sourceDirectory", "sourceDirectories");
Expand Down Expand Up @@ -519,30 +573,21 @@ public void executeReport(Locale locale) throws MavenReportException {

CheckstyleResults results = checkstyleExecutor.executeCheckstyle(request);

boolean haveResults = results.getFileCount() > 0;
CheckstyleReportRenderer r = new CheckstyleReportRenderer(
getSink(),
i18n,
locale,
project,
siteTool,
effectiveConfigLocation,
constructXrefLocation(false, haveResults),
constructXrefLocation(true, haveResults),
linkXRef ? getTestSourceDirectories() : Collections.emptyList(),
enableRulesSummary,
enableSeveritySummary,
enableFilesSummary,
results);
if (linkXRef) {
initializeXrefLocation(r);
if (r.getXrefLocation() == null && results.getFileCount() > 0) {
getLog().warn("Unable to locate Source XRef to link to - DISABLED");
}

initializeXrefTestLocation(r);
if (r.getXrefTestLocation() == null && results.getFileCount() > 0) {
getLog().warn("Unable to locate Test Source XRef to link to - DISABLED");
}

r.setTestSourceDirectories(getTestSourceDirectories());
}
if (treeWalkerNames != null) {
r.setTreeWalkerNames(treeWalkerNames);
}
Expand Down Expand Up @@ -673,24 +718,6 @@ protected DefaultLogger getConsoleListener() throws MavenReportException {
return consoleListener;
}

private void initializeXrefLocation(CheckstyleReportRenderer renderer) {
String relativePath = determineRelativePath(xrefLocation);
if (xrefLocation.exists() || checkMavenJxrPluginIsConfigured()) {
// XRef was already generated by manual execution of a lifecycle binding
// the report is on its way
renderer.setXrefLocation(relativePath);
}
}

private void initializeXrefTestLocation(CheckstyleReportRenderer renderer) {
String relativePath = determineRelativePath(xrefTestLocation);
if (xrefTestLocation.exists() || checkMavenJxrPluginIsConfigured()) {
// XRef was already generated by manual execution of a lifecycle binding
// the report is on its way
renderer.setXrefTestLocation(relativePath);
}
}

private String determineRelativePath(File location) {
String relativePath =
PathTool.getRelativePath(getReportOutputDirectory().getAbsolutePath(), location.getAbsolutePath());
Expand All @@ -701,17 +728,6 @@ private String determineRelativePath(File location) {
return relativePath + "/" + location.getName();
}

private boolean checkMavenJxrPluginIsConfigured() {
for (ReportPlugin report : (Iterable<ReportPlugin>) getProject().getReportPlugins()) {
String artifactId = report.getArtifactId();
if ("maven-jxr-plugin".equals(artifactId) || "jxr-maven-plugin".equals(artifactId)) {
return true;
}
}

return false;
}

protected List<File> getSourceDirectories() {
if (sourceDirectories == null) {
sourceDirectories = filterBuildTarget(project.getCompileSourceRoots());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@
*/
package org.apache.maven.plugins.checkstyle;

import java.util.List;

import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorRequest;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.MavenReportException;

/**
Expand All @@ -40,19 +36,6 @@
requiresDependencyResolution = ResolutionScope.COMPILE,
threadSafe = true)
public class CheckstyleAggregateReport extends AbstractCheckstyleReport {
/**
* The projects in the reactor for aggregation report.
*
* @since 2.8
*/
@Parameter(property = "reactorProjects", readonly = true)
private List<MavenProject> reactorProjects;

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

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorRequest;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.MavenReportException;

/**
Expand All @@ -39,12 +38,6 @@
*/
@Mojo(name = "checkstyle", requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true)
public class CheckstyleReport extends AbstractCheckstyleReport {

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

/**
* {@inheritDoc}
*/
Expand Down
Loading