Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MPH-195] Get rid of localRepository from mojo parameter #88

Merged
merged 1 commit into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 10 additions & 27 deletions src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@
import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.util.List;

import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.plugin.AbstractMojo;
Expand All @@ -42,7 +39,6 @@
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.resolution.ArtifactDescriptorRequest;
import org.eclipse.aether.resolution.ArtifactDescriptorResult;
import org.eclipse.aether.resolution.ArtifactRequest;
Expand Down Expand Up @@ -73,22 +69,10 @@ public abstract class AbstractHelpMojo extends AbstractMojo {
protected RepositorySystem repositorySystem;

/**
* Remote repositories used for the project.
* Current Maven project.
*/
@Parameter(defaultValue = "${project.remoteArtifactRepositories}", required = true, readonly = true)
protected List<ArtifactRepository> remoteRepositories;

/**
* Plugin repositories used for the project.
*/
@Parameter(defaultValue = "${project.pluginArtifactRepositories}", required = true, readonly = true)
protected List<ArtifactRepository> pluginArtifactRepositories;

/**
* Local Repository.
*/
@Parameter(defaultValue = "${localRepository}", required = true, readonly = true)
protected ArtifactRepository localRepository;
@Parameter(defaultValue = "${project}", readonly = true, required = true)
protected MavenProject project;

/**
* The current build session instance. This is used for
Expand Down Expand Up @@ -185,9 +169,8 @@ protected org.eclipse.aether.artifact.Artifact getAetherArtifact(String artifact
protected MavenProject getMavenProject(String artifactString) throws MojoExecutionException {
try {
ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
pbr.setRemoteRepositories(remoteRepositories);
pbr.setLocalRepository(localRepository);
pbr.setPluginArtifactRepositories(pluginArtifactRepositories);
pbr.setRemoteRepositories(project.getRemoteArtifactRepositories());
pbr.setPluginArtifactRepositories(project.getPluginArtifactRepositories());
pbr.setProject(null);
pbr.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
pbr.setResolveDependencies(true);
Expand All @@ -205,15 +188,15 @@ protected MavenProject getMavenProject(String artifactString) throws MojoExecuti

protected org.eclipse.aether.resolution.ArtifactResult resolveArtifact(
org.eclipse.aether.artifact.Artifact artifact) throws RepositoryException {
List<RemoteRepository> repositories = RepositoryUtils.toRepos(remoteRepositories);
RepositorySystemSession repositorySession =
session.getProjectBuildingRequest().getRepositorySession();
RepositorySystemSession repositorySession = session.getRepositorySession();

// use descriptor to respect relocation
ArtifactDescriptorResult artifactDescriptor = repositorySystem.readArtifactDescriptor(
repositorySession, new ArtifactDescriptorRequest(artifact, repositories, null));
repositorySession,
new ArtifactDescriptorRequest(artifact, project.getRemoteProjectRepositories(), null));

return repositorySystem.resolveArtifact(
repositorySession, new ArtifactRequest(artifactDescriptor.getArtifact(), repositories, null));
repositorySession,
new ArtifactRequest(artifactDescriptor.getArtifact(), project.getRemoteProjectRepositories(), null));
}
}
17 changes: 4 additions & 13 deletions src/main/java/org/apache/maven/plugins/help/DescribeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,6 @@ public class DescribeMojo extends AbstractHelpMojo {
// Mojo parameters
// ----------------------------------------------------------------------

/**
* The current project, if there is one. This is listed as optional, since
* the help plugin should be able to function on its own. If this
* parameter is empty at execution time, this Mojo will instead use the
* super-project.
*/
@org.apache.maven.plugins.annotations.Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;

/**
* The Maven Plugin to describe. This must be specified in one of three ways:
* <br/>
Expand Down Expand Up @@ -389,8 +380,8 @@ private void describePlugin(PluginDescriptor pd, StringBuilder buffer)
// Can be null because of MPLUGIN-137 (and descriptors generated with maven-plugin-tools-api <= 2.4.3)
Artifact aetherArtifact = new DefaultArtifact(pd.getGroupId(), pd.getArtifactId(), "jar", pd.getVersion());
ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
pbr.setRemoteRepositories(remoteRepositories);
pbr.setLocalRepository(localRepository);
pbr.setRemoteRepositories(project.getRemoteArtifactRepositories());
pbr.setPluginArtifactRepositories(project.getPluginArtifactRepositories());
pbr.setProject(null);
pbr.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
try {
Expand Down Expand Up @@ -733,7 +724,6 @@ private boolean describeCommand(StringBuilder descriptionBuffer) throws MojoExec
* @return The sequence of display lines, never <code>null</code>.
* @throws MojoFailureException if any can not invoke the method
* @throws MojoExecutionException if no line was found for <code>text</code>
* @see HelpMojo#toLines(String, int, int, int)
*/
private static List<String> toLines(String text, int indent, int indentSize, int lineLength)
throws MojoFailureException, MojoExecutionException {
Expand Down Expand Up @@ -864,7 +854,8 @@ private boolean isReportGoal(MojoDescriptor md) {
PluginDescriptor pd = md.getPluginDescriptor();
List<URL> urls = new ArrayList<>();
ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
pbr.setRemoteRepositories(remoteRepositories);
pbr.setRemoteRepositories(project.getRemoteArtifactRepositories());
pbr.setPluginArtifactRepositories(project.getPluginArtifactRepositories());
pbr.setResolveDependencies(true);
pbr.setProject(null);
pbr.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,6 @@ public class EffectivePomMojo extends AbstractEffectiveMojo {
// Mojo parameters
// ----------------------------------------------------------------------

/**
* The Maven project.
*
* @since 2.0.2
*/
@Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;

/**
* The projects in the current build. The effective-POM for
* each of these projects will written.
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,6 @@ public class EvaluateMojo extends AbstractHelpMojo {
@Parameter(property = "expression")
private String expression;

/**
* Maven project built from the given {@link #artifact}. Otherwise, the current Maven project or the super pom.
*/
@Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;

/**
* The system settings for Maven.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public void testLookupPluginDescriptorPrefixWithoutVersion() throws Throwable {
writeDeclaredField(mojo, "pluginVersionResolver", pluginVersionResolver, true);
writeDeclaredField(mojo, "pluginManager", pluginManager, true);
writeField(mojo, "session", session, true);
writeDeclaredField(mojo, "project", new MavenProject(), true);
writeField(mojo, "project", new MavenProject(), true);
when(mojoDescriptorCreator.findPluginForPrefix("help", session)).thenReturn(plugin);
when(pluginVersionResolver.resolve(any(PluginVersionRequest.class))).thenReturn(versionResult);
when(versionResult.getVersion()).thenReturn("1.0");
Expand Down