From b6a8fe4cee0a7a18c0e7705e208f0d428e189565 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 | 181 ++++++++---------- .../mojo/versions/api/PropertyVersions.java | 5 +- .../versions/api/PropertyVersionsBuilder.java | 3 +- .../api/VersionRetrievalException.java | 85 ++++++++ .../mojo/versions/api/VersionsHelper.java | 21 +- .../api/DefaultVersionsHelperTest.java | 88 +++++---- .../mojo/versions/utils/VersionStub.java | 76 ++++++++ ...AbstractVersionsDependencyUpdaterMojo.java | 5 +- .../versions/AbstractVersionsDisplayMojo.java | 5 +- .../mojo/versions/AbstractVersionsReport.java | 30 +-- .../versions/AbstractVersionsUpdaterMojo.java | 53 +++-- .../versions/CompareDependenciesMojo.java | 7 +- .../versions/DependencyUpdatesReportMojo.java | 10 +- .../DisplayDependencyUpdatesMojo.java | 20 +- .../versions/DisplayParentUpdatesMojo.java | 17 +- .../versions/DisplayPluginUpdatesMojo.java | 13 +- .../versions/DisplayPropertyUpdatesMojo.java | 15 +- .../mojo/versions/ForceReleasesMojo.java | 19 +- .../mojo/versions/LockSnapshotsMojo.java | 13 +- .../versions/ParentUpdatesReportMojo.java | 14 +- .../versions/PluginUpdatesReportMojo.java | 14 +- .../versions/PropertyUpdatesReportMojo.java | 9 +- .../mojo/versions/ResolveRangesMojo.java | 19 +- .../org/codehaus/mojo/versions/SetMojo.java | 15 +- .../mojo/versions/SetPropertyMojo.java | 7 +- .../codehaus/mojo/versions/SetScmTagMojo.java | 14 +- .../mojo/versions/UnlockSnapshotsMojo.java | 7 +- .../mojo/versions/UpdateChildModulesMojo.java | 13 +- .../mojo/versions/UpdateParentMojo.java | 15 +- .../mojo/versions/UpdatePropertiesMojo.java | 13 +- .../mojo/versions/UpdatePropertyMojo.java | 13 +- .../mojo/versions/UseDepVersionMojo.java | 19 +- .../mojo/versions/UseLatestReleasesMojo.java | 19 +- .../mojo/versions/UseLatestSnapshotsMojo.java | 19 +- .../mojo/versions/UseLatestVersionsMojo.java | 19 +- .../versions/UseLatestVersionsMojoBase.java | 11 +- .../mojo/versions/UseNextReleasesMojo.java | 22 +-- .../mojo/versions/UseNextSnapshotsMojo.java | 21 +- .../mojo/versions/UseNextVersionsMojo.java | 15 +- .../mojo/versions/UseReactorMojo.java | 21 +- .../mojo/versions/UseReleasesMojo.java | 19 +- .../DependencyUpdatesReportMojoTest.java | 64 +++---- .../DisplayDependencyUpdatesMojoTest.java | 28 +-- .../DisplayPropertyUpdatesMojoTest.java | 6 +- .../mojo/versions/ForceReleasesMojoTest.java | 29 ++- .../versions/ParentUpdatesReportMojoTest.java | 12 +- .../versions/PluginUpdatesReportMojoTest.java | 23 ++- .../PropertyUpdatesReportMojoTest.java | 9 +- ...ratePatternsForIncludesAnExcludesTest.java | 6 +- .../codehaus/mojo/versions/SetMojoTest.java | 8 +- .../mojo/versions/SetPropertyMojoTest.java | 44 +++-- .../mojo/versions/UpdateParentMojoTest.java | 66 +++++-- .../UpdatePropertiesMojoTestBase.java | 9 +- .../versions/UseLatestReleasesMojoTest.java | 20 +- .../versions/UseLatestVersionsMojoTest.java | 48 ++++- .../mojo/versions/UseReleasesMojoTest.java | 20 +- .../mojo/versions/utils/MockUtils.java | 39 ++-- .../mojo/versions/utils/VersionStub.java | 76 ++++++++ 59 files changed, 909 insertions(+), 607 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 14c99efdc4..24af9c1d97 100644 --- a/pom.xml +++ b/pom.xml @@ -194,6 +194,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..58b93b7dff 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,9 @@ 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.RepositorySystemSession; +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 +117,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. * @@ -145,6 +140,10 @@ public class DefaultVersionsHelper private RepositorySystem repositorySystem; + private org.eclipse.aether.RepositorySystem aetherRepositorySystem; + + private RepositorySystemSession repositorySystemSession; + /** * The {@link Log} to send log messages to. * @@ -388,61 +387,64 @@ 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( repositorySystemSession, new VersionRangeRequest( + RepositoryUtils.toArtifact( artifact ).setVersion( "(,)" ), + RepositoryUtils.toRepos( remoteRepositories ), + "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,28 +493,6 @@ 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 @@ -674,12 +654,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 +678,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 +719,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 +730,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 +864,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,7 +897,6 @@ public static class Builder { private RepositorySystem repositorySystem; private ArtifactResolver artifactResolver; - private ArtifactMetadataSource artifactMetadataSource; private List remoteArtifactRepositories; private List remotePluginRepositories; private ArtifactRepository localRepository; @@ -931,6 +909,8 @@ public static class Builder private Log log; private MavenSession mavenSession; private MojoExecution mojoExecution; + private org.eclipse.aether.RepositorySystem aetherRepositorySystem; + private RepositorySystemSession repositorySystemSession; public Builder() { @@ -948,12 +928,6 @@ public Builder withArtifactResolver( ArtifactResolver artifactResolver ) return this; } - public Builder withArtifactMetadataSource( ArtifactMetadataSource artifactMetadataSource ) - { - this.artifactMetadataSource = artifactMetadataSource; - return this; - } - public Builder withRemoteArtifactRepositories( List remoteArtifactRepositories ) { @@ -1028,6 +1002,18 @@ public Builder withMojoExecution( MojoExecution mojoExecution ) return this; } + public Builder withAetherRepositorySystem( org.eclipse.aether.RepositorySystem aetherRepositorySystem ) + { + this.aetherRepositorySystem = aetherRepositorySystem; + return this; + } + + public Builder withRepositorySystemSession( RepositorySystemSession repositorySystemSession ) + { + this.repositorySystemSession = repositorySystemSession; + return this; + } + /** * Builds the constructed {@linkplain DefaultVersionsHelper} object * @return constructed {@linkplain DefaultVersionsHelper} @@ -1061,7 +1047,8 @@ public DefaultVersionsHelper build() throws MojoExecutionException { instance.ruleSet = enrichRuleSet( ignoredVersions, instance.ruleSet ); } - instance.artifactMetadataSource = artifactMetadataSource; + instance.aetherRepositorySystem = aetherRepositorySystem; + instance.repositorySystemSession = repositorySystemSession; instance.localRepository = localRepository; instance.remoteArtifactRepositories = remoteArtifactRepositories; instance.remotePluginRepositories = remotePluginRepositories; 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..e05546df9e 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,36 @@ 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.singletonList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; @@ -59,9 +60,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 +72,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,17 +217,18 @@ 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(); return new DefaultVersionsHelper.Builder() .withRepositorySystem( lookup( RepositorySystem.class ) ) .withArtifactResolver( new DefaultArtifactResolver() ) - .withArtifactMetadataSource( metadataSource ) + .withAetherRepositorySystem( aetherRepositorySystem ) .withRemoteArtifactRepositories( new ArrayList<>() ) .withRemotePluginRepositories( new ArrayList<>() ) .withLocalRepository( new DefaultArtifactRepository( 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 9b8cc5c5cd..c710c457b0 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 @@ -31,7 +31,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; @@ -157,12 +156,12 @@ public abstract class AbstractVersionsDependencyUpdaterMojo @Inject protected AbstractVersionsDependencyUpdaterMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver ); } /** 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 47057ffd46..a2b0f2c478 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 @@ -30,7 +30,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; @@ -85,12 +84,12 @@ public abstract class AbstractVersionsDisplayMojo @Inject protected AbstractVersionsDisplayMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver ); } @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..e80cb61a18 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,10 +43,12 @@ 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; import org.codehaus.plexus.i18n.I18N; +import org.eclipse.aether.RepositorySystemSession; /** * Base class for all versions reports. @@ -78,12 +78,17 @@ 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; + /** + * The current {@link RepositorySystemSession} + * + * @since 2.14.0 + */ + @Parameter( defaultValue = "${repositorySystemSession}", readonly = true ) + protected RepositorySystemSession repositorySystemSession; /** * @since 1.0-alpha-3 */ @@ -197,14 +202,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,7 +226,8 @@ public VersionsHelper getHelper() helper = new DefaultVersionsHelper.Builder() .withRepositorySystem( repositorySystem ) .withArtifactResolver( artifactResolver ) - .withArtifactMetadataSource( artifactMetadataSource ) + .withAetherRepositorySystem( aetherRepositorySystem ) + .withRepositorySystemSession( repositorySystemSession ) .withRemoteArtifactRepositories( remoteArtifactRepositories ) .withRemotePluginRepositories( remotePluginRepositories ) .withLocalRepository( localRepository ) @@ -295,7 +303,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 ad4bbf6425..90d0925b26 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.model.RuleSet; import org.codehaus.mojo.versions.ordering.InvalidSegmentException; @@ -69,6 +68,7 @@ import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.WriterFactory; import org.codehaus.stax2.XMLInputFactory2; +import org.eclipse.aether.RepositorySystemSession; /** * Abstract base class for Versions Mojos. @@ -89,25 +89,37 @@ 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 org.eclipse.aether.RepositorySystem aetherRepositorySystem; + + /** + * The current {@link RepositorySystemSession} + * + * @since 2.14.0 */ - protected MavenProjectBuilder projectBuilder; + @Parameter( defaultValue = "${repositorySystemSession}", readonly = true ) + protected RepositorySystemSession repositorySystemSession; + /** + * 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 @@ -128,9 +140,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 @@ -242,14 +254,14 @@ public abstract class AbstractVersionsUpdaterMojo @Inject protected AbstractVersionsUpdaterMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver ) { this.repositorySystem = repositorySystem; + this.aetherRepositorySystem = aetherRepositorySystem; this.projectBuilder = projectBuilder; - this.artifactMetadataSource = artifactMetadataSource; this.wagonManager = wagonManager; this.artifactResolver = artifactResolver; } @@ -261,7 +273,8 @@ public VersionsHelper getHelper() throws MojoExecutionException helper = new DefaultVersionsHelper.Builder() .withRepositorySystem( repositorySystem ) .withArtifactResolver( artifactResolver ) - .withArtifactMetadataSource( artifactMetadataSource ) + .withAetherRepositorySystem( aetherRepositorySystem ) + .withRepositorySystemSession( repositorySystemSession ) .withRemoteArtifactRepositories( remoteArtifactRepositories ) .withRemotePluginRepositories( remotePluginRepositories ) .withLocalRepository( localRepository ) @@ -346,13 +359,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 ); @@ -419,7 +432,7 @@ protected void process( File outFile ) { getLog().error( e ); } - catch ( ArtifactMetadataRetrievalException e ) + catch ( VersionRetrievalException e ) { throw new MojoExecutionException( e.getMessage(), e ); } @@ -472,11 +485,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 1182945f14..48cf5c0ed0 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; @@ -126,13 +125,13 @@ public class CompareDependenciesMojo @Inject public CompareDependenciesMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver, MavenProjectBuilder mavenProjectBuilder ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver ); this.mavenProjectBuilder = mavenProjectBuilder; } @@ -144,7 +143,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 extractPluginDependenciesFromPluginsInPluginManagement( Build build ) @@ -592,7 +590,7 @@ public void execute() logUpdates( getHelper().lookupDependenciesUpdates( pluginDependencies, false ), "Plugin Dependencies" ); } } - catch ( ArtifactMetadataRetrievalException e ) + catch ( VersionRetrievalException e ) { throw new MojoExecutionException( e.getMessage(), e ); } @@ -788,15 +786,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 066aab7e2b..69d3e5bca8 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,12 +20,9 @@ */ import javax.inject.Inject; -import javax.xml.stream.XMLStreamException; 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; @@ -35,6 +32,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.rewriting.ModifiedPomXMLEventReader; import org.codehaus.mojo.versions.utils.DependencyBuilder; @@ -53,12 +51,12 @@ public class DisplayParentUpdatesMojo @Inject public DisplayParentUpdatesMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + org.eclipse.aether.RepositorySystem aetherRepositorySystem, + MavenProjectBuilder projectBuilder, + WagonManager wagonManager, + ArtifactResolver artifactResolver ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver ); } @Override @@ -103,7 +101,7 @@ public void execute() { artifactVersion = findLatestVersion( artifact, versionRange, null, false ); } - catch ( ArtifactMetadataRetrievalException e ) + catch ( VersionRetrievalException e ) { throw new MojoExecutionException( e.getMessage(), e ); } @@ -151,7 +149,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 fe15039f7c..2d2352b49d 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.ordering.MavenVersionComparator; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.codehaus.mojo.versions.utils.DependencyBuilder; @@ -164,8 +163,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, @@ -173,7 +172,7 @@ public DisplayPluginUpdatesMojo( RepositorySystem repositorySystem, PluginManager pluginManager, RuntimeInformation runtimeInformation ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver ); this.lifecycleExecutor = lifecycleExecutor; this.modelInterpolator = modelInterpolator; this.pluginManager = pluginManager; @@ -535,7 +534,7 @@ public void execute() } } } - catch ( ArtifactMetadataRetrievalException e ) + catch ( VersionRetrievalException e ) { throw new MojoExecutionException( e.getMessage(), e ); } @@ -1818,14 +1817,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 c39f11ac1e..a6586ecb03 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; @@ -144,12 +141,12 @@ public class DisplayPropertyUpdatesMojo @Inject public DisplayPropertyUpdatesMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + org.eclipse.aether.RepositorySystem aetherRepositorySystem, + MavenProjectBuilder projectBuilder, + WagonManager wagonManager, + ArtifactResolver artifactResolver ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver ); } public void execute() @@ -258,8 +255,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 abd249228b..c6986713a3 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 @@ -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.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.VersionRange; @@ -43,6 +41,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.rewriting.ModifiedPomXMLEventReader; import static java.util.Collections.singletonList; @@ -69,12 +68,12 @@ public class ForceReleasesMojo @Inject public ForceReleasesMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + org.eclipse.aether.RepositorySystem aetherRepositorySystem, + MavenProjectBuilder projectBuilder, + WagonManager wagonManager, + ArtifactResolver artifactResolver ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver ); } /** @@ -85,7 +84,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 { @@ -107,14 +106,14 @@ protected void update( ModifiedPomXMLEventReader pom ) useReleases( pom, singletonList( getParentDependency() ) ); } } - catch ( ArtifactMetadataRetrievalException | IOException e ) + catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } } private void useReleases( 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/LockSnapshotsMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/LockSnapshotsMojo.java index 2749037519..9f21a8a4ea 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 @@ -29,7 +29,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; @@ -67,12 +66,12 @@ public class LockSnapshotsMojo @Inject public LockSnapshotsMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + org.eclipse.aether.RepositorySystem aetherRepositorySystem, + MavenProjectBuilder projectBuilder, + WagonManager wagonManager, + ArtifactResolver artifactResolver ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver ); } /** @@ -83,7 +82,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 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 fef10ea975..b937649c39 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; @@ -247,14 +246,12 @@ public class SetMojo extends AbstractVersionsUpdaterMojo @Inject public SetMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver, - Prompter prompter ) + org.eclipse.aether.RepositorySystem aetherRepositorySystem, + MavenProjectBuilder projectBuilder, + WagonManager wagonManager, + ArtifactResolver artifactResolver ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); - this.prompter = prompter; + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver ); } private synchronized void addChange( String groupId, String artifactId, String oldVersion, String newVersion ) @@ -566,7 +563,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 f2e6787122..459514cd1b 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; @@ -92,12 +91,12 @@ public class SetPropertyMojo @Inject public SetPropertyMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver ); } /** @@ -108,7 +107,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 b11d51d33a..34d5a82dbc 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 @@ -8,8 +8,6 @@ import java.util.List; 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; @@ -68,12 +66,12 @@ public class SetScmTagMojo extends AbstractVersionsUpdaterMojo @Inject public SetScmTagMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + org.eclipse.aether.RepositorySystem aetherRepositorySystem, + MavenProjectBuilder projectBuilder, + WagonManager wagonManager, + ArtifactResolver artifactResolver ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver ); } /** @@ -96,7 +94,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 408cec4349..259ef6616b 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 @@ -29,7 +29,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; @@ -66,12 +65,12 @@ public class UnlockSnapshotsMojo extends AbstractVersionsDependencyUpdaterMojo @Inject public UnlockSnapshotsMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver ); } /** @@ -82,7 +81,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 be50bbeb08..c499904b8c 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; @@ -71,12 +70,12 @@ public class UpdateChildModulesMojo @Inject public UpdateChildModulesMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + org.eclipse.aether.RepositorySystem aetherRepositorySystem, + MavenProjectBuilder projectBuilder, + WagonManager wagonManager, + ArtifactResolver artifactResolver ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver ); } /** @@ -209,7 +208,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 caa60b4ce8..e17069dceb 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 @@ -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.DefaultArtifactVersion; @@ -45,6 +43,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.ordering.InvalidSegmentException; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.codehaus.mojo.versions.utils.DependencyBuilder; @@ -137,12 +136,12 @@ public class UpdateParentMojo extends AbstractVersionsUpdaterMojo @Inject public UpdateParentMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver ); } /** @@ -154,7 +153,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 ) { @@ -203,10 +202,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 ); @@ -214,7 +209,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 8211e28179..87d501624f 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; @@ -139,12 +138,12 @@ public class UpdatePropertiesMojo extends AbstractVersionsDependencyUpdaterMojo @Inject public UpdatePropertiesMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + org.eclipse.aether.RepositorySystem aetherRepositorySystem, + MavenProjectBuilder projectBuilder, + WagonManager wagonManager, + ArtifactResolver artifactResolver ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver ); } /** @@ -156,7 +155,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 9e22942623..bf5f6e6a5b 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; @@ -138,12 +137,12 @@ 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 ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver ); } /** @@ -155,7 +154,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 bfbc42d9eb..38bae17eef 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 @@ -27,8 +27,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; @@ -40,6 +38,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.rewriting.ModifiedPomXMLEventReader; import static java.util.Collections.singletonList; @@ -73,17 +72,17 @@ public class UseDepVersionMojo extends AbstractVersionsDependencyUpdaterMojo @Inject public UseDepVersionMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + org.eclipse.aether.RepositorySystem aetherRepositorySystem, + MavenProjectBuilder projectBuilder, + WagonManager wagonManager, + ArtifactResolver artifactResolver ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver ); } @Override protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException, ArtifactMetadataRetrievalException + throws MojoExecutionException, MojoFailureException, XMLStreamException, VersionRetrievalException { if ( depVersion == null || depVersion.equals( "" ) ) @@ -122,14 +121,14 @@ protected void update( ModifiedPomXMLEventReader pom ) useDepVersion( pom, singletonList( getParentDependency() ) ); } } - catch ( ArtifactMetadataRetrievalException | IOException e ) + catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } } private void useDepVersion( ModifiedPomXMLEventReader pom, Collection dependencies ) - 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 5c80e70909..ccad81aae6 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 @@ -31,8 +31,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; @@ -46,6 +44,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.ordering.InvalidSegmentException; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.codehaus.mojo.versions.utils.SegmentUtils; @@ -102,12 +101,12 @@ public class UseLatestReleasesMojo @Inject public UseLatestReleasesMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + org.eclipse.aether.RepositorySystem aetherRepositorySystem, + MavenProjectBuilder projectBuilder, + WagonManager wagonManager, + ArtifactResolver artifactResolver ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver ); } /** @@ -118,7 +117,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 { @@ -140,14 +139,14 @@ protected void update( ModifiedPomXMLEventReader pom ) useLatestReleases( pom, singletonList( getParentDependency() ) ); } } - catch ( ArtifactMetadataRetrievalException | IOException e ) + catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } } private void useLatestReleases( ModifiedPomXMLEventReader pom, Collection dependencies ) - 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 33d1785553..5831078e44 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 @@ -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.ordering.InvalidSegmentException; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.codehaus.mojo.versions.utils.SegmentUtils; @@ -91,12 +90,12 @@ public class UseLatestSnapshotsMojo @Inject public UseLatestSnapshotsMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + org.eclipse.aether.RepositorySystem aetherRepositorySystem, + MavenProjectBuilder projectBuilder, + WagonManager wagonManager, + ArtifactResolver artifactResolver ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver ); } /** @@ -107,7 +106,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 { @@ -129,14 +128,14 @@ protected void update( ModifiedPomXMLEventReader pom ) useLatestSnapshots( pom, singletonList( getParentDependency() ) ); } } - catch ( ArtifactMetadataRetrievalException | IOException e ) + catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } } private void useLatestSnapshots( ModifiedPomXMLEventReader pom, Collection dependencies ) - 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 57235889ca..7865c7a669 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 @@ -27,8 +27,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; @@ -40,6 +38,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.ordering.InvalidSegmentException; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.codehaus.mojo.versions.utils.SegmentUtils; @@ -99,12 +98,12 @@ public class UseLatestVersionsMojo @Inject public UseLatestVersionsMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + org.eclipse.aether.RepositorySystem aetherRepositorySystem, + MavenProjectBuilder projectBuilder, + WagonManager wagonManager, + ArtifactResolver artifactResolver ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver ); } @Override @@ -125,7 +124,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 { @@ -147,14 +146,14 @@ protected void update( ModifiedPomXMLEventReader pom ) useLatestVersions( pom, singletonList( getParentDependency() ) ); } } - catch ( ArtifactMetadataRetrievalException | IOException e ) + catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } } private void useLatestVersions( ModifiedPomXMLEventReader pom, Collection dependencies ) - 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 90f0deb7ac..e9f40929a7 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 @@ -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.DefaultArtifactVersion; @@ -39,6 +37,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.rewriting.ModifiedPomXMLEventReader; /** @@ -49,12 +48,12 @@ public abstract class UseLatestVersionsMojoBase extends AbstractVersionsDependencyUpdaterMojo { public UseLatestVersionsMojoBase( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver ); } /** @@ -68,7 +67,7 @@ public UseLatestVersionsMojoBase( RepositorySystem repositorySystem, * @param changeRecorderTitle 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, @@ -77,7 +76,7 @@ protected final void useLatestVersions( ModifiedPomXMLEventReader pom, newestVersionProducer, String changeRecorderTitle, 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 05705f90dc..1442c1e696 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 @@ -27,8 +27,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; @@ -38,6 +36,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.rewriting.ModifiedPomXMLEventReader; import static java.util.Collections.singletonList; @@ -65,12 +64,12 @@ public class UseNextReleasesMojo @Inject public UseNextReleasesMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver ); } /** @@ -81,7 +80,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 { @@ -99,19 +98,20 @@ protected void update( ModifiedPomXMLEventReader pom ) { useNextReleases( pom, getProject().getDependencies() ); } + + if ( getProject().getParent() != null && isProcessingParent() ) + { + useNextReleases( pom, singletonList( getParentDependency() ) ); + } } - catch ( ArtifactMetadataRetrievalException | IOException e ) + catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } - if ( getProject().getParent() != null && isProcessingParent() ) - { - useNextReleases( pom, singletonList( getParentDependency() ) ); - } } private void useNextReleases( ModifiedPomXMLEventReader pom, Collection dependencies ) - 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 afaf413029..a6af6d8929 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 @@ -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; @@ -41,6 +39,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.ordering.InvalidSegmentException; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.codehaus.mojo.versions.utils.SegmentUtils; @@ -90,16 +89,18 @@ 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 ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver ); // the below is necessary for UseLatestVersionsMojoBase.useLatestVersions to select snapshots allowSnapshots = true; } + + /** * @param pom the pom to update. * @throws org.apache.maven.plugin.MojoExecutionException when things go wrong @@ -108,7 +109,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 { @@ -127,14 +128,14 @@ protected void update( ModifiedPomXMLEventReader pom ) useNextSnapshots( pom, singletonList( getParentDependency() ) ); } } - catch ( ArtifactMetadataRetrievalException | IOException e ) + catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } } private void useNextSnapshots( ModifiedPomXMLEventReader pom, Collection dependencies ) - 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 529e983e40..37b6c954b8 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 @@ -26,8 +26,6 @@ import java.util.Collection; 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; @@ -37,6 +35,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.rewriting.ModifiedPomXMLEventReader; import static java.util.Collections.singletonList; @@ -57,12 +56,12 @@ public class UseNextVersionsMojo @Inject public UseNextVersionsMojo( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver ); } /** @@ -73,7 +72,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 { @@ -86,23 +85,25 @@ protected void update( ModifiedPomXMLEventReader pom ) useNextVersions( pom, dependencyManagement.getDependencies() ); } } + if ( getProject().getDependencies() != null && isProcessingDependencies() ) { useNextVersions( pom, getProject().getDependencies() ); } + if ( getProject().getParent() != null && isProcessingParent() ) { useNextVersions( pom, singletonList( getParentDependency() ) ); } } - catch ( ArtifactMetadataRetrievalException | IOException e ) + catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } } private void useNextVersions( ModifiedPomXMLEventReader pom, Collection dependencies ) - 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 a8333cb370..a5d962da90 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 @@ -28,8 +28,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; @@ -40,6 +38,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.rewriting.ModifiedPomXMLEventReader; /** @@ -57,12 +56,12 @@ public class UseReactorMojo @Inject public UseReactorMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + org.eclipse.aether.RepositorySystem aetherRepositorySystem, + MavenProjectBuilder projectBuilder, + WagonManager wagonManager, + ArtifactResolver artifactResolver ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver ); } /** @@ -73,7 +72,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 { @@ -95,14 +94,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 ) @@ -132,7 +131,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 1a4704f8f2..9105d021ad 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 @@ -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.model.Dependency; @@ -44,6 +42,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.rewriting.ModifiedPomXMLEventReader; import static java.util.Collections.singletonList; @@ -83,12 +82,12 @@ public class UseReleasesMojo @Inject public UseReleasesMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + org.eclipse.aether.RepositorySystem aetherRepositorySystem, + MavenProjectBuilder projectBuilder, + WagonManager wagonManager, + ArtifactResolver artifactResolver ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, aetherRepositorySystem, projectBuilder, wagonManager, artifactResolver ); } /** @@ -99,7 +98,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 { @@ -121,14 +120,14 @@ protected void update( ModifiedPomXMLEventReader pom ) useReleases( pom, singletonList( getParentDependency() ) ); } } - catch ( ArtifactMetadataRetrievalException | IOException e ) + catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } } private void useReleases( ModifiedPomXMLEventReader pom, Collection dependencies ) - 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..9e809deca8 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,15 @@ 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.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 +67,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(); @@ -88,10 +83,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 +155,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 +170,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 +195,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 +213,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 +233,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 +251,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 +273,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 +297,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 +315,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 +323,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 +336,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 +344,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 +360,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 25250b203d..65873c6c5c 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,7 @@ 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.mockRepositorySystem; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.anyOf; @@ -112,7 +112,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,11 +157,11 @@ public void testVersionsWithQualifiersNotConsideredAsMinorUpdates() tempPath = Files.createTempFile( "display-dependency-updates", "" ); final File tempFile = tempPath.toFile(); new DisplayDependencyUpdatesMojo( mockRepositorySystem(), - null, mockArtifactMetadataSource( new HashMap() + 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, null, new StubArtifactResolver( new ArtifactStubFactory(), false, false ) ) {{ setProject( createProject() ); @@ -200,10 +200,10 @@ public void testAllowMajorUpdatesFalse() tempPath = Files.createTempFile( "display-dependency-updates", "" ); final File tempFile = tempPath.toFile(); new DisplayDependencyUpdatesMojo( mockRepositorySystem(), - null, mockArtifactMetadataSource( new HashMap() + mockAetherRepositorySystem( new HashMap() {{ put( "default-dependency", new String[] {"1.0.0", "1.1.0", "2.0.0"} ); - }} ), null, + }} ), null, null, new StubArtifactResolver( new ArtifactStubFactory(), false, false ) ) {{ setProject( createProject() ); @@ -241,10 +241,10 @@ public void testAllowMinorUpdatesFalse() tempPath = Files.createTempFile( "display-dependency-updates", "" ); final File tempFile = tempPath.toFile(); new DisplayDependencyUpdatesMojo( mockRepositorySystem(), - null, mockArtifactMetadataSource( new HashMap() + mockAetherRepositorySystem( new HashMap() {{ put( "default-dependency", new String[] {"1.0.0", "1.0.1", "1.1.0", "2.0.0"} ); - }} ), null, + }} ), null, null, new StubArtifactResolver( new ArtifactStubFactory(), false, false ) ) {{ setProject( createProject() ); @@ -283,10 +283,10 @@ public void testAllowIncrementalUpdatesFalse() tempPath = Files.createTempFile( "display-dependency-updates", "" ); final File tempFile = tempPath.toFile(); new DisplayDependencyUpdatesMojo( mockRepositorySystem(), - null, mockArtifactMetadataSource( new HashMap() + 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, null, new StubArtifactResolver( new ArtifactStubFactory(), false, false ) ) {{ setProject( createProject() ); @@ -326,11 +326,11 @@ public void testVersionsWithQualifiersNotConsideredAsIncrementalUpdates() tempPath = Files.createTempFile( "display-dependency-updates", "" ); final File tempFile = tempPath.toFile(); new DisplayDependencyUpdatesMojo( mockRepositorySystem(), - null, mockArtifactMetadataSource( new HashMap() + 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, null, new StubArtifactResolver( new ArtifactStubFactory(), false, false ) ) {{ setProject( createProject() ); @@ -384,7 +384,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" } ); }} ); @@ -415,7 +415,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 983fa90629..7dd22a8b00 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.VersionChange; import org.codehaus.mojo.versions.utils.DependencyBuilder; import org.codehaus.mojo.versions.utils.TestChangeRecorder; @@ -22,7 +23,7 @@ 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.mockRepositorySystem; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; @@ -63,8 +64,8 @@ public void setUp() throws IllegalAccessException { changeRecorder = new TestChangeRecorder(); mojo = new ForceReleasesMojo( mockRepositorySystem(), - null, mockArtifactMetadataSource(), - null, new StubArtifactResolver( new ArtifactStubFactory(), + mockAetherRepositorySystem(), + null, null, new StubArtifactResolver( new ArtifactStubFactory(), false, false ) ); setVariableValueToObject( mojo, "reactorProjects", emptyList() ); setVariableValueToObject( mojo, "changeRecorder", changeRecorder ); @@ -101,6 +102,10 @@ public void testProcessParent() .thenReturn( mojo.getProject().getModel() ); mojo.update( null ); } + catch ( VersionRetrievalException e ) + { + throw new RuntimeException( e ); + } assertThat( changeRecorder.getChanges(), hasItem( new VersionChange( "default-group", "artifactA", "1.0.0-SNAPSHOT", "1.0.0" ) ) ); @@ -125,6 +130,10 @@ public void testReplaceSnapshotWithRelease() .thenReturn( mojo.getProject().getModel() ); mojo.update( null ); } + catch ( org.codehaus.mojo.versions.api.VersionRetrievalException e ) + { + throw new RuntimeException( e ); + } assertThat( changeRecorder.getChanges(), hasItem( new VersionChange( "default-group", "artifactA", "1.0.0-SNAPSHOT", "1.0.0" ) ) ); @@ -149,6 +158,10 @@ public void testUpgrade() .thenReturn( mojo.getProject().getModel() ); mojo.update( null ); } + catch ( org.codehaus.mojo.versions.api.VersionRetrievalException e ) + { + throw new RuntimeException( e ); + } assertThat( changeRecorder.getChanges(), hasItem( new VersionChange( "default-group", "artifactA", "1.1.0-SNAPSHOT", "2.0.0" ) ) ); @@ -173,6 +186,10 @@ public void testDowngrade() .thenReturn( mojo.getProject().getModel() ); mojo.update( null ); } + catch ( org.codehaus.mojo.versions.api.VersionRetrievalException e ) + { + throw new RuntimeException( e ); + } assertThat( changeRecorder.getChanges(), hasItem( new VersionChange( "default-group", "artifactA", "2.1.0-SNAPSHOT", "2.0.0" ) ) ); @@ -182,7 +199,7 @@ public void testDowngrade() public void testFailIfNotReplaced() throws MojoExecutionException, XMLStreamException, MojoFailureException { - mojo.artifactMetadataSource = mockArtifactMetadataSource( singletonMap( "test-artifact", + mojo.aetherRepositorySystem = mockAetherRepositorySystem( singletonMap( "test-artifact", new String[] {} ) ); mojo.getProject().setDependencies( singletonList( DependencyBuilder.newBuilder() .withGroupId( "default-group" ) @@ -205,5 +222,9 @@ public void testFailIfNotReplaced() { assertThat( e.getMessage(), startsWith( "No matching" ) ); } + catch ( org.codehaus.mojo.versions.api.VersionRetrievalException e ) + { + throw new RuntimeException( e ); + } } } 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..06e395b5fc 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,13 +31,14 @@ 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.mockRepositorySystem; import static org.hamcrest.CoreMatchers.containsString; @@ -57,11 +58,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 +80,8 @@ 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" ) ) ); }}.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..65437fea57 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,7 +45,7 @@ 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.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.not; @@ -68,15 +68,13 @@ 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(); } public TestPluginUpdatesReportMojo withPlugins( Plugin... plugins ) @@ -85,10 +83,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 +130,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 +160,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 +184,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 f17e63817c..4ebed3b4bf 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 ) { + @Override protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException { } }; diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/SetMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/SetMojoTest.java index bce9eaa048..6f767ebbfa 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/SetMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/SetMojoTest.java @@ -48,7 +48,7 @@ public void tearDown() throws IOException @Test public void testGetIncrementedVersion() throws MojoExecutionException { - new SetMojo( null, null, null, null, null, null ) + new SetMojo( null, null, null, null, null ) { { assertThat( getIncrementedVersion( "1.0.0", null ), is( "1.0.1-SNAPSHOT" ) ); @@ -63,7 +63,7 @@ public void testGetIncrementedVersion() throws MojoExecutionException @Test public void testNextSnapshotIndexLowerBound() { - new SetMojo( null, null, null, null, null, null ) + new SetMojo( null, null, null, null, null ) { { try @@ -83,7 +83,7 @@ public void testNextSnapshotIndexLowerBound() @Test public void testNextSnapshotIndexUpperBound() { - new SetMojo( null, null, null, null, null, null ) + new SetMojo( null, null, null, null, null ) { { try @@ -105,7 +105,7 @@ public void testNextSnapshotIndexWithoutNextSnapshot() throws MojoFailureExcepti { try { - new SetMojo( null, null, null, null, null, null ) + new SetMojo( null, null, null, null, null ) { { project = new MavenProject(); 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 0350f8c684..8afea7e76a 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.VersionChange; import org.codehaus.mojo.versions.ordering.InvalidSegmentException; import org.codehaus.mojo.versions.utils.TestChangeRecorder; @@ -31,7 +31,7 @@ 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.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.hasItem; @@ -53,13 +53,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,10 +75,7 @@ public void setUp() throws IllegalAccessException changeRecorder = new TestChangeRecorder(); artifactResolver = mock( ArtifactResolver.class ); - mojo = new UpdateParentMojo( repositorySystem, - null, - artifactMetadataSource, - null, + mojo = new UpdateParentMojo( repositorySystem, aetherRepositorySystem, null, null, artifactResolver ) {{ setProject( createProject() ); @@ -115,7 +112,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,7 +121,7 @@ private static RepositorySystem mockRepositorySystem() @Test @SuppressWarnings( "deprecation" ) public void testArtifactIdDoesNotExist() - throws ArtifactMetadataRetrievalException, MojoExecutionException, + throws VersionRetrievalException, MojoExecutionException, XMLStreamException, MojoFailureException, InvalidVersionSpecificationException { mojo.getProject().setParent( new MavenProject() @@ -135,7 +133,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() ) ); @@ -145,6 +143,10 @@ public void testArtifactIdDoesNotExist() pomHelper.when( () -> PomHelper.setProjectParentVersion( any(), any() ) ).thenReturn( true ); mojo.update( null ); } + catch ( org.codehaus.mojo.versions.api.VersionRetrievalException e ) + { + throw new RuntimeException( e ); + } } @Test @@ -158,6 +160,10 @@ public void testParentDowngradeAllowed() .thenReturn( true ); mojo.update( null ); } + catch ( org.codehaus.mojo.versions.api.VersionRetrievalException e ) + { + throw new RuntimeException( e ); + } assertThat( changeRecorder.getChanges(), hasItem( new VersionChange( "default-group", "parent-artifact", "1.0.1-SNAPSHOT", "1.0.0" ) ) ); @@ -174,12 +180,16 @@ public void testParentDowngradeForbidden() .thenReturn( true ); mojo.update( null ); } + catch ( org.codehaus.mojo.versions.api.VersionRetrievalException e ) + { + throw new RuntimeException( e ); + } assertThat( changeRecorder.getChanges(), is( empty() ) ); } @Test public void testParentDowngradeAllowedWithRange() - throws MojoExecutionException, ArtifactMetadataRetrievalException, + throws MojoExecutionException, VersionRetrievalException, InvalidVersionSpecificationException, InvalidSegmentException { mojo.allowDowngrade = true; @@ -196,7 +206,7 @@ public void testParentDowngradeAllowedWithRange() @Test public void testParentDowngradeForbiddenWithRange() - throws MojoExecutionException, ArtifactMetadataRetrievalException, + throws MojoExecutionException, VersionRetrievalException, InvalidVersionSpecificationException, InvalidSegmentException { mojo.allowDowngrade = false; @@ -206,7 +216,7 @@ public void testParentDowngradeForbiddenWithRange() @Test public void testAllowSnapshots() - throws MojoExecutionException, ArtifactMetadataRetrievalException, + throws MojoExecutionException, VersionRetrievalException, InvalidVersionSpecificationException, InvalidSegmentException { mojo.allowSnapshots = true; @@ -240,6 +250,10 @@ public void testAllowSnapshotsWithParentVersion() .thenReturn( true ); mojo.update( null ); } + catch ( org.codehaus.mojo.versions.api.VersionRetrievalException e ) + { + throw new RuntimeException( e ); + } assertThat( changeRecorder.getChanges(), hasItem( new VersionChange( "default-group", "issue-670-artifact", "0.0.1-1", "0.0.1-1-impl-SNAPSHOT" ) ) ); @@ -248,7 +262,7 @@ public void testAllowSnapshotsWithParentVersion() @Test public void testIgnoredVersions() throws MojoExecutionException, IllegalAccessException, - ArtifactMetadataRetrievalException, InvalidVersionSpecificationException, InvalidSegmentException + VersionRetrievalException, InvalidVersionSpecificationException, InvalidSegmentException { mojo.getProject().setParent( new MavenProject() {{ @@ -298,6 +312,10 @@ private void testSkipResolution( String version ) { throw new RuntimeException( e ); } + catch ( org.codehaus.mojo.versions.api.VersionRetrievalException e ) + { + throw new RuntimeException( e ); + } assertThat( changeRecorder.getChanges(), hasItem( new VersionChange( "default-group", "parent-artifact", "1.0.0", version ) ) ); @@ -319,6 +337,10 @@ public void testShouldUpgradeToSnapshot() throws MojoExecutionException, XMLStre pomHelper.when( () -> PomHelper.setProjectParentVersion( any(), any() ) ).thenReturn( true ); mojo.update( null ); } + catch ( org.codehaus.mojo.versions.api.VersionRetrievalException e ) + { + throw new RuntimeException( e ); + } assertThat( changeRecorder.getChanges(), hasItem( new VersionChange( "default-group", "parent-artifact", "0.9.0", "1.0.1-SNAPSHOT" ) ) ); @@ -326,7 +348,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 +369,7 @@ public void testAllowMinorUpdates() @Test public void testAllowIncrementalUpdates() - throws MojoExecutionException, ArtifactMetadataRetrievalException, + throws MojoExecutionException, VersionRetrievalException, InvalidVersionSpecificationException, InvalidSegmentException { mojo.getProject().setParent( new MavenProject() @@ -381,6 +403,10 @@ public void testParentVersionRange() throws MojoExecutionException, XMLStreamExc pomHelper.when( () -> PomHelper.setProjectParentVersion( any(), any() ) ).thenReturn( true ); mojo.update( null ); } + catch ( org.codehaus.mojo.versions.api.VersionRetrievalException e ) + { + throw new RuntimeException( e ); + } assertThat( changeRecorder.getChanges(), hasItem( new VersionChange( "default-group", "dummy-parent2", "1.0", "2.0" ) ) ); @@ -402,6 +428,10 @@ public void testParentVersionRange2() throws MojoExecutionException, XMLStreamEx pomHelper.when( () -> PomHelper.setProjectParentVersion( any(), any() ) ).thenReturn( true ); mojo.update( null ); } + catch ( org.codehaus.mojo.versions.api.VersionRetrievalException e ) + { + throw new RuntimeException( e ); + } assertThat( changeRecorder.getChanges(), empty() ); } } 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 431bc30906..a087aea1ab 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 @@ -21,7 +21,6 @@ import java.nio.file.Path; import java.util.HashMap; -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; @@ -31,7 +30,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; @@ -43,7 +42,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 @@ -52,7 +51,7 @@ public void setUp() throws Exception super.setUp(); pomDir = createTempDir( "update-property" ); changeRecorder = new TestChangeRecorder(); - 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"} ); }} ); @@ -76,7 +75,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, "changeRecorder", changeRecorder ); setVariableValueToObject( mojo, "generateBackupPoms", false ); return (T) mojo; 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 72fd58f2d5..6291292f27 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,11 +5,11 @@ 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; @@ -24,14 +24,13 @@ 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.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,18 +45,17 @@ 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"} ); }} ); - mojo = new UseLatestReleasesMojo( repositorySystemMock, - null, - artifactMetadataSourceMock, - null, + mojo = new UseLatestReleasesMojo( repositorySystemMock, aetherRepositorySystem, null, null, null ) {{ reactorProjects = emptyList(); @@ -105,6 +103,10 @@ public void testDontUpgradeToBeta() .thenReturn( mojo.getProject().getModel() ); mojo.update( null ); } + catch ( org.codehaus.mojo.versions.api.VersionRetrievalException e ) + { + throw new RuntimeException( e ); + } assertThat( changeRecorder.getChanges(), Matchers.empty() ); } } 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 98c5a34f1a..dd6ba11a00 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,12 +7,12 @@ 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; @@ -28,7 +28,7 @@ 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.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.hasItem; @@ -54,10 +54,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"} ); @@ -67,8 +69,8 @@ public void setUp() throws Exception }} ); mojo = new UseLatestVersionsMojo( repositorySystemMock, + aetherRepositorySystem, null, - artifactMetadataSourceMock, null, null ) {{ @@ -115,6 +117,10 @@ public void testDependenciesDowngradeIncremental() .thenReturn( true ); mojo.update( null ); } + catch ( org.codehaus.mojo.versions.api.VersionRetrievalException e ) + { + throw new RuntimeException( e ); + } assertThat( changeRecorder.getChanges(), hasItem( new VersionChange( "default-group", "dependency-artifact", "1.1.1-SNAPSHOT", "1.1.0" ) ) ); } @@ -140,6 +146,10 @@ public void testDependenciesDowngradeMinor() .thenReturn( true ); mojo.update( null ); } + catch ( org.codehaus.mojo.versions.api.VersionRetrievalException e ) + { + throw new RuntimeException( e ); + } assertThat( changeRecorder.getChanges(), hasItem( new VersionChange( "default-group", "dependency-artifact", "1.1.0-SNAPSHOT", "1.1.0" ) ) ); @@ -162,6 +172,10 @@ public void testDependenciesDowngradeMajor() .thenReturn( true ); mojo.update( null ); } + catch ( org.codehaus.mojo.versions.api.VersionRetrievalException e ) + { + throw new RuntimeException( e ); + } assertThat( changeRecorder.getChanges(), hasItem( new VersionChange( "default-group", "dependency-artifact", "1.1.1-SNAPSHOT", "1.1.0" ) ) ); @@ -186,6 +200,10 @@ public void testDependencyManagementDowngrade() .thenReturn( true ); mojo.update( null ); } + catch ( org.codehaus.mojo.versions.api.VersionRetrievalException e ) + { + throw new RuntimeException( e ); + } assertThat( changeRecorder.getChanges(), hasItem( new VersionChange( "default-group", "dependency-artifact", "1.1.1-SNAPSHOT", "1.1.0" ) ) ); } @@ -218,6 +236,10 @@ public void testParentDowngrade() .thenReturn( true ); mojo.update( null ); } + catch ( org.codehaus.mojo.versions.api.VersionRetrievalException e ) + { + throw new RuntimeException( e ); + } assertThat( changeRecorder.getChanges(), hasItem( new VersionChange( "default-group", "dependency-artifact", "1.1.1-SNAPSHOT", "1.1.0" ) ) ); } @@ -246,6 +268,10 @@ public void testPoisonDependencyVersion() .thenReturn( true ); mojo.update( null ); } + catch ( org.codehaus.mojo.versions.api.VersionRetrievalException e ) + { + throw new RuntimeException( e ); + } // So, the regular update should take place despite an irregular, or — if I may — "poison", dependency // being present in the dependency list assertThat( changeRecorder.getChanges(), @@ -266,6 +292,10 @@ public void testIgnoredVersions() .thenReturn( true ); mojo.update( null ); } + catch ( org.codehaus.mojo.versions.api.VersionRetrievalException e ) + { + throw new RuntimeException( e ); + } assertThat( changeRecorder.getChanges(), Is.is( empty() ) ); } @@ -289,6 +319,10 @@ public void testIncludeFilter() .thenReturn( true ); mojo.update( null ); } + catch ( org.codehaus.mojo.versions.api.VersionRetrievalException e ) + { + throw new RuntimeException( e ); + } assertThat( changeRecorder.getChanges(), hasSize( 1 ) ); assertThat( changeRecorder.getChanges(), hasItem( new VersionChange( "default-group", "other-artifact", "1.0", @@ -315,6 +349,10 @@ public void testExcludeFilter() .thenReturn( true ); mojo.update( null ); } + catch ( org.codehaus.mojo.versions.api.VersionRetrievalException e ) + { + throw new RuntimeException( e ); + } assertThat( changeRecorder.getChanges(), hasSize( 1 ) ); assertThat( changeRecorder.getChanges(), not( hasItem( new VersionChange( "default-group", "other-artifact", "1.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 6e2b40bfbf..3a72b55d02 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 @@ -22,7 +22,7 @@ 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.mockRepositorySystem; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; @@ -63,8 +63,8 @@ public void setUp() throws IllegalAccessException { changeRecorder = new TestChangeRecorder(); mojo = new UseReleasesMojo( mockRepositorySystem(), - null, mockArtifactMetadataSource(), - null, new StubArtifactResolver( new ArtifactStubFactory(), + mockAetherRepositorySystem(), + null, null, new StubArtifactResolver( new ArtifactStubFactory(), false, false ) ); setVariableValueToObject( mojo, "reactorProjects", emptyList() ); setVariableValueToObject( mojo, "changeRecorder", changeRecorder ); @@ -101,6 +101,10 @@ public void testProcessParent() .thenReturn( mojo.getProject().getModel() ); mojo.update( null ); } + catch ( org.codehaus.mojo.versions.api.VersionRetrievalException e ) + { + throw new RuntimeException( e ); + } assertThat( changeRecorder.getChanges(), hasItem( new VersionChange( "default-group", "artifactA", "1.0.0-SNAPSHOT", "1.0.0" ) ) ); @@ -125,6 +129,10 @@ public void testReplaceSnapshotWithRelease() .thenReturn( mojo.getProject().getModel() ); mojo.update( null ); } + catch ( org.codehaus.mojo.versions.api.VersionRetrievalException e ) + { + throw new RuntimeException( e ); + } assertThat( changeRecorder.getChanges(), hasItem( new VersionChange( "default-group", "artifactA", "1.0.0-SNAPSHOT", "1.0.0" ) ) ); @@ -134,7 +142,7 @@ public void testReplaceSnapshotWithRelease() public void testFailIfNotReplaced() throws MojoExecutionException, XMLStreamException, MojoFailureException { - mojo.artifactMetadataSource = mockArtifactMetadataSource( singletonMap( "test-artifact", + mojo.aetherRepositorySystem = mockAetherRepositorySystem( singletonMap( "test-artifact", new String[] {} ) ); mojo.getProject().setDependencies( singletonList( DependencyBuilder.newBuilder() .withGroupId( "default-group" ) @@ -157,5 +165,9 @@ public void testFailIfNotReplaced() { assertThat( e.getMessage(), startsWith( "No matching" ) ); } + catch ( org.codehaus.mojo.versions.api.VersionRetrievalException e ) + { + throw new RuntimeException( e ); + } } } 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..4fc1943dd6 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,15 +26,16 @@ 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.model.Dependency; import org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub; import org.apache.maven.repository.RepositorySystem; import org.codehaus.plexus.i18n.I18N; +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 org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; @@ -54,42 +55,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() 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(); + } +}