Skip to content

Commit

Permalink
[MPH-198] Get rid of maven-reporting-exec
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Mar 10, 2023
1 parent 6c7542f commit db5ac68
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
10 changes: 3 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,11 @@
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-api</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-exec</artifactId>
<version>1.6.0</version>
<exclusions>
<!-- we only need one interface MavenReport -->
<exclusion>
<groupId>org.apache.maven</groupId>
<artifactId>maven-settings-builder</artifactId>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/apache/maven/plugins/help/DescribeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.maven.lifecycle.mapping.LifecycleMapping;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.plugin.MavenPluginManager;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
Expand All @@ -54,7 +55,6 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.reporting.MavenReport;
import org.apache.maven.reporting.exec.MavenPluginManagerHelper;
import org.apache.maven.shared.utils.logging.MessageUtils;
import org.apache.maven.tools.plugin.generator.GeneratorUtils;
import org.apache.maven.tools.plugin.util.PluginUtils;
Expand Down Expand Up @@ -100,7 +100,7 @@ public class DescribeMojo extends AbstractHelpMojo {
* Component used to get a plugin descriptor from a given plugin.
*/
@Component
private MavenPluginManagerHelper pluginManager;
protected MavenPluginManager pluginManager;

/**
* Component used to get a plugin by its prefix and get mojo descriptors.
Expand Down Expand Up @@ -310,7 +310,8 @@ private PluginDescriptor lookupPluginDescriptor(PluginInfo pi) throws MojoExecut
}

try {
return pluginManager.getPluginDescriptor(forLookup, session);
return pluginManager.getPluginDescriptor(
forLookup, project.getRemotePluginRepositories(), session.getRepositorySession());
} catch (Exception e) {
throw new MojoExecutionException(
"Error retrieving plugin descriptor for:" + LS + LS + "groupId: '"
Expand Down
38 changes: 27 additions & 11 deletions src/test/java/org/apache/maven/plugins/help/DescribeMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
package org.apache.maven.plugins.help;

import java.lang.reflect.InvocationTargetException;
import java.util.Collections;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.internal.MojoDescriptorCreator;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.MavenPluginManager;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
Expand All @@ -31,7 +33,7 @@
import org.apache.maven.plugin.version.PluginVersionResult;
import org.apache.maven.plugins.help.DescribeMojo.PluginInfo;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.exec.MavenPluginManagerHelper;
import org.eclipse.aether.RepositorySystemSession;
import org.junit.Test;
import org.mockito.ArgumentCaptor;

Expand Down Expand Up @@ -196,14 +198,19 @@ public void testLookupPluginDescriptorPrefixWithVersion() throws Throwable {

MojoDescriptorCreator mojoDescriptorCreator = mock(MojoDescriptorCreator.class);
PluginVersionResolver pluginVersionResolver = mock(PluginVersionResolver.class);
MavenPluginManagerHelper pluginManager = mock(MavenPluginManagerHelper.class);
MavenPluginManager pluginManager = mock(MavenPluginManager.class);
MavenSession session = mock(MavenSession.class);
when(session.getRepositorySession()).thenReturn(mock(RepositorySystemSession.class));
writeDeclaredField(mojo, "mojoDescriptorCreator", mojoDescriptorCreator, true);
writeDeclaredField(mojo, "pluginVersionResolver", pluginVersionResolver, true);
writeDeclaredField(mojo, "pluginManager", pluginManager, true);
writeField(mojo, "session", session, true);
MavenProject mavenProject = new MavenProject();
mavenProject.setPluginArtifactRepositories(Collections.emptyList());
writeField(mojo, "project", mavenProject, true);
when(mojoDescriptorCreator.findPluginForPrefix("help", session)).thenReturn(plugin);
when(pluginManager.getPluginDescriptor(any(Plugin.class), eq(session))).thenReturn(pd);
when(pluginManager.getPluginDescriptor(any(Plugin.class), anyList(), any()))
.thenReturn(pd);

PluginDescriptor returned = (PluginDescriptor) invokeMethod(mojo, true, "lookupPluginDescriptor", pi);

Expand All @@ -212,7 +219,7 @@ public void testLookupPluginDescriptorPrefixWithVersion() throws Throwable {
verify(mojoDescriptorCreator).findPluginForPrefix("help", session);
verify(pluginVersionResolver, never()).resolve(any(PluginVersionRequest.class));
ArgumentCaptor<Plugin> argument = ArgumentCaptor.forClass(Plugin.class);
verify(pluginManager).getPluginDescriptor(argument.capture(), eq(session));
verify(pluginManager).getPluginDescriptor(argument.capture(), anyList(), any());
Plugin capturedPlugin = argument.getValue();
assertEquals("org.test", capturedPlugin.getGroupId());
assertEquals("test", capturedPlugin.getArtifactId());
Expand All @@ -234,18 +241,22 @@ public void testLookupPluginDescriptorPrefixWithoutVersion() throws Throwable {

MojoDescriptorCreator mojoDescriptorCreator = mock(MojoDescriptorCreator.class);
PluginVersionResolver pluginVersionResolver = mock(PluginVersionResolver.class);
MavenPluginManagerHelper pluginManager = mock(MavenPluginManagerHelper.class);
MavenPluginManager pluginManager = mock(MavenPluginManager.class);
PluginVersionResult versionResult = mock(PluginVersionResult.class);
MavenSession session = mock(MavenSession.class);
when(session.getRepositorySession()).thenReturn(mock(RepositorySystemSession.class));
writeDeclaredField(mojo, "mojoDescriptorCreator", mojoDescriptorCreator, true);
writeDeclaredField(mojo, "pluginVersionResolver", pluginVersionResolver, true);
writeDeclaredField(mojo, "pluginManager", pluginManager, true);
writeField(mojo, "session", session, true);
writeField(mojo, "project", new MavenProject(), true);
MavenProject mavenProject = new MavenProject();
mavenProject.setPluginArtifactRepositories(Collections.emptyList());
writeField(mojo, "project", mavenProject, true);
when(mojoDescriptorCreator.findPluginForPrefix("help", session)).thenReturn(plugin);
when(pluginVersionResolver.resolve(any(PluginVersionRequest.class))).thenReturn(versionResult);
when(versionResult.getVersion()).thenReturn("1.0");
when(pluginManager.getPluginDescriptor(any(Plugin.class), eq(session))).thenReturn(pd);
when(pluginManager.getPluginDescriptor(any(Plugin.class), anyList(), any()))
.thenReturn(pd);

PluginDescriptor returned = (PluginDescriptor) invokeMethod(mojo, true, "lookupPluginDescriptor", pi);
assertEquals(pd, returned);
Expand All @@ -256,7 +267,7 @@ public void testLookupPluginDescriptorPrefixWithoutVersion() throws Throwable {
assertEquals("org.test", versionArgument.getValue().getGroupId());
assertEquals("test", versionArgument.getValue().getArtifactId());
ArgumentCaptor<Plugin> argument = ArgumentCaptor.forClass(Plugin.class);
verify(pluginManager).getPluginDescriptor(argument.capture(), eq(session));
verify(pluginManager).getPluginDescriptor(argument.capture(), anyList(), any());
Plugin capturedPlugin = argument.getValue();
assertEquals("org.test", capturedPlugin.getGroupId());
assertEquals("test", capturedPlugin.getArtifactId());
Expand All @@ -276,13 +287,18 @@ public void testLookupPluginDescriptorGAV() throws Throwable {

MojoDescriptorCreator mojoDescriptorCreator = mock(MojoDescriptorCreator.class);
PluginVersionResolver pluginVersionResolver = mock(PluginVersionResolver.class);
MavenPluginManagerHelper pluginManager = mock(MavenPluginManagerHelper.class);
MavenPluginManager pluginManager = mock(MavenPluginManager.class);
MavenSession session = mock(MavenSession.class);
when(session.getRepositorySession()).thenReturn(mock(RepositorySystemSession.class));
writeDeclaredField(mojo, "mojoDescriptorCreator", mojoDescriptorCreator, true);
writeDeclaredField(mojo, "pluginVersionResolver", pluginVersionResolver, true);
writeDeclaredField(mojo, "pluginManager", pluginManager, true);
writeField(mojo, "session", session, true);
when(pluginManager.getPluginDescriptor(any(Plugin.class), eq(session))).thenReturn(pd);
MavenProject mavenProject = new MavenProject();
mavenProject.setPluginArtifactRepositories(Collections.emptyList());
writeField(mojo, "project", mavenProject, true);
when(pluginManager.getPluginDescriptor(any(Plugin.class), anyList(), any()))
.thenReturn(pd);

PluginDescriptor returned = (PluginDescriptor) invokeMethod(mojo, true, "lookupPluginDescriptor", pi);

Expand All @@ -291,7 +307,7 @@ public void testLookupPluginDescriptorGAV() throws Throwable {
verify(mojoDescriptorCreator, never()).findPluginForPrefix(any(String.class), any(MavenSession.class));
verify(pluginVersionResolver, never()).resolve(any(PluginVersionRequest.class));
ArgumentCaptor<Plugin> argument = ArgumentCaptor.forClass(Plugin.class);
verify(pluginManager).getPluginDescriptor(argument.capture(), eq(session));
verify(pluginManager).getPluginDescriptor(argument.capture(), anyList(), any());
Plugin capturedPlugin = argument.getValue();
assertEquals("org.test", capturedPlugin.getGroupId());
assertEquals("test", capturedPlugin.getArtifactId());
Expand Down

0 comments on commit db5ac68

Please sign in to comment.