Skip to content

Commit

Permalink
Prepare for Doxia 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-o committed Nov 14, 2023
1 parent eb71af5 commit 5e7636b
Show file tree
Hide file tree
Showing 19 changed files with 104 additions and 123 deletions.
19 changes: 7 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ under the License.
</parent>

<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.2-SNAPSHOT</version>
<version>4.0.0-M1-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<name>Apache Maven Checkstyle Plugin</name>
Expand Down Expand Up @@ -77,10 +77,10 @@ under the License.
<aetherVersion>1.0.0.v20140518</aetherVersion>
<mavenVersion>3.2.5</mavenVersion>
<checkstyleVersion>9.3</checkstyleVersion>
<doxiaVersion>1.11.1</doxiaVersion>
<doxiaSitetoolsVersion>1.11.1</doxiaSitetoolsVersion>
<sitePluginVersion>3.12.1</sitePluginVersion>
<jxrPluginVersion>3.3.0</jxrPluginVersion>
<doxiaVersion>2.0.0-M8</doxiaVersion>
<doxiaSitetoolsVersion>2.0.0-M13</doxiaSitetoolsVersion>
<sitePluginVersion>4.0.0-M11</sitePluginVersion>
<jxrPluginVersion>4.0.0-M1-SNAPSHOT</jxrPluginVersion>
<project.build.outputTimestamp>2023-10-21T10:39:27Z</project.build.outputTimestamp>
</properties>

Expand Down Expand Up @@ -125,12 +125,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-M8</version>
</dependency>
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-impl</artifactId>
<version>3.2.0</version>
<version>4.0.0-M11</version>
</dependency>

<!-- doxia -->
Expand Down Expand Up @@ -190,11 +190,6 @@ under the License.
<artifactId>checkstyle</artifactId>
<version>${checkstyleVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>

<!-- test -->
<dependency>
Expand Down
26 changes: 0 additions & 26 deletions src/it/MCHECKSTYLE-412/src/main/java/org/MyClass.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,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 @@ -473,6 +474,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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,19 +40,19 @@ public List<String> getCompileClasspathElements() throws DependencyResolutionReq
/** {@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;
}

Expand Down Expand Up @@ -84,15 +83,13 @@ public String getInceptionYear() {
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";
}
}
Loading

0 comments on commit 5e7636b

Please sign in to comment.