Skip to content

Commit

Permalink
[MCHECKSTYLE-445] Upgrade to Doxia 2.0.0 Milestone Stack
Browse files Browse the repository at this point in the history
This closes #114
  • Loading branch information
michael-o committed Aug 19, 2024
1 parent b92666d commit 0e7bd00
Show file tree
Hide file tree
Showing 25 changed files with 116 additions and 130 deletions.
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 @@ -50,6 +50,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 @@ -474,6 +475,14 @@ 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;
}

/** {@inheritDoc} */
public void executeReport(Locale locale) throws MavenReportException {
checkDeprecatedParameterUsage(sourceDirectory, "sourceDirectory", "sourceDirectories");
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@
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;
Expand All @@ -39,8 +44,6 @@
* Abstract class to test reports generation.
*/
public abstract class AbstractCheckstyleTestCase extends AbstractMojoTestCase {
private Locale oldLocale;

private ArtifactStubFactory artifactStubFactory;

/**
Expand All @@ -53,21 +56,10 @@ protected void setUp() throws Exception {
// 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
*
Expand Down Expand Up @@ -121,8 +113,17 @@ protected CheckstyleReport createReportMojo(String goal, File pluginXmlFile) thr
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;
}

Expand All @@ -148,4 +149,22 @@ protected File generateReport(CheckstyleReport mojo, File pluginXmlFile) throws
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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
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;

Expand All @@ -35,11 +35,8 @@
*/
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 {
Expand Down Expand Up @@ -117,9 +114,9 @@ private String readFile(File file) throws IOException {
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");
Expand Down Expand Up @@ -173,6 +170,11 @@ private void generateReport(String pluginXml) throws Exception {
}

private static String getHtmlHeader(String s) {
return ">" + s + "</h3>";
return ">" + s + "</h2>";
}

@Override
protected String getGoal() {
return "checkstyle";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -39,4 +57,9 @@ public List<ArtifactRepository> getRemoteArtifactRepositories() {

return Collections.singletonList(repository);
}

@Override
public List<RemoteRepository> getRemoteProjectRepositories() {
return RepositoryUtils.toRepos(getRemoteArtifactRepositories());
}
}
Loading

0 comments on commit 0e7bd00

Please sign in to comment.