From 175297634edad0432f5b38c5861733a6c6418d8b Mon Sep 17 00:00:00 2001 From: Andrzej Jarmoniuk Date: Sun, 27 Nov 2022 10:44:36 +0100 Subject: [PATCH] #704: Removing ArtifactRepository leftovers; using ranges for version resolution --- .../versions/api/DefaultVersionsHelper.java | 24 +- .../codehaus/mojo/versions/api/PomHelper.java | 1 - .../mojo/versions/api/VersionsHelper.java | 17 + .../enforcer/MaxDependencyUpdatesTest.java | 25 +- .../mojo/versions/AbstractVersionsReport.java | 34 -- .../versions/AbstractVersionsUpdaterMojo.java | 3 +- .../versions/DisplayPluginUpdatesMojo.java | 504 +++++++----------- .../codehaus/mojo/versions/RevertMojo.java | 4 - .../PropertyUpdatesReportMojoTest.java | 4 - .../mojo/versions/UpdateParentMojoTest.java | 3 - 10 files changed, 250 insertions(+), 369 deletions(-) diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java b/versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java index 85ce4a8aef..669efd5430 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java @@ -53,6 +53,7 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; +import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; import org.apache.maven.model.Plugin; @@ -175,7 +176,8 @@ public Log getLog() } @Override - public ArtifactVersions lookupArtifactVersions( Artifact artifact, boolean usePluginRepositories ) + public ArtifactVersions lookupArtifactVersions( Artifact artifact, VersionRange versionRange, + boolean usePluginRepositories ) throws VersionRetrievalException { try @@ -189,11 +191,14 @@ public ArtifactVersions lookupArtifactVersions( Artifact artifact, boolean usePl return new ArtifactVersions( artifact, aetherRepositorySystem.resolveVersionRange( mavenSession.getRepositorySession(), new VersionRangeRequest( - toArtifact( artifact ).setVersion( "(,)" ), - usePluginRepositories - ? mavenSession.getCurrentProject().getRemotePluginRepositories() - : mavenSession.getCurrentProject().getRemoteProjectRepositories(), - "lookupArtifactVersions" ) ) + toArtifact( artifact ).setVersion( + versionRange != null + ? versionRange.toString() + : "(,)" ), + usePluginRepositories + ? mavenSession.getCurrentProject().getRemotePluginRepositories() + : mavenSession.getCurrentProject().getRemoteProjectRepositories(), + "lookupArtifactVersions" ) ) .getVersions() .parallelStream() .filter( v -> ignoredVersions.stream() @@ -237,6 +242,13 @@ public ArtifactVersions lookupArtifactVersions( Artifact artifact, boolean usePl } } + @Override + public ArtifactVersions lookupArtifactVersions( Artifact artifact, boolean usePluginRepositories ) + throws VersionRetrievalException + { + return lookupArtifactVersions( artifact, null, usePluginRepositories ); + } + /** * Returns a list of versions which should not be considered when looking for updates. * diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/api/PomHelper.java b/versions-common/src/main/java/org/codehaus/mojo/versions/api/PomHelper.java index f0fbd59472..edddded6fd 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/api/PomHelper.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/api/PomHelper.java @@ -1548,7 +1548,6 @@ public static MavenProject getStandaloneSuperProject( ProjectBuilder projectBuil } return result.getProject(); } - /** *

Convenience method for creating a {@link ProjectBuildingRequest} instance based on maven session.

*

Note: The method initializes the remote repositories with the remote artifact repositories. diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/api/VersionsHelper.java b/versions-common/src/main/java/org/codehaus/mojo/versions/api/VersionsHelper.java index 4f56849e91..8e66f93223 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/api/VersionsHelper.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/api/VersionsHelper.java @@ -27,6 +27,7 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.model.Dependency; import org.apache.maven.model.Plugin; import org.apache.maven.plugin.MojoExecutionException; @@ -154,6 +155,22 @@ Artifact createDependencyArtifact( String groupId, String artifactId, String ver ArtifactVersions lookupArtifactVersions( Artifact artifact, boolean usePluginRepositories ) throws VersionRetrievalException; + /** + * Looks up the versions of the specified artifact that are available in either the local repository, or the + * appropriate remote repositories. + * + * @param artifact The artifact to look for versions of. + * @param versionRange versionRange to restrict the search + * @param usePluginRepositories true will consult the pluginRepositories, while false will + * consult the repositories for normal dependencies. + * @return The details of the available artifact versions. + * @throws VersionRetrievalException thrown if version resolution fails + * @since 1.0-alpha-3 + */ + ArtifactVersions lookupArtifactVersions( Artifact artifact, VersionRange versionRange, + boolean usePluginRepositories ) + throws VersionRetrievalException; + /** * Looks up the updates for a set of dependencies. * diff --git a/versions-enforcer/src/test/java/org/apache/maven/plugins/enforcer/MaxDependencyUpdatesTest.java b/versions-enforcer/src/test/java/org/apache/maven/plugins/enforcer/MaxDependencyUpdatesTest.java index 7493bcce74..62e029e813 100644 --- a/versions-enforcer/src/test/java/org/apache/maven/plugins/enforcer/MaxDependencyUpdatesTest.java +++ b/versions-enforcer/src/test/java/org/apache/maven/plugins/enforcer/MaxDependencyUpdatesTest.java @@ -20,14 +20,11 @@ import java.util.HashMap; -import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.plugin.MojoExecution; -import org.apache.maven.plugin.testing.stubs.StubArtifactRepository; import org.apache.maven.project.MavenProject; import org.apache.maven.repository.RepositorySystem; -import org.apache.maven.settings.Settings; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.junit.Test; @@ -57,23 +54,17 @@ private static EnforcerRuleHelper mockRuleHelper( MavenProject mavenProject, when( ruleHelper.evaluate( anyString() ) ) .then( ( a ) -> "${project}".equals( a.getArgument( 0 ) ) ? mavenProject - : "${localRepository}".equals( a.getArgument( 0 ) ) - ? new StubArtifactRepository( "" ) - : "${settings}".equals( a.getArgument( 0 ) ) - ? new Settings() - : "${session}".equals( a.getArgument( 0 ) ) - ? mockMavenSession() - : "${mojoExecution}".equals( a.getArgument( 0 ) ) - ? mock( MojoExecution.class ) - : null ); + : "${session}".equals( a.getArgument( 0 ) ) + ? mockMavenSession() + : "${mojoExecution}".equals( a.getArgument( 0 ) ) + ? mock( MojoExecution.class ) + : null ); when( ruleHelper.getComponent( ArgumentMatchers.>any() ) ) .then( ( a ) -> a.getArgument( 0 ) == RepositorySystem.class ? mockRepositorySystem() - : a.getArgument( 0 ) == ArtifactResolver.class - ? mock( ArtifactResolver.class ) - : a.getArgument( 0 ) == org.eclipse.aether.RepositorySystem.class - ? aetherRepositorySystem - : null ); + : a.getArgument( 0 ) == org.eclipse.aether.RepositorySystem.class + ? aetherRepositorySystem + : null ); return ruleHelper; } diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsReport.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsReport.java index b33e642016..bf7d697965 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsReport.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsReport.java @@ -24,9 +24,6 @@ import java.util.Map; import java.util.Set; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.versioning.ArtifactVersion; -import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.doxia.sink.Sink; import org.apache.maven.doxia.siterenderer.Renderer; import org.apache.maven.execution.MavenSession; @@ -38,9 +35,7 @@ import org.apache.maven.reporting.MavenReportException; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.wagon.Wagon; -import org.codehaus.mojo.versions.api.ArtifactVersions; import org.codehaus.mojo.versions.api.DefaultVersionsHelper; -import org.codehaus.mojo.versions.api.VersionRetrievalException; import org.codehaus.mojo.versions.api.VersionsHelper; import org.codehaus.mojo.versions.model.RuleSet; import org.codehaus.mojo.versions.reporting.ReportRendererFactory; @@ -243,35 +238,6 @@ protected void executeReport( Locale locale ) protected abstract void doGenerateReport( Locale locale, Sink sink ) throws MavenReportException, MojoExecutionException; - /** - * Finds the latest version of the specified artifact that matches the version range. - * - * @param artifact The artifact. - * @param versionRange The version range. - * @param allowingSnapshots null for no override, otherwise the local override to apply. - * @param usePluginRepositories Use plugin repositories - * @return The latest version of the specified artifact that matches the specified version range or - * null if no matching version could be found. - * @throws MavenReportException If the artifact metadata could not be found. - * @since 1.0-alpha-1 - */ - protected ArtifactVersion findLatestVersion( Artifact artifact, VersionRange versionRange, - Boolean allowingSnapshots, boolean usePluginRepositories ) - throws MavenReportException - { - boolean includeSnapshots = allowingSnapshots != null ? allowingSnapshots : this.allowSnapshots; - try - { - final ArtifactVersions artifactVersions = - getHelper().lookupArtifactVersions( artifact, usePluginRepositories ); - return artifactVersions.getNewestVersion( versionRange, includeSnapshots ); - } - catch ( VersionRetrievalException e ) - { - throw new MavenReportException( e.getMessage(), e ); - } - } - @Override protected MavenProject getProject() { diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsUpdaterMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsUpdaterMojo.java index c2f28e7902..35817f2df1 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsUpdaterMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsUpdaterMojo.java @@ -308,7 +308,8 @@ protected ArtifactVersion findLatestVersion( Artifact artifact, VersionRange ver throws MojoExecutionException, VersionRetrievalException { boolean includeSnapshots = allowingSnapshots != null ? allowingSnapshots : this.allowSnapshots; - final ArtifactVersions artifactVersions = getHelper().lookupArtifactVersions( artifact, usePluginRepositories ); + final ArtifactVersions artifactVersions = getHelper().lookupArtifactVersions( artifact, versionRange, + usePluginRepositories ); return artifactVersions.getNewestVersion( versionRange, null, includeSnapshots, false ); } diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayPluginUpdatesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayPluginUpdatesMojo.java index c38aaebbe3..4bcb72f0a3 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayPluginUpdatesMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayPluginUpdatesMojo.java @@ -31,36 +31,35 @@ import java.lang.reflect.Method; import java.net.URL; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; -import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.Stack; import java.util.TreeMap; import java.util.TreeSet; import java.util.regex.Pattern; -import org.apache.maven.BuildFailureException; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.ArtifactUtils; -import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.execution.MavenSession; -import org.apache.maven.execution.RuntimeInformation; import org.apache.maven.lifecycle.Lifecycle; import org.apache.maven.lifecycle.LifecycleExecutionException; import org.apache.maven.lifecycle.LifecycleExecutor; import org.apache.maven.lifecycle.mapping.LifecycleMapping; +import org.apache.maven.model.BuildBase; import org.apache.maven.model.Model; import org.apache.maven.model.Plugin; import org.apache.maven.model.Prerequisites; @@ -87,7 +86,7 @@ import org.apache.maven.project.ProjectBuildingException; import org.apache.maven.project.ProjectBuildingResult; import org.apache.maven.repository.RepositorySystem; -import org.apache.maven.settings.Settings; +import org.apache.maven.rtinfo.RuntimeInformation; import org.apache.maven.wagon.Wagon; import org.codehaus.mojo.versions.api.ArtifactVersions; import org.codehaus.mojo.versions.api.PomHelper; @@ -102,6 +101,11 @@ import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.StringUtils; +import static java.util.Collections.emptyMap; +import static java.util.Optional.ofNullable; +import static java.util.stream.Collectors.toMap; +import static java.util.stream.Collectors.toSet; + /** * Displays all plugins that have newer versions available, taking care of Maven version prerequisites. * @@ -110,7 +114,7 @@ */ @Mojo( name = "display-plugin-updates", threadSafe = true ) public class DisplayPluginUpdatesMojo - extends AbstractVersionsDisplayMojo + extends AbstractVersionsDisplayMojo { // ------------------------------ FIELDS ------------------------------ @@ -154,9 +158,11 @@ public class DisplayPluginUpdatesMojo private PluginManager pluginManager; /** - * @since 1.3 + * (Injected) instance of {@link RuntimeInformation} + * + * @since 2.14.0 */ - private RuntimeInformation runtimeInformation; + private final RuntimeInformation runtimeInformation; /** * The (injected) instance of {@link ProjectBuilder} @@ -165,6 +171,8 @@ public class DisplayPluginUpdatesMojo */ protected final ProjectBuilder projectBuilder; + private final Map lifecycleMapping; + // --------------------- GETTER / SETTER METHODS --------------------- @Inject @@ -177,7 +185,8 @@ public DisplayPluginUpdatesMojo( RepositorySystem repositorySystem, ModelInterpolator modelInterpolator, PluginManager pluginManager, RuntimeInformation runtimeInformation, - Map changeRecorders ) + Map changeRecorders, + Map lifecycleMapping ) { super( repositorySystem, aetherRepositorySystem, wagonMap, changeRecorders ); this.projectBuilder = projectBuilder; @@ -185,6 +194,7 @@ public DisplayPluginUpdatesMojo( RepositorySystem repositorySystem, this.modelInterpolator = modelInterpolator; this.pluginManager = pluginManager; this.runtimeInformation = runtimeInformation; + this.lifecycleMapping = lifecycleMapping; } /** @@ -194,19 +204,19 @@ public DisplayPluginUpdatesMojo( RepositorySystem repositorySystem, * @throws MojoExecutionException when things go wrong. */ private Map getSuperPomPluginManagement() - throws MojoExecutionException + throws MojoExecutionException { - if ( new DefaultArtifactVersion( "3.0" ).compareTo( runtimeInformation.getApplicationVersion() ) <= 0 ) + if ( runtimeInformation.isMavenVersion( "[3,)" ) ) { getLog().debug( "Using Maven 3.x strategy to determine superpom defined plugins" ); try { Method getPluginsBoundByDefaultToAllLifecycles = - LifecycleExecutor.class.getMethod( "getPluginsBoundByDefaultToAllLifecycles", - String.class ); + LifecycleExecutor.class.getMethod( "getPluginsBoundByDefaultToAllLifecycles", + String.class ); Set plugins = - (Set) getPluginsBoundByDefaultToAllLifecycles.invoke( lifecycleExecutor, new Object[] { - getProject().getPackaging()} ); + (Set) getPluginsBoundByDefaultToAllLifecycles.invoke( lifecycleExecutor, new Object[] { + getProject().getPackaging()} ); // we need to provide a copy with the version blanked out so that inferring from super-pom // works as for 2.x as 3.x fills in the version on us! Map result = new LinkedHashMap<>( plugins.size() ); @@ -225,8 +235,8 @@ private Map getSuperPomPluginManagement() ModifiedPomXMLEventReader pom = newModifiedPomXER( buf, superPom.toString() ); Pattern pathRegex = Pattern.compile( "/project(/profiles/profile)?" - + "((/build(/pluginManagement)?)|(/reporting))" - + "/plugins/plugin" ); + + "((/build(/pluginManagement)?)|(/reporting))" + + "/plugins/plugin" ); Stack pathStack = new Stack<>(); StackState curState = null; while ( pom.hasNext() ) @@ -272,8 +282,8 @@ else if ( event.isEndElement() ) Plugin plugin = new Plugin(); plugin.setArtifactId( curState.artifactId ); plugin.setGroupId( curState.groupId == null - ? PomHelper.APACHE_MAVEN_PLUGINS_GROUPID - : curState.groupId ); + ? PomHelper.APACHE_MAVEN_PLUGINS_GROUPID + : curState.groupId ); plugin.setVersion( curState.version ); if ( !result.containsKey( plugin.getKey() ) ) { @@ -382,7 +392,7 @@ private Map getPluginManagement( Model model ) */ @SuppressWarnings( "checkstyle:MethodLength" ) public void execute() - throws MojoExecutionException, MojoFailureException + throws MojoExecutionException, MojoFailureException { logInit(); Set pluginsWithVersionsSpecified; @@ -408,11 +418,11 @@ public void execute() Map parentReportPlugins = new HashMap<>(); Set plugins = getProjectPlugins( superPomPluginManagement, parentPlugins, parentBuildPlugins, - parentReportPlugins, pluginsWithVersionsSpecified ); + parentReportPlugins, pluginsWithVersionsSpecified ); List pluginUpdates = new ArrayList<>(); List pluginLockdowns = new ArrayList<>(); - ArtifactVersion curMavenVersion = runtimeInformation.getApplicationVersion(); + ArtifactVersion curMavenVersion = new DefaultArtifactVersion( runtimeInformation.getMavenVersion() ); ArtifactVersion specMavenVersion = MinimalMavenBuildVersionFinder.find( getProject(), "2.0", getLog() ); ArtifactVersion minMavenVersion = null; boolean superPomDrivingMinVersion = false; @@ -442,7 +452,7 @@ public void execute() String effectiveVersion = version; Artifact artifactRange = getHelper().createPluginArtifact( plugin.getGroupId(), plugin.getArtifactId(), - version ); + version ); ArtifactVersion artifactVersion = null; try @@ -477,7 +487,7 @@ public void execute() if ( minRequires == null || compare( minRequires, pluginRequires ) > 0 ) { Map upgradePlugins = - mavenUpgrades.computeIfAbsent( pluginRequires, k -> new LinkedHashMap<>() ); + mavenUpgrades.computeIfAbsent( pluginRequires, k -> new LinkedHashMap<>() ); String upgradePluginKey = compactKey( groupId, artifactId ); if ( !upgradePlugins.containsKey( upgradePluginKey ) ) @@ -487,15 +497,15 @@ public void execute() { // plugin version configured that require a Maven version higher than spec upgradePlugins.put( upgradePluginKey, - pad( upgradePluginKey, - INFO_PAD_SIZE + getOutputLineWidthOffset(), newer ) ); + pad( upgradePluginKey, + INFO_PAD_SIZE + getOutputLineWidthOffset(), newer ) ); } else { // plugin that can be upgraded upgradePlugins.put( upgradePluginKey, pad( upgradePluginKey, INFO_PAD_SIZE - + getOutputLineWidthOffset(), - effectiveVersion, " -> ", newer ) ); + + getOutputLineWidthOffset(), + effectiveVersion, " -> ", newer ) ); } } minRequires = pluginRequires; @@ -552,15 +562,15 @@ public void execute() getLog().debug( "[" + coords + "].superPom.version=" + version ); newVersion = artifactVersion != null ? artifactVersion.toString() - : ( version != null ? version - : ( effectiveVersion != null ? effectiveVersion : "(unknown)" ) ); + : ( version != null ? version + : ( effectiveVersion != null ? effectiveVersion : "(unknown)" ) ); if ( version != null ) { superPomDrivingMinVersion = true; } pluginLockdowns.add( pad( compactKey( groupId, artifactId ), WARN_PAD_SIZE + getOutputLineWidthOffset(), - superPomDrivingMinVersion ? FROM_SUPER_POM : "", newVersion ) ); + superPomDrivingMinVersion ? FROM_SUPER_POM : "", newVersion ) ); } else if ( artifactVersion != null ) { @@ -571,11 +581,12 @@ else if ( artifactVersion != null ) newVersion = null; } if ( version != null && artifactVersion != null && newVersion != null && effectiveVersion != null - && new DefaultArtifactVersion( effectiveVersion ).compareTo( new DefaultArtifactVersion( newVersion ) ) - < 0 ) + && + new DefaultArtifactVersion( effectiveVersion ).compareTo( new DefaultArtifactVersion( newVersion ) ) + < 0 ) { pluginUpdates.add( pad( compactKey( groupId, artifactId ), INFO_PAD_SIZE + getOutputLineWidthOffset(), - effectiveVersion, " -> ", newVersion ) ); + effectiveVersion, " -> ", newVersion ) ); } } @@ -704,11 +715,12 @@ else if ( minMavenVersion != null && compare( specMavenVersion, minMavenVersion /** * Builds a {@link MavenProject} instance for the plugin with a given {@code groupId}, * {@code artifactId}, and {@code version}. - * @param groupId {@code groupId} of the plugin + * + * @param groupId {@code groupId} of the plugin * @param artifactId {@code artifactId} of the plugin - * @param version {@code version} of the plugin + * @param version {@code version} of the plugin * @return retrieved {@link MavenProject} instance for the given plugin - * @throws MojoExecutionException thrown if the artifact for the plugin could not be constructed + * @throws MojoExecutionException thrown if the artifact for the plugin could not be constructed * @throws ProjectBuildingException thrown if the {@link MavenProject} instance could not be constructed */ private MavenProject getPluginProject( String groupId, String artifactId, String version ) @@ -731,7 +743,7 @@ private MavenProject getPluginProject( String groupId, String artifactId, String if ( !result.getProblems().isEmpty() ) { getLog().warn( "Problems encountered during construction of the plugin POM for " - + probe.toString() ); + + probe.toString() ); result.getProblems().forEach( p -> getLog().warn( "\t" + p.getMessage() ) ); } @@ -762,13 +774,13 @@ private static String pad( String start, int len, String... ends ) } private Map getParentsPlugins( List parents ) - throws MojoExecutionException + throws MojoExecutionException { Map parentPlugins = new HashMap<>(); for ( MavenProject parentProject : parents ) { getLog().debug( "Processing parent: " + parentProject.getGroupId() + ":" + parentProject.getArtifactId() - + ":" + parentProject.getVersion() + " -> " + parentProject.getFile() ); + + ":" + parentProject.getVersion() + " -> " + parentProject.getFile() ); StringWriter writer = new StringWriter(); boolean havePom = false; @@ -778,8 +790,8 @@ private Map getParentsPlugins( List parents ) if ( originalModel == null ) { getLog().warn( "project.getOriginalModel()==null for " + parentProject.getGroupId() + ":" - + parentProject.getArtifactId() + ":" + parentProject.getVersion() - + " is null, substituting project.getModel()" ); + + parentProject.getArtifactId() + ":" + parentProject.getVersion() + + " is null, substituting project.getModel()" ); originalModel = parentProject.getModel(); } try @@ -795,15 +807,15 @@ private Map getParentsPlugins( List parents ) ModelBuildingRequest modelBuildingRequest = new DefaultModelBuildingRequest(); modelBuildingRequest.setUserProperties( getProject().getProperties() ); interpolatedModel = modelInterpolator.interpolateModel( originalModel, null, - modelBuildingRequest, - new IgnoringModelProblemCollector() ); + modelBuildingRequest, + new IgnoringModelProblemCollector() ); if ( havePom ) { try { Set withVersionSpecified = - findPluginsWithVersionsSpecified( new StringBuilder( writer.toString() ), - getSafeProjectPathInfo( parentProject ) ); + findPluginsWithVersionsSpecified( new StringBuilder( writer.toString() ), + getSafeProjectPathInfo( parentProject ) ); Map map = getPluginManagement( interpolatedModel ); map.keySet().retainAll( withVersionSpecified ); @@ -834,16 +846,11 @@ private Map getParentsPlugins( List parents ) private String getSafeProjectPathInfo( MavenProject project ) { - File file = project.getFile(); - if ( file != null ) - { - return file.getAbsolutePath(); - } - else - { - // path is used only as information in error message, we can fallback to project artifact info here - return project.toString(); - } + return ofNullable( project.getFile() ) + .map( File::getAbsolutePath ) + // path is used only as information in error message, + // we can fallback to project artifact info here + .orElse( project.toString() ); } private boolean isMavenPluginProject() @@ -853,12 +860,10 @@ private boolean isMavenPluginProject() private String compactKey( String groupId, String artifactId ) { - if ( PomHelper.APACHE_MAVEN_PLUGINS_GROUPID.equals( groupId ) ) - { - // a core plugin... group id is not needed - return artifactId; - } - return groupId + ":" + artifactId; + return PomHelper.APACHE_MAVEN_PLUGINS_GROUPID.equals( groupId ) + // a core plugin... group id is not needed + ? artifactId + : groupId + ":" + artifactId; } private static final class StackState @@ -889,10 +894,10 @@ public String toString() * @return a set of Strings which correspond to the plugin coordinates where there is a version specified. */ private Set findPluginsWithVersionsSpecified( MavenProject project ) - throws IOException, XMLStreamException + throws IOException, XMLStreamException { return findPluginsWithVersionsSpecified( PomHelper.readXmlFile( project.getFile() ), - getSafeProjectPathInfo( project ) ); + getSafeProjectPathInfo( project ) ); } /** @@ -903,13 +908,13 @@ private Set findPluginsWithVersionsSpecified( MavenProject project ) * @return a set of Strings which correspond to the plugin coordinates where there is a version specified. */ private Set findPluginsWithVersionsSpecified( StringBuilder pomContents, String path ) - throws XMLStreamException + throws XMLStreamException { Set result = new HashSet<>(); ModifiedPomXMLEventReader pom = newModifiedPomXER( pomContents, path ); Pattern pathRegex = Pattern.compile( "/project(/profiles/profile)?" - + "((/build(/pluginManagement)?)|(/reporting))" + "/plugins/plugin" ); + + "((/build(/pluginManagement)?)|(/reporting))" + "/plugins/plugin" ); Stack pathStack = new Stack<>(); StackState curState = null; while ( pom.hasNext() ) @@ -979,75 +984,48 @@ else if ( event.isEndElement() ) */ private ArtifactVersion getPrerequisitesMavenVersion( MavenProject pluginProject ) { - Prerequisites prerequisites = pluginProject.getPrerequisites(); - if ( null == prerequisites ) - { - return new DefaultArtifactVersion( "2.0" ); - } - - String prerequisitesMavenValue = prerequisites.getMaven(); - if ( null == prerequisitesMavenValue ) - { - return new DefaultArtifactVersion( "2.0" ); - } + return ofNullable( pluginProject.getPrerequisites() ) + .map( Prerequisites::getMaven ) + .map( DefaultArtifactVersion::new ) + .orElse( new DefaultArtifactVersion( "2.0" ) ); + } - return new DefaultArtifactVersion( prerequisitesMavenValue ); + /** + * Retrieves plugins from the given model + * + * @param build build + * @param onlyIncludeInherited {@code true} to only return the plugins definitions that will be inherited by + * child projects. + * @return map of plugin name x version + */ + private Map getPluginsFromBuild( BuildBase build, boolean onlyIncludeInherited ) + { + return ofNullable( build ) + .flatMap( b -> ofNullable( b.getPlugins() ) + .map( plugins -> plugins.stream() + .filter( plugin -> plugin.getVersion() != null ) + .filter( plugin -> !onlyIncludeInherited || getPluginInherited( plugin ) ) + .collect( toMap( Plugin::getKey, Plugin::getVersion ) ) ) ) + .orElse( emptyMap() ); } /** * Gets the build plugins of a specific project. * * @param model the model to get the build plugins from. - * @param onlyIncludeInherited true to only return the plugins definitions that will be inherited by + * @param onlyIncludeInherited {@code true} to only return the plugins definitions that will be inherited by * child projects. * @return The map of effective plugin versions keyed by coordinates. * @since 1.0-alpha-1 */ private Map getBuildPlugins( Model model, boolean onlyIncludeInherited ) { - Map buildPlugins = new HashMap<>(); - try - { - for ( Plugin plugin : model.getBuild().getPlugins() ) - { - String coord = plugin.getKey(); - String version = plugin.getVersion(); - if ( version != null && ( !onlyIncludeInherited || getPluginInherited( plugin ) ) ) - { - buildPlugins.put( coord, version ); - } - } - } - catch ( NullPointerException e ) - { - // guess there are no plugins here - } - try - { - for ( Profile profile : model.getProfiles() ) - { - try - { - for ( Plugin plugin : profile.getBuild().getPlugins() ) - { - String coord = plugin.getKey(); - String version = plugin.getVersion(); - if ( version != null && ( !onlyIncludeInherited || getPluginInherited( plugin ) ) ) - { - buildPlugins.put( coord, version ); - } - } - } - catch ( NullPointerException e ) - { - // guess there are no plugins here - } - } - } - catch ( NullPointerException e ) - { - // guess there are no profiles here - } + Map buildPlugins = + new HashMap<>( getPluginsFromBuild( model.getBuild(), onlyIncludeInherited ) ); + ofNullable( model.getProfiles() ) + .ifPresent( profiles -> profiles.stream() + .map( profile -> getPluginsFromBuild( profile.getBuild(), onlyIncludeInherited ) ) + .forEach( buildPlugins::putAll ) ); return buildPlugins; } @@ -1061,7 +1039,7 @@ private Map getBuildPlugins( Model model, boolean onlyIncludeInh private static boolean getPluginInherited( Object plugin ) { return "true".equalsIgnoreCase( plugin instanceof ReportPlugin ? ( (ReportPlugin) plugin ).getInherited() - : ( (Plugin) plugin ).getInherited() ); + : ( (Plugin) plugin ).getInherited() ); } /** @@ -1073,35 +1051,15 @@ private static boolean getPluginInherited( Object plugin ) * @since 1.0-alpha-1 */ private Map getLifecyclePlugins( MavenProject project ) - throws MojoExecutionException + throws MojoExecutionException { - Map lifecyclePlugins = new HashMap<>(); - try - { - Set plugins = getBoundPlugins( project, "clean,deploy,site" ); - for ( Plugin plugin : plugins ) - { - lifecyclePlugins.put( plugin.getKey(), plugin ); - } - } - catch ( PluginNotFoundException e ) - { - throw new MojoExecutionException( "Could not find plugin", e ); - } - catch ( LifecycleExecutionException e ) - { - throw new MojoExecutionException( "Could not determine lifecycle", e ); - } - catch ( IllegalAccessException e ) - { - throw new MojoExecutionException( "Could not determine lifecycles", e ); - } - catch ( NullPointerException e ) - { - // Maven 3.x - - } - return lifecyclePlugins; + return getBoundPlugins( project, "clean,deploy,site" ) + .parallelStream() + .filter( Objects::nonNull ) + .filter( p -> p.getKey() != null ) + .collect( HashMap::new, + ( m, p ) -> m.put( p.getKey(), p ), + Map::putAll ); } /** @@ -1111,76 +1069,58 @@ private Map getLifecyclePlugins( MavenProject project ) * @param project the project * @param thePhases the the phases * @return the bound plugins - * @throws org.apache.maven.plugin.PluginNotFoundException the plugin not found exception - * @throws LifecycleExecutionException the lifecycle execution exception - * @throws IllegalAccessException the illegal access exception + * @throws MojoFailureException thrown if plugin retrieval did not succeed */ // pilfered this from enforcer-rules // TODO coordinate with Brian Fox to remove the duplicate code private Set getBoundPlugins( MavenProject project, String thePhases ) - throws PluginNotFoundException, LifecycleExecutionException, IllegalAccessException + throws MojoExecutionException { - if ( new DefaultArtifactVersion( "3.0" ).compareTo( runtimeInformation.getApplicationVersion() ) <= 0 ) + if ( runtimeInformation.isMavenVersion( "[3,)" ) ) { - getLog().debug( "Using Maven 3.0+ strategy to determine lifecycle defined plugins" ); try { Method getPluginsBoundByDefaultToAllLifecycles = - LifecycleExecutor.class.getMethod( "getPluginsBoundByDefaultToAllLifecycles", - String.class ); + LifecycleExecutor.class.getMethod( "getPluginsBoundByDefaultToAllLifecycles", + String.class ); Set plugins = - (Set) getPluginsBoundByDefaultToAllLifecycles.invoke( lifecycleExecutor, new Object[] { - project.getPackaging() == null ? "jar" : project.getPackaging()} ); + (Set) getPluginsBoundByDefaultToAllLifecycles.invoke( lifecycleExecutor, new Object[] { + project.getPackaging() == null ? "jar" : project.getPackaging()} ); // we need to provide a copy with the version blanked out so that inferring from super-pom // works as for 2.x as 3.x fills in the version on us! - Set result = new LinkedHashSet<>( plugins.size() ); - for ( Plugin plugin : plugins ) - { - Plugin dup = new Plugin(); - dup.setGroupId( plugin.getGroupId() ); - dup.setArtifactId( plugin.getArtifactId() ); - result.add( dup ); - } - return result; + return plugins.parallelStream() + .map( p -> new Plugin() + {{ + setGroupId( p.getGroupId() ); + setArtifactId( p.getArtifactId() ); + }} ) + .collect( toSet() ); } catch ( NoSuchMethodException | InvocationTargetException | IllegalAccessException e1 ) { - // no much we can do here + getLog().warn( e1.getMessage() ); } } - List lifecycles = null; + getLog().debug( "Using Maven 2.0.10+ strategy to determine lifecycle defined plugins" ); try { Method getLifecycles = LifecycleExecutor.class.getMethod( "getLifecycles" ); - lifecycles = (List) getLifecycles.invoke( lifecycleExecutor, new Object[0] ); + List lifecycles = (List) getLifecycles.invoke( lifecycleExecutor, new Object[0] ); + // lookup the bindings for all the passed in phases + return Arrays.stream( thePhases.split( "," ) ) + .filter( StringUtils::isNotEmpty ) + .map( phase -> getLifecycleForPhase( lifecycles, phase ) ) + .filter( Objects::nonNull ) + .collect( HashSet::new, + ( s, l ) -> s.addAll( getAllPlugins( project, l ) ), + Set::addAll ); } catch ( NoSuchMethodException | InvocationTargetException | IllegalAccessException e1 ) { - // no much we can do here + getLog().warn( e1.getMessage() ); } - - Set allPlugins = new HashSet<>(); - - // lookup the bindings for all the passed in phases - for ( String lifecyclePhase : thePhases.split( "," ) ) - { - if ( StringUtils.isNotEmpty( lifecyclePhase ) ) - { - try - { - Lifecycle lifecycle = getLifecycleForPhase( lifecycles, lifecyclePhase ); - allPlugins.addAll( getAllPlugins( project, lifecycle ) ); - } - catch ( BuildFailureException e ) - { - // i'm going to swallow this because the - // user may have declared a phase that - // doesn't exist for every module. - } - } - } - return allPlugins; + throw new MojoExecutionException( "Could not retrieve plugins" ); } /** @@ -1189,19 +1129,18 @@ private Set getBoundPlugins( MavenProject project, String thePhases ) * @param lifecycles The list of lifecycles. * @param phase the phase * @return the lifecycle for phase - * @throws BuildFailureException the build failure exception - * @throws LifecycleExecutionException the lifecycle execution exception */ private Lifecycle getLifecycleForPhase( List lifecycles, String phase ) - throws BuildFailureException, LifecycleExecutionException { - Lifecycle lifecycle = getPhaseToLifecycleMap( lifecycles ).get( phase ); - - if ( lifecycle == null ) + try + { + return getPhaseToLifecycleMap( lifecycles ).get( phase ); + } + catch ( LifecycleExecutionException e ) { - throw new BuildFailureException( "Unable to find lifecycle for phase '" + phase + "'" ); + getLog().warn( "Unable to find lifecycle for phase '" + phase + "'" ); + return null; } - return lifecycle; } /* @@ -1214,41 +1153,43 @@ private Lifecycle getLifecycleForPhase( List lifecycles, String phase * @param project the project * @param lifecycle the lifecycle * @return the all plugins - * @throws PluginNotFoundException the plugin not found exception - * @throws LifecycleExecutionException the lifecycle execution exception */ private Set getAllPlugins( MavenProject project, Lifecycle lifecycle ) - throws PluginNotFoundException, LifecycleExecutionException - { - Set plugins = new HashSet<>(); - // first, bind those associated with the packaging - Map mappings = findMappingsForLifecycle( project, lifecycle ); - - for ( Map.Entry entry : mappings.entrySet() ) + List mappings = new ArrayList<>(); + try { - String value = (String) entry.getValue(); - String[] tokens = value.split( ":" ); - - Plugin plugin = new Plugin(); - plugin.setGroupId( tokens[0] ); - plugin.setArtifactId( tokens[1] ); - plugins.add( plugin ); + findMappingsForLifecycle( project, lifecycle ) + .values() + .stream() + .map( v -> (String) v ) + .forEach( mappings::add ); } - - for ( String value : findOptionalMojosForLifecycle( project, lifecycle ) ) + catch ( LifecycleExecutionException | PluginNotFoundException e ) { - String[] tokens = value.split( ":" ); - - Plugin plugin = new Plugin(); - plugin.setGroupId( tokens[0] ); - plugin.setArtifactId( tokens[1] ); - plugins.add( plugin ); + getLog().warn( "Unable to find mappings", e ); } - plugins.addAll( project.getBuildPlugins() ); + try + { + mappings.addAll( findOptionalMojosForLifecycle( project, lifecycle ) ); + } + catch ( LifecycleExecutionException | PluginNotFoundException e ) + { + getLog().warn( "Unable to find optional mojos", e ); + } - return plugins; + return mappings + .stream() + .map( v -> + { + Plugin p = new Plugin(); + String[] tokens = ( (String) v ).split( ":" ); + p.setGroupId( tokens[0] ); + p.setArtifactId( tokens[1] ); + return p; + } ) + .collect( toSet() ); } /** @@ -1261,51 +1202,20 @@ private Set getAllPlugins( MavenProject project, Lifecycle lifecycle ) * @throws PluginNotFoundException the plugin not found exception */ private Map findMappingsForLifecycle( MavenProject project, Lifecycle lifecycle ) - throws LifecycleExecutionException, PluginNotFoundException + throws LifecycleExecutionException, PluginNotFoundException { String packaging = project.getPackaging(); - Map mappings = null; - - LifecycleMapping m = (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging, - session.getSettings(), session.getLocalRepository() ); - if ( m != null ) - { - mappings = m.getPhases( lifecycle.getId() ); - } - - Map defaultMappings = lifecycle.getDefaultPhases(); - - if ( mappings == null ) - { - try - { - m = (LifecycleMapping) session.lookup( LifecycleMapping.ROLE, packaging ); - mappings = m.getPhases( lifecycle.getId() ); - } - catch ( ComponentLookupException e ) - { - if ( defaultMappings == null ) - { - throw new LifecycleExecutionException( "Cannot find lifecycle mapping for packaging: '" + packaging - + "'.", e ); - } - } - } - - if ( mappings == null ) - { - if ( defaultMappings == null ) - { - throw new LifecycleExecutionException( "Cannot find lifecycle mapping for packaging: '" + packaging - + "', and there is no default" ); - } - else - { - mappings = defaultMappings; - } - } - return mappings; + return ofNullable( findExtension( project, LifecycleMapping.ROLE, packaging ) ) + .filter( o -> o instanceof LifecycleMapping ) + .map( o -> (LifecycleMapping) o ) + .map( mapping -> mapping.getPhases( lifecycle.getId() ) ) + .orElse( ofNullable( lifecycleMapping.get( packaging ) ) + .map( mapping -> mapping.getPhases( lifecycle.getId() ) ) + .orElse( ofNullable( lifecycle.getDefaultPhases() ) + .orElseThrow( () -> + new LifecycleExecutionException( "Cannot find lifecycle mapping for packaging: '" + + packaging + "', and there is no default" ) ) ) ); } /** @@ -1318,13 +1228,12 @@ private Set getAllPlugins( MavenProject project, Lifecycle lifecycle ) * @throws PluginNotFoundException the plugin not found exception */ private List findOptionalMojosForLifecycle( MavenProject project, Lifecycle lifecycle ) - throws LifecycleExecutionException, PluginNotFoundException + throws LifecycleExecutionException, PluginNotFoundException { String packaging = project.getPackaging(); List optionalMojos = null; - LifecycleMapping m = (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging, - session.getSettings(), session.getLocalRepository() ); + LifecycleMapping m = (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging ); if ( m != null ) { @@ -1341,7 +1250,7 @@ private List findOptionalMojosForLifecycle( MavenProject project, Lifecy catch ( ComponentLookupException e ) { getLog().debug( "Error looking up lifecycle mapping to retrieve optional mojos. Lifecycle ID: " - + lifecycle.getId() + ". Error: " + e.getMessage(), e ); + + lifecycle.getId() + ". Error: " + e.getMessage(), e ); } } @@ -1356,18 +1265,15 @@ private List findOptionalMojosForLifecycle( MavenProject project, Lifecy /** * Find extension. * - * @param project the project - * @param role the role - * @param roleHint the role hint - * @param settings the settings - * @param localRepository the local repository + * @param project the project + * @param role the role + * @param roleHint the role hint * @return the object * @throws LifecycleExecutionException the lifecycle execution exception * @throws PluginNotFoundException the plugin not found exception */ - private Object findExtension( MavenProject project, String role, String roleHint, Settings settings, - ArtifactRepository localRepository ) - throws LifecycleExecutionException, PluginNotFoundException + private Object findExtension( MavenProject project, String role, String roleHint ) + throws LifecycleExecutionException, PluginNotFoundException { Object pluginComponent = null; @@ -1394,7 +1300,7 @@ private Object findExtension( MavenProject project, String role, String roleHint catch ( PluginManagerException e ) { throw new LifecycleExecutionException( "Error getting extensions from the plugin '" - + plugin.getKey() + "': " + e.getMessage(), e ); + + plugin.getKey() + "': " + e.getMessage(), e ); } } } @@ -1412,7 +1318,7 @@ private Object findExtension( MavenProject project, String role, String roleHint * @throws PluginNotFoundException the plugin not found exception */ private PluginDescriptor loadPluginDescriptor( Plugin plugin, MavenProject project, MavenSession session ) - throws LifecycleExecutionException, PluginNotFoundException + throws LifecycleExecutionException, PluginNotFoundException { PluginDescriptor pluginDescriptor; try @@ -1422,7 +1328,7 @@ private PluginDescriptor loadPluginDescriptor( Plugin plugin, MavenProject proje catch ( PluginManagerException e ) { throw new LifecycleExecutionException( "Internal error in the plugin manager getting plugin '" - + plugin.getKey() + "': " + e.getMessage(), e ); + + plugin.getKey() + "': " + e.getMessage(), e ); } catch ( PluginVersionResolutionException | InvalidVersionSpecificationException | InvalidPluginException // | ArtifactNotFoundException | ArtifactResolutionException | PluginVersionNotFoundException e ) @@ -1441,7 +1347,7 @@ private PluginDescriptor loadPluginDescriptor( Plugin plugin, MavenProject proje * @since 1.0-alpha-1 */ private List getParentProjects( MavenProject project ) - throws MojoExecutionException + throws MojoExecutionException { List parents = new ArrayList<>(); while ( project.getParent() != null ) @@ -1465,7 +1371,7 @@ private List getParentProjects( MavenProject project ) * @throws LifecycleExecutionException the lifecycle execution exception. */ public Map getPhaseToLifecycleMap( List lifecycles ) - throws LifecycleExecutionException + throws LifecycleExecutionException { Map phaseToLifecycleMap = new HashMap<>(); @@ -1477,9 +1383,9 @@ public Map getPhaseToLifecycleMap( List lifecycles { Lifecycle prevLifecycle = phaseToLifecycleMap.get( phase ); throw new LifecycleExecutionException( "Phase '" + phase - + "' is defined in more than one lifecycle: '" - + lifecycle.getId() + "' and '" - + prevLifecycle.getId() + "'" ); + + "' is defined in more than one lifecycle: '" + + lifecycle.getId() + "' and '" + + prevLifecycle.getId() + "'" ); } else { @@ -1507,7 +1413,7 @@ private Set getProjectPlugins( Map superPomPluginManagem Map parentBuildPlugins, Map parentReportPlugins, Set pluginsWithVersionsSpecified ) - throws MojoExecutionException + throws MojoExecutionException { Map plugins = new HashMap<>(); @@ -1544,13 +1450,13 @@ private Set getProjectPlugins( Map superPomPluginManagem ModelBuildingRequest modelBuildingRequest = new DefaultModelBuildingRequest(); modelBuildingRequest.setUserProperties( getProject().getProperties() ); Model originalModel = - modelInterpolator.interpolateModel( getProject().getOriginalModel(), getProject().getBasedir(), - modelBuildingRequest, new IgnoringModelProblemCollector() ); + modelInterpolator.interpolateModel( getProject().getOriginalModel(), getProject().getBasedir(), + modelBuildingRequest, new IgnoringModelProblemCollector() ); try { addProjectPlugins( plugins, originalModel.getBuild().getPluginManagement().getPlugins(), - excludePluginManagement ); + excludePluginManagement ); } catch ( NullPointerException e ) { @@ -1642,7 +1548,7 @@ private Set getProjectPlugins( Map superPomPluginManagem try { addProjectPlugins( plugins, profile.getBuild().getPluginManagement().getPlugins(), - excludePluginManagement ); + excludePluginManagement ); } catch ( NullPointerException e ) { @@ -1692,8 +1598,8 @@ private void addProjectPlugins( Map plugins, Collection String version = plugin.getVersion(); String parentVersion = parentDefinitions.get( coord ); if ( version == null - && ( !plugins.containsKey( coord ) || plugins.get( coord ).getVersion() == null ) - && parentVersion != null ) + && ( !plugins.containsKey( coord ) || plugins.get( coord ).getVersion() == null ) + && parentVersion != null ) { Plugin parentPlugin = new Plugin(); parentPlugin.setGroupId( plugin.getGroupId() ); diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/RevertMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/RevertMojo.java index dd49650b40..1f232613b7 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/RevertMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/RevertMojo.java @@ -27,7 +27,6 @@ import java.nio.file.Paths; import java.util.Set; -import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; @@ -74,9 +73,6 @@ public class RevertMojo extends AbstractMojo */ protected final ProjectBuilder projectBuilder; - @Parameter( defaultValue = "${localRepository}", readonly = true ) - protected ArtifactRepository localRepository; - @Inject protected RevertMojo( ProjectBuilder projectBuilder ) { diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/PropertyUpdatesReportMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/PropertyUpdatesReportMojoTest.java index c62ac79d10..89f0a75cc7 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/PropertyUpdatesReportMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/PropertyUpdatesReportMojoTest.java @@ -28,7 +28,6 @@ import org.apache.maven.doxia.tools.SiteTool; import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.apache.maven.plugin.testing.MojoRule; -import org.apache.maven.plugin.testing.stubs.StubArtifactRepository; import org.junit.Rule; import org.junit.Test; @@ -47,7 +46,6 @@ public class PropertyUpdatesReportMojoTest extends AbstractMojoTestCase public MojoRule mojoRule = new MojoRule( this ); private static final org.eclipse.aether.RepositorySystem AETHER_REPOSITORY_SYSTEM = mockAetherRepositorySystem(); private static final SiteTool SITE_TOOL = mockSiteTool(); - private static final StubArtifactRepository LOCAL_REPOSITORY = new StubArtifactRepository( "" ); @Test public void testIncludeParentTrueShouldContainProperty() throws Exception @@ -59,7 +57,6 @@ public void testIncludeParentTrueShouldContainProperty() throws Exception (PropertyUpdatesReportMojo) mojoRule.lookupConfiguredMojo( new File( "src/test/resources/org/codehaus/mojo/display-property-updates/issue-367/child" ), "property-updates-report" ); - setVariableValueToObject( mojo, "localRepository", LOCAL_REPOSITORY ); setVariableValueToObject( mojo, "siteTool", SITE_TOOL ); setVariableValueToObject( mojo, "aetherRepositorySystem", AETHER_REPOSITORY_SYSTEM ); setVariableValueToObject( mojo, "includeParent", true ); @@ -82,7 +79,6 @@ public void testIncludeParentFalseShouldNotContainProperty() throws Exception (PropertyUpdatesReportMojo) mojoRule.lookupConfiguredMojo( new File( "src/test/resources/org/codehaus/mojo/display-property-updates/issue-367/child" ), "property-updates-report" ); - setVariableValueToObject( mojo, "localRepository", new StubArtifactRepository( "" ) ); setVariableValueToObject( mojo, "siteTool", SITE_TOOL ); setVariableValueToObject( mojo, "aetherRepositorySystem", AETHER_REPOSITORY_SYSTEM ); setVariableValueToObject( mojo, "includeParent", false ); diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdateParentMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdateParentMojoTest.java index 2673a73bb2..f7a25407ee 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdateParentMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdateParentMojoTest.java @@ -7,7 +7,6 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; -import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.artifact.versioning.VersionRange; @@ -50,8 +49,6 @@ public class UpdateParentMojoTest private UpdateParentMojo mojo; - private ArtifactResolver artifactResolver; - private static RepositorySystem repositorySystem; private static org.eclipse.aether.RepositorySystem aetherRepositorySystem;