You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2023/11/16 21:44:30 UTC

(maven-checkstyle-plugin) branch doxia-2.0.0 updated (6769305 -> 4e82254)

This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a change to branch doxia-2.0.0
in repository https://gitbox.apache.org/repos/asf/maven-checkstyle-plugin.git


 discard 6769305  Dynamically calculate xrefLocation/xrefTestLocation
     new 4e82254  Dynamically calculate xrefLocation/xrefTestLocation

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (6769305)
            \
             N -- N -- N   refs/heads/doxia-2.0.0 (4e82254)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../maven/plugins/checkstyle/AbstractCheckstyleReport.java     | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)


(maven-checkstyle-plugin) 01/01: Dynamically calculate xrefLocation/xrefTestLocation

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch doxia-2.0.0
in repository https://gitbox.apache.org/repos/asf/maven-checkstyle-plugin.git

commit 4e82254bfadd4c33fa70961bf2e91d77fd2f55c9
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Thu Nov 16 21:03:29 2023 +0100

    Dynamically calculate xrefLocation/xrefTestLocation
    
    @kriegaex
---
 .../checkstyle/AbstractCheckstyleReport.java       | 103 +++++++++++----------
 .../checkstyle/CheckstyleReportRenderer.java       |  32 ++-----
 2 files changed, 64 insertions(+), 71 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleReport.java b/src/main/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleReport.java
index a1d2257..b28444e 100644
--- a/src/main/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleReport.java
+++ b/src/main/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleReport.java
@@ -26,6 +26,7 @@ import java.io.IOException;
 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;
@@ -41,6 +42,7 @@ import org.apache.maven.model.Dependency;
 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;
@@ -345,8 +347,8 @@ 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
      */
@@ -354,15 +356,19 @@ public abstract class AbstractCheckstyleReport extends AbstractMavenReport {
     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;
 
     /**
@@ -482,6 +488,45 @@ public abstract class AbstractCheckstyleReport extends AbstractMavenReport {
         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");
@@ -527,6 +572,7 @@ public abstract class AbstractCheckstyleReport extends AbstractMavenReport {
 
             CheckstyleResults results = checkstyleExecutor.executeCheckstyle(request);
 
+            boolean haveResults = results.getFileCount() > 0;
             CheckstyleReportRenderer r = new CheckstyleReportRenderer(
                     getSink(),
                     i18n,
@@ -534,23 +580,13 @@ public abstract class AbstractCheckstyleReport extends AbstractMavenReport {
                     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);
             }
@@ -675,24 +711,6 @@ public abstract class AbstractCheckstyleReport extends AbstractMavenReport {
         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());
@@ -703,17 +721,6 @@ public abstract class AbstractCheckstyleReport extends AbstractMavenReport {
         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());
diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReportRenderer.java b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReportRenderer.java
index b1dd166..3e985fb 100644
--- a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReportRenderer.java
+++ b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReportRenderer.java
@@ -69,7 +69,7 @@ public class CheckstyleReportRenderer extends AbstractMavenReportRenderer {
 
     private String xrefTestLocation;
 
-    private List<File> testSourceDirectories = new ArrayList<>();
+    private List<File> testSourceDirectories;
 
     private List<String> treeWalkerNames = Collections.singletonList("TreeWalker");
 
@@ -84,6 +84,9 @@ public class CheckstyleReportRenderer extends AbstractMavenReportRenderer {
             MavenProject project,
             SiteTool siteTool,
             String ruleset,
+            String xrefLocation,
+            String xrefTestLocation,
+            List<File> testSourceDirectories,
             boolean enableRulesSummary,
             boolean enableSeveritySummary,
             boolean enableFilesSummary,
@@ -94,6 +97,9 @@ public class CheckstyleReportRenderer extends AbstractMavenReportRenderer {
         this.project = project;
         this.siteTool = siteTool;
         this.ruleset = ruleset;
+        this.xrefLocation = xrefLocation;
+        this.xrefTestLocation = xrefTestLocation;
+        this.testSourceDirectories = testSourceDirectories;
         this.enableRulesSummary = enableRulesSummary;
         this.enableSeveritySummary = enableSeveritySummary;
         this.enableFilesSummary = enableFilesSummary;
@@ -541,9 +547,9 @@ public class CheckstyleReportRenderer extends AbstractMavenReportRenderer {
     private String getEffectiveXrefLocation(List<AuditEvent> eventList) {
         String absoluteFilename = eventList.get(0).getFileName();
         if (isTestSource(absoluteFilename)) {
-            return getXrefTestLocation();
+            return xrefTestLocation;
         } else {
-            return getXrefLocation();
+            return xrefLocation;
         }
     }
 
@@ -557,26 +563,6 @@ public class CheckstyleReportRenderer extends AbstractMavenReportRenderer {
         return false;
     }
 
-    public String getXrefLocation() {
-        return xrefLocation;
-    }
-
-    public void setXrefLocation(String xrefLocation) {
-        this.xrefLocation = xrefLocation;
-    }
-
-    public String getXrefTestLocation() {
-        return xrefTestLocation;
-    }
-
-    public void setXrefTestLocation(String xrefTestLocation) {
-        this.xrefTestLocation = xrefTestLocation;
-    }
-
-    public void setTestSourceDirectories(List<File> testSourceDirectories) {
-        this.testSourceDirectories = testSourceDirectories;
-    }
-
     public void setTreeWalkerNames(List<String> treeWalkerNames) {
         this.treeWalkerNames = treeWalkerNames;
     }