From 1ed7d4d133afc52075a716a04e8c0b4538533f42 Mon Sep 17 00:00:00 2001 From: Andrzej Jarmoniuk Date: Sun, 20 Nov 2022 11:29:37 +0100 Subject: [PATCH] #704: Removing ArtifactMetadataSource --- pom.xml | 5 + .../versions/api/DefaultVersionsHelper.java | 215 +++++++----------- .../mojo/versions/api/PropertyVersions.java | 5 +- .../versions/api/PropertyVersionsBuilder.java | 3 +- .../api/VersionRetrievalException.java | 85 +++++++ .../mojo/versions/api/VersionsHelper.java | 21 +- .../api/DefaultVersionsHelperTest.java | 99 ++++---- .../mojo/versions/utils/VersionStub.java | 76 +++++++ ...AbstractVersionsDependencyUpdaterMojo.java | 7 +- .../versions/AbstractVersionsDisplayMojo.java | 7 +- .../mojo/versions/AbstractVersionsReport.java | 23 +- .../versions/AbstractVersionsUpdaterMojo.java | 45 ++-- .../versions/CompareDependenciesMojo.java | 9 +- .../versions/DependencyUpdatesReportMojo.java | 10 +- .../DisplayDependencyUpdatesMojo.java | 16 +- .../versions/DisplayParentUpdatesMojo.java | 13 +- .../versions/DisplayPluginUpdatesMojo.java | 15 +- .../versions/DisplayPropertyUpdatesMojo.java | 11 +- .../mojo/versions/ForceReleasesMojo.java | 15 +- .../mojo/versions/LockSnapshotsMojo.java | 9 +- .../versions/ParentUpdatesReportMojo.java | 14 +- .../versions/PluginUpdatesReportMojo.java | 14 +- .../versions/PropertyUpdatesReportMojo.java | 9 +- .../mojo/versions/ResolveRangesMojo.java | 15 +- .../org/codehaus/mojo/versions/SetMojo.java | 9 +- .../mojo/versions/SetPropertyMojo.java | 15 +- .../codehaus/mojo/versions/SetScmTagMojo.java | 10 +- .../mojo/versions/UnlockSnapshotsMojo.java | 9 +- .../mojo/versions/UpdateChildModulesMojo.java | 9 +- .../mojo/versions/UpdateParentMojo.java | 17 +- .../mojo/versions/UpdatePropertiesMojo.java | 9 +- .../mojo/versions/UpdatePropertyMojo.java | 15 +- .../mojo/versions/UseDepVersionMojo.java | 15 +- .../mojo/versions/UseLatestReleasesMojo.java | 15 +- .../mojo/versions/UseLatestSnapshotsMojo.java | 15 +- .../mojo/versions/UseLatestVersionsMojo.java | 15 +- .../versions/UseLatestVersionsMojoBase.java | 21 +- .../mojo/versions/UseNextReleasesMojo.java | 25 +- .../mojo/versions/UseNextSnapshotsMojo.java | 21 +- .../mojo/versions/UseNextVersionsMojo.java | 15 +- .../mojo/versions/UseReactorMojo.java | 17 +- .../mojo/versions/UseReleasesMojo.java | 15 +- .../DependencyUpdatesReportMojoTest.java | 67 +++--- .../DisplayDependencyUpdatesMojoTest.java | 107 +++++---- .../DisplayPropertyUpdatesMojoTest.java | 6 +- .../mojo/versions/ForceReleasesMojoTest.java | 25 +- .../versions/ParentUpdatesReportMojoTest.java | 15 +- .../versions/PluginUpdatesReportMojoTest.java | 24 +- .../PropertyUpdatesReportMojoTest.java | 9 +- ...ratePatternsForIncludesAnExcludesTest.java | 6 +- .../mojo/versions/SetPropertyMojoTest.java | 44 ++-- .../mojo/versions/UpdateParentMojoTest.java | 68 +++--- .../UpdatePropertiesMojoTestBase.java | 9 +- .../versions/UseLatestReleasesMojoTest.java | 28 ++- .../versions/UseLatestVersionsMojoTest.java | 51 +++-- .../mojo/versions/UseReleasesMojoTest.java | 24 +- .../mojo/versions/utils/MockUtils.java | 61 +++-- .../mojo/versions/utils/VersionStub.java | 76 +++++++ 58 files changed, 922 insertions(+), 706 deletions(-) create mode 100644 versions-common/src/main/java/org/codehaus/mojo/versions/api/VersionRetrievalException.java create mode 100644 versions-common/src/test/java/org/codehaus/mojo/versions/utils/VersionStub.java create mode 100644 versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/utils/VersionStub.java diff --git a/pom.xml b/pom.xml index 7336f447ab..8e37806153 100644 --- a/pom.xml +++ b/pom.xml @@ -196,6 +196,11 @@ slf4j-simple 1.7.36 + + org.apache.commons + commons-text + 1.9 + 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 4f425ff300..1ee58570b6 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 @@ -47,11 +47,10 @@ import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; +import org.apache.maven.RepositoryUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; @@ -90,6 +89,8 @@ import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import org.eclipse.aether.resolution.VersionRangeRequest; +import org.eclipse.aether.resolution.VersionRangeResolutionException; /** * Helper class that provides common functionality required by both the mojos and the reports. @@ -115,13 +116,6 @@ public class DefaultVersionsHelper */ private RuleSet ruleSet; - /** - * The artifact metadata source to use. - * - * @since 1.0-alpha-3 - */ - private ArtifactMetadataSource artifactMetadataSource; - /** * The local repository to consult. * @@ -129,22 +123,10 @@ public class DefaultVersionsHelper */ private ArtifactRepository localRepository; - /** - * The remote artifact repositories to consult. - * - * @since 1.0-alpha-3 - */ - private List remoteArtifactRepositories; - - /** - * The remote plugin repositories to consult. - * - * @since 1.0-alpha-3 - */ - private List remotePluginRepositories; - private RepositorySystem repositorySystem; + private org.eclipse.aether.RepositorySystem aetherRepositorySystem; + /** * The {@link Log} to send log messages to. * @@ -388,61 +370,65 @@ public Log getLog() @Override public ArtifactVersions lookupArtifactVersions( Artifact artifact, boolean usePluginRepositories ) - throws ArtifactMetadataRetrievalException + throws VersionRetrievalException { - List remoteRepositories = usePluginRepositories - ? remotePluginRepositories : remoteArtifactRepositories; - final List versions = - artifactMetadataSource.retrieveAvailableVersions( artifact, localRepository, remoteRepositories ); - final List ignoredVersions = getIgnoredVersions( artifact ); - if ( !ignoredVersions.isEmpty() ) + try { - if ( getLog().isDebugEnabled() ) + Collection ignoredVersions = getIgnoredVersions( artifact ); + if ( !ignoredVersions.isEmpty() && getLog().isDebugEnabled() ) { - getLog().debug( "Found ignored versions: " + showIgnoredVersions( ignoredVersions ) ); - } - - final Iterator i = versions.iterator(); - while ( i.hasNext() ) - { - final String version = i.next().toString(); - for ( final IgnoreVersion ignoreVersion : ignoredVersions ) - { - if ( TYPE_REGEX.equals( ignoreVersion.getType() ) ) - { - Pattern p = Pattern.compile( ignoreVersion.getVersion() ); - if ( p.matcher( version ).matches() ) - { - if ( getLog().isDebugEnabled() ) - { - getLog().debug( "Version " + version + " for artifact " - + ArtifactUtils.versionlessKey( artifact ) - + " found on ignore list: " - + ignoreVersion ); - } - i.remove(); - break; - } - } - else if ( TYPE_EXACT.equals( ignoreVersion.getType() ) ) - { - if ( version.equals( ignoreVersion.getVersion() ) ) - { - if ( getLog().isDebugEnabled() ) - { - getLog().debug( "Version " + version + " for artifact " - + ArtifactUtils.versionlessKey( artifact ) - + " found on ignore list: " - + ignoreVersion ); - } - i.remove(); - break; - } - } - } + getLog().debug( "Found ignored versions: " + ignoredVersions.stream() + .map( IgnoreVersion::toString ).collect( Collectors.joining( ", " ) ) ); } + return new ArtifactVersions( artifact, + aetherRepositorySystem.resolveVersionRange( mavenSession.getRepositorySession(), + new VersionRangeRequest( + RepositoryUtils.toArtifact( artifact ).setVersion( "(,)" ), + usePluginRepositories + ? mavenSession.getCurrentProject().getRemotePluginRepositories() + : mavenSession.getCurrentProject().getRemoteProjectRepositories(), + "lookupArtifactVersions" ) ) + .getVersions() + .parallelStream() + .filter( v -> ignoredVersions.stream() + .noneMatch( i -> + { + if ( TYPE_REGEX.equals( i.getType() ) + && Pattern.compile( i.getVersion() ).matcher( v.toString() ).matches() ) + { + if ( getLog().isDebugEnabled() ) + { + getLog().debug( "Version " + v + " for artifact " + + ArtifactUtils.versionlessKey( artifact ) + + " found on ignore list: " + + i ); + } + return true; + } + + if ( TYPE_EXACT.equals( i.getType() ) + && i.getVersion().equals( v.toString() ) ) + { + if ( getLog().isDebugEnabled() ) + { + getLog().debug( "Version " + v + " for artifact " + + ArtifactUtils.versionlessKey( artifact ) + + " found on ignore list: " + + i ); + } + return true; + } + + return false; + } ) ) + .map( v -> new DefaultArtifactVersion( v.toString() ) ) + .collect( Collectors.toList() ), + getVersionComparator( artifact ) ); + } + catch ( VersionRangeResolutionException e ) + { + throw new VersionRetrievalException( e.getMessage(), e ); } - return new ArtifactVersions( artifact, versions, getVersionComparator( artifact ) ); } /** @@ -491,35 +477,15 @@ private List getIgnoredVersions( Artifact artifact ) return ret; } - /** - * Pretty print a list of ignored versions. - * - * @param ignoredVersions A list of ignored versions - * @return A String representation of the list - */ - private String showIgnoredVersions( List ignoredVersions ) - { - StringBuilder buf = new StringBuilder(); - Iterator iterator = ignoredVersions.iterator(); - while ( iterator.hasNext() ) - { - IgnoreVersion ignoreVersion = iterator.next(); - buf.append( ignoreVersion ); - if ( iterator.hasNext() ) - { - buf.append( ", " ); - } - } - return buf.toString(); - } - @Override public void resolveArtifact( Artifact artifact, boolean usePluginRepositories ) throws ArtifactResolutionException, ArtifactNotFoundException { - List remoteRepositories = - usePluginRepositories ? remotePluginRepositories : remoteArtifactRepositories; - artifactResolver.resolve( artifact, remoteRepositories, localRepository ); + artifactResolver.resolve( artifact, + usePluginRepositories + ? mavenSession.getCurrentProject().getPluginArtifactRepositories() + : mavenSession.getCurrentProject().getRemoteArtifactRepositories(), + localRepository ); } @Override @@ -674,12 +640,11 @@ public ArtifactVersion createArtifactVersion( String version ) * @param dependencies The set of {@link Dependency} instances to look up. * @param usePluginRepositories Search the plugin repositories. * @return map containing the ArtifactVersions object per dependency - * @throws ArtifactMetadataRetrievalException if the lookup does not succeed */ @Override public Map lookupDependenciesUpdates( Set dependencies, boolean usePluginRepositories ) - throws ArtifactMetadataRetrievalException + throws VersionRetrievalException { ExecutorService executor = Executors.newFixedThreadPool( LOOKUP_PARALLEL_THREADS ); try @@ -699,8 +664,8 @@ public Map lookupDependenciesUpdates( Set lookupDependenciesUpdates( Set lookupPluginsUpdates( Set plugins, boolean allowSnapshots ) - throws ArtifactMetadataRetrievalException + throws VersionRetrievalException { ExecutorService executor = Executors.newFixedThreadPool( LOOKUP_PARALLEL_THREADS ); try @@ -740,8 +705,8 @@ public Map lookupPluginsUpdates( Set plugi } catch ( ExecutionException | InterruptedException ie ) { - throw new ArtifactMetadataRetrievalException( "Unable to acquire metadata for plugins " + plugins + ": " - + ie.getMessage(), ie, null ); + throw new VersionRetrievalException( "Unable to acquire metadata for plugins " + plugins + ": " + + ie.getMessage(), ie ); } finally { @@ -751,7 +716,7 @@ public Map lookupPluginsUpdates( Set plugi @Override public PluginUpdatesDetails lookupPluginUpdates( Plugin plugin, boolean allowSnapshots ) - throws ArtifactMetadataRetrievalException + throws VersionRetrievalException { String version = plugin.getVersion() != null ? plugin.getVersion() @@ -885,7 +850,7 @@ else if ( !excludePropertiesList.isEmpty() && excludePropertiesList.contains( pr .getProperty( property.getName() ) ); propertyVersions.put( property, versions ); } - catch ( ArtifactMetadataRetrievalException e ) + catch ( VersionRetrievalException e ) { throw new MojoExecutionException( e.getMessage(), e ); } @@ -918,9 +883,6 @@ public static class Builder { private RepositorySystem repositorySystem; private ArtifactResolver artifactResolver; - private ArtifactMetadataSource artifactMetadataSource; - private List remoteArtifactRepositories; - private List remotePluginRepositories; private ArtifactRepository localRepository; private Collection ignoredVersions; private RuleSet ruleSet; @@ -931,6 +893,7 @@ public static class Builder private Log log; private MavenSession mavenSession; private MojoExecution mojoExecution; + private org.eclipse.aether.RepositorySystem aetherRepositorySystem; public Builder() { @@ -948,26 +911,6 @@ public Builder withArtifactResolver( ArtifactResolver artifactResolver ) return this; } - public Builder withArtifactMetadataSource( ArtifactMetadataSource artifactMetadataSource ) - { - this.artifactMetadataSource = artifactMetadataSource; - return this; - } - - public Builder withRemoteArtifactRepositories( - List remoteArtifactRepositories ) - { - this.remoteArtifactRepositories = remoteArtifactRepositories; - return this; - } - - public Builder withRemotePluginRepositories( - List remotePluginRepositories ) - { - this.remotePluginRepositories = remotePluginRepositories; - return this; - } - public Builder withLocalRepository( ArtifactRepository localRepository ) { this.localRepository = localRepository; @@ -1028,6 +971,12 @@ public Builder withMojoExecution( MojoExecution mojoExecution ) return this; } + public Builder withAetherRepositorySystem( org.eclipse.aether.RepositorySystem aetherRepositorySystem ) + { + this.aetherRepositorySystem = aetherRepositorySystem; + return this; + } + /** * Builds the constructed {@linkplain DefaultVersionsHelper} object * @return constructed {@linkplain DefaultVersionsHelper} @@ -1061,10 +1010,8 @@ public DefaultVersionsHelper build() throws MojoExecutionException { instance.ruleSet = enrichRuleSet( ignoredVersions, instance.ruleSet ); } - instance.artifactMetadataSource = artifactMetadataSource; + instance.aetherRepositorySystem = aetherRepositorySystem; instance.localRepository = localRepository; - instance.remoteArtifactRepositories = remoteArtifactRepositories; - instance.remotePluginRepositories = remotePluginRepositories; instance.log = log; return instance; } diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/api/PropertyVersions.java b/versions-common/src/main/java/org/codehaus/mojo/versions/api/PropertyVersions.java index 825be779e2..cfef7f9cd4 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/api/PropertyVersions.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/api/PropertyVersions.java @@ -32,7 +32,6 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.ArtifactUtils; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; @@ -74,7 +73,7 @@ public class PropertyVersions private final PropertyVersions.PropertyVersionComparator comparator; PropertyVersions( String profileId, String name, VersionsHelper helper, Set associations ) - throws ArtifactMetadataRetrievalException + throws VersionRetrievalException { this.profileId = profileId; this.name = name; @@ -88,7 +87,7 @@ public class PropertyVersions private static SortedSet resolveAssociatedVersions( VersionsHelper helper, Set associations, VersionComparator versionComparator ) - throws ArtifactMetadataRetrievalException + throws VersionRetrievalException { SortedSet versions = null; for ( ArtifactAssociation association : associations ) diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/api/PropertyVersionsBuilder.java b/versions-common/src/main/java/org/codehaus/mojo/versions/api/PropertyVersionsBuilder.java index 2e3c7a7312..2fe8963834 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/api/PropertyVersionsBuilder.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/api/PropertyVersionsBuilder.java @@ -26,7 +26,6 @@ import java.util.TreeSet; import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.codehaus.mojo.versions.ordering.VersionComparator; @@ -91,7 +90,7 @@ public ArtifactAssociation[] getAssociations() } public PropertyVersions newPropertyVersions() - throws ArtifactMetadataRetrievalException + throws VersionRetrievalException { return new PropertyVersions( profileId, name, helper, associations ); } diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/api/VersionRetrievalException.java b/versions-common/src/main/java/org/codehaus/mojo/versions/api/VersionRetrievalException.java new file mode 100644 index 0000000000..c1f1a4138e --- /dev/null +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/api/VersionRetrievalException.java @@ -0,0 +1,85 @@ +package org.codehaus.mojo.versions.api; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * Exception thrown if version information cannot be retrieved + */ +public class VersionRetrievalException extends Exception +{ + /** + * Constructs a new exception with {@code null} as its detail message. + * The cause is not initialized, and may subsequently be initialized by a + * call to {@link #initCause}. + */ + public VersionRetrievalException() + { + super(); + } + + /** + * Constructs a new exception with the specified detail message. The + * cause is not initialized, and may subsequently be initialized by + * a call to {@link #initCause}. + * + * @param message the detail message. The detail message is saved for + * later retrieval by the {@link #getMessage()} method. + */ + public VersionRetrievalException( String message ) + { + super( message ); + } + + /** + * Constructs a new exception with the specified cause and a detail + * message of {@code (cause==null ? null : cause.toString())} (which + * typically contains the class and detail message of {@code cause}). + * This constructor is useful for exceptions that are little more than + * wrappers for other throwables (for example, {@link + * java.security.PrivilegedActionException}). + * + * @param cause the cause (which is saved for later retrieval by the + * {@link #getCause()} method). (A {@code null} value is + * permitted, and indicates that the cause is nonexistent or + * unknown.) + */ + public VersionRetrievalException( Throwable cause ) + { + super( cause ); + } + + /** + * Constructs a new exception with the specified detail message and + * cause.

Note that the detail message associated with + * {@code cause} is not automatically incorporated in + * this exception's detail message. + * + * @param message the detail message (which is saved for later retrieval + * by the {@link #getMessage()} method). + * @param cause the cause (which is saved for later retrieval by the + * {@link #getCause()} method). (A {@code null} value is + * permitted, and indicates that the cause is nonexistent or + * unknown.) + */ + public VersionRetrievalException( String message, Throwable cause ) + { + super( message, cause ); + } +} 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 bd803639d6..28a11879dd 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 @@ -25,7 +25,6 @@ import java.util.Set; import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.versioning.ArtifactVersion; @@ -150,11 +149,11 @@ Artifact createDependencyArtifact( String groupId, String artifactId, String ver * @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 ArtifactMetadataRetrievalException When things go wrong. + * @throws VersionRetrievalException thrown if version resolution fails * @since 1.0-alpha-3 */ ArtifactVersions lookupArtifactVersions( Artifact artifact, boolean usePluginRepositories ) - throws ArtifactMetadataRetrievalException; + throws VersionRetrievalException; /** * Looks up the updates for a set of dependencies. @@ -162,12 +161,12 @@ ArtifactVersions lookupArtifactVersions( Artifact artifact, boolean usePluginRep * @param dependencies The set of {@link Dependency} instances to look up. * @param usePluginRepositories Search the plugin repositories. * @return A map, keyed by dependency, with values of type {@link org.codehaus.mojo.versions.api.ArtifactVersions}. - * @throws ArtifactMetadataRetrievalException When things go wrong. + * @throws VersionRetrievalException thrown if version resolution fails * @since 1.0-beta-1 */ Map lookupDependenciesUpdates( Set dependencies, boolean usePluginRepositories ) - throws ArtifactMetadataRetrievalException; + throws VersionRetrievalException; /** * Creates an {@link org.codehaus.mojo.versions.api.ArtifactVersions} instance from a dependency. @@ -175,11 +174,11 @@ Map lookupDependenciesUpdates( Set dep * @param dependency The dependency. * @param usePluginRepositories Search the plugin repositories. * @return The details of updates to the dependency. - * @throws ArtifactMetadataRetrievalException When things go wrong. + * @throws VersionRetrievalException thrown if version resolution fails * @since 1.0-beta-1 */ ArtifactVersions lookupDependencyUpdates( Dependency dependency, boolean usePluginRepositories ) - throws ArtifactMetadataRetrievalException; + throws VersionRetrievalException; /** * Looks up the updates for a set of plugins. @@ -187,11 +186,11 @@ ArtifactVersions lookupDependencyUpdates( Dependency dependency, boolean usePlug * @param plugins The set of {@link Plugin} instances to look up. * @param allowSnapshots Include snapshots in the list of updates. * @return A map, keyed by plugin, with values of type {@link org.codehaus.mojo.versions.api.PluginUpdatesDetails}. - * @throws ArtifactMetadataRetrievalException When things go wrong. + * @throws VersionRetrievalException thrown if version resolution fails * @since 1.0-beta-1 */ Map lookupPluginsUpdates( Set plugins, boolean allowSnapshots ) - throws ArtifactMetadataRetrievalException; + throws VersionRetrievalException; /** * Looks up the updates for a plugin. @@ -199,11 +198,9 @@ Map lookupPluginsUpdates( Set plugins, boo * @param plugin The {@link Plugin} instance to look up. * @param allowSnapshots Include snapshots in the list of updates. * @return The plugin update details. - * @throws ArtifactMetadataRetrievalException When things go wrong. * @since 1.0-beta-1 */ - PluginUpdatesDetails lookupPluginUpdates( Plugin plugin, boolean allowSnapshots ) - throws ArtifactMetadataRetrievalException; + PluginUpdatesDetails lookupPluginUpdates( Plugin plugin, boolean allowSnapshots ) throws VersionRetrievalException; /** * Returns an {@link ExpressionEvaluator} for the specified project. diff --git a/versions-common/src/test/java/org/codehaus/mojo/versions/api/DefaultVersionsHelperTest.java b/versions-common/src/test/java/org/codehaus/mojo/versions/api/DefaultVersionsHelperTest.java index 047bc3f421..b442516370 100644 --- a/versions-common/src/test/java/org/codehaus/mojo/versions/api/DefaultVersionsHelperTest.java +++ b/versions-common/src/test/java/org/codehaus/mojo/versions/api/DefaultVersionsHelperTest.java @@ -23,35 +23,37 @@ import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; -import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.artifact.resolver.DefaultArtifactResolver; import org.apache.maven.artifact.versioning.ArtifactVersion; -import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugin.logging.SystemStreamLog; import org.apache.maven.plugin.testing.AbstractMojoTestCase; +import org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub; import org.apache.maven.project.MavenProject; -import org.apache.maven.project.artifact.MavenMetadataSource; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.settings.Settings; import org.codehaus.mojo.versions.model.IgnoreVersion; import org.codehaus.mojo.versions.model.Rule; import org.codehaus.mojo.versions.model.RuleSet; import org.codehaus.mojo.versions.ordering.VersionComparators; +import org.codehaus.mojo.versions.utils.VersionStub; +import org.eclipse.aether.resolution.VersionRangeRequest; +import org.eclipse.aether.resolution.VersionRangeResult; +import org.eclipse.aether.version.Version; import org.hamcrest.CoreMatchers; import org.junit.Test; -import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; @@ -59,9 +61,7 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.core.IsIterableContaining.hasItems; import static org.mockito.Mockito.any; -import static org.mockito.Mockito.anyList; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.same; import static org.mockito.Mockito.when; /** @@ -73,64 +73,68 @@ public class DefaultVersionsHelperTest extends AbstractMojoTestCase @Test public void testPerRuleVersionsIgnored() throws Exception { - final ArtifactMetadataSource metadataSource = mock( ArtifactMetadataSource.class ); + final org.eclipse.aether.RepositorySystem repositorySystem = mock( org.eclipse.aether.RepositorySystem.class ); final Artifact artifact = mock( Artifact.class ); when( artifact.getGroupId() ).thenReturn( "com.mycompany.maven" ); when( artifact.getArtifactId() ).thenReturn( "artifact-one" ); - - final List artifactVersions = new ArrayList<>(); - - artifactVersions.add( new DefaultArtifactVersion( "one" ) ); - artifactVersions.add( new DefaultArtifactVersion( "two" ) ); - final ArtifactVersion three = new DefaultArtifactVersion( "three" ); - artifactVersions.add( three ); - final ArtifactVersion oneTwoHundred = new DefaultArtifactVersion( "1.200" ); - artifactVersions.add( oneTwoHundred ); - final ArtifactVersion illegal = new DefaultArtifactVersion( "illegalVersion" ); - artifactVersions.add( illegal ); - - when( metadataSource.retrieveAvailableVersions( same( artifact ), any( ArtifactRepository.class ), anyList() ) ) - .thenReturn( artifactVersions ); - - VersionsHelper helper = createHelper( metadataSource ); + when( artifact.getType() ).thenReturn( "jar" ); + when( artifact.getArtifactHandler() ).thenReturn( new DefaultArtifactHandlerStub( "default" ) ); + when( repositorySystem.resolveVersionRange( any(), any( VersionRangeRequest.class ) ) ) + .then( i -> new VersionRangeResult( i.getArgument( 1 ) ) + .setVersions( Arrays.asList( + new VersionStub( "one" ), + new VersionStub( "two" ), + new VersionStub( "three" ), + new VersionStub( "1.200" ), + new VersionStub( "illegalVersion" ) ) ) ); + + VersionsHelper helper = createHelper( repositorySystem ); final ArtifactVersions versions = helper.lookupArtifactVersions( artifact, true ); - final List actual = asList( versions.getVersions( true ) ); + final List actual = Arrays.stream( versions.getVersions( true ) ) + .map( ArtifactVersion::toString ) + .collect( Collectors.toList() ); assertEquals( 3, actual.size() ); - assertThat( actual, hasItems( three, oneTwoHundred, illegal ) ); + assertThat( actual, hasItems( "three", "1.200", "illegalVersion" ) ); } @Test public void testGlobalRuleVersionsIgnored() throws Exception { - final ArtifactMetadataSource metadataSource = mock( ArtifactMetadataSource.class ); + final org.eclipse.aether.RepositorySystem repositorySystem = mock( org.eclipse.aether.RepositorySystem.class ); final Artifact artifact = mock( Artifact.class ); when( artifact.getGroupId() ).thenReturn( "other.company" ); when( artifact.getArtifactId() ).thenReturn( "artifact-two" ); + when( artifact.getType() ).thenReturn( "jar" ); + when( artifact.getArtifactHandler() ).thenReturn( new DefaultArtifactHandlerStub( "default" ) ); - final List artifactVersions = new ArrayList<>(); + final List artifactVersions = new ArrayList<>(); - final ArtifactVersion one = new DefaultArtifactVersion( "one" ); - final ArtifactVersion two = new DefaultArtifactVersion( "two" ); - final ArtifactVersion three = new DefaultArtifactVersion( "three" ); + final Version one = new VersionStub( "one" ); + final Version two = new VersionStub( "two" ); + final Version three = new VersionStub( "three" ); artifactVersions.add( one ); artifactVersions.add( two ); - artifactVersions.add( new DefaultArtifactVersion( "three-alpha" ) ); - artifactVersions.add( new DefaultArtifactVersion( "three-beta" ) ); + artifactVersions.add( new VersionStub( "three-alpha" ) ); + artifactVersions.add( new VersionStub( "three-beta" ) ); artifactVersions.add( three ); - final ArtifactVersion illegal = new DefaultArtifactVersion( "illegalVersion" ); + final Version illegal = new VersionStub( "illegalVersion" ); artifactVersions.add( illegal ); - when( metadataSource.retrieveAvailableVersions( same( artifact ), any( ArtifactRepository.class ), anyList() ) ) - .thenReturn( artifactVersions ); + when( repositorySystem.resolveVersionRange( any(), any( VersionRangeRequest.class ) ) ) + .then( i -> new VersionRangeResult( i.getArgument( 1 ) ) + .setVersions( artifactVersions ) ); - VersionsHelper helper = createHelper( metadataSource ); + VersionsHelper helper = createHelper( repositorySystem ); final ArtifactVersions versions = helper.lookupArtifactVersions( artifact, true ); - final List actual = asList( versions.getVersions( true ) ); + final List actual = Arrays.stream( versions.getVersions( true ) ) + .map( ArtifactVersion::toString ) + .map( VersionStub::new ) + .collect( Collectors.toList() ); assertEquals( 4, actual.size() ); assertThat( actual, hasItems( one, two, three, illegal ) ); @@ -214,19 +218,24 @@ public void testIsClasspathUriDetectsThatItIsDifferentProtocol() throws Exceptio private DefaultVersionsHelper createHelper() throws Exception { - return createHelper( new MavenMetadataSource() ); + return createHelper( null ); } - private DefaultVersionsHelper createHelper( ArtifactMetadataSource metadataSource ) throws Exception + private DefaultVersionsHelper createHelper( org.eclipse.aether.RepositorySystem aetherRepositorySystem ) + throws Exception { final String resourcePath = "/" + getClass().getPackage().getName().replace( '.', '/' ) + "/rules.xml"; - final String rulesUri = getClass().getResource( resourcePath ).toExternalForm(); + final String rulesUri = Objects.requireNonNull( getClass().getResource( resourcePath ) ).toExternalForm(); + MavenSession mavenSession = mock( MavenSession.class ); + when( mavenSession.getCurrentProject() ).thenReturn( mock( MavenProject.class ) ); + when( mavenSession.getCurrentProject().getRemotePluginRepositories() ) + .thenReturn( emptyList() ); + when( mavenSession.getCurrentProject().getRemotePluginRepositories() ) + .thenReturn( emptyList() ); return new DefaultVersionsHelper.Builder() .withRepositorySystem( lookup( RepositorySystem.class ) ) .withArtifactResolver( new DefaultArtifactResolver() ) - .withArtifactMetadataSource( metadataSource ) - .withRemoteArtifactRepositories( new ArrayList<>() ) - .withRemotePluginRepositories( new ArrayList<>() ) + .withAetherRepositorySystem( aetherRepositorySystem ) .withLocalRepository( new DefaultArtifactRepository( "", "", new DefaultRepositoryLayout() ) ) .withWagonManager( lookup( WagonManager.class ) ) @@ -234,7 +243,7 @@ private DefaultVersionsHelper createHelper( ArtifactMetadataSource metadataSourc .withServerId( "" ) .withRulesUri( rulesUri ) .withLog( mock( Log.class ) ) - .withMavenSession( mock( MavenSession.class ) ) + .withMavenSession( mavenSession ) .withMojoExecution( mock( MojoExecution.class ) ).build(); } diff --git a/versions-common/src/test/java/org/codehaus/mojo/versions/utils/VersionStub.java b/versions-common/src/test/java/org/codehaus/mojo/versions/utils/VersionStub.java new file mode 100644 index 0000000000..699644eeca --- /dev/null +++ b/versions-common/src/test/java/org/codehaus/mojo/versions/utils/VersionStub.java @@ -0,0 +1,76 @@ +package org.codehaus.mojo.versions.utils; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.eclipse.aether.version.Version; + +/** + * Stubs the {@link org.eclipse.aether.version.Version} + */ +public class VersionStub implements Version +{ + private final String version; + + /** + * Creates a new instance with the given version string + * @param version version to be set + */ + public VersionStub( String version ) + { + assert version != null; + this.version = version; + } + + @Override + public String toString() + { + return version; + } + + @Override + public int compareTo( Version o ) + { + return o != null + ? version.compareTo( o.toString() ) + : 1; + } + + @Override + public boolean equals( Object o ) + { + if ( this == o ) + { + return true; + } + + if ( !( o instanceof Version ) ) + { + return false; + } + + return version.equals( o.toString() ); + } + + @Override + public int hashCode() + { + return version.hashCode(); + } +} diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsDependencyUpdaterMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsDependencyUpdaterMojo.java index 42a46b92dd..5bee054503 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsDependencyUpdaterMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsDependencyUpdaterMojo.java @@ -32,7 +32,6 @@ import org.apache.commons.lang3.StringUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.model.Dependency; @@ -160,14 +159,14 @@ public abstract class AbstractVersionsDependencyUpdaterMojo @Inject protected AbstractVersionsDependencyUpdaterMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver, Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); } /** diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsDisplayMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsDisplayMojo.java index fd01229369..98a6779361 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsDisplayMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsDisplayMojo.java @@ -31,7 +31,6 @@ import org.apache.commons.lang3.StringUtils; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProjectBuilder; @@ -87,14 +86,14 @@ public abstract class AbstractVersionsDisplayMojo @Inject protected AbstractVersionsDisplayMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver, Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); } @SuppressWarnings( "unchecked" ) 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 26b993dd34..45e0b1654f 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 @@ -26,8 +26,6 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.versioning.ArtifactVersion; @@ -45,6 +43,7 @@ import org.apache.maven.settings.Settings; 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; @@ -78,11 +77,9 @@ public abstract class AbstractVersionsReport private boolean skip; /** - * The artifact metadata source to use. - * - * @since 1.0-alpha-1 + * The (injected) {@link org.eclipse.aether.RepositorySystem aetherRepositorySystem} instance. */ - protected ArtifactMetadataSource artifactMetadataSource; + protected org.eclipse.aether.RepositorySystem aetherRepositorySystem; /** * @since 1.0-alpha-3 @@ -197,14 +194,16 @@ public abstract class AbstractVersionsReport // --------------------- GETTER / SETTER METHODS --------------------- - protected AbstractVersionsReport( I18N i18n, RepositorySystem repositorySystem, ArtifactResolver artifactResolver, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, + protected AbstractVersionsReport( I18N i18n, RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, + ArtifactResolver artifactResolver, + WagonManager wagonManager, ReportRendererFactory rendererFactory ) { this.i18n = i18n; this.repositorySystem = repositorySystem; + this.aetherRepositorySystem = aetherRepositorySystem; this.artifactResolver = artifactResolver; - this.artifactMetadataSource = artifactMetadataSource; this.wagonManager = wagonManager; this.rendererFactory = rendererFactory; } @@ -219,9 +218,7 @@ public VersionsHelper getHelper() helper = new DefaultVersionsHelper.Builder() .withRepositorySystem( repositorySystem ) .withArtifactResolver( artifactResolver ) - .withArtifactMetadataSource( artifactMetadataSource ) - .withRemoteArtifactRepositories( remoteArtifactRepositories ) - .withRemotePluginRepositories( remotePluginRepositories ) + .withAetherRepositorySystem( aetherRepositorySystem ) .withLocalRepository( localRepository ) .withWagonManager( wagonManager ) .withSettings( settings ) @@ -295,7 +292,7 @@ protected ArtifactVersion findLatestVersion( Artifact artifact, VersionRange ver getHelper().lookupArtifactVersions( artifact, usePluginRepositories ); return artifactVersions.getNewestVersion( versionRange, includeSnapshots ); } - catch ( ArtifactMetadataRetrievalException e ) + catch ( VersionRetrievalException e ) { throw new MavenReportException( e.getMessage(), e ); } 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 4b7aace6e6..4b69512ba5 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 @@ -33,8 +33,6 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; @@ -58,6 +56,7 @@ import org.codehaus.mojo.versions.api.Property; import org.codehaus.mojo.versions.api.PropertyVersions; import org.codehaus.mojo.versions.api.Segment; +import org.codehaus.mojo.versions.api.VersionRetrievalException; import org.codehaus.mojo.versions.api.VersionsHelper; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.model.RuleSet; @@ -87,25 +86,29 @@ public abstract class AbstractVersionsUpdaterMojo @Parameter( defaultValue = "${project}", required = true, readonly = true ) protected MavenProject project; - protected RepositorySystem repositorySystem; + /** + * The (injected) {@link RepositorySystem} instance. + */ + protected final RepositorySystem repositorySystem; /** - * @since 1.0-alpha-1 + * The (injected) {@link org.eclipse.aether.RepositorySystem} instance. */ - protected MavenProjectBuilder projectBuilder; + protected org.eclipse.aether.RepositorySystem aetherRepositorySystem; + /** + * The (injected) {@link MavenProjectBuilder} instance. + */ /** * @since 1.0-alpha-1 */ - @Parameter( defaultValue = "${reactorProjects}", required = true, readonly = true ) - protected List reactorProjects; + protected final MavenProjectBuilder projectBuilder; /** - * The artifact metadata source to use. - * * @since 1.0-alpha-1 */ - protected ArtifactMetadataSource artifactMetadataSource; + @Parameter( defaultValue = "${reactorProjects}", required = true, readonly = true ) + protected List reactorProjects; /** * @since 1.0-alpha-3 @@ -126,9 +129,9 @@ public abstract class AbstractVersionsUpdaterMojo protected ArtifactRepository localRepository; /** - * @since 1.0-alpha-3 + * The (injected) {@link WagonManager} instance. */ - private WagonManager wagonManager; + private final WagonManager wagonManager; /** * @since 1.0-alpha-3 @@ -239,15 +242,15 @@ public abstract class AbstractVersionsUpdaterMojo @Inject protected AbstractVersionsUpdaterMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver, Map changeRecorders ) { this.repositorySystem = repositorySystem; + this.aetherRepositorySystem = aetherRepositorySystem; this.projectBuilder = projectBuilder; - this.artifactMetadataSource = artifactMetadataSource; this.wagonManager = wagonManager; this.artifactResolver = artifactResolver; this.changeRecorders = changeRecorders; @@ -260,9 +263,7 @@ public VersionsHelper getHelper() throws MojoExecutionException helper = new DefaultVersionsHelper.Builder() .withRepositorySystem( repositorySystem ) .withArtifactResolver( artifactResolver ) - .withArtifactMetadataSource( artifactMetadataSource ) - .withRemoteArtifactRepositories( remoteArtifactRepositories ) - .withRemotePluginRepositories( remotePluginRepositories ) + .withAetherRepositorySystem( aetherRepositorySystem ) .withLocalRepository( localRepository ) .withWagonManager( wagonManager ) .withSettings( settings ) @@ -341,13 +342,13 @@ protected void validateInput() throws MojoExecutionException * @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 ArtifactMetadataRetrievalException If the artifact metadata could not be found. + * @throws VersionRetrievalException If the artifact metadata could not be found. * @throws MojoExecutionException if something goes wrong. * @since 1.0-alpha-1 */ protected ArtifactVersion findLatestVersion( Artifact artifact, VersionRange versionRange, Boolean allowingSnapshots, boolean usePluginRepositories ) - throws ArtifactMetadataRetrievalException, MojoExecutionException + throws MojoExecutionException, VersionRetrievalException { boolean includeSnapshots = allowingSnapshots != null ? allowingSnapshots : this.allowSnapshots; final ArtifactVersions artifactVersions = getHelper().lookupArtifactVersions( artifact, usePluginRepositories ); @@ -414,7 +415,7 @@ protected void process( File outFile ) { getLog().error( e ); } - catch ( ArtifactMetadataRetrievalException e ) + catch ( VersionRetrievalException e ) { throw new MojoExecutionException( e.getMessage(), e ); } @@ -467,11 +468,11 @@ protected final void writeFile( File outFile, StringBuilder input ) * @throws MojoExecutionException If things go wrong. * @throws MojoFailureException If things go wrong. * @throws javax.xml.stream.XMLStreamException If things go wrong. - * @throws ArtifactMetadataRetrievalException if something goes wrong. + * @throws VersionRetrievalException if version retrieval goes wrong * @since 1.0-alpha-1 */ protected abstract void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException, ArtifactMetadataRetrievalException; + throws MojoExecutionException, MojoFailureException, XMLStreamException, VersionRetrievalException; /** * @param artifact The artifact. diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/CompareDependenciesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/CompareDependenciesMojo.java index 22a54c5520..a955c8555b 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/CompareDependenciesMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/CompareDependenciesMojo.java @@ -33,7 +33,6 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.model.Dependency; import org.apache.maven.plugin.MojoExecutionException; @@ -128,15 +127,15 @@ public class CompareDependenciesMojo @Inject public CompareDependenciesMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver, MavenProjectBuilder mavenProjectBuilder, Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); this.mavenProjectBuilder = mavenProjectBuilder; } @@ -148,7 +147,7 @@ public CompareDependenciesMojo( RepositorySystem repositorySystem, * @see AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader) */ protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException + throws MojoExecutionException, MojoFailureException, XMLStreamException { if ( this.ignoreRemoteDependencies && this.ignoreRemoteDependencyManagement ) { diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DependencyUpdatesReportMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DependencyUpdatesReportMojo.java index 69c5a66e67..5ed1df38b9 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DependencyUpdatesReportMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DependencyUpdatesReportMojo.java @@ -33,8 +33,6 @@ import java.util.stream.Collectors; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.doxia.sink.Sink; @@ -45,6 +43,7 @@ import org.apache.maven.reporting.MavenReportException; import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.ArtifactVersions; +import org.codehaus.mojo.versions.api.VersionRetrievalException; import org.codehaus.mojo.versions.reporting.ReportRendererFactory; import org.codehaus.mojo.versions.reporting.model.DependencyUpdatesModel; import org.codehaus.mojo.versions.utils.DependencyComparator; @@ -111,11 +110,12 @@ public class DependencyUpdatesReportMojo extends AbstractVersionsReport changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); } private static Set extractPluginDependenciesFromPluginsInPluginManagement( Build build ) @@ -595,7 +593,7 @@ public void execute() logUpdates( getHelper().lookupDependenciesUpdates( pluginDependencies, false ), "Plugin Dependencies" ); } } - catch ( ArtifactMetadataRetrievalException e ) + catch ( VersionRetrievalException e ) { throw new MojoExecutionException( e.getMessage(), e ); } @@ -791,15 +789,11 @@ private void logUpdates( Map updates, String secti /** * @param pom the pom to update. - * @throws org.apache.maven.plugin.MojoExecutionException when things go wrong - * @throws org.apache.maven.plugin.MojoFailureException when things go wrong in a very bad way - * @throws javax.xml.stream.XMLStreamException when things go wrong with XML streaming * @see org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader) * @since 1.0-alpha-1 */ @Override protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException { // do nothing } diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayParentUpdatesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayParentUpdatesMojo.java index c07dd91c74..a932c5aa28 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayParentUpdatesMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayParentUpdatesMojo.java @@ -20,14 +20,11 @@ */ import javax.inject.Inject; -import javax.xml.stream.XMLStreamException; import java.util.Map; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; @@ -37,6 +34,7 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.repository.RepositorySystem; +import org.codehaus.mojo.versions.api.VersionRetrievalException; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.codehaus.mojo.versions.utils.DependencyBuilder; @@ -56,14 +54,14 @@ public class DisplayParentUpdatesMojo @Inject public DisplayParentUpdatesMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver, Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); } @Override @@ -108,7 +106,7 @@ public void execute() { artifactVersion = findLatestVersion( artifact, versionRange, null, false ); } - catch ( ArtifactMetadataRetrievalException e ) + catch ( VersionRetrievalException e ) { throw new MojoExecutionException( e.getMessage(), e ); } @@ -156,7 +154,6 @@ public void execute() @Override protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException, ArtifactMetadataRetrievalException { } } 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 85e64ea4ca..41840c2785 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 @@ -50,8 +50,6 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; @@ -94,6 +92,7 @@ import org.apache.maven.settings.Settings; import org.codehaus.mojo.versions.api.ArtifactVersions; import org.codehaus.mojo.versions.api.PomHelper; +import org.codehaus.mojo.versions.api.VersionRetrievalException; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.ordering.MavenVersionComparator; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; @@ -165,8 +164,8 @@ public class DisplayPluginUpdatesMojo @Inject @SuppressWarnings( "checkstyle:ParameterNumber" ) public DisplayPluginUpdatesMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver, LifecycleExecutor lifecycleExecutor, @@ -175,8 +174,8 @@ public DisplayPluginUpdatesMojo( RepositorySystem repositorySystem, RuntimeInformation runtimeInformation, Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); this.lifecycleExecutor = lifecycleExecutor; this.modelInterpolator = modelInterpolator; this.pluginManager = pluginManager; @@ -538,7 +537,7 @@ public void execute() } } } - catch ( ArtifactMetadataRetrievalException e ) + catch ( VersionRetrievalException e ) { throw new MojoExecutionException( e.getMessage(), e ); } @@ -1821,14 +1820,10 @@ private Map getReportPlugins( Model model, boolean onlyIncludeIn /** * @param pom the pom to update. - * @throws MojoExecutionException when things go wrong - * @throws MojoFailureException when things go wrong in a very bad way - * @throws XMLStreamException when things go wrong with XML streaming * @see AbstractVersionsUpdaterMojo#update(ModifiedPomXMLEventReader) * @since 1.0-alpha-1 */ protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException { // do nothing } diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayPropertyUpdatesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayPropertyUpdatesMojo.java index 8b81d31be6..7bf8d69256 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayPropertyUpdatesMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayPropertyUpdatesMojo.java @@ -20,7 +20,6 @@ */ import javax.inject.Inject; -import javax.xml.stream.XMLStreamException; import java.util.ArrayList; import java.util.List; @@ -29,8 +28,6 @@ import java.util.TreeSet; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; @@ -145,14 +142,14 @@ public class DisplayPropertyUpdatesMojo @Inject public DisplayPropertyUpdatesMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver, Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); } public void execute() @@ -261,8 +258,8 @@ else if ( updates.isEmpty() ) logLine( false, "" ); } + @Override protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException, ArtifactMetadataRetrievalException { } } diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/ForceReleasesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/ForceReleasesMojo.java index 419c458e89..256c979469 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/ForceReleasesMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/ForceReleasesMojo.java @@ -29,8 +29,6 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.VersionRange; @@ -46,6 +44,7 @@ import org.codehaus.mojo.versions.api.recording.ChangeRecord; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.api.PomHelper; +import org.codehaus.mojo.versions.api.VersionRetrievalException; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import static java.util.Collections.singletonList; @@ -72,14 +71,14 @@ public class ForceReleasesMojo @Inject public ForceReleasesMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver, Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -90,7 +89,7 @@ public ForceReleasesMojo( RepositorySystem repositorySystem, * @see AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader) */ protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException + throws MojoExecutionException, MojoFailureException, XMLStreamException, VersionRetrievalException { try { @@ -114,7 +113,7 @@ protected void update( ModifiedPomXMLEventReader pom ) ChangeRecord.ChangeKind.PARENT ); } } - catch ( ArtifactMetadataRetrievalException | IOException e ) + catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } @@ -122,7 +121,7 @@ protected void update( ModifiedPomXMLEventReader pom ) private void useReleases( ModifiedPomXMLEventReader pom, Collection dependencies, ChangeRecord.ChangeKind changeKind ) - throws XMLStreamException, MojoExecutionException, ArtifactMetadataRetrievalException + throws XMLStreamException, MojoExecutionException, VersionRetrievalException { for ( Dependency dep : dependencies ) { diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/LockSnapshotsMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/LockSnapshotsMojo.java index 992105005b..735c43244e 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/LockSnapshotsMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/LockSnapshotsMojo.java @@ -30,7 +30,6 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.model.Dependency; import org.apache.maven.model.DependencyManagement; @@ -69,14 +68,14 @@ public class LockSnapshotsMojo @Inject public LockSnapshotsMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver, Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -87,7 +86,7 @@ public LockSnapshotsMojo( RepositorySystem repositorySystem, * @see AbstractVersionsUpdaterMojo#update(ModifiedPomXMLEventReader) */ protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException + throws MojoExecutionException, MojoFailureException, XMLStreamException { try { diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/ParentUpdatesReportMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/ParentUpdatesReportMojo.java index 54adc31619..83bb2ab4b5 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/ParentUpdatesReportMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/ParentUpdatesReportMojo.java @@ -25,8 +25,6 @@ import java.util.Locale; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.doxia.sink.Sink; import org.apache.maven.plugins.annotations.Mojo; @@ -36,6 +34,7 @@ import org.apache.maven.reporting.MavenReportException; import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.ArtifactVersions; +import org.codehaus.mojo.versions.api.VersionRetrievalException; import org.codehaus.mojo.versions.reporting.ReportRendererFactory; import org.codehaus.mojo.versions.reporting.model.ParentUpdatesModel; import org.codehaus.mojo.versions.utils.DependencyBuilder; @@ -55,11 +54,14 @@ public class ParentUpdatesReportMojo extends AbstractVersionsReport reactorProjects; @Inject - protected ParentUpdatesReportMojo( I18N i18n, RepositorySystem repositorySystem, ArtifactResolver artifactResolver, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, + protected ParentUpdatesReportMojo( I18N i18n, + RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, + ArtifactResolver artifactResolver, + WagonManager wagonManager, ReportRendererFactory rendererFactory ) { - super( i18n, repositorySystem, artifactResolver, artifactMetadataSource, wagonManager, rendererFactory ); + super( i18n, repositorySystem, aetherRepositorySystem, artifactResolver, wagonManager, rendererFactory ); } /** @@ -115,7 +117,7 @@ protected void doGenerateReport( Locale locale, Sink sink ) throws MavenReportEx .build(), artifactVersions ) ) .render(); } - catch ( ArtifactMetadataRetrievalException e ) + catch ( VersionRetrievalException e ) { throw new MavenReportException( e.getMessage(), e ); } diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/PluginUpdatesReportMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/PluginUpdatesReportMojo.java index 717dec32a1..40427c1962 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/PluginUpdatesReportMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/PluginUpdatesReportMojo.java @@ -31,8 +31,6 @@ import java.util.TreeSet; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.doxia.sink.Sink; import org.apache.maven.model.Plugin; @@ -42,6 +40,7 @@ import org.apache.maven.reporting.MavenReportException; import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.PluginUpdatesDetails; +import org.codehaus.mojo.versions.api.VersionRetrievalException; import org.codehaus.mojo.versions.reporting.ReportRendererFactory; import org.codehaus.mojo.versions.reporting.model.PluginUpdatesModel; import org.codehaus.mojo.versions.utils.PluginComparator; @@ -85,11 +84,14 @@ public class PluginUpdatesReportMojo extends AbstractVersionsReport changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -147,7 +146,7 @@ public ResolveRangesMojo( RepositorySystem repositorySystem, * @see AbstractVersionsUpdaterMojo#update(ModifiedPomXMLEventReader) */ protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException, ArtifactMetadataRetrievalException + throws MojoExecutionException, MojoFailureException, XMLStreamException, VersionRetrievalException { // Note we have to get the dependencies from the model because the dependencies in the // project may have already had their range resolved [MNG-4138] @@ -190,7 +189,7 @@ private boolean hasDependencyManagement() } private void resolveRangesInParent( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, ArtifactMetadataRetrievalException, XMLStreamException + throws MojoExecutionException, VersionRetrievalException, XMLStreamException { Matcher versionMatcher = matchRangeRegex.matcher( getProject().getModel().getParent().getVersion() ); @@ -236,7 +235,7 @@ private void resolveRangesInParent( ModifiedPomXMLEventReader pom ) } private void resolveRanges( ModifiedPomXMLEventReader pom, Collection dependencies ) - throws XMLStreamException, MojoExecutionException, ArtifactMetadataRetrievalException + throws XMLStreamException, MojoExecutionException, VersionRetrievalException { for ( Dependency dep : dependencies ) diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetMojo.java index 595f4d30d3..4924289303 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetMojo.java @@ -42,7 +42,6 @@ import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.model.Model; import org.apache.maven.model.Parent; @@ -248,15 +247,15 @@ public class SetMojo extends AbstractVersionsUpdaterMojo @Inject public SetMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver, Map changeRecorders, Prompter prompter ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); this.prompter = prompter; } @@ -569,7 +568,7 @@ else if ( moduleDir.isDirectory() ) * @throws javax.xml.stream.XMLStreamException when things go wrong. */ protected synchronized void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException + throws MojoExecutionException, MojoFailureException, XMLStreamException { ContextualLog log = new DelegatingContextualLog( getLog() ); try diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetPropertyMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetPropertyMojo.java index 804339fc76..6abca80b7c 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetPropertyMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetPropertyMojo.java @@ -27,7 +27,6 @@ import java.util.Map; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -93,14 +92,14 @@ public class SetPropertyMojo @Inject public SetPropertyMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, + MavenProjectBuilder projectBuilder, + WagonManager wagonManager, + ArtifactResolver artifactResolver, Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -111,7 +110,7 @@ public SetPropertyMojo( RepositorySystem repositorySystem, * @see AbstractVersionsUpdaterMojo#update(ModifiedPomXMLEventReader) */ protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException + throws MojoExecutionException, MojoFailureException, XMLStreamException { Property[] propertiesConfig; String properties; diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetScmTagMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetScmTagMojo.java index 32d5e3f8bc..777ec9287e 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetScmTagMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetScmTagMojo.java @@ -9,8 +9,6 @@ import java.util.Map; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.model.Scm; import org.apache.maven.plugin.MojoExecutionException; @@ -70,14 +68,14 @@ public class SetScmTagMojo extends AbstractVersionsUpdaterMojo @Inject public SetScmTagMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver, Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -100,7 +98,7 @@ public void execute() throws MojoExecutionException, MojoFailureException @Override protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException, ArtifactMetadataRetrievalException + throws MojoExecutionException, MojoFailureException, XMLStreamException { try { diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UnlockSnapshotsMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UnlockSnapshotsMojo.java index 7f6a8a591d..e3c18336ba 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UnlockSnapshotsMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UnlockSnapshotsMojo.java @@ -30,7 +30,6 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.model.Dependency; import org.apache.maven.model.DependencyManagement; @@ -70,14 +69,14 @@ public class UnlockSnapshotsMojo extends AbstractVersionsDependencyUpdaterMojo @Inject public UnlockSnapshotsMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver, Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -88,7 +87,7 @@ public UnlockSnapshotsMojo( RepositorySystem repositorySystem, * @see AbstractVersionsUpdaterMojo#update(ModifiedPomXMLEventReader) */ protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException + throws MojoExecutionException, MojoFailureException, XMLStreamException { try { diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdateChildModulesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdateChildModulesMojo.java index dc52b603bd..0cd87fa827 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdateChildModulesMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdateChildModulesMojo.java @@ -30,7 +30,6 @@ import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.model.Model; import org.apache.maven.model.Parent; @@ -72,14 +71,14 @@ public class UpdateChildModulesMojo @Inject public UpdateChildModulesMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver, Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -212,7 +211,7 @@ else if ( d1 > d2 ) * @throws XMLStreamException when things go wrong. */ protected synchronized void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException + throws MojoExecutionException, MojoFailureException, XMLStreamException { getLog().debug( "Updating parent to " + sourceVersion ); diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdateParentMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdateParentMojo.java index 73d1fd0799..1dac708177 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdateParentMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdateParentMojo.java @@ -30,8 +30,6 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; @@ -46,6 +44,7 @@ import org.codehaus.mojo.versions.api.ArtifactVersions; import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.api.Segment; +import org.codehaus.mojo.versions.api.VersionRetrievalException; import org.codehaus.mojo.versions.api.recording.ChangeRecord; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.ordering.InvalidSegmentException; @@ -141,14 +140,14 @@ public class UpdateParentMojo extends AbstractVersionsUpdaterMojo @Inject public UpdateParentMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver, Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -160,7 +159,7 @@ public UpdateParentMojo( RepositorySystem repositorySystem, * @since 1.0-alpha-1 */ protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException + throws MojoExecutionException, MojoFailureException, XMLStreamException, VersionRetrievalException { if ( getProject().getParent() == null ) { @@ -213,10 +212,6 @@ protected void update( ModifiedPomXMLEventReader pom ) { throw new MojoExecutionException( "Invalid version range specification: " + initialVersion, e ); } - catch ( ArtifactMetadataRetrievalException e ) - { - throw new MojoExecutionException( e.getMessage(), e ); - } catch ( InvalidSegmentException e ) { throw new MojoExecutionException( "Invalid segment specification for version " + initialVersion, e ); @@ -224,7 +219,7 @@ protected void update( ModifiedPomXMLEventReader pom ) } protected ArtifactVersion resolveTargetVersion( String initialVersion ) - throws MojoExecutionException, ArtifactMetadataRetrievalException, InvalidVersionSpecificationException, + throws MojoExecutionException, VersionRetrievalException, InvalidVersionSpecificationException, InvalidSegmentException { Artifact artifact = getHelper().createDependencyArtifact( DependencyBuilder diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojo.java index 7816f0b619..a5c5d8a094 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojo.java @@ -26,7 +26,6 @@ import java.util.Optional; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; @@ -142,14 +141,14 @@ public class UpdatePropertiesMojo extends AbstractVersionsDependencyUpdaterMojo @Inject public UpdatePropertiesMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver, Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -161,7 +160,7 @@ public UpdatePropertiesMojo( RepositorySystem repositorySystem, * @since 1.0-alpha-1 */ protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException + throws MojoExecutionException, MojoFailureException, XMLStreamException { Map propertyVersions = getHelper().getVersionPropertiesMap( VersionsHelper.VersionPropertiesMapRequest.builder() diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertyMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertyMojo.java index 1cc59dd2dc..abef1cf509 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertyMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertyMojo.java @@ -26,7 +26,6 @@ import java.util.Optional; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; @@ -141,14 +140,14 @@ public class UpdatePropertyMojo @Inject public UpdatePropertyMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, + MavenProjectBuilder projectBuilder, + WagonManager wagonManager, + ArtifactResolver artifactResolver, Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -160,7 +159,7 @@ public UpdatePropertyMojo( RepositorySystem repositorySystem, * @since 1.0-alpha-1 */ protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException + throws MojoExecutionException, MojoFailureException, XMLStreamException { Property propertyConfig = new Property( property ); propertyConfig.setVersion( newVersion ); diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseDepVersionMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseDepVersionMojo.java index bedc8533be..c895e14680 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseDepVersionMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseDepVersionMojo.java @@ -28,8 +28,6 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.model.Dependency; import org.apache.maven.model.DependencyManagement; @@ -41,6 +39,7 @@ import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.ArtifactVersions; import org.codehaus.mojo.versions.api.PomHelper; +import org.codehaus.mojo.versions.api.VersionRetrievalException; import org.codehaus.mojo.versions.api.recording.ChangeRecord; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; @@ -76,19 +75,19 @@ public class UseDepVersionMojo extends AbstractVersionsDependencyUpdaterMojo @Inject public UseDepVersionMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver, Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); } @Override protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException, ArtifactMetadataRetrievalException + throws MojoExecutionException, MojoFailureException, XMLStreamException, VersionRetrievalException { if ( depVersion == null || depVersion.equals( "" ) ) @@ -129,7 +128,7 @@ protected void update( ModifiedPomXMLEventReader pom ) ChangeRecord.ChangeKind.PARENT ); } } - catch ( ArtifactMetadataRetrievalException | IOException e ) + catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } @@ -137,7 +136,7 @@ protected void update( ModifiedPomXMLEventReader pom ) private void useDepVersion( ModifiedPomXMLEventReader pom, Collection dependencies, ChangeRecord.ChangeKind changeKind ) - throws MojoExecutionException, XMLStreamException, ArtifactMetadataRetrievalException + throws MojoExecutionException, XMLStreamException, VersionRetrievalException { for ( Dependency dep : dependencies ) { diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestReleasesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestReleasesMojo.java index c106e8c1c1..f0f8d9a2aa 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestReleasesMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestReleasesMojo.java @@ -32,8 +32,6 @@ import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.DefaultArtifactHandler; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.VersionRange; @@ -47,6 +45,7 @@ import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.api.Segment; +import org.codehaus.mojo.versions.api.VersionRetrievalException; import org.codehaus.mojo.versions.api.recording.ChangeRecord; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.ordering.InvalidSegmentException; @@ -105,14 +104,14 @@ public class UseLatestReleasesMojo @Inject public UseLatestReleasesMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver, Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -123,7 +122,7 @@ public UseLatestReleasesMojo( RepositorySystem repositorySystem, * @see org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader) */ protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException + throws MojoExecutionException, MojoFailureException, XMLStreamException, VersionRetrievalException { try { @@ -147,7 +146,7 @@ protected void update( ModifiedPomXMLEventReader pom ) ChangeRecord.ChangeKind.PARENT ); } } - catch ( ArtifactMetadataRetrievalException | IOException e ) + catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } @@ -155,7 +154,7 @@ protected void update( ModifiedPomXMLEventReader pom ) private void useLatestReleases( ModifiedPomXMLEventReader pom, Collection dependencies, ChangeRecord.ChangeKind changeKind ) - throws XMLStreamException, MojoExecutionException, ArtifactMetadataRetrievalException + throws XMLStreamException, MojoExecutionException, VersionRetrievalException { Optional unchangedSegment = SegmentUtils.determineUnchangedSegment( allowMajorUpdates, allowMinorUpdates, allowIncrementalUpdates, getLog() ); diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java index 9173a53c7e..96f183b654 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java @@ -30,8 +30,6 @@ import java.util.Optional; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.model.Dependency; import org.apache.maven.model.DependencyManagement; @@ -43,6 +41,7 @@ import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.api.Segment; +import org.codehaus.mojo.versions.api.VersionRetrievalException; import org.codehaus.mojo.versions.api.recording.ChangeRecord; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.ordering.InvalidSegmentException; @@ -94,14 +93,14 @@ public class UseLatestSnapshotsMojo @Inject public UseLatestSnapshotsMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver, Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -112,7 +111,7 @@ public UseLatestSnapshotsMojo( RepositorySystem repositorySystem, * @see AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader) */ protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException + throws MojoExecutionException, MojoFailureException, XMLStreamException, VersionRetrievalException { try { @@ -136,7 +135,7 @@ protected void update( ModifiedPomXMLEventReader pom ) ChangeRecord.ChangeKind.PARENT ); } } - catch ( ArtifactMetadataRetrievalException | IOException e ) + catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } @@ -144,7 +143,7 @@ protected void update( ModifiedPomXMLEventReader pom ) private void useLatestSnapshots( ModifiedPomXMLEventReader pom, Collection dependencies, ChangeRecord.ChangeKind changeKind ) - throws XMLStreamException, MojoExecutionException, ArtifactMetadataRetrievalException + throws XMLStreamException, MojoExecutionException, VersionRetrievalException { Optional unchangedSegment = SegmentUtils.determineUnchangedSegment( allowMajorUpdates, allowMinorUpdates, allowIncrementalUpdates, getLog() ); diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojo.java index 095f68b855..d7d018d906 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojo.java @@ -28,8 +28,6 @@ import java.util.Optional; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.model.Dependency; import org.apache.maven.model.DependencyManagement; @@ -43,6 +41,7 @@ import org.codehaus.mojo.versions.api.Segment; import org.codehaus.mojo.versions.api.recording.ChangeRecord; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; +import org.codehaus.mojo.versions.api.VersionRetrievalException; import org.codehaus.mojo.versions.ordering.InvalidSegmentException; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.codehaus.mojo.versions.utils.SegmentUtils; @@ -102,14 +101,14 @@ public class UseLatestVersionsMojo @Inject public UseLatestVersionsMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver, Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); } @Override @@ -130,7 +129,7 @@ public void execute() throws MojoExecutionException, MojoFailureException * @see AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader) */ protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException + throws MojoExecutionException, MojoFailureException, XMLStreamException, VersionRetrievalException { try { @@ -154,7 +153,7 @@ protected void update( ModifiedPomXMLEventReader pom ) ChangeRecord.ChangeKind.PARENT ); } } - catch ( ArtifactMetadataRetrievalException | IOException e ) + catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } @@ -162,7 +161,7 @@ protected void update( ModifiedPomXMLEventReader pom ) private void useLatestVersions( ModifiedPomXMLEventReader pom, Collection dependencies, ChangeRecord.ChangeKind changeKind ) - throws XMLStreamException, MojoExecutionException, ArtifactMetadataRetrievalException + throws XMLStreamException, MojoExecutionException, VersionRetrievalException { Optional unchangedSegment = SegmentUtils.determineUnchangedSegment( allowMajorUpdates, allowMinorUpdates, allowIncrementalUpdates, getLog() ); diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojoBase.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojoBase.java index 341a3fdb93..da94696cd4 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojoBase.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojoBase.java @@ -30,8 +30,6 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; @@ -40,6 +38,7 @@ import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.ArtifactVersions; +import org.codehaus.mojo.versions.api.VersionRetrievalException; import org.codehaus.mojo.versions.api.recording.ChangeRecord; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; @@ -52,14 +51,14 @@ public abstract class UseLatestVersionsMojoBase extends AbstractVersionsDependencyUpdaterMojo { public UseLatestVersionsMojoBase( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver, - Map changeRecorders ) + org.eclipse.aether.RepositorySystem aetherRepositorySystem, + MavenProjectBuilder projectBuilder, + WagonManager wagonManager, + ArtifactResolver artifactResolver, + Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -73,7 +72,7 @@ public UseLatestVersionsMojoBase( RepositorySystem repositorySystem, * @param changeKind title for the change recorder records * @param filters optional array of filters * @throws XMLStreamException thrown if the POM update doesn't succeed - * @throws ArtifactMetadataRetrievalException thrown if an artifact cannot be retried + * @throws VersionRetrievalException thrown if an artifact versions cannot be retrieved */ @SafeVarargs protected final void useLatestVersions( ModifiedPomXMLEventReader pom, @@ -82,7 +81,7 @@ protected final void useLatestVersions( ModifiedPomXMLEventReader pom, newestVersionProducer, ChangeRecord.ChangeKind changeKind, Predicate... filters ) - throws XMLStreamException, MojoExecutionException, ArtifactMetadataRetrievalException + throws XMLStreamException, MojoExecutionException, VersionRetrievalException { for ( Dependency dep : dependencies ) { diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextReleasesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextReleasesMojo.java index eb703c3138..64ab6c8b5e 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextReleasesMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextReleasesMojo.java @@ -28,8 +28,6 @@ import java.util.regex.Pattern; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.model.Dependency; import org.apache.maven.model.DependencyManagement; @@ -41,6 +39,7 @@ import org.codehaus.mojo.versions.api.recording.ChangeRecord; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.api.PomHelper; +import org.codehaus.mojo.versions.api.VersionRetrievalException; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import static java.util.Collections.singletonList; @@ -68,14 +67,14 @@ public class UseNextReleasesMojo @Inject public UseNextReleasesMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver, Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -86,7 +85,7 @@ public UseNextReleasesMojo( RepositorySystem repositorySystem, * @see AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader) */ protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException, ArtifactMetadataRetrievalException + throws MojoExecutionException, MojoFailureException, XMLStreamException, VersionRetrievalException { try { @@ -105,21 +104,21 @@ protected void update( ModifiedPomXMLEventReader pom ) { useNextReleases( pom, getProject().getDependencies(), ChangeRecord.ChangeKind.DEPENDENCY ); } + + if ( getProject().getParent() != null && isProcessingParent() ) + { + useNextReleases( pom, singletonList( getParentDependency() ), ChangeRecord.ChangeKind.PARENT ); + } } - catch ( ArtifactMetadataRetrievalException | IOException e ) + catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } - if ( getProject().getParent() != null && isProcessingParent() ) - { - useNextReleases( pom, singletonList( getParentDependency() ), - ChangeRecord.ChangeKind.PARENT ); - } } private void useNextReleases( ModifiedPomXMLEventReader pom, Collection dependencies, ChangeRecord.ChangeKind changeKind ) - throws XMLStreamException, MojoExecutionException, ArtifactMetadataRetrievalException + throws XMLStreamException, MojoExecutionException, VersionRetrievalException { useLatestVersions( pom, dependencies, ( dep, versions ) -> of( versions.getNewerVersions( dep.getVersion(), false )[0] ), diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextSnapshotsMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextSnapshotsMojo.java index f1bef54ca3..ced9081288 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextSnapshotsMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextSnapshotsMojo.java @@ -29,8 +29,6 @@ import java.util.Optional; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.model.Dependency; import org.apache.maven.model.DependencyManagement; @@ -42,6 +40,7 @@ import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.api.Segment; +import org.codehaus.mojo.versions.api.VersionRetrievalException; import org.codehaus.mojo.versions.api.recording.ChangeRecord; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.ordering.InvalidSegmentException; @@ -93,14 +92,14 @@ public class UseNextSnapshotsMojo @Inject public UseNextSnapshotsMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, + MavenProjectBuilder projectBuilder, + WagonManager wagonManager, + ArtifactResolver artifactResolver, Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); // the below is necessary for UseLatestVersionsMojoBase.useLatestVersions to select snapshots allowSnapshots = true; } @@ -113,7 +112,7 @@ public UseNextSnapshotsMojo( RepositorySystem repositorySystem, * @see org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader) */ protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException + throws MojoExecutionException, MojoFailureException, XMLStreamException, VersionRetrievalException { try { @@ -134,7 +133,7 @@ protected void update( ModifiedPomXMLEventReader pom ) ChangeRecord.ChangeKind.PARENT ); } } - catch ( ArtifactMetadataRetrievalException | IOException e ) + catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } @@ -142,7 +141,7 @@ protected void update( ModifiedPomXMLEventReader pom ) private void useNextSnapshots( ModifiedPomXMLEventReader pom, Collection dependencies, ChangeRecord.ChangeKind changeKind ) - throws XMLStreamException, MojoExecutionException, ArtifactMetadataRetrievalException + throws XMLStreamException, MojoExecutionException, VersionRetrievalException { Optional unchangedSegment = SegmentUtils.determineUnchangedSegment( allowMajorUpdates, allowMinorUpdates, diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextVersionsMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextVersionsMojo.java index ab2629cff9..925ca661c6 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextVersionsMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextVersionsMojo.java @@ -27,8 +27,6 @@ import java.util.Map; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.model.Dependency; import org.apache.maven.model.DependencyManagement; @@ -40,6 +38,7 @@ import org.codehaus.mojo.versions.api.recording.ChangeRecord; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.api.PomHelper; +import org.codehaus.mojo.versions.api.VersionRetrievalException; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import static java.util.Collections.singletonList; @@ -60,14 +59,14 @@ public class UseNextVersionsMojo @Inject public UseNextVersionsMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver, Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -78,7 +77,7 @@ public UseNextVersionsMojo( RepositorySystem repositorySystem, * @see org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader) */ protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException + throws MojoExecutionException, MojoFailureException, XMLStreamException, VersionRetrievalException { try { @@ -102,7 +101,7 @@ protected void update( ModifiedPomXMLEventReader pom ) ChangeRecord.ChangeKind.PARENT ); } } - catch ( ArtifactMetadataRetrievalException | IOException e ) + catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } @@ -110,7 +109,7 @@ protected void update( ModifiedPomXMLEventReader pom ) private void useNextVersions( ModifiedPomXMLEventReader pom, Collection dependencies, ChangeRecord.ChangeKind changeKind ) - throws XMLStreamException, MojoExecutionException, ArtifactMetadataRetrievalException + throws XMLStreamException, MojoExecutionException, VersionRetrievalException { useLatestVersions( pom, dependencies, ( dep, versions ) -> of( versions.getNewerVersions( dep.getVersion(), allowSnapshots )[0] ), diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseReactorMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseReactorMojo.java index c2b5802978..f583ce2287 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseReactorMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseReactorMojo.java @@ -29,8 +29,6 @@ import org.apache.commons.lang3.StringUtils; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.model.Dependency; import org.apache.maven.model.DependencyManagement; @@ -41,6 +39,7 @@ import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.PomHelper; +import org.codehaus.mojo.versions.api.VersionRetrievalException; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; @@ -59,14 +58,14 @@ public class UseReactorMojo @Inject public UseReactorMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver, Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -77,7 +76,7 @@ public UseReactorMojo( RepositorySystem repositorySystem, * @see AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader) */ protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException + throws MojoExecutionException, MojoFailureException, XMLStreamException, VersionRetrievalException { try { @@ -99,14 +98,14 @@ protected void update( ModifiedPomXMLEventReader pom ) useReactor( pom, getProject().getDependencies() ); } } - catch ( ArtifactMetadataRetrievalException | IOException e ) + catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } } private void useReactor( ModifiedPomXMLEventReader pom, Collection dependencies ) - throws XMLStreamException, MojoExecutionException, ArtifactMetadataRetrievalException + throws XMLStreamException, MojoExecutionException, VersionRetrievalException { for ( Dependency dep : dependencies ) @@ -136,7 +135,7 @@ private void useReactor( ModifiedPomXMLEventReader pom, Collection d } private void useReactor( ModifiedPomXMLEventReader pom, MavenProject parent ) - throws XMLStreamException, ArtifactMetadataRetrievalException + throws XMLStreamException, VersionRetrievalException { for ( MavenProject project : reactorProjects ) { diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseReleasesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseReleasesMojo.java index 295f14b4f1..e1a69d156e 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseReleasesMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseReleasesMojo.java @@ -31,8 +31,6 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.model.Dependency; @@ -45,6 +43,7 @@ import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.ArtifactVersions; import org.codehaus.mojo.versions.api.PomHelper; +import org.codehaus.mojo.versions.api.VersionRetrievalException; import org.codehaus.mojo.versions.api.recording.ChangeRecord; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; @@ -86,14 +85,14 @@ public class UseReleasesMojo @Inject public UseReleasesMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver, Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, - changeRecorders ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -104,7 +103,7 @@ public UseReleasesMojo( RepositorySystem repositorySystem, * @see org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader) */ protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException + throws MojoExecutionException, MojoFailureException, XMLStreamException, VersionRetrievalException { try { @@ -128,7 +127,7 @@ protected void update( ModifiedPomXMLEventReader pom ) ChangeRecord.ChangeKind.PARENT ); } } - catch ( ArtifactMetadataRetrievalException | IOException e ) + catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } @@ -136,7 +135,7 @@ protected void update( ModifiedPomXMLEventReader pom ) private void useReleases( ModifiedPomXMLEventReader pom, Collection dependencies, ChangeRecord.ChangeKind changeKind ) - throws XMLStreamException, MojoExecutionException, ArtifactMetadataRetrievalException + throws XMLStreamException, MojoExecutionException, VersionRetrievalException { for ( Dependency dep : dependencies ) { diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/DependencyUpdatesReportMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/DependencyUpdatesReportMojoTest.java index b7e853e788..4443242d70 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/DependencyUpdatesReportMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/DependencyUpdatesReportMojoTest.java @@ -28,8 +28,6 @@ import java.util.Locale; import java.util.Set; -import org.apache.maven.artifact.DefaultArtifact; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.doxia.module.xhtml5.Xhtml5SinkFactory; import org.apache.maven.doxia.sink.SinkFactory; import org.apache.maven.model.Dependency; @@ -37,7 +35,6 @@ import org.apache.maven.model.Model; import org.apache.maven.project.MavenProject; import org.apache.maven.reporting.MavenReportException; -import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.model.RuleSet; import org.codehaus.mojo.versions.reporting.ReportRendererFactoryImpl; import org.codehaus.mojo.versions.utils.DependencyBuilder; @@ -47,17 +44,16 @@ import org.junit.Test; import static org.apache.maven.artifact.Artifact.SCOPE_COMPILE; -import static org.codehaus.mojo.versions.utils.MockUtils.mockArtifactMetadataSource; +import static org.codehaus.mojo.versions.utils.MockUtils.mockAetherRepositorySystem; import static org.codehaus.mojo.versions.utils.MockUtils.mockI18N; +import static org.codehaus.mojo.versions.utils.MockUtils.mockMavenSession; +import static org.codehaus.mojo.versions.utils.MockUtils.mockRepositorySystem; import static org.hamcrest.CoreMatchers.allOf; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.matchesPattern; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; /** * Basic tests for {@linkplain DependencyUpdatesReportMojo}. @@ -72,7 +68,7 @@ private static class TestDependencyUpdatesReportMojo extends DependencyUpdatesRe TestDependencyUpdatesReportMojo() { - super( MOCK_I18N, mockRepositorySystem(), null, mockArtifactMetadataSource(), + super( MOCK_I18N, mockRepositorySystem(), mockAetherRepositorySystem(), null, null, new ReportRendererFactoryImpl( MOCK_I18N ) ); siteTool = MockUtils.mockSiteTool(); @@ -80,6 +76,8 @@ private static class TestDependencyUpdatesReportMojo extends DependencyUpdatesRe project.setOriginalModel( new Model() ); project.getOriginalModel().setDependencyManagement( new DependencyManagement() ); project.getModel().setDependencyManagement( new DependencyManagement() ); + + session = mockMavenSession(); } public TestDependencyUpdatesReportMojo withDependencies( Dependency... dependencies ) @@ -88,10 +86,10 @@ public TestDependencyUpdatesReportMojo withDependencies( Dependency... dependenc return this; } - public TestDependencyUpdatesReportMojo withArtifactMetadataSource( - ArtifactMetadataSource artifactMetadataSource ) + public TestDependencyUpdatesReportMojo withAetherRepositorySystem( + org.eclipse.aether.RepositorySystem repositorySystem ) { - this.artifactMetadataSource = artifactMetadataSource; + this.aetherRepositorySystem = repositorySystem; return this; } @@ -160,20 +158,6 @@ public TestDependencyUpdatesReportMojo withOriginalProperty( String name, String project.getOriginalModel().getProperties().put( name, value ); return this; } - - private static RepositorySystem mockRepositorySystem() - { - RepositorySystem repositorySystem = mock( RepositorySystem.class ); - when( repositorySystem.createDependencyArtifact( any( Dependency.class ) ) ).thenAnswer( - invocation -> - { - Dependency dependency = invocation.getArgument( 0 ); - return new DefaultArtifact( dependency.getGroupId(), dependency.getArtifactId(), - dependency.getVersion(), dependency.getScope(), dependency.getType(), - dependency.getClassifier(), null ); - } ); - return repositorySystem; - } } private static Dependency dependencyOf( String artifactId ) @@ -189,13 +173,13 @@ private static Dependency dependencyOf( String artifactId, String version ) } @Test - public void testOnlyUpgradableDependencies() throws IOException, MavenReportException + public void testOnlyUpgradableDependencies() throws IOException, MavenReportException, IllegalAccessException { OutputStream os = new ByteArrayOutputStream(); SinkFactory sinkFactory = new Xhtml5SinkFactory(); new TestDependencyUpdatesReportMojo() .withOnlyUpgradable( true ) - .withArtifactMetadataSource( mockArtifactMetadataSource( new HashMap() + .withAetherRepositorySystem( mockAetherRepositorySystem( new HashMap() {{ put( "artifactA", new String[] { "1.0.0", "2.0.0" } ); put( "artifactB", new String[] { "1.0.0" } ); @@ -214,7 +198,8 @@ public void testOnlyUpgradableDependencies() throws IOException, MavenReportExce } @Test - public void testOnlyUpgradableWithOriginalDependencyManagement() throws IOException, MavenReportException + public void testOnlyUpgradableWithOriginalDependencyManagement() + throws IOException, MavenReportException, IllegalAccessException { OutputStream os = new ByteArrayOutputStream(); SinkFactory sinkFactory = new Xhtml5SinkFactory(); @@ -231,7 +216,8 @@ public void testOnlyUpgradableWithOriginalDependencyManagement() throws IOExcept } @Test - public void testOnlyUpgradableWithTransitiveDependencyManagement() throws IOException, MavenReportException + public void testOnlyUpgradableWithTransitiveDependencyManagement() + throws IOException, MavenReportException, IllegalAccessException { OutputStream os = new ByteArrayOutputStream(); SinkFactory sinkFactory = new Xhtml5SinkFactory(); @@ -250,7 +236,7 @@ public void testOnlyUpgradableWithTransitiveDependencyManagement() throws IOExce } @Test - public void testOnlyProjectDependencies() throws IOException, MavenReportException + public void testOnlyProjectDependencies() throws IOException, MavenReportException, IllegalAccessException { OutputStream os = new ByteArrayOutputStream(); SinkFactory sinkFactory = new Xhtml5SinkFactory(); @@ -268,7 +254,8 @@ public void testOnlyProjectDependencies() throws IOException, MavenReportExcepti } @Test - public void testOnlyProjectDependenciesWithIgnoredVersions() throws IOException, MavenReportException + public void testOnlyProjectDependenciesWithIgnoredVersions() + throws IOException, MavenReportException, IllegalAccessException { OutputStream os = new ByteArrayOutputStream(); SinkFactory sinkFactory = new Xhtml5SinkFactory(); @@ -289,12 +276,12 @@ public void testOnlyProjectDependenciesWithIgnoredVersions() throws IOException, * Dependencies should be rendered in alphabetical order */ @Test - public void testDependenciesInAlphabeticalOrder() throws IOException, MavenReportException + public void testDependenciesInAlphabeticalOrder() throws IOException, MavenReportException, IllegalAccessException { OutputStream os = new ByteArrayOutputStream(); SinkFactory sinkFactory = new Xhtml5SinkFactory(); new TestDependencyUpdatesReportMojo() - .withArtifactMetadataSource( mockArtifactMetadataSource( new HashMap() + .withAetherRepositorySystem( mockAetherRepositorySystem( new HashMap() {{ put( "amstrad", new String[] {"1.0.0", "2.0.0"} ); put( "atari", new String[] {"1.0.0", "2.0.0"} ); @@ -313,7 +300,8 @@ public void testDependenciesInAlphabeticalOrder() throws IOException, MavenRepor * Dependency updates for dependency should override those for dependency management */ @Test - public void testDependenciesShouldOverrideDependencyManagement() throws IOException, MavenReportException + public void testDependenciesShouldOverrideDependencyManagement() + throws IOException, MavenReportException, IllegalAccessException { OutputStream os = new ByteArrayOutputStream(); SinkFactory sinkFactory = new Xhtml5SinkFactory(); @@ -330,7 +318,7 @@ public void testDependenciesShouldOverrideDependencyManagement() throws IOExcept } @Test - public void testWrongReportBounds() throws IOException, MavenReportException + public void testWrongReportBounds() throws IOException, MavenReportException, IllegalAccessException { OutputStream os = new ByteArrayOutputStream(); SinkFactory sinkFactory = new Xhtml5SinkFactory(); @@ -338,7 +326,7 @@ public void testWrongReportBounds() throws IOException, MavenReportException .withOnlyUpgradable( true ) .withDependencies( dependencyOf( "test-artifact" ) ) - .withArtifactMetadataSource( mockArtifactMetadataSource( new HashMap() + .withAetherRepositorySystem( mockAetherRepositorySystem( new HashMap() {{ put( "test-artifact", new String[] { "1.0.0", "2.0.0-M1" } ); }} ) ) @@ -351,7 +339,7 @@ public void testWrongReportBounds() throws IOException, MavenReportException } @Test - public void testIt001Overview() throws IOException, MavenReportException + public void testIt001Overview() throws IOException, MavenReportException, IllegalAccessException { OutputStream os = new ByteArrayOutputStream(); SinkFactory sinkFactory = new Xhtml5SinkFactory(); @@ -359,7 +347,7 @@ public void testIt001Overview() throws IOException, MavenReportException .withOnlyUpgradable( true ) .withDependencies( dependencyOf( "test-artifact", "1.1" ) ) - .withArtifactMetadataSource( mockArtifactMetadataSource( new HashMap() + .withAetherRepositorySystem( mockAetherRepositorySystem( new HashMap() {{ put( "test-artifact", new String[] { "1.1.0-2", "1.1", "1.1.1", "1.1.1-2", "1.1.2", "1.1.3", "1.2", "1.2.1", "1.2.2", "1.3", "2.0", "2.1", "3.0"} ); @@ -375,7 +363,8 @@ public void testIt001Overview() throws IOException, MavenReportException } @Test - public void testResolvedVersionsWithoutTransitiveDependencyManagement() throws IOException, MavenReportException + public void testResolvedVersionsWithoutTransitiveDependencyManagement() + throws IOException, MavenReportException, IllegalAccessException { OutputStream os = new ByteArrayOutputStream(); SinkFactory sinkFactory = new Xhtml5SinkFactory(); diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojoTest.java index 6c0207ec2d..f399589147 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojoTest.java @@ -47,7 +47,8 @@ import static java.util.Collections.singletonList; import static org.codehaus.mojo.versions.model.TestIgnoreVersions.TYPE_REGEX; import static org.codehaus.mojo.versions.model.TestIgnoreVersions.matches; -import static org.codehaus.mojo.versions.utils.MockUtils.mockArtifactMetadataSource; +import static org.codehaus.mojo.versions.utils.MockUtils.mockAetherRepositorySystem; +import static org.codehaus.mojo.versions.utils.MockUtils.mockMavenSession; import static org.codehaus.mojo.versions.utils.MockUtils.mockRepositorySystem; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.anyOf; @@ -112,7 +113,7 @@ public void testRuleSetPresentAndWorking() throws Exception // This is just an example of how to create it-style tests as unit tests; the advantage is easier debugging mojo.outputFile = outputFile; - mojo.artifactMetadataSource = mockArtifactMetadataSource( new HashMap() + mojo.aetherRepositorySystem = mockAetherRepositorySystem( new HashMap() {{ put( "dummy-api", new String[] { "1.0.0", "1.0.1", "1.1.0-M1", "1.2.0-SNAPSHOT" } ); }} ); @@ -157,16 +158,15 @@ public void testVersionsWithQualifiersNotConsideredAsMinorUpdates() tempPath = Files.createTempFile( "display-dependency-updates", "" ); final File tempFile = tempPath.toFile(); new DisplayDependencyUpdatesMojo( mockRepositorySystem(), - null, - mockArtifactMetadataSource( new HashMap() - {{ - put( "default-dependency", - new String[] {"1.0.0", "1.1.0", "2.0.0-SNAPSHOT", "2.0.0-beta", - "2.0.0-rc1"} ); - }} ), - null, - new StubArtifactResolver( new ArtifactStubFactory(), false, false ), - null ) + mockAetherRepositorySystem( new HashMap() + {{ + put( "default-dependency", new String[] {"1.0.0", "1.1.0", "2.0.0-SNAPSHOT", "2.0.0-beta", + "2.0.0-rc1"} ); + }} ), + null, + null, + new StubArtifactResolver( new ArtifactStubFactory(), false, false ), + null ) {{ setProject( createProject() ); setVariableValueToObject( this, "allowAnyUpdates", false ); @@ -178,6 +178,8 @@ public void testVersionsWithQualifiersNotConsideredAsMinorUpdates() this.allowSnapshots = true; this.outputFile = tempFile; setPluginContext( new HashMap<>() ); + + session = mockMavenSession(); }}.execute(); assertThat( String.join( "", Files.readAllLines( tempPath ) ), @@ -204,14 +206,14 @@ public void testAllowMajorUpdatesFalse() tempPath = Files.createTempFile( "display-dependency-updates", "" ); final File tempFile = tempPath.toFile(); new DisplayDependencyUpdatesMojo( mockRepositorySystem(), - null, - mockArtifactMetadataSource( new HashMap() - {{ - put( "default-dependency", new String[] {"1.0.0", "1.1.0", "2.0.0"} ); - }} ), - null, - new StubArtifactResolver( new ArtifactStubFactory(), false, false ), - null ) + mockAetherRepositorySystem( new HashMap() + {{ + put( "default-dependency", new String[] {"1.0.0", "1.1.0", "2.0.0"} ); + }} ), + null, + null, + new StubArtifactResolver( new ArtifactStubFactory(), false, false ), + null ) {{ setProject( createProject() ); setVariableValueToObject( this, "allowAnyUpdates", false ); @@ -222,6 +224,8 @@ public void testAllowMajorUpdatesFalse() setVariableValueToObject( this, "dependencyExcludes", emptyList() ); this.outputFile = tempFile; setPluginContext( new HashMap<>() ); + + session = mockMavenSession(); }}.execute(); String output = String.join( "", Files.readAllLines( tempPath ) ); @@ -248,15 +252,14 @@ public void testAllowMinorUpdatesFalse() tempPath = Files.createTempFile( "display-dependency-updates", "" ); final File tempFile = tempPath.toFile(); new DisplayDependencyUpdatesMojo( mockRepositorySystem(), - null, - mockArtifactMetadataSource( new HashMap() - {{ - put( "default-dependency", - new String[] {"1.0.0", "1.0.1", "1.1.0", "2.0.0"} ); - }} ), - null, - new StubArtifactResolver( new ArtifactStubFactory(), false, false ), - null ) + mockAetherRepositorySystem( new HashMap() + {{ + put( "default-dependency", new String[] {"1.0.0", "1.0.1", "1.1.0", "2.0.0"} ); + }} ), + null, + null, + new StubArtifactResolver( new ArtifactStubFactory(), false, false ), + null ) {{ setProject( createProject() ); setVariableValueToObject( this, "allowAnyUpdates", false ); @@ -267,6 +270,8 @@ public void testAllowMinorUpdatesFalse() setVariableValueToObject( this, "dependencyExcludes", emptyList() ); this.outputFile = tempFile; setPluginContext( new HashMap<>() ); + + session = mockMavenSession(); }}.execute(); String output = String.join( "", Files.readAllLines( tempPath ) ); @@ -294,15 +299,14 @@ public void testAllowIncrementalUpdatesFalse() tempPath = Files.createTempFile( "display-dependency-updates", "" ); final File tempFile = tempPath.toFile(); new DisplayDependencyUpdatesMojo( mockRepositorySystem(), - null, - mockArtifactMetadataSource( new HashMap() - {{ - put( "default-dependency", - new String[] {"1.0.0", "1.0.0-1", "1.0.1", "1.1.0", "2.0.0"} ); - }} ), - null, - new StubArtifactResolver( new ArtifactStubFactory(), false, false ), - null ) + mockAetherRepositorySystem( new HashMap() + {{ + put( "default-dependency", new String[] {"1.0.0", "1.0.0-1", "1.0.1", "1.1.0", "2.0.0"} ); + }} ), + null, + null, + new StubArtifactResolver( new ArtifactStubFactory(), false, false ), + null ) {{ setProject( createProject() ); setVariableValueToObject( this, "allowAnyUpdates", false ); @@ -313,6 +317,8 @@ public void testAllowIncrementalUpdatesFalse() setVariableValueToObject( this, "dependencyExcludes", emptyList() ); this.outputFile = tempFile; setPluginContext( new HashMap<>() ); + + session = mockMavenSession(); }}.execute(); String output = String.join( "", Files.readAllLines( tempPath ) ); @@ -341,16 +347,15 @@ public void testVersionsWithQualifiersNotConsideredAsIncrementalUpdates() tempPath = Files.createTempFile( "display-dependency-updates", "" ); final File tempFile = tempPath.toFile(); new DisplayDependencyUpdatesMojo( mockRepositorySystem(), - null, - mockArtifactMetadataSource( new HashMap() - {{ - put( "default-dependency", - new String[] {"1.0.0", "1.1.0", "1.9.0-SNAPSHOT", "1.9.0-beta", - "1.9.0-rc1"} ); - }} ), - null, - new StubArtifactResolver( new ArtifactStubFactory(), false, false ), - null ) + mockAetherRepositorySystem( new HashMap() + {{ + put( "default-dependency", new String[] {"1.0.0", "1.1.0", "1.9.0-SNAPSHOT", "1.9.0-beta", + "1.9.0-rc1"} ); + }} ), + null, + null, + new StubArtifactResolver( new ArtifactStubFactory(), false, false ), + null ) {{ setProject( createProject() ); setVariableValueToObject( this, "allowAnyUpdates", false ); @@ -362,6 +367,8 @@ public void testVersionsWithQualifiersNotConsideredAsIncrementalUpdates() this.allowSnapshots = true; this.outputFile = tempFile; setPluginContext( new HashMap<>() ); + + session = mockMavenSession(); }}.execute(); assertThat( String.join( "", Files.readAllLines( tempPath ) ), @@ -403,7 +410,7 @@ public void testDetermineUpdatedSegment() throws Exception // This is just an example of how to create it-style tests as unit tests; the advantage is easier debugging mojo.outputFile = outputFile; - mojo.artifactMetadataSource = mockArtifactMetadataSource( new HashMap() + mojo.aetherRepositorySystem = mockAetherRepositorySystem( new HashMap() {{ put( "dummy-api", new String[] { "1.0.0", "1.0.1", "1.1.0-M1", "1.2.0-SNAPSHOT" } ); }} ); @@ -434,7 +441,7 @@ public void testVersionInterpolation() throws Exception // This is just an example of how to create it-style tests as unit tests; the advantage is easier debugging mojo.outputFile = outputFile; - mojo.artifactMetadataSource = mockArtifactMetadataSource( new HashMap() + mojo.aetherRepositorySystem = mockAetherRepositorySystem( new HashMap() {{ put( "dummy-api", new String[] { "2.0.1" } ); }} ); diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/DisplayPropertyUpdatesMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/DisplayPropertyUpdatesMojoTest.java index c9f896a110..a1e78b1a3f 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/DisplayPropertyUpdatesMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/DisplayPropertyUpdatesMojoTest.java @@ -25,7 +25,6 @@ import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.apache.maven.plugin.testing.MojoRule; -import org.codehaus.mojo.versions.utils.MockUtils; import org.codehaus.mojo.versions.utils.TestUtils; import org.junit.After; import org.junit.Before; @@ -33,6 +32,7 @@ import org.junit.Test; import static org.apache.commons.codec.CharEncoding.UTF_8; +import static org.codehaus.mojo.versions.utils.MockUtils.mockAetherRepositorySystem; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.matchesPattern; import static org.hamcrest.Matchers.not; @@ -80,7 +80,7 @@ public void testPropertiesFromParent() throws Exception mojo.outputEncoding = UTF_8; mojo.outputFile = tempFile.toFile(); mojo.setPluginContext( new HashMap<>() ); - mojo.artifactMetadataSource = MockUtils.mockArtifactMetadataSource(); + mojo.aetherRepositorySystem = mockAetherRepositorySystem(); mojo.includeParent = true; mojo.execute(); @@ -101,7 +101,7 @@ public void testDisablePropertiesFromParent() throws Exception mojo.outputEncoding = UTF_8; mojo.outputFile = tempFile.toFile(); mojo.setPluginContext( new HashMap<>() ); - mojo.artifactMetadataSource = MockUtils.mockArtifactMetadataSource(); + mojo.aetherRepositorySystem = mockAetherRepositorySystem(); mojo.includeParent = false; mojo.execute(); diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/ForceReleasesMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/ForceReleasesMojoTest.java index 3bdf537f95..0c9d66182c 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/ForceReleasesMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/ForceReleasesMojoTest.java @@ -11,6 +11,7 @@ import org.apache.maven.plugin.testing.stubs.StubArtifactResolver; import org.apache.maven.project.MavenProject; import org.codehaus.mojo.versions.api.PomHelper; +import org.codehaus.mojo.versions.api.VersionRetrievalException; import org.codehaus.mojo.versions.change.DefaultVersionChange; import org.codehaus.mojo.versions.utils.DependencyBuilder; import org.codehaus.mojo.versions.utils.TestChangeRecorder; @@ -22,7 +23,8 @@ import static java.util.Collections.singletonList; import static java.util.Collections.singletonMap; import static org.apache.maven.artifact.Artifact.SCOPE_COMPILE; -import static org.codehaus.mojo.versions.utils.MockUtils.mockArtifactMetadataSource; +import static org.codehaus.mojo.versions.utils.MockUtils.mockAetherRepositorySystem; +import static org.codehaus.mojo.versions.utils.MockUtils.mockMavenSession; import static org.codehaus.mojo.versions.utils.MockUtils.mockRepositorySystem; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; @@ -63,9 +65,10 @@ public void setUp() throws IllegalAccessException { changeRecorder = new TestChangeRecorder(); mojo = new ForceReleasesMojo( mockRepositorySystem(), - null, mockArtifactMetadataSource(), - null, new StubArtifactResolver( new ArtifactStubFactory(), false, false ), - changeRecorder.asTestMap() ); + mockAetherRepositorySystem(), + null, null, new StubArtifactResolver( new ArtifactStubFactory(), + false, false ), + changeRecorder.asTestMap() ); setVariableValueToObject( mojo, "reactorProjects", emptyList() ); mojo.project = new MavenProject() {{ @@ -76,11 +79,13 @@ null, new StubArtifactResolver( new ArtifactStubFactory(), false, false ), setVersion( "1.0.0" ); }} ); }}; + mojo.session = mockMavenSession(); } @Test public void testProcessParent() - throws MojoExecutionException, XMLStreamException, MojoFailureException, IllegalAccessException + throws MojoExecutionException, XMLStreamException, MojoFailureException, IllegalAccessException, + VersionRetrievalException { setVariableValueToObject( mojo, "processParent", true ); mojo.getProject().setParent( new MavenProject( new Model() @@ -107,7 +112,7 @@ public void testProcessParent() @Test public void testReplaceSnapshotWithRelease() - throws MojoExecutionException, XMLStreamException, MojoFailureException + throws MojoExecutionException, XMLStreamException, MojoFailureException, VersionRetrievalException { mojo.getProject().setDependencies( singletonList( DependencyBuilder.newBuilder() .withGroupId( "default-group" ) @@ -131,7 +136,7 @@ public void testReplaceSnapshotWithRelease() @Test public void testUpgrade() - throws MojoExecutionException, XMLStreamException, MojoFailureException + throws MojoExecutionException, XMLStreamException, MojoFailureException, VersionRetrievalException { mojo.getProject().setDependencies( singletonList( DependencyBuilder.newBuilder() .withGroupId( "default-group" ) @@ -155,7 +160,7 @@ public void testUpgrade() @Test public void testDowngrade() - throws MojoExecutionException, XMLStreamException, MojoFailureException + throws MojoExecutionException, XMLStreamException, MojoFailureException, VersionRetrievalException { mojo.getProject().setDependencies( singletonList( DependencyBuilder.newBuilder() .withGroupId( "default-group" ) @@ -179,9 +184,9 @@ public void testDowngrade() @Test public void testFailIfNotReplaced() - throws MojoExecutionException, XMLStreamException, MojoFailureException + throws MojoExecutionException, XMLStreamException, MojoFailureException, VersionRetrievalException { - mojo.artifactMetadataSource = mockArtifactMetadataSource( singletonMap( "test-artifact", + mojo.aetherRepositorySystem = mockAetherRepositorySystem( singletonMap( "test-artifact", new String[] {} ) ); mojo.getProject().setDependencies( singletonList( DependencyBuilder.newBuilder() .withGroupId( "default-group" ) diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/ParentUpdatesReportMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/ParentUpdatesReportMojoTest.java index 7854a027f1..43e8c3046c 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/ParentUpdatesReportMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/ParentUpdatesReportMojoTest.java @@ -31,14 +31,16 @@ import org.apache.maven.doxia.module.xhtml5.Xhtml5SinkFactory; import org.apache.maven.doxia.sink.SinkFactory; import org.apache.maven.model.Model; +import org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub; import org.apache.maven.project.MavenProject; import org.apache.maven.reporting.MavenReportException; import org.codehaus.mojo.versions.reporting.ReportRendererFactoryImpl; import org.codehaus.plexus.i18n.I18N; import org.junit.Test; -import static org.codehaus.mojo.versions.utils.MockUtils.mockArtifactMetadataSource; +import static org.codehaus.mojo.versions.utils.MockUtils.mockAetherRepositorySystem; import static org.codehaus.mojo.versions.utils.MockUtils.mockI18N; +import static org.codehaus.mojo.versions.utils.MockUtils.mockMavenSession; import static org.codehaus.mojo.versions.utils.MockUtils.mockRepositorySystem; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.MatcherAssert.assertThat; @@ -57,11 +59,11 @@ public void testAllowSnapshots() throws IOException, MavenReportException { OutputStream os = new ByteArrayOutputStream(); SinkFactory sinkFactory = new Xhtml5SinkFactory(); - new ParentUpdatesReportMojo( MOCK_I18N, mockRepositorySystem(), null, - mockArtifactMetadataSource( new HashMap() + new ParentUpdatesReportMojo( MOCK_I18N, mockRepositorySystem(), + mockAetherRepositorySystem( new HashMap() {{ put( "default-artifact", new String[] {"1.0.0", "1.0.1", "1.1.0", "2.0.0", "2.0.1-SNAPSHOT"} ); - }} ), null, new ReportRendererFactoryImpl( MOCK_I18N ) ) + }} ), null, null, new ReportRendererFactoryImpl( MOCK_I18N ) ) {{ allowSnapshots = true; project = new MavenProject( new Model() @@ -79,7 +81,10 @@ public void testAllowSnapshots() throws IOException, MavenReportException reactorProjects = new ArrayList<>(); project.setParentArtifact( new DefaultArtifact( project.getParent().getGroupId(), project.getParent().getArtifactId(), project.getParent().getVersion(), - Artifact.SCOPE_COMPILE, "pom", "default", null ) ); + Artifact.SCOPE_COMPILE, "pom", "default", + new DefaultArtifactHandlerStub( "default" ) ) ); + + session = mockMavenSession(); }}.generate( sinkFactory.createSink( os ), sinkFactory, Locale.getDefault() ); String output = os.toString(); diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/PluginUpdatesReportMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/PluginUpdatesReportMojoTest.java index 46053944ce..e799b17afd 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/PluginUpdatesReportMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/PluginUpdatesReportMojoTest.java @@ -29,12 +29,12 @@ import java.util.Set; import org.apache.maven.artifact.DefaultArtifact; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.doxia.module.xhtml5.Xhtml5SinkFactory; import org.apache.maven.doxia.sink.SinkFactory; import org.apache.maven.model.Build; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginManagement; +import org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub; import org.apache.maven.project.MavenProject; import org.apache.maven.reporting.MavenReportException; import org.apache.maven.repository.RepositorySystem; @@ -45,8 +45,9 @@ import org.junit.Test; import static org.apache.maven.artifact.Artifact.SCOPE_RUNTIME; -import static org.codehaus.mojo.versions.utils.MockUtils.mockArtifactMetadataSource; +import static org.codehaus.mojo.versions.utils.MockUtils.mockAetherRepositorySystem; import static org.codehaus.mojo.versions.utils.MockUtils.mockI18N; +import static org.codehaus.mojo.versions.utils.MockUtils.mockMavenSession; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.MatcherAssert.assertThat; @@ -68,15 +69,15 @@ private static class TestPluginUpdatesReportMojo extends PluginUpdatesReportMojo static final I18N MOCK_I18N = mockI18N(); TestPluginUpdatesReportMojo() { - super( MOCK_I18N, mockRepositorySystem(), null, mockArtifactMetadataSource(), - null, new ReportRendererFactoryImpl( MOCK_I18N ) ); + super( MOCK_I18N, mockRepositorySystem(), mockAetherRepositorySystem(), + null, null, new ReportRendererFactoryImpl( MOCK_I18N ) ); siteTool = MockUtils.mockSiteTool(); project = new MavenProject(); project.setBuild( new Build() ); project.getBuild().setPluginManagement( new PluginManagement() ); - artifactMetadataSource = mockArtifactMetadataSource(); + session = mockMavenSession(); } public TestPluginUpdatesReportMojo withPlugins( Plugin... plugins ) @@ -85,10 +86,10 @@ public TestPluginUpdatesReportMojo withPlugins( Plugin... plugins ) return this; } - public TestPluginUpdatesReportMojo withArtifactMetadataSource( - ArtifactMetadataSource artifactMetadataSource ) + public TestPluginUpdatesReportMojo withAetherRepositorySystem( + org.eclipse.aether.RepositorySystem repositorySystem ) { - this.artifactMetadataSource = artifactMetadataSource; + this.aetherRepositorySystem = repositorySystem; return this; } @@ -132,7 +133,8 @@ private static RepositorySystem mockRepositorySystem() { Plugin plugin = invocation.getArgument( 0 ); return new DefaultArtifact( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion(), - SCOPE_RUNTIME, "maven-plugin", "jar", null ); + SCOPE_RUNTIME, "maven-plugin", "jar", + new DefaultArtifactHandlerStub( "default" ) ); } ); return repositorySystem; } @@ -161,7 +163,7 @@ public void testOnlyUpgradablePlugins() throws IOException, MavenReportException OutputStream os = new ByteArrayOutputStream(); SinkFactory sinkFactory = new Xhtml5SinkFactory(); new TestPluginUpdatesReportMojo() - .withArtifactMetadataSource( mockArtifactMetadataSource( new HashMap() + .withAetherRepositorySystem( mockAetherRepositorySystem( new HashMap() {{ put( "artifactA", new String[] { "1.0.0", "2.0.0" } ); put( "artifactB", new String[] { "1.0.0" } ); @@ -185,7 +187,7 @@ public void testOnlyUpgradableWithPluginManagement() throws IOException, MavenRe OutputStream os = new ByteArrayOutputStream(); SinkFactory sinkFactory = new Xhtml5SinkFactory(); new TestPluginUpdatesReportMojo() - .withArtifactMetadataSource( mockArtifactMetadataSource( new HashMap() + .withAetherRepositorySystem( mockAetherRepositorySystem( new HashMap() {{ put( "artifactA", new String[] { "1.0.0", "2.0.0" } ); put( "artifactB", new String[] { "1.0.0" } ); 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 f0adb37f64..c62ac79d10 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 @@ -23,7 +23,6 @@ import java.io.OutputStream; import java.util.Locale; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.doxia.module.xhtml5.Xhtml5SinkFactory; import org.apache.maven.doxia.sink.SinkFactory; import org.apache.maven.doxia.tools.SiteTool; @@ -33,7 +32,7 @@ import org.junit.Rule; import org.junit.Test; -import static org.codehaus.mojo.versions.utils.MockUtils.mockArtifactMetadataSource; +import static org.codehaus.mojo.versions.utils.MockUtils.mockAetherRepositorySystem; import static org.codehaus.mojo.versions.utils.MockUtils.mockSiteTool; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.MatcherAssert.assertThat; @@ -46,7 +45,7 @@ public class PropertyUpdatesReportMojoTest extends AbstractMojoTestCase { @Rule public MojoRule mojoRule = new MojoRule( this ); - private static final ArtifactMetadataSource ARTIFACT_METADATA_SOURCE = mockArtifactMetadataSource(); + 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( "" ); @@ -62,7 +61,7 @@ public void testIncludeParentTrueShouldContainProperty() throws Exception "property-updates-report" ); setVariableValueToObject( mojo, "localRepository", LOCAL_REPOSITORY ); setVariableValueToObject( mojo, "siteTool", SITE_TOOL ); - setVariableValueToObject( mojo, "artifactMetadataSource", ARTIFACT_METADATA_SOURCE ); + setVariableValueToObject( mojo, "aetherRepositorySystem", AETHER_REPOSITORY_SYSTEM ); setVariableValueToObject( mojo, "includeParent", true ); mojo.generate( sinkFactory.createSink( os ), sinkFactory, Locale.getDefault() ); @@ -85,7 +84,7 @@ public void testIncludeParentFalseShouldNotContainProperty() throws Exception "property-updates-report" ); setVariableValueToObject( mojo, "localRepository", new StubArtifactRepository( "" ) ); setVariableValueToObject( mojo, "siteTool", SITE_TOOL ); - setVariableValueToObject( mojo, "artifactMetadataSource", ARTIFACT_METADATA_SOURCE ); + setVariableValueToObject( mojo, "aetherRepositorySystem", AETHER_REPOSITORY_SYSTEM ); setVariableValueToObject( mojo, "includeParent", false ); mojo.generate( sinkFactory.createSink( os ), sinkFactory, Locale.getDefault() ); diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/SeparatePatternsForIncludesAnExcludesTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/SeparatePatternsForIncludesAnExcludesTest.java index 5605952eb2..a4a30b8f20 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/SeparatePatternsForIncludesAnExcludesTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/SeparatePatternsForIncludesAnExcludesTest.java @@ -1,11 +1,7 @@ package org.codehaus.mojo.versions; -import javax.xml.stream.XMLStreamException; - import java.util.List; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.junit.Before; import org.junit.Test; @@ -23,8 +19,8 @@ public void setUp() { mojo = new AbstractVersionsDependencyUpdaterMojo( null, null, null, null, null, null ) { + @Override protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException { } }; diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/SetPropertyMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/SetPropertyMojoTest.java index 1005ade873..b4cffc0894 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/SetPropertyMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/SetPropertyMojoTest.java @@ -19,26 +19,29 @@ * under the License. */ -import java.io.File; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Arrays; -import java.util.Objects; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.apache.maven.plugin.testing.MojoRule; -import org.apache.maven.plugin.testing.stubs.StubArtifactRepository; +import org.eclipse.aether.resolution.VersionRangeRequest; +import org.eclipse.aether.resolution.VersionRangeResult; import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static org.codehaus.mojo.versions.utils.TestUtils.copyDir; +import static org.codehaus.mojo.versions.utils.TestUtils.createTempDir; +import static org.codehaus.mojo.versions.utils.TestUtils.tearDownTempDir; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.matchesPattern; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** * Basic tests for {@linkplain SetPropertyMojoTest}. @@ -56,7 +59,7 @@ public class SetPropertyMojoTest extends AbstractMojoTestCase public void setUp() throws Exception { super.setUp(); - pomDir = Files.createTempDirectory( "set-property-" ); + pomDir = createTempDir( "set-property" ); } @After @@ -64,26 +67,25 @@ public void tearDown() throws Exception { try { - if ( pomDir != null && pomDir.toFile().exists() ) - { - Arrays.stream( Objects.requireNonNull( pomDir.toFile().listFiles() ) ).forEach( File::delete ); - pomDir.toFile().delete(); - } + tearDownTempDir( pomDir ); } finally { super.tearDown(); } } - @Test + @Test public void testNullNewVersion() throws Exception { - Files.copy( Paths.get( "src/test/resources/org/codehaus/mojo/set-property/null-new-version/pom.xml" ), - Paths.get( pomDir.toString(), "pom.xml" ), REPLACE_EXISTING ); + copyDir( Paths.get( "src/test/resources/org/codehaus/mojo/set-property/null-new-version" ), pomDir ); SetPropertyMojo mojo = (SetPropertyMojo) mojoRule.lookupConfiguredMojo( pomDir.toFile(), "set-property" ); - mojo.localRepository = new StubArtifactRepository( pomDir.toString() ); + + mojo.aetherRepositorySystem = mock( org.eclipse.aether.RepositorySystem.class ); + when( mojo.aetherRepositorySystem.resolveVersionRange( any(), any( VersionRangeRequest.class ) ) ) + .then( i -> new VersionRangeResult( i.getArgument( 1 ) ) ); + setVariableValueToObject( mojo, "newVersion", null ); mojo.execute(); @@ -98,11 +100,14 @@ public void testNullNewVersion() public void testNewVersionEmpty() throws Exception { - Files.copy( Paths.get( "src/test/resources/org/codehaus/mojo/set-property/null-new-version/pom.xml" ), - Paths.get( pomDir.toString(), "pom.xml" ), REPLACE_EXISTING ); + copyDir( Paths.get( "src/test/resources/org/codehaus/mojo/set-property/null-new-version" ), pomDir ); SetPropertyMojo mojo = (SetPropertyMojo) mojoRule.lookupConfiguredMojo( pomDir.toFile(), "set-property" ); - mojo.localRepository = new StubArtifactRepository( pomDir.toString() ); + + mojo.aetherRepositorySystem = mock( org.eclipse.aether.RepositorySystem.class ); + when( mojo.aetherRepositorySystem.resolveVersionRange( any(), any( VersionRangeRequest.class ) ) ) + .then( i -> new VersionRangeResult( i.getArgument( 1 ) ) ); + setVariableValueToObject( mojo, "newVersion", "" ); mojo.execute(); @@ -117,8 +122,7 @@ public void testNewVersionEmpty() public void testNullProperty() throws Exception { - Files.copy( Paths.get( "src/test/resources/org/codehaus/mojo/set-property/null-property/pom.xml" ), - Paths.get( pomDir.toString(), "pom.xml" ), REPLACE_EXISTING ); + copyDir( Paths.get( "src/test/resources/org/codehaus/mojo/set-property/null-property" ), pomDir ); SetPropertyMojo mojo = (SetPropertyMojo) mojoRule.lookupConfiguredMojo( pomDir.toFile(), "set-property" ); 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 27b9724589..4707286319 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,8 +7,6 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; @@ -17,9 +15,11 @@ import org.apache.maven.model.Model; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub; import org.apache.maven.project.MavenProject; import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.PomHelper; +import org.codehaus.mojo.versions.api.VersionRetrievalException; import org.codehaus.mojo.versions.change.DefaultVersionChange; import org.codehaus.mojo.versions.ordering.InvalidSegmentException; import org.codehaus.mojo.versions.utils.TestChangeRecorder; @@ -31,7 +31,8 @@ import static java.util.Collections.singleton; import static org.apache.maven.artifact.Artifact.SCOPE_COMPILE; import static org.apache.maven.plugin.testing.ArtifactStubFactory.setVariableValueToObject; -import static org.codehaus.mojo.versions.utils.MockUtils.mockArtifactMetadataSource; +import static org.codehaus.mojo.versions.utils.MockUtils.mockAetherRepositorySystem; +import static org.codehaus.mojo.versions.utils.MockUtils.mockMavenSession; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.hasItem; @@ -53,13 +54,13 @@ public class UpdateParentMojoTest private static RepositorySystem repositorySystem; - private static ArtifactMetadataSource artifactMetadataSource; + private static org.eclipse.aether.RepositorySystem aetherRepositorySystem; @BeforeClass public static void setUpStatic() { repositorySystem = mockRepositorySystem(); - artifactMetadataSource = mockArtifactMetadataSource( new HashMap() + aetherRepositorySystem = mockAetherRepositorySystem( new HashMap() {{ put( "parent-artifact", new String[] { "0.9.0", "1.0.0", "1.0.1-SNAPSHOT" } ); put( "issue-670-artifact", new String[] { "0.0.1-1", "0.0.1-1-impl-SNAPSHOT" } ); @@ -75,15 +76,12 @@ public void setUp() throws IllegalAccessException changeRecorder = new TestChangeRecorder(); artifactResolver = mock( ArtifactResolver.class ); - mojo = new UpdateParentMojo( repositorySystem, - null, - artifactMetadataSource, - null, - artifactResolver, - changeRecorder.asTestMap() ) + mojo = new UpdateParentMojo( repositorySystem, aetherRepositorySystem, null, null, + artifactResolver, changeRecorder.asTestMap() ) {{ setProject( createProject() ); reactorProjects = Collections.emptyList(); + session = mockMavenSession(); }}; } @@ -115,7 +113,8 @@ private static RepositorySystem mockRepositorySystem() Dependency dependency = invocation.getArgument( 0 ); return new DefaultArtifact( dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency.getScope(), dependency.getType(), dependency.getClassifier() != null - ? dependency.getClassifier() : "default", null ); + ? dependency.getClassifier() : "default", + new DefaultArtifactHandlerStub( "default" ) ); } ); return repositorySystem; } @@ -123,8 +122,9 @@ private static RepositorySystem mockRepositorySystem() @Test @SuppressWarnings( "deprecation" ) public void testArtifactIdDoesNotExist() - throws ArtifactMetadataRetrievalException, MojoExecutionException, - XMLStreamException, MojoFailureException, InvalidVersionSpecificationException + throws VersionRetrievalException, MojoExecutionException, + XMLStreamException, MojoFailureException, InvalidVersionSpecificationException, + VersionRetrievalException { mojo.getProject().setParent( new MavenProject() {{ @@ -135,7 +135,7 @@ public void testArtifactIdDoesNotExist() Artifact artifact = new DefaultArtifact( "default-group", "unknown-artifact", "1.0.1-SNAPSHOT", SCOPE_COMPILE, "pom", - "default", null ); + "default", new DefaultArtifactHandlerStub( "default" ) ); assertThat( mojo.findLatestVersion( artifact, VersionRange.createFromVersionSpec( "1.0.1-SNAPSHOT" ), null, false ), is( nullValue() ) ); @@ -149,7 +149,8 @@ public void testArtifactIdDoesNotExist() @Test public void testParentDowngradeAllowed() - throws MojoExecutionException, XMLStreamException, MojoFailureException + throws MojoExecutionException, XMLStreamException, MojoFailureException, + VersionRetrievalException { mojo.allowDowngrade = true; try ( MockedStatic pomHelper = mockStatic( PomHelper.class ) ) @@ -165,7 +166,8 @@ public void testParentDowngradeAllowed() @Test public void testParentDowngradeForbidden() - throws MojoExecutionException, XMLStreamException, MojoFailureException + throws MojoExecutionException, XMLStreamException, MojoFailureException, + VersionRetrievalException { mojo.allowDowngrade = false; try ( MockedStatic pomHelper = mockStatic( PomHelper.class ) ) @@ -179,7 +181,7 @@ public void testParentDowngradeForbidden() @Test public void testParentDowngradeAllowedWithRange() - throws MojoExecutionException, ArtifactMetadataRetrievalException, + throws MojoExecutionException, VersionRetrievalException, InvalidVersionSpecificationException, InvalidSegmentException { mojo.allowDowngrade = true; @@ -196,7 +198,7 @@ public void testParentDowngradeAllowedWithRange() @Test public void testParentDowngradeForbiddenWithRange() - throws MojoExecutionException, ArtifactMetadataRetrievalException, + throws MojoExecutionException, VersionRetrievalException, InvalidVersionSpecificationException, InvalidSegmentException { mojo.allowDowngrade = false; @@ -206,7 +208,7 @@ public void testParentDowngradeForbiddenWithRange() @Test public void testAllowSnapshots() - throws MojoExecutionException, ArtifactMetadataRetrievalException, + throws MojoExecutionException, VersionRetrievalException, InvalidVersionSpecificationException, InvalidSegmentException { mojo.allowSnapshots = true; @@ -223,7 +225,8 @@ public void testAllowSnapshots() @Test public void testAllowSnapshotsWithParentVersion() - throws MojoExecutionException, XMLStreamException, MojoFailureException + throws MojoExecutionException, XMLStreamException, MojoFailureException, + VersionRetrievalException { mojo.allowSnapshots = true; mojo.parentVersion = "0.0.1-1-impl-SNAPSHOT"; @@ -248,7 +251,7 @@ public void testAllowSnapshotsWithParentVersion() @Test public void testIgnoredVersions() throws MojoExecutionException, IllegalAccessException, - ArtifactMetadataRetrievalException, InvalidVersionSpecificationException, InvalidSegmentException + VersionRetrievalException, InvalidVersionSpecificationException, InvalidSegmentException { mojo.getProject().setParent( new MavenProject() {{ @@ -260,24 +263,24 @@ public void testIgnoredVersions() } @Test - public void testSkipResolutionDowngradeUnknownVersion() + public void testSkipResolutionDowngradeUnknownVersion() throws VersionRetrievalException { testSkipResolution( "0.8.0" ); } @Test - public void testSkipResolutionDowngrade() + public void testSkipResolutionDowngrade() throws VersionRetrievalException { testSkipResolution( "0.9.0" ); } @Test - public void testSkipResolutionUpgradeUnknownVersion() + public void testSkipResolutionUpgradeUnknownVersion() throws VersionRetrievalException { testSkipResolution( "2.0.0" ); } - private void testSkipResolution( String version ) + private void testSkipResolution( String version ) throws VersionRetrievalException { mojo.parentVersion = version; mojo.skipResolution = true; @@ -304,7 +307,8 @@ private void testSkipResolution( String version ) } @Test - public void testShouldUpgradeToSnapshot() throws MojoExecutionException, XMLStreamException, MojoFailureException + public void testShouldUpgradeToSnapshot() throws MojoExecutionException, XMLStreamException, MojoFailureException, + VersionRetrievalException { mojo.getProject().setParent( new MavenProject() {{ @@ -326,7 +330,7 @@ public void testShouldUpgradeToSnapshot() throws MojoExecutionException, XMLStre @Test public void testAllowMinorUpdates() - throws MojoExecutionException, ArtifactMetadataRetrievalException, + throws MojoExecutionException, VersionRetrievalException, InvalidVersionSpecificationException, InvalidSegmentException { mojo.getProject().setParent( new MavenProject() @@ -347,7 +351,7 @@ public void testAllowMinorUpdates() @Test public void testAllowIncrementalUpdates() - throws MojoExecutionException, ArtifactMetadataRetrievalException, + throws MojoExecutionException, VersionRetrievalException, InvalidVersionSpecificationException, InvalidSegmentException { mojo.getProject().setParent( new MavenProject() @@ -366,7 +370,8 @@ public void testAllowIncrementalUpdates() } @Test - public void testParentVersionRange() throws MojoExecutionException, XMLStreamException, MojoFailureException + public void testParentVersionRange() throws MojoExecutionException, XMLStreamException, MojoFailureException, + VersionRetrievalException { mojo.getProject().setParent( new MavenProject() {{ @@ -387,7 +392,8 @@ public void testParentVersionRange() throws MojoExecutionException, XMLStreamExc } @Test - public void testParentVersionRange2() throws MojoExecutionException, XMLStreamException, MojoFailureException + public void testParentVersionRange2() throws MojoExecutionException, XMLStreamException, MojoFailureException, + VersionRetrievalException { mojo.getProject().setParent( new MavenProject() {{ diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertiesMojoTestBase.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertiesMojoTestBase.java index afcb78fe8c..4d69cabbf4 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertiesMojoTestBase.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertiesMojoTestBase.java @@ -22,7 +22,6 @@ import java.util.HashMap; import java.util.Map; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.plugin.Mojo; import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.apache.maven.plugin.testing.MojoRule; @@ -33,7 +32,7 @@ import org.junit.Before; import org.junit.Rule; -import static org.codehaus.mojo.versions.utils.MockUtils.mockArtifactMetadataSource; +import static org.codehaus.mojo.versions.utils.MockUtils.mockAetherRepositorySystem; import static org.codehaus.mojo.versions.utils.TestUtils.createTempDir; import static org.codehaus.mojo.versions.utils.TestUtils.tearDownTempDir; @@ -45,7 +44,7 @@ public abstract class UpdatePropertiesMojoTestBase extends AbstractMojoTestCase @Rule public MojoRule mojoRule = new MojoRule( this ); protected Path pomDir; - protected ArtifactMetadataSource artifactMetadataSource; + protected org.eclipse.aether.RepositorySystem aetherRepositorySystem; protected TestChangeRecorder changeRecorder; @Before @@ -53,7 +52,7 @@ public void setUp() throws Exception { super.setUp(); pomDir = createTempDir( "update-property" ); - artifactMetadataSource = mockArtifactMetadataSource( new HashMap() + aetherRepositorySystem = mockAetherRepositorySystem( new HashMap() {{ put( "default-artifact", new String[] {"1.0.0", "1.0.1-rc1", "1.1.0-alpha", "2.0.0-M1"} ); }} ); @@ -77,7 +76,7 @@ protected T setUpMojo( String goal ) throws Exception { T mojo = (T) mojoRule.lookupConfiguredMojo( pomDir.toFile(), goal ); setVariableValueToObject( mojo, "localRepository", new StubArtifactRepository( pomDir.toString() ) ); - setVariableValueToObject( mojo, "artifactMetadataSource", artifactMetadataSource ); + setVariableValueToObject( mojo, "aetherRepositorySystem", aetherRepositorySystem ); setVariableValueToObject( mojo, "generateBackupPoms", false ); setVariableValueToObject( mojo, "changeRecorderFormat", "test" ); changeRecorder = (TestChangeRecorder) diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseLatestReleasesMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseLatestReleasesMojoTest.java index 82446fda07..f2c7d708e1 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseLatestReleasesMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseLatestReleasesMojoTest.java @@ -5,14 +5,15 @@ import java.util.HashMap; import org.apache.maven.artifact.DefaultArtifact; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.model.Dependency; import org.apache.maven.model.Model; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub; import org.apache.maven.project.MavenProject; import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.PomHelper; +import org.codehaus.mojo.versions.api.VersionRetrievalException; import org.codehaus.mojo.versions.utils.DependencyBuilder; import org.codehaus.mojo.versions.utils.TestChangeRecorder; import org.hamcrest.Matchers; @@ -24,14 +25,14 @@ import static java.util.Collections.singletonList; import static org.apache.maven.artifact.Artifact.SCOPE_COMPILE; import static org.apache.maven.plugin.testing.ArtifactStubFactory.setVariableValueToObject; -import static org.codehaus.mojo.versions.utils.MockUtils.mockArtifactMetadataSource; +import static org.codehaus.mojo.versions.utils.MockUtils.mockAetherRepositorySystem; +import static org.codehaus.mojo.versions.utils.MockUtils.mockMavenSession; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mockStatic; import static org.mockito.Mockito.when; -@SuppressWarnings( "deprecation" ) public class UseLatestReleasesMojoTest { private UseLatestReleasesMojo mojo; @@ -46,10 +47,12 @@ public void setUp() throws Exception Dependency dependency = invocation.getArgument( 0 ); return new DefaultArtifact( dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency.getScope(), dependency.getType(), - dependency.getClassifier() != null ? dependency.getClassifier() : "default", null ); + dependency.getClassifier() != null ? dependency.getClassifier() : "default", + new DefaultArtifactHandlerStub( "default" ) ); } ); - ArtifactMetadataSource artifactMetadataSourceMock = mockArtifactMetadataSource( new HashMap() + org.eclipse.aether.RepositorySystem aetherRepositorySystem = mockAetherRepositorySystem( + new HashMap() {{ put( "dependency-artifact", new String[] {"0.9.0", "1.0.0-beta"} ); }} ); @@ -57,11 +60,11 @@ public void setUp() throws Exception changeRecorder = new TestChangeRecorder(); mojo = new UseLatestReleasesMojo( repositorySystemMock, - null, - artifactMetadataSourceMock, - null, - null, - changeRecorder.asTestMap() ) + aetherRepositorySystem, + null, + null, + null, + changeRecorder.asTestMap() ) {{ reactorProjects = emptyList(); MavenProject project = new MavenProject() @@ -84,12 +87,15 @@ public void setUp() throws Exception }} ); }}; setProject( project ); + + session = mockMavenSession(); }}; } @Test public void testDontUpgradeToBeta() - throws MojoExecutionException, XMLStreamException, MojoFailureException, IllegalAccessException + throws MojoExecutionException, XMLStreamException, MojoFailureException, IllegalAccessException, + VersionRetrievalException { setVariableValueToObject( mojo, "processDependencies", true ); setVariableValueToObject( mojo, "allowSnapshots", false ); diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseLatestVersionsMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseLatestVersionsMojoTest.java index ed0b35723e..4152a9019a 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseLatestVersionsMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseLatestVersionsMojoTest.java @@ -7,15 +7,16 @@ import java.util.HashMap; import org.apache.maven.artifact.DefaultArtifact; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.model.Dependency; import org.apache.maven.model.DependencyManagement; import org.apache.maven.model.Model; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub; import org.apache.maven.project.MavenProject; import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.PomHelper; +import org.codehaus.mojo.versions.api.VersionRetrievalException; import org.codehaus.mojo.versions.change.DefaultVersionChange; import org.codehaus.mojo.versions.utils.DependencyBuilder; import org.codehaus.mojo.versions.utils.TestChangeRecorder; @@ -28,7 +29,8 @@ import static java.util.Collections.singleton; import static org.apache.maven.artifact.Artifact.SCOPE_COMPILE; import static org.apache.maven.plugin.testing.ArtifactStubFactory.setVariableValueToObject; -import static org.codehaus.mojo.versions.utils.MockUtils.mockArtifactMetadataSource; +import static org.codehaus.mojo.versions.utils.MockUtils.mockAetherRepositorySystem; +import static org.codehaus.mojo.versions.utils.MockUtils.mockMavenSession; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.hasItem; @@ -54,10 +56,12 @@ public void setUp() throws Exception Dependency dependency = invocation.getArgument( 0 ); return new DefaultArtifact( dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency.getScope(), dependency.getType(), - dependency.getClassifier() != null ? dependency.getClassifier() : "default", null ); + dependency.getClassifier() != null ? dependency.getClassifier() : "default", + new DefaultArtifactHandlerStub( "default" ) ); } ); - ArtifactMetadataSource artifactMetadataSourceMock = mockArtifactMetadataSource( new HashMap() + org.eclipse.aether.RepositorySystem aetherRepositorySystem = mockAetherRepositorySystem( + new HashMap() {{ put( "dependency-artifact", new String[] {"1.1.1-SNAPSHOT", "1.1.0", "1.1.0-SNAPSHOT", "1.0.0", "1.0.0-SNAPSHOT", "0.9.0"} ); @@ -69,11 +73,11 @@ public void setUp() throws Exception changeRecorder = new TestChangeRecorder(); mojo = new UseLatestVersionsMojo( repositorySystemMock, - null, - artifactMetadataSourceMock, - null, - null, - changeRecorder.asTestMap() ) + aetherRepositorySystem, + null, + null, + null, + changeRecorder.asTestMap() ) {{ reactorProjects = emptyList(); MavenProject project = new MavenProject() @@ -95,13 +99,16 @@ public void setUp() throws Exception }} ); }}; setProject( project ); + + session = mockMavenSession(); }}; setVariableValueToObject( mojo, "processDependencyManagement", false ); } @Test public void testDependenciesDowngradeIncremental() - throws MojoExecutionException, XMLStreamException, MojoFailureException, IllegalAccessException + throws MojoExecutionException, XMLStreamException, MojoFailureException, IllegalAccessException, + VersionRetrievalException { setVariableValueToObject( mojo, "processDependencies", true ); setVariableValueToObject( mojo, "allowSnapshots", false ); @@ -122,7 +129,8 @@ public void testDependenciesDowngradeIncremental() @Test public void testDependenciesDowngradeMinor() - throws MojoExecutionException, XMLStreamException, MojoFailureException, IllegalAccessException + throws MojoExecutionException, XMLStreamException, MojoFailureException, IllegalAccessException, + VersionRetrievalException { setVariableValueToObject( mojo, "processDependencies", true ); setVariableValueToObject( mojo, "allowSnapshots", false ); @@ -148,7 +156,8 @@ public void testDependenciesDowngradeMinor() @Test public void testDependenciesDowngradeMajor() - throws MojoExecutionException, XMLStreamException, MojoFailureException, IllegalAccessException + throws MojoExecutionException, XMLStreamException, MojoFailureException, IllegalAccessException, + VersionRetrievalException { setVariableValueToObject( mojo, "processDependencies", true ); setVariableValueToObject( mojo, "allowSnapshots", false ); @@ -170,7 +179,8 @@ public void testDependenciesDowngradeMajor() @Test public void testDependencyManagementDowngrade() - throws MojoExecutionException, XMLStreamException, MojoFailureException, IllegalAccessException + throws MojoExecutionException, XMLStreamException, MojoFailureException, IllegalAccessException, + VersionRetrievalException { setVariableValueToObject( mojo, "processDependencyManagement", true ); setVariableValueToObject( mojo, "allowSnapshots", false ); @@ -193,7 +203,8 @@ public void testDependencyManagementDowngrade() @Test public void testParentDowngrade() - throws MojoExecutionException, XMLStreamException, MojoFailureException, IllegalAccessException + throws MojoExecutionException, XMLStreamException, MojoFailureException, IllegalAccessException, + VersionRetrievalException { setVariableValueToObject( mojo, "processParent", true ); setVariableValueToObject( mojo, "allowSnapshots", false ); @@ -225,7 +236,8 @@ public void testParentDowngrade() @Test public void testPoisonDependencyVersion() - throws MojoExecutionException, XMLStreamException, MojoFailureException, IllegalAccessException + throws MojoExecutionException, XMLStreamException, MojoFailureException, IllegalAccessException, + VersionRetrievalException { mojo.getProject().getModel().setDependencies( Arrays.asList( DependencyBuilder.dependencyWith( "default-group", "dependency-artifact", "1.1.1-SNAPSHOT", @@ -255,7 +267,8 @@ public void testPoisonDependencyVersion() @Test public void testIgnoredVersions() - throws MojoExecutionException, XMLStreamException, MojoFailureException, IllegalAccessException + throws MojoExecutionException, XMLStreamException, MojoFailureException, IllegalAccessException, + VersionRetrievalException { setVariableValueToObject( mojo, "processDependencies", true ); setVariableValueToObject( mojo, "ignoredVersions", singleton( "1.1.0" ) ); @@ -271,7 +284,8 @@ public void testIgnoredVersions() @Test public void testIncludeFilter() - throws MojoExecutionException, XMLStreamException, MojoFailureException, IllegalAccessException + throws MojoExecutionException, XMLStreamException, MojoFailureException, IllegalAccessException, + VersionRetrievalException { mojo.getProject().getModel().setDependencies( Arrays.asList( DependencyBuilder.dependencyWith( "default-group", "dependency-artifact", "0.9.0", @@ -296,7 +310,8 @@ public void testIncludeFilter() @Test public void testExcludeFilter() - throws MojoExecutionException, XMLStreamException, MojoFailureException, IllegalAccessException + throws MojoExecutionException, XMLStreamException, MojoFailureException, IllegalAccessException, + VersionRetrievalException { mojo.getProject().getModel().setDependencies( Arrays.asList( DependencyBuilder.dependencyWith( "default-group", "dependency-artifact", "0.9.0", diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseReleasesMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseReleasesMojoTest.java index fe28fdf43a..463a00e395 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseReleasesMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseReleasesMojoTest.java @@ -11,6 +11,7 @@ import org.apache.maven.plugin.testing.stubs.StubArtifactResolver; import org.apache.maven.project.MavenProject; import org.codehaus.mojo.versions.api.PomHelper; +import org.codehaus.mojo.versions.api.VersionRetrievalException; import org.codehaus.mojo.versions.change.DefaultVersionChange; import org.codehaus.mojo.versions.utils.DependencyBuilder; import org.codehaus.mojo.versions.utils.TestChangeRecorder; @@ -22,7 +23,8 @@ import static java.util.Collections.singletonList; import static java.util.Collections.singletonMap; import static org.apache.maven.artifact.Artifact.SCOPE_COMPILE; -import static org.codehaus.mojo.versions.utils.MockUtils.mockArtifactMetadataSource; +import static org.codehaus.mojo.versions.utils.MockUtils.mockAetherRepositorySystem; +import static org.codehaus.mojo.versions.utils.MockUtils.mockMavenSession; import static org.codehaus.mojo.versions.utils.MockUtils.mockRepositorySystem; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; @@ -63,9 +65,11 @@ public void setUp() throws IllegalAccessException { changeRecorder = new TestChangeRecorder(); mojo = new UseReleasesMojo( mockRepositorySystem(), - null, mockArtifactMetadataSource(), - null, new StubArtifactResolver( new ArtifactStubFactory(), false, false ), - changeRecorder.asTestMap() ); + mockAetherRepositorySystem(), + null, + null, + new StubArtifactResolver( new ArtifactStubFactory(), false, false ), + changeRecorder.asTestMap() ); setVariableValueToObject( mojo, "reactorProjects", emptyList() ); mojo.project = new MavenProject() {{ @@ -76,11 +80,13 @@ null, new StubArtifactResolver( new ArtifactStubFactory(), false, false ), setVersion( "1.0.0" ); }} ); }}; + mojo.session = mockMavenSession(); } @Test public void testProcessParent() - throws MojoExecutionException, XMLStreamException, MojoFailureException, IllegalAccessException + throws MojoExecutionException, XMLStreamException, MojoFailureException, IllegalAccessException, + VersionRetrievalException { setVariableValueToObject( mojo, "processParent", true ); mojo.getProject().setParent( new MavenProject( new Model() @@ -107,7 +113,8 @@ public void testProcessParent() @Test public void testReplaceSnapshotWithRelease() - throws MojoExecutionException, XMLStreamException, MojoFailureException + throws MojoExecutionException, XMLStreamException, MojoFailureException, + VersionRetrievalException { mojo.getProject().setDependencies( singletonList( DependencyBuilder.newBuilder() .withGroupId( "default-group" ) @@ -131,9 +138,10 @@ public void testReplaceSnapshotWithRelease() @Test public void testFailIfNotReplaced() - throws MojoExecutionException, XMLStreamException, MojoFailureException + throws MojoExecutionException, XMLStreamException, MojoFailureException, + VersionRetrievalException { - mojo.artifactMetadataSource = mockArtifactMetadataSource( singletonMap( "test-artifact", + mojo.aetherRepositorySystem = mockAetherRepositorySystem( singletonMap( "test-artifact", new String[] {} ) ); mojo.getProject().setDependencies( singletonList( DependencyBuilder.newBuilder() .withGroupId( "default-group" ) diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/utils/MockUtils.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/utils/MockUtils.java index 991a944098..bf980f3786 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/utils/MockUtils.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/utils/MockUtils.java @@ -26,16 +26,21 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; -import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.doxia.tools.SiteTool; import org.apache.maven.doxia.tools.SiteToolException; +import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; import org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub; +import org.apache.maven.project.MavenProject; import org.apache.maven.repository.RepositorySystem; import org.codehaus.plexus.i18n.I18N; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.resolution.VersionRangeRequest; +import org.eclipse.aether.resolution.VersionRangeResolutionException; +import org.eclipse.aether.resolution.VersionRangeResult; +import org.eclipse.aether.version.Version; +import static java.util.Collections.emptyList; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; @@ -54,42 +59,44 @@ public class MockUtils }}; /** - * Creates a mocked {@linkplain ArtifactMetadataSource}, providing the default version set - * @return mocked {@linkplain ArtifactMetadataSource} + * Creates a mocked {@linkplain org.eclipse.aether.RepositorySystem}, providing the default version set + * @return mocked {@linkplain org.eclipse.aether.RepositorySystem} */ - public static ArtifactMetadataSource mockArtifactMetadataSource() + public static org.eclipse.aether.RepositorySystem mockAetherRepositorySystem() { - return mockArtifactMetadataSource( DEFAULT_VERSION_MAP ); + return mockAetherRepositorySystem( DEFAULT_VERSION_MAP ); } /** - * Creates a mocked {@linkplain ArtifactMetadataSource}, providing the version map given in the argument + * Creates a mocked {@linkplain org.eclipse.aether.RepositorySystem}, providing the version map given in + * the argument. * @param versionMap requested version map - * @return mocked {@linkplain ArtifactMetadataSource} + * @return mocked {@linkplain org.eclipse.aether.RepositorySystem} */ - public static ArtifactMetadataSource mockArtifactMetadataSource( Map versionMap ) + public static org.eclipse.aether.RepositorySystem mockAetherRepositorySystem( Map versionMap ) { - ArtifactMetadataSource artifactMetadataSource = mock( ArtifactMetadataSource.class ); + org.eclipse.aether.RepositorySystem repositorySystem = mock( org.eclipse.aether.RepositorySystem.class ); try { - when( artifactMetadataSource.retrieveAvailableVersions( any( Artifact.class ), any(), any() ) ).then( + when( repositorySystem.resolveVersionRange( any(), any( VersionRangeRequest.class ) ) ).then( invocation -> { - Artifact artifact = invocation.getArgument( 0 ); + VersionRangeRequest request = invocation.getArgument( 1 ); return versionMap.entrySet().stream() - .filter( e -> e.getKey().equals( artifact.getArtifactId() ) ) + .filter( e -> e.getKey().equals( request.getArtifact().getArtifactId() ) ) .findAny() .map( e -> Arrays.stream( e.getValue() ) - .map( DefaultArtifactVersion::new ) - .collect( ArrayList::new, ArrayList::add, ArrayList::add ) ) + .map( VersionStub::new ) + .collect( () -> new ArrayList(), ArrayList::add, ArrayList::addAll ) ) + .map( versions -> new VersionRangeResult( request ).setVersions( versions ) ) .orElse( null ); // should tell us if we haven't populated all cases in the test } ); } - catch ( ArtifactMetadataRetrievalException e ) + catch ( VersionRangeResolutionException e ) { throw new RuntimeException( e ); } - return artifactMetadataSource; + return repositorySystem; } public static I18N mockI18N() @@ -129,4 +136,22 @@ public static RepositorySystem mockRepositorySystem() } ); return repositorySystem; } + + /** + * Creates a very simple mock of {@link MavenSession} + * by providing only a non-{@code null} implementation of its {@link MavenSession#getRepositorySession()} method. + * @return mocked {@link MavenSession} + */ + public static MavenSession mockMavenSession() + { + MavenSession session = mock( MavenSession.class ); + when( session.getRepositorySession() ) + .thenReturn( mock( RepositorySystemSession.class ) ); + when( session.getCurrentProject() ).thenReturn( mock( MavenProject.class ) ); + when( session.getCurrentProject().getRemotePluginRepositories() ).thenReturn( emptyList() ); + when( session.getCurrentProject().getPluginArtifactRepositories() ).thenReturn( emptyList() ); + when( session.getCurrentProject().getRemoteArtifactRepositories() ).thenReturn( emptyList() ); + when( session.getCurrentProject().getRemoteProjectRepositories() ).thenReturn( emptyList() ); + return session; + } } diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/utils/VersionStub.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/utils/VersionStub.java new file mode 100644 index 0000000000..807e21574f --- /dev/null +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/utils/VersionStub.java @@ -0,0 +1,76 @@ +package org.codehaus.mojo.versions.utils; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.eclipse.aether.version.Version; + +/** + * Stubs the {@link Version} + */ +public class VersionStub implements Version +{ + private final String version; + + /** + * Creates a new instance with the given version string + * @param version version to be set + */ + public VersionStub( String version ) + { + assert version != null; + this.version = version; + } + + @Override + public String toString() + { + return version; + } + + @Override + public int compareTo( Version o ) + { + return o != null + ? version.compareTo( o.toString() ) + : 1; + } + + @Override + public boolean equals( Object o ) + { + if ( this == o ) + { + return true; + } + + if ( !( o instanceof Version ) ) + { + return false; + } + + return version.equals( o.toString() ); + } + + @Override + public int hashCode() + { + return version.hashCode(); + } +}