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 2024/08/18 19:32:06 UTC
(maven-checkstyle-plugin) branch doxia-2.0.0 updated (42c3d47 -> c1a3bfa)
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
omit 42c3d47 [MCHECKSTYLE-446] Dynamically calculate xrefLocation/xrefTestLocation
omit a03c6bd [MCHECKSTYLE-445] Upgrade to Doxia 2.0.0 Milestone Stack
new 40bb0b2 [MCHECKSTYLE-445] Upgrade to Doxia 2.0.0 Milestone Stack
new c1a3bfa [MCHECKSTYLE-446] 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 (42c3d47)
\
N -- N -- N refs/heads/doxia-2.0.0 (c1a3bfa)
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 2 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:
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(maven-checkstyle-plugin) 01/02: [MCHECKSTYLE-445] Upgrade to Doxia 2.0.0 Milestone Stack
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 40bb0b2edf48d2fc0557580bbdbbfabe2ad42a04
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Sat Dec 3 00:59:34 2022 +0100
[MCHECKSTYLE-445] Upgrade to Doxia 2.0.0 Milestone Stack
This closes #114
---
pom.xml | 12 +++---
src/it/MCHECKSTYLE-222-resources/verify.groovy | 2 +-
src/it/MCHECKSTYLE-222-testResources/verify.groovy | 2 +-
src/it/MCHECKSTYLE-338/verify.groovy | 4 +-
.../MCHECKSTYLE-412/src/main/java/org/MyClass.java | 26 ------------
.../verify.groovy | 8 ++--
src/it/MCHECKSTYLE-99/verify.groovy | 8 ++--
src/it/checkstyle-goal/verify.groovy | 2 +-
.../checkstyle/AbstractCheckstyleReport.java | 9 ++++
.../checkstyle/CheckstyleAggregateReport.java | 17 --------
.../maven/plugins/checkstyle/CheckstyleReport.java | 7 ----
.../checkstyle/AbstractCheckstyleTestCase.java | 49 +++++++++++++++-------
.../plugins/checkstyle/CheckstyleReportTest.java | 20 +++++----
.../checkstyle/stubs/CheckstyleProjectStub.java | 23 ++++++++++
.../checkstyle/stubs/MinMavenProjectStub.java | 17 ++++----
.../checkstyle/stubs/ModuleMavenProjectStub.java | 21 ++++------
.../checkstyle/stubs/MultiMavenProjectStub.java | 11 ++---
.../plugin-configs/custom-plugin-config.xml | 1 -
.../dep-resolution-exception-plugin-config.xml | 1 -
.../resources/plugin-configs/min-plugin-config.xml | 1 -
.../plugin-configs/no-files-plugin-config.xml | 1 -
.../plugin-configs/no-rules-plugin-config.xml | 1 -
.../plugin-configs/no-severity-plugin-config.xml | 1 -
.../test-source-directory-plugin-config.xml | 1 -
.../plugin-configs/useFile-plugin-config.xml | 1 -
25 files changed, 116 insertions(+), 130 deletions(-)
diff --git a/pom.xml b/pom.xml
index 3d0abfb..a49b94b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -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>
@@ -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 -->
diff --git a/src/it/MCHECKSTYLE-222-resources/verify.groovy b/src/it/MCHECKSTYLE-222-resources/verify.groovy
index db588b9..0d9ff04 100644
--- a/src/it/MCHECKSTYLE-222-resources/verify.groovy
+++ b/src/it/MCHECKSTYLE-222-resources/verify.groovy
@@ -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;
diff --git a/src/it/MCHECKSTYLE-222-testResources/verify.groovy b/src/it/MCHECKSTYLE-222-testResources/verify.groovy
index db588b9..0d9ff04 100644
--- a/src/it/MCHECKSTYLE-222-testResources/verify.groovy
+++ b/src/it/MCHECKSTYLE-222-testResources/verify.groovy
@@ -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;
diff --git a/src/it/MCHECKSTYLE-338/verify.groovy b/src/it/MCHECKSTYLE-338/verify.groovy
index 71b05da..6c606b9 100644
--- a/src/it/MCHECKSTYLE-338/verify.groovy
+++ b/src/it/MCHECKSTYLE-338/verify.groovy
@@ -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' )
diff --git a/src/it/MCHECKSTYLE-412/src/main/java/org/MyClass.java b/src/it/MCHECKSTYLE-412/src/main/java/org/MyClass.java
deleted file mode 100644
index 1645c13..0000000
--- a/src/it/MCHECKSTYLE-412/src/main/java/org/MyClass.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package org;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/**
- * My class.
- */
-public class MyClass {
-}
diff --git a/src/it/MCHECKSTYLE-99-custom-xref-test-location/verify.groovy b/src/it/MCHECKSTYLE-99-custom-xref-test-location/verify.groovy
index c0e8435..e15f882 100644
--- a/src/it/MCHECKSTYLE-99-custom-xref-test-location/verify.groovy
+++ b/src/it/MCHECKSTYLE-99-custom-xref-test-location/verify.groovy
@@ -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;
diff --git a/src/it/MCHECKSTYLE-99/verify.groovy b/src/it/MCHECKSTYLE-99/verify.groovy
index 1567552..fc04c77 100644
--- a/src/it/MCHECKSTYLE-99/verify.groovy
+++ b/src/it/MCHECKSTYLE-99/verify.groovy
@@ -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;
diff --git a/src/it/checkstyle-goal/verify.groovy b/src/it/checkstyle-goal/verify.groovy
index 9cdc38c..22a61c4 100644
--- a/src/it/checkstyle-goal/verify.groovy
+++ b/src/it/checkstyle-goal/verify.groovy
@@ -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;
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 e86b6d9..23593ef 100644
--- a/src/main/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleReport.java
+++ b/src/main/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleReport.java
@@ -50,6 +50,7 @@ import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutor;
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;
@@ -474,6 +475,14 @@ public abstract class AbstractCheckstyleReport extends AbstractMavenReport {
return i18n.getString("checkstyle-report", locale, "report.checkstyle." + key);
}
+ protected MavenProject getProject() {
+ return project;
+ }
+
+ protected List<MavenProject> getReactorProjects() {
+ return reactorProjects;
+ }
+
/** {@inheritDoc} */
public void executeReport(Locale locale) throws MavenReportException {
checkDeprecatedParameterUsage(sourceDirectory, "sourceDirectory", "sourceDirectories");
diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleAggregateReport.java b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleAggregateReport.java
index 0419d28..232e248 100644
--- a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleAggregateReport.java
+++ b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleAggregateReport.java
@@ -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;
/**
@@ -40,19 +36,6 @@ import org.apache.maven.reporting.MavenReportException;
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}
*/
diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReport.java b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReport.java
index 15f16e0..ed575f4 100644
--- a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReport.java
+++ b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReport.java
@@ -25,7 +25,6 @@ import org.apache.maven.model.Resource;
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;
/**
@@ -39,12 +38,6 @@ import org.apache.maven.reporting.MavenReportException;
*/
@Mojo(name = "checkstyle", requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true)
public class CheckstyleReport extends AbstractCheckstyleReport {
-
- /** {@inheritDoc} */
- protected MavenProject getProject() {
- return project;
- }
-
/**
* {@inheritDoc}
*/
diff --git a/src/test/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleTestCase.java b/src/test/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleTestCase.java
index 9db52c9..7aaa6fd 100644
--- a/src/test/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleTestCase.java
+++ b/src/test/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleTestCase.java
@@ -21,9 +21,14 @@ package org.apache.maven.plugins.checkstyle;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
-import java.util.Locale;
+import java.util.Collections;
+import java.util.List;
+import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.LegacySupport;
+import org.apache.maven.plugin.MojoExecution;
+import org.apache.maven.plugin.descriptor.MojoDescriptor;
+import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.plugin.testing.ArtifactStubFactory;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
@@ -39,8 +44,6 @@ import org.eclipse.aether.repository.LocalRepository;
* Abstract class to test reports generation.
*/
public abstract class AbstractCheckstyleTestCase extends AbstractMojoTestCase {
- private Locale oldLocale;
-
private ArtifactStubFactory artifactStubFactory;
/**
@@ -53,21 +56,10 @@ public abstract class AbstractCheckstyleTestCase extends AbstractMojoTestCase {
// required for mojo lookups to work
super.setUp();
- oldLocale = Locale.getDefault();
- Locale.setDefault(Locale.ENGLISH);
-
artifactStubFactory = new DependencyArtifactStubFactory(getTestFile("target"), true, false);
artifactStubFactory.getWorkingDir().mkdirs();
}
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
-
- Locale.setDefault(oldLocale);
- oldLocale = null;
- }
-
/**
* Get the current Maven project
*
@@ -121,8 +113,17 @@ public abstract class AbstractCheckstyleTestCase extends AbstractMojoTestCase {
repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
.newInstance(repoSession, new LocalRepository(artifactStubFactory.getWorkingDir())));
+ List<MavenProject> reactorProjects =
+ mojo.getReactorProjects() != null ? mojo.getReactorProjects() : Collections.emptyList();
+
+ setVariableValueToObject(mojo, "mojoExecution", getMockMojoExecution());
setVariableValueToObject(mojo, "session", legacySupport.getSession());
- setVariableValueToObject(mojo, "remoteRepositories", mojo.getProject().getRemoteArtifactRepositories());
+ setVariableValueToObject(mojo, "repoSession", legacySupport.getRepositorySession());
+ setVariableValueToObject(mojo, "reactorProjects", reactorProjects);
+ setVariableValueToObject(
+ mojo, "remoteProjectRepositories", mojo.getProject().getRemoteProjectRepositories());
+ setVariableValueToObject(
+ mojo, "siteDirectory", new File(mojo.getProject().getBasedir(), "src/site"));
return mojo;
}
@@ -148,4 +149,22 @@ public abstract class AbstractCheckstyleTestCase extends AbstractMojoTestCase {
protected String readFile(File checkstyleTestDir, String fileName) throws IOException {
return new String(Files.readAllBytes(checkstyleTestDir.toPath().resolve(fileName)));
}
+
+ private MojoExecution getMockMojoExecution() {
+ MojoDescriptor md = new MojoDescriptor();
+ md.setGoal(getGoal());
+
+ MojoExecution me = new MojoExecution(md);
+
+ PluginDescriptor pd = new PluginDescriptor();
+ Plugin p = new Plugin();
+ p.setGroupId("org.apache.maven.plugins");
+ p.setArtifactId("maven-checkstyle-plugin");
+ pd.setPlugin(p);
+ md.setPluginDescriptor(pd);
+
+ return me;
+ }
+
+ protected abstract String getGoal();
}
diff --git a/src/test/java/org/apache/maven/plugins/checkstyle/CheckstyleReportTest.java b/src/test/java/org/apache/maven/plugins/checkstyle/CheckstyleReportTest.java
index 1326330..038839b 100644
--- a/src/test/java/org/apache/maven/plugins/checkstyle/CheckstyleReportTest.java
+++ b/src/test/java/org/apache/maven/plugins/checkstyle/CheckstyleReportTest.java
@@ -22,10 +22,10 @@ import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
-import java.util.Locale;
import java.util.ResourceBundle;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.apache.maven.doxia.tools.SiteTool;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.codehaus.plexus.util.FileUtils;
@@ -35,11 +35,8 @@ import org.codehaus.plexus.util.FileUtils;
*/
public class CheckstyleReportTest extends AbstractCheckstyleTestCase {
public void testNoSource() throws Exception {
- // clean up after earlier runs
- File report = new File("target/test-harness/checkstyle/no-source/checkstyle.html");
- report.delete();
- File generatedReport = generateReport("checkstyle", "no-source-plugin-config.xml");
- assertFalse(report + " exists", generatedReport.exists());
+ File generatedReport = generateReport(getGoal(), "no-source-plugin-config.xml");
+ assertFalse(FileUtils.fileExists(generatedReport.getAbsolutePath()));
}
public void testMinConfiguration() throws Exception {
@@ -117,9 +114,9 @@ public class CheckstyleReportTest extends AbstractCheckstyleTestCase {
private void generateReport(String pluginXml) throws Exception {
File pluginXmlFile = new File(getBasedir(), "src/test/resources/plugin-configs/" + pluginXml);
ResourceBundle bundle =
- ResourceBundle.getBundle("checkstyle-report", Locale.getDefault(), this.getClassLoader());
+ ResourceBundle.getBundle("checkstyle-report", SiteTool.DEFAULT_LOCALE, this.getClassLoader());
- CheckstyleReport mojo = createReportMojo("checkstyle", pluginXmlFile);
+ CheckstyleReport mojo = createReportMojo(getGoal(), pluginXmlFile);
PluginDescriptor descriptorStub = new PluginDescriptor();
descriptorStub.setGroupId("org.apache.maven.plugins");
@@ -173,6 +170,11 @@ public class CheckstyleReportTest extends AbstractCheckstyleTestCase {
}
private static String getHtmlHeader(String s) {
- return ">" + s + "</h3>";
+ return ">" + s + "</h2>";
+ }
+
+ @Override
+ protected String getGoal() {
+ return "checkstyle";
}
}
diff --git a/src/test/java/org/apache/maven/plugins/checkstyle/stubs/CheckstyleProjectStub.java b/src/test/java/org/apache/maven/plugins/checkstyle/stubs/CheckstyleProjectStub.java
index 82e3d04..f85404b 100644
--- a/src/test/java/org/apache/maven/plugins/checkstyle/stubs/CheckstyleProjectStub.java
+++ b/src/test/java/org/apache/maven/plugins/checkstyle/stubs/CheckstyleProjectStub.java
@@ -18,16 +18,34 @@
*/
package org.apache.maven.plugins.checkstyle.stubs;
+import java.io.File;
import java.util.Collections;
import java.util.List;
+import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.MavenArtifactRepository;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+import org.eclipse.aether.repository.RemoteRepository;
public abstract class CheckstyleProjectStub extends MavenProjectStub {
+ /**
+ * @return the POM file name
+ */
+ protected abstract String getPOM();
+
+ @Override
+ public File getBasedir() {
+ return new File(super.getBasedir() + "/src/test/resources/plugin-configs/");
+ }
+
+ @Override
+ public File getFile() {
+ return new File(getBasedir(), getPOM());
+ }
+
@Override
public List<ArtifactRepository> getRemoteArtifactRepositories() {
ArtifactRepository repository = new MavenArtifactRepository(
@@ -39,4 +57,9 @@ public abstract class CheckstyleProjectStub extends MavenProjectStub {
return Collections.singletonList(repository);
}
+
+ @Override
+ public List<RemoteRepository> getRemoteProjectRepositories() {
+ return RepositoryUtils.toRepos(getRemoteArtifactRepositories());
+ }
}
diff --git a/src/test/java/org/apache/maven/plugins/checkstyle/stubs/MinMavenProjectStub.java b/src/test/java/org/apache/maven/plugins/checkstyle/stubs/MinMavenProjectStub.java
index a9bb6ca..1dcaa0c 100644
--- a/src/test/java/org/apache/maven/plugins/checkstyle/stubs/MinMavenProjectStub.java
+++ b/src/test/java/org/apache/maven/plugins/checkstyle/stubs/MinMavenProjectStub.java
@@ -18,7 +18,6 @@
*/
package org.apache.maven.plugins.checkstyle.stubs;
-import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -41,19 +40,19 @@ public class MinMavenProjectStub extends CheckstyleProjectStub {
/** {@inheritDoc} */
public List<String> getTestClasspathElements() throws DependencyResolutionRequiredException {
List<String> list = new ArrayList<>(getCompileClasspathElements());
- list.add("target/test-classes");
+ list.add(getBasedir() + "/target/test-classes");
return list;
}
/** {@inheritDoc} */
public List<String> getCompileSourceRoots() {
- return Collections.singletonList("target/classes");
+ return Collections.singletonList(getBasedir() + "/target/classes");
}
/** {@inheritDoc} */
public List<String> getTestCompileSourceRoots() {
List<String> list = new ArrayList<>(getCompileSourceRoots());
- list.add("target/test-classes");
+ list.add(getBasedir() + "/target/test-classes");
return list;
}
@@ -84,15 +83,13 @@ public class MinMavenProjectStub extends CheckstyleProjectStub {
public Build getBuild() {
Build build = new Build();
- build.setDirectory("target/test-harness/checkstyle/min");
+ build.setDirectory(getBasedir() + "/target/test-harness/checkstyle/min");
return build;
}
- /** {@inheritDoc} */
- public File getFile() {
- File file = new File(getBasedir(), "pom.xml");
-
- return file;
+ @Override
+ protected String getPOM() {
+ return "min-plugin-config.xml";
}
}
diff --git a/src/test/java/org/apache/maven/plugins/checkstyle/stubs/ModuleMavenProjectStub.java b/src/test/java/org/apache/maven/plugins/checkstyle/stubs/ModuleMavenProjectStub.java
index 4279abf..4bc3136 100644
--- a/src/test/java/org/apache/maven/plugins/checkstyle/stubs/ModuleMavenProjectStub.java
+++ b/src/test/java/org/apache/maven/plugins/checkstyle/stubs/ModuleMavenProjectStub.java
@@ -18,7 +18,6 @@
*/
package org.apache.maven.plugins.checkstyle.stubs;
-import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -42,19 +41,19 @@ public class ModuleMavenProjectStub extends CheckstyleProjectStub {
/** {@inheritDoc} */
public List<String> getTestClasspathElements() throws DependencyResolutionRequiredException {
List<String> list = new ArrayList<>(getCompileClasspathElements());
- list.add("target/test-classes");
+ list.add(getBasedir() + "/target/test-classes");
return list;
}
/** {@inheritDoc} */
public List<String> getCompileSourceRoots() {
- return Collections.singletonList("target/classes");
+ return Collections.singletonList(getBasedir() + "/target/classes");
}
/** {@inheritDoc} */
public List<String> getTestCompileSourceRoots() {
List<String> list = new ArrayList<>(getCompileSourceRoots());
- list.add("target/test-classes");
+ list.add(getBasedir() + "/target/test-classes");
return list;
}
@@ -85,17 +84,15 @@ public class ModuleMavenProjectStub extends CheckstyleProjectStub {
public Build getBuild() {
Build build = new Build();
- build.setDirectory("target/test-harness/checkstyle/multi");
- build.setSourceDirectory("src/test/test-sources");
- build.setTestSourceDirectory("src/test/java");
+ build.setDirectory(getBasedir() + "/target/test-harness/checkstyle/multi");
+ build.setSourceDirectory(getBasedir() + "/src/test/test-sources");
+ build.setTestSourceDirectory(getBasedir() + "/src/test/java");
return build;
}
- /** {@inheritDoc} */
- public File getFile() {
- File file = new File(getBasedir(), "pom.xml");
-
- return file;
+ @Override
+ protected String getPOM() {
+ return "multi-plugin-config.xml";
}
}
diff --git a/src/test/java/org/apache/maven/plugins/checkstyle/stubs/MultiMavenProjectStub.java b/src/test/java/org/apache/maven/plugins/checkstyle/stubs/MultiMavenProjectStub.java
index a0c5f94..20790ee 100644
--- a/src/test/java/org/apache/maven/plugins/checkstyle/stubs/MultiMavenProjectStub.java
+++ b/src/test/java/org/apache/maven/plugins/checkstyle/stubs/MultiMavenProjectStub.java
@@ -18,7 +18,6 @@
*/
package org.apache.maven.plugins.checkstyle.stubs;
-import java.io.File;
import java.util.Collections;
import java.util.List;
@@ -89,15 +88,13 @@ public class MultiMavenProjectStub extends CheckstyleProjectStub {
public Build getBuild() {
Build build = new Build();
- build.setDirectory("target/test-harness/checkstyle/multi");
+ build.setDirectory(getBasedir() + "/target/test-harness/checkstyle/multi");
return build;
}
- /** {@inheritDoc} */
- public File getFile() {
- File file = new File(getBasedir(), "pom.xml");
-
- return file;
+ @Override
+ protected String getPOM() {
+ return "multi-plugin-config.xml";
}
}
diff --git a/src/test/resources/plugin-configs/custom-plugin-config.xml b/src/test/resources/plugin-configs/custom-plugin-config.xml
index 830a928..4d3703b 100644
--- a/src/test/resources/plugin-configs/custom-plugin-config.xml
+++ b/src/test/resources/plugin-configs/custom-plugin-config.xml
@@ -28,7 +28,6 @@ under the License.
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<outputDirectory>${basedir}/target/test-harness/checkstyle/custom</outputDirectory>
- <localRepository>${localRepository}</localRepository>
<enableRulesSummary>true</enableRulesSummary>
<enableSeveritySummary>true</enableSeveritySummary>
<enableFilesSummary>true</enableFilesSummary>
diff --git a/src/test/resources/plugin-configs/dep-resolution-exception-plugin-config.xml b/src/test/resources/plugin-configs/dep-resolution-exception-plugin-config.xml
index 7d1c8cb..aba1d2e 100644
--- a/src/test/resources/plugin-configs/dep-resolution-exception-plugin-config.xml
+++ b/src/test/resources/plugin-configs/dep-resolution-exception-plugin-config.xml
@@ -24,7 +24,6 @@ under the License.
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<outputDirectory>${basedir}/target/test-harness/checkstyle/dep-resolution</outputDirectory>
- <localRepository>${localRepository}</localRepository>
<enableRulesSummary>true</enableRulesSummary>
<enableSeveritySummary>true</enableSeveritySummary>
<enableFilesSummary>true</enableFilesSummary>
diff --git a/src/test/resources/plugin-configs/min-plugin-config.xml b/src/test/resources/plugin-configs/min-plugin-config.xml
index 1cb1e8e..b897fff 100644
--- a/src/test/resources/plugin-configs/min-plugin-config.xml
+++ b/src/test/resources/plugin-configs/min-plugin-config.xml
@@ -28,7 +28,6 @@ under the License.
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<outputDirectory>${basedir}/target/test-harness/checkstyle/min</outputDirectory>
- <localRepository>${localRepository}</localRepository>
<enableRulesSummary>true</enableRulesSummary>
<enableSeveritySummary>true</enableSeveritySummary>
<enableFilesSummary>true</enableFilesSummary>
diff --git a/src/test/resources/plugin-configs/no-files-plugin-config.xml b/src/test/resources/plugin-configs/no-files-plugin-config.xml
index 49061c7..d09c3a9 100644
--- a/src/test/resources/plugin-configs/no-files-plugin-config.xml
+++ b/src/test/resources/plugin-configs/no-files-plugin-config.xml
@@ -28,7 +28,6 @@ under the License.
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<outputDirectory>${basedir}/target/test-harness/checkstyle/no-files</outputDirectory>
- <localRepository>${localRepository}</localRepository>
<enableRulesSummary>true</enableRulesSummary>
<enableSeveritySummary>true</enableSeveritySummary>
<enableFilesSummary>false</enableFilesSummary>
diff --git a/src/test/resources/plugin-configs/no-rules-plugin-config.xml b/src/test/resources/plugin-configs/no-rules-plugin-config.xml
index a3795ed..60b4cd8 100644
--- a/src/test/resources/plugin-configs/no-rules-plugin-config.xml
+++ b/src/test/resources/plugin-configs/no-rules-plugin-config.xml
@@ -28,7 +28,6 @@ under the License.
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<outputDirectory>${basedir}/target/test-harness/checkstyle/no-rules</outputDirectory>
- <localRepository>${localRepository}</localRepository>
<enableRulesSummary>false</enableRulesSummary>
<enableSeveritySummary>true</enableSeveritySummary>
<enableFilesSummary>true</enableFilesSummary>
diff --git a/src/test/resources/plugin-configs/no-severity-plugin-config.xml b/src/test/resources/plugin-configs/no-severity-plugin-config.xml
index fb785b1..f65b18a 100644
--- a/src/test/resources/plugin-configs/no-severity-plugin-config.xml
+++ b/src/test/resources/plugin-configs/no-severity-plugin-config.xml
@@ -28,7 +28,6 @@ under the License.
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<outputDirectory>${basedir}/target/test-harness/checkstyle/no-severity</outputDirectory>
- <localRepository>${localRepository}</localRepository>
<enableRulesSummary>true</enableRulesSummary>
<enableSeveritySummary>false</enableSeveritySummary>
<enableFilesSummary>true</enableFilesSummary>
diff --git a/src/test/resources/plugin-configs/test-source-directory-plugin-config.xml b/src/test/resources/plugin-configs/test-source-directory-plugin-config.xml
index 9ca9d03..79cf03a 100644
--- a/src/test/resources/plugin-configs/test-source-directory-plugin-config.xml
+++ b/src/test/resources/plugin-configs/test-source-directory-plugin-config.xml
@@ -28,7 +28,6 @@ under the License.
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<outputDirectory>${basedir}/target/test-harness/checkstyle/no-source</outputDirectory>
- <localRepository>${localRepository}</localRepository>
<enableRulesSummary>true</enableRulesSummary>
<enableSeveritySummary>true</enableSeveritySummary>
<enableFilesSummary>true</enableFilesSummary>
diff --git a/src/test/resources/plugin-configs/useFile-plugin-config.xml b/src/test/resources/plugin-configs/useFile-plugin-config.xml
index f78464d..acb5ba3 100644
--- a/src/test/resources/plugin-configs/useFile-plugin-config.xml
+++ b/src/test/resources/plugin-configs/useFile-plugin-config.xml
@@ -28,7 +28,6 @@ under the License.
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<outputDirectory>${basedir}/target/test-harness/checkstyle/useFile</outputDirectory>
- <localRepository>${localRepository}</localRepository>
<enableRulesSummary>true</enableRulesSummary>
<enableSeveritySummary>true</enableSeveritySummary>
<enableFilesSummary>true</enableFilesSummary>
(maven-checkstyle-plugin) 02/02: [MCHECKSTYLE-446] 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 c1a3bfaa1ed1ae7e00f28dc1be0ae9a79c0c7776
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Thu Nov 16 21:03:29 2023 +0100
[MCHECKSTYLE-446] Dynamically calculate xrefLocation/xrefTestLocation
---
.../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 23593ef..0193c54 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;
@@ -42,6 +43,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;
@@ -346,8 +348,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
*/
@@ -355,15 +357,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;
/**
@@ -483,6 +489,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");
@@ -528,6 +573,7 @@ public abstract class AbstractCheckstyleReport extends AbstractMavenReport {
CheckstyleResults results = checkstyleExecutor.executeCheckstyle(request);
+ boolean haveResults = results.getFileCount() > 0;
CheckstyleReportRenderer r = new CheckstyleReportRenderer(
getSink(),
i18n,
@@ -535,23 +581,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);
}
@@ -682,24 +718,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());
@@ -710,17 +728,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 3db3497..8b47d6f 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;
@@ -542,9 +548,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;
}
}
@@ -558,26 +564,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;
}