Skip to content

Commit 0e7bd00

Browse files
committed
[MCHECKSTYLE-445] Upgrade to Doxia 2.0.0 Milestone Stack
This closes #114
1 parent b92666d commit 0e7bd00

25 files changed

+116
-130
lines changed

Diff for: pom.xml

+6-6
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ under the License.
7878
<resolverVersion>1.4.1</resolverVersion>
7979
<checkstyleVersion>9.3</checkstyleVersion>
8080
<slf4jVersion>1.7.36</slf4jVersion>
81-
<doxiaVersion>1.11.1</doxiaVersion>
82-
<doxiaSitetoolsVersion>1.11.1</doxiaSitetoolsVersion>
83-
<sitePluginVersion>3.12.1</sitePluginVersion>
84-
<jxrPluginVersion>3.3.0</jxrPluginVersion>
81+
<doxiaVersion>2.0.0-M12</doxiaVersion>
82+
<doxiaSitetoolsVersion>2.0.0-M19</doxiaSitetoolsVersion>
83+
<sitePluginVersion>3.20.0</sitePluginVersion>
84+
<jxrPluginVersion>3.4.0</jxrPluginVersion>
8585
<project.build.outputTimestamp>2024-06-02T14:45:45Z</project.build.outputTimestamp>
8686
</properties>
8787

@@ -132,12 +132,12 @@ under the License.
132132
<dependency>
133133
<groupId>org.apache.maven.reporting</groupId>
134134
<artifactId>maven-reporting-api</artifactId>
135-
<version>3.1.1</version>
135+
<version>4.0.0-M12</version>
136136
</dependency>
137137
<dependency>
138138
<groupId>org.apache.maven.reporting</groupId>
139139
<artifactId>maven-reporting-impl</artifactId>
140-
<version>3.2.0</version>
140+
<version>4.0.0-M15</version>
141141
</dependency>
142142

143143
<!-- doxia -->

Diff for: src/it/MCHECKSTYLE-222-resources/verify.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
* under the License.
1818
*/
1919

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

2222
return true;

Diff for: src/it/MCHECKSTYLE-222-testResources/verify.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
* under the License.
1818
*/
1919

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

2222
return true;

Diff for: src/it/MCHECKSTYLE-338/verify.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ assert buildLog.text.contains( 'EmptyLogging: EmptyLoggingCheck on file TestFals
2525
assert !buildLog.text.contains( 'EmptyLogging: EmptyLoggingCheck on file TestTrue.java' )
2626

2727
// verify that the "checkstyle" goal does the same
28-
site = new File( basedir, 'omitignoredmodules-false/target/site/checkstyle.html' )
28+
site = new File( basedir, 'omitignoredmodules-false/target/reports/checkstyle.html' )
2929
assert site.text.contains( 'EmptyLoggingCheck on file TestFalse.java' )
30-
site = new File( basedir, 'omitignoredmodules-true/target/site/checkstyle.html' )
30+
site = new File( basedir, 'omitignoredmodules-true/target/reports/checkstyle.html' )
3131
assert !site.text.contains( 'EmptyLoggingCheck on file TestTrue.java' )

Diff for: src/it/MCHECKSTYLE-412/src/main/java/org/MyClass.java

-26
This file was deleted.

Diff for: src/it/MCHECKSTYLE-99-custom-xref-test-location/verify.groovy

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
* under the License.
1919
*/
2020

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

2626
return true;

Diff for: src/it/MCHECKSTYLE-99/verify.groovy

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
* under the License.
1919
*/
2020

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

2626
return true;

Diff for: src/it/checkstyle-goal/verify.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ assert new File( basedir, 'target/checkstyle-checker.xml' ).exists();
2424
assert new File( basedir, 'target/checkstyle-header.txt' ).exists();
2525
assert new File( basedir, 'target/checkstyle-result.xml' ).exists();
2626

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

3030
return true;

Diff for: src/main/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleReport.java

+9
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorException;
5151
import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorRequest;
5252
import org.apache.maven.plugins.checkstyle.exec.CheckstyleResults;
53+
import org.apache.maven.project.MavenProject;
5354
import org.apache.maven.reporting.AbstractMavenReport;
5455
import org.apache.maven.reporting.MavenReportException;
5556
import org.codehaus.plexus.configuration.PlexusConfiguration;
@@ -474,6 +475,14 @@ protected String getI18nString(Locale locale, String key) {
474475
return i18n.getString("checkstyle-report", locale, "report.checkstyle." + key);
475476
}
476477

478+
protected MavenProject getProject() {
479+
return project;
480+
}
481+
482+
protected List<MavenProject> getReactorProjects() {
483+
return reactorProjects;
484+
}
485+
477486
/** {@inheritDoc} */
478487
public void executeReport(Locale locale) throws MavenReportException {
479488
checkDeprecatedParameterUsage(sourceDirectory, "sourceDirectory", "sourceDirectories");

Diff for: src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleAggregateReport.java

-17
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,9 @@
1818
*/
1919
package org.apache.maven.plugins.checkstyle;
2020

21-
import java.util.List;
22-
2321
import org.apache.maven.plugins.annotations.Mojo;
24-
import org.apache.maven.plugins.annotations.Parameter;
2522
import org.apache.maven.plugins.annotations.ResolutionScope;
2623
import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorRequest;
27-
import org.apache.maven.project.MavenProject;
2824
import org.apache.maven.reporting.MavenReportException;
2925

3026
/**
@@ -40,19 +36,6 @@
4036
requiresDependencyResolution = ResolutionScope.COMPILE,
4137
threadSafe = true)
4238
public class CheckstyleAggregateReport extends AbstractCheckstyleReport {
43-
/**
44-
* The projects in the reactor for aggregation report.
45-
*
46-
* @since 2.8
47-
*/
48-
@Parameter(property = "reactorProjects", readonly = true)
49-
private List<MavenProject> reactorProjects;
50-
51-
/** {@inheritDoc} */
52-
protected MavenProject getProject() {
53-
return project;
54-
}
55-
5639
/**
5740
* {@inheritDoc}
5841
*/

Diff for: src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleReport.java

-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.apache.maven.plugins.annotations.Mojo;
2626
import org.apache.maven.plugins.annotations.ResolutionScope;
2727
import org.apache.maven.plugins.checkstyle.exec.CheckstyleExecutorRequest;
28-
import org.apache.maven.project.MavenProject;
2928
import org.apache.maven.reporting.MavenReportException;
3029

3130
/**
@@ -39,12 +38,6 @@
3938
*/
4039
@Mojo(name = "checkstyle", requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true)
4140
public class CheckstyleReport extends AbstractCheckstyleReport {
42-
43-
/** {@inheritDoc} */
44-
protected MavenProject getProject() {
45-
return project;
46-
}
47-
4841
/**
4942
* {@inheritDoc}
5043
*/

Diff for: src/test/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleTestCase.java

+34-15
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@
2121
import java.io.File;
2222
import java.io.IOException;
2323
import java.nio.file.Files;
24-
import java.util.Locale;
24+
import java.util.Collections;
25+
import java.util.List;
2526

27+
import org.apache.maven.model.Plugin;
2628
import org.apache.maven.plugin.LegacySupport;
29+
import org.apache.maven.plugin.MojoExecution;
30+
import org.apache.maven.plugin.descriptor.MojoDescriptor;
31+
import org.apache.maven.plugin.descriptor.PluginDescriptor;
2732
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
2833
import org.apache.maven.plugin.testing.ArtifactStubFactory;
2934
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
@@ -39,8 +44,6 @@
3944
* Abstract class to test reports generation.
4045
*/
4146
public abstract class AbstractCheckstyleTestCase extends AbstractMojoTestCase {
42-
private Locale oldLocale;
43-
4447
private ArtifactStubFactory artifactStubFactory;
4548

4649
/**
@@ -53,21 +56,10 @@ protected void setUp() throws Exception {
5356
// required for mojo lookups to work
5457
super.setUp();
5558

56-
oldLocale = Locale.getDefault();
57-
Locale.setDefault(Locale.ENGLISH);
58-
5959
artifactStubFactory = new DependencyArtifactStubFactory(getTestFile("target"), true, false);
6060
artifactStubFactory.getWorkingDir().mkdirs();
6161
}
6262

63-
@Override
64-
protected void tearDown() throws Exception {
65-
super.tearDown();
66-
67-
Locale.setDefault(oldLocale);
68-
oldLocale = null;
69-
}
70-
7163
/**
7264
* Get the current Maven project
7365
*
@@ -121,8 +113,17 @@ protected CheckstyleReport createReportMojo(String goal, File pluginXmlFile) thr
121113
repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
122114
.newInstance(repoSession, new LocalRepository(artifactStubFactory.getWorkingDir())));
123115

116+
List<MavenProject> reactorProjects =
117+
mojo.getReactorProjects() != null ? mojo.getReactorProjects() : Collections.emptyList();
118+
119+
setVariableValueToObject(mojo, "mojoExecution", getMockMojoExecution());
124120
setVariableValueToObject(mojo, "session", legacySupport.getSession());
125-
setVariableValueToObject(mojo, "remoteRepositories", mojo.getProject().getRemoteArtifactRepositories());
121+
setVariableValueToObject(mojo, "repoSession", legacySupport.getRepositorySession());
122+
setVariableValueToObject(mojo, "reactorProjects", reactorProjects);
123+
setVariableValueToObject(
124+
mojo, "remoteProjectRepositories", mojo.getProject().getRemoteProjectRepositories());
125+
setVariableValueToObject(
126+
mojo, "siteDirectory", new File(mojo.getProject().getBasedir(), "src/site"));
126127
return mojo;
127128
}
128129

@@ -148,4 +149,22 @@ protected File generateReport(CheckstyleReport mojo, File pluginXmlFile) throws
148149
protected String readFile(File checkstyleTestDir, String fileName) throws IOException {
149150
return new String(Files.readAllBytes(checkstyleTestDir.toPath().resolve(fileName)));
150151
}
152+
153+
private MojoExecution getMockMojoExecution() {
154+
MojoDescriptor md = new MojoDescriptor();
155+
md.setGoal(getGoal());
156+
157+
MojoExecution me = new MojoExecution(md);
158+
159+
PluginDescriptor pd = new PluginDescriptor();
160+
Plugin p = new Plugin();
161+
p.setGroupId("org.apache.maven.plugins");
162+
p.setArtifactId("maven-checkstyle-plugin");
163+
pd.setPlugin(p);
164+
md.setPluginDescriptor(pd);
165+
166+
return me;
167+
}
168+
169+
protected abstract String getGoal();
151170
}

Diff for: src/test/java/org/apache/maven/plugins/checkstyle/CheckstyleReportTest.java

+11-9
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
import java.io.File;
2323
import java.io.FileReader;
2424
import java.io.IOException;
25-
import java.util.Locale;
2625
import java.util.ResourceBundle;
2726

2827
import org.apache.maven.artifact.DependencyResolutionRequiredException;
28+
import org.apache.maven.doxia.tools.SiteTool;
2929
import org.apache.maven.plugin.descriptor.PluginDescriptor;
3030
import org.codehaus.plexus.util.FileUtils;
3131

@@ -35,11 +35,8 @@
3535
*/
3636
public class CheckstyleReportTest extends AbstractCheckstyleTestCase {
3737
public void testNoSource() throws Exception {
38-
// clean up after earlier runs
39-
File report = new File("target/test-harness/checkstyle/no-source/checkstyle.html");
40-
report.delete();
41-
File generatedReport = generateReport("checkstyle", "no-source-plugin-config.xml");
42-
assertFalse(report + " exists", generatedReport.exists());
38+
File generatedReport = generateReport(getGoal(), "no-source-plugin-config.xml");
39+
assertFalse(FileUtils.fileExists(generatedReport.getAbsolutePath()));
4340
}
4441

4542
public void testMinConfiguration() throws Exception {
@@ -117,9 +114,9 @@ private String readFile(File file) throws IOException {
117114
private void generateReport(String pluginXml) throws Exception {
118115
File pluginXmlFile = new File(getBasedir(), "src/test/resources/plugin-configs/" + pluginXml);
119116
ResourceBundle bundle =
120-
ResourceBundle.getBundle("checkstyle-report", Locale.getDefault(), this.getClassLoader());
117+
ResourceBundle.getBundle("checkstyle-report", SiteTool.DEFAULT_LOCALE, this.getClassLoader());
121118

122-
CheckstyleReport mojo = createReportMojo("checkstyle", pluginXmlFile);
119+
CheckstyleReport mojo = createReportMojo(getGoal(), pluginXmlFile);
123120

124121
PluginDescriptor descriptorStub = new PluginDescriptor();
125122
descriptorStub.setGroupId("org.apache.maven.plugins");
@@ -173,6 +170,11 @@ private void generateReport(String pluginXml) throws Exception {
173170
}
174171

175172
private static String getHtmlHeader(String s) {
176-
return ">" + s + "</h3>";
173+
return ">" + s + "</h2>";
174+
}
175+
176+
@Override
177+
protected String getGoal() {
178+
return "checkstyle";
177179
}
178180
}

Diff for: src/test/java/org/apache/maven/plugins/checkstyle/stubs/CheckstyleProjectStub.java

+23
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,34 @@
1818
*/
1919
package org.apache.maven.plugins.checkstyle.stubs;
2020

21+
import java.io.File;
2122
import java.util.Collections;
2223
import java.util.List;
2324

25+
import org.apache.maven.RepositoryUtils;
2426
import org.apache.maven.artifact.repository.ArtifactRepository;
2527
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
2628
import org.apache.maven.artifact.repository.MavenArtifactRepository;
2729
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
2830
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
31+
import org.eclipse.aether.repository.RemoteRepository;
2932

3033
public abstract class CheckstyleProjectStub extends MavenProjectStub {
34+
/**
35+
* @return the POM file name
36+
*/
37+
protected abstract String getPOM();
38+
39+
@Override
40+
public File getBasedir() {
41+
return new File(super.getBasedir() + "/src/test/resources/plugin-configs/");
42+
}
43+
44+
@Override
45+
public File getFile() {
46+
return new File(getBasedir(), getPOM());
47+
}
48+
3149
@Override
3250
public List<ArtifactRepository> getRemoteArtifactRepositories() {
3351
ArtifactRepository repository = new MavenArtifactRepository(
@@ -39,4 +57,9 @@ public List<ArtifactRepository> getRemoteArtifactRepositories() {
3957

4058
return Collections.singletonList(repository);
4159
}
60+
61+
@Override
62+
public List<RemoteRepository> getRemoteProjectRepositories() {
63+
return RepositoryUtils.toRepos(getRemoteArtifactRepositories());
64+
}
4265
}

0 commit comments

Comments
 (0)