Skip to content

Commit

Permalink
[MJAVADOC-782] Align read-only parameters naming with other plugins
Browse files Browse the repository at this point in the history
This closes #251
  • Loading branch information
michael-o committed Nov 26, 2023
1 parent 867dc73 commit 488624f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ public abstract class AbstractJavadocMojo extends AbstractMojo {
@Parameter(defaultValue = "${project}", readonly = true, required = true)
protected MavenProject project;

@Parameter(defaultValue = "${mojoExecution}", readonly = true)
private MojoExecution mojo;
@Parameter(defaultValue = "${mojoExecution}", readonly = true, required = true)
protected MojoExecution mojoExecution;

/**
* Specify if the Javadoc plugin should operate in offline mode. If maven is run in offline
Expand Down Expand Up @@ -421,8 +421,8 @@ public abstract class AbstractJavadocMojo extends AbstractMojo {
/**
* The projects in the reactor for aggregation report.
*/
@Parameter(property = "reactorProjects", readonly = true)
private List<MavenProject> reactorProjects;
@Parameter(defaultValue = "${reactorProjects}", required = true, readonly = true)
protected List<MavenProject> reactorProjects;

/**
* Set this to <code>true</code> to debug the Javadoc plugin. With this, <code>javadoc.bat(or.sh)</code>,
Expand Down Expand Up @@ -1828,7 +1828,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
abstract void doExecute() throws MojoExecutionException, MojoFailureException;

protected final void verifyRemovedParameter(String paramName) {
Xpp3Dom configDom = mojo.getConfiguration();
Xpp3Dom configDom = mojoExecution.getConfiguration();
if (configDom != null) {
if (configDom.getChild(paramName) != null) {
throw new IllegalArgumentException(
Expand All @@ -1838,7 +1838,7 @@ protected final void verifyRemovedParameter(String paramName) {
}

private void verifyReplacedParameter(String oldParamName, String newParamNew) {
Xpp3Dom configDom = mojo.getConfiguration();
Xpp3Dom configDom = mojoExecution.getConfiguration();
if (configDom != null) {
if (configDom.getChild(oldParamName) != null) {
throw new IllegalArgumentException("parameter '" + oldParamName + "' has been replaced with "
Expand Down Expand Up @@ -6042,6 +6042,10 @@ protected void logError(String message, Throwable t) {
}
}

protected List<MavenProject> getReactorProjects() {
return reactorProjects;
}

/**
* @param prefix The prefix of the exception.
* @param e The exception.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ protected void setUp() throws Exception {
private JavadocReport lookupMojo(File testPom) throws Exception {
JavadocReport mojo = (JavadocReport) lookupMojo("aggregate", testPom);

MojoExecution mojoExec = new MojoExecution(new Plugin(), "aggregate", null);
setVariableValueToObject(mojo, "mojo", mojoExec);
Plugin p = new Plugin();
p.setGroupId("org.apache.maven.plugins");
p.setArtifactId("maven-javadoc-plugin");
MojoExecution mojoExecution = new MojoExecution(p, "aggregate", null);

setVariableValueToObject(mojo, "mojoExecution", mojoExecution);

MavenProject currentProject = new MavenProjectStub();
currentProject.setGroupId("GROUPID");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ public class JavadocJarTest extends AbstractMojoTestCase {
private JavadocJar lookupMojo(File testPom) throws Exception {
JavadocJar mojo = (JavadocJar) lookupMojo("jar", testPom);

MojoExecution mojoExec = new MojoExecution(new Plugin(), "javadoc", null);
Plugin p = new Plugin();
p.setGroupId("org.apache.maven.plugins");
p.setArtifactId("maven-javadoc-plugin");
MojoExecution mojoExecution = new MojoExecution(p, "jar", null);

setVariableValueToObject(mojo, "mojo", mojoExec);
setVariableValueToObject(mojo, "mojoExecution", mojoExecution);

MavenProject currentProject = new MavenProjectStub();
currentProject.setGroupId("GROUPID");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -113,17 +114,23 @@ protected void tearDown() throws Exception {
private JavadocReport lookupMojo(Path testPom) throws Exception {
JavadocReport mojo = (JavadocReport) lookupMojo("javadoc", testPom.toFile());

MojoExecution mojoExec = new MojoExecution(new Plugin(), "javadoc", null);
Plugin p = new Plugin();
p.setGroupId("org.apache.maven.plugins");
p.setArtifactId("maven-javadoc-plugin");
MojoExecution mojoExecution = new MojoExecution(p, "javadoc", null);

setVariableValueToObject(mojo, "mojo", mojoExec);
setVariableValueToObject(mojo, "mojoExecution", mojoExecution);

MavenProject currentProject = new MavenProjectStub();
currentProject.setGroupId("GROUPID");
currentProject.setArtifactId("ARTIFACTID");

List<MavenProject> reactorProjects =
mojo.getReactorProjects() != null ? mojo.getReactorProjects() : Collections.emptyList();
MavenSession session = newMavenSession(currentProject);
setVariableValueToObject(mojo, "session", session);
setVariableValueToObject(mojo, "repoSession", session.getRepositorySession());
setVariableValueToObject(mojo, "reactorProjects", reactorProjects);
return mojo;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ public void testTestJavadoc() throws Exception {
new File(getBasedir(), "src/test/resources/unit/test-javadoc-test/test-javadoc-test-plugin-config.xml");
TestJavadocReport mojo = (TestJavadocReport) lookupMojo("test-javadoc", testPom);

MojoExecution mojoExec = new MojoExecution(new Plugin(), "test-javadoc", null);
Plugin p = new Plugin();
p.setGroupId("org.apache.maven.plugins");
p.setArtifactId("maven-javadoc-plugin");
MojoExecution mojoExecution = new MojoExecution(p, "test-javadoc", null);

setVariableValueToObject(mojo, "mojo", mojoExec);
setVariableValueToObject(mojo, "mojoExecution", mojoExecution);

MavenProject currentProject = new MavenProjectStub();
currentProject.setGroupId("GROUPID");
Expand Down

0 comments on commit 488624f

Please sign in to comment.