catch ( InvalidVersionSpecificationException e )
{
throw new MojoFailureException( "Invalid comparison version: " + e.getMessage() );
}
final Artifact previousArtifact;
try
{
previousArtifact =
factory.createDependencyArtifact( project.getGroupId(),
project.getArtifactId(),
range,
project.getPackaging(),
comparisonClassifier,
Artifact.SCOPE_COMPILE );
if ( !previousArtifact.getVersionRange().isSelectedVersionKnown( previousArtifact ) )
{
getLog().debug( "Searching for versions in range: " + previousArtifact.getVersionRange() );
@SuppressWarnings( "unchecked" )
// type is konwn
List<ArtifactVersion> availableVersions =
metadataSource.retrieveAvailableVersions( previousArtifact, localRepository,
project.getRemoteArtifactRepositories() );
filterSnapshots( availableVersions );
ArtifactVersion version = range.matchVersion( availableVersions );
if ( version != null )
{
previousArtifact.selectVersion( version.toString() );
}
}
}
catch ( OverConstrainedVersionException ocve )
{
throw new MojoFailureException( "Invalid comparison version: " + ocve.getMessage() );
}
catch ( ArtifactMetadataRetrievalException amre )
{
throw new MojoExecutionException( "Error determining previous version: " + amre.getMessage(), amre );
}
if ( previousArtifact.getVersion() == null )
{
getLog().info( "Unable to find a previous version of the project in the repository" );
return null;
}
try
{
resolver.resolve( previousArtifact, project.getRemoteArtifactRepositories(), localRepository );
}
catch ( ArtifactResolutionException are )
{
throw new MojoExecutionException( "Artifact " + previousArtifact + " cannot be resolved", are );
}
catch ( ArtifactNotFoundException anfe )
{
throw new MojoExecutionException( "Artifact " + previousArtifact
+ " does not exist on local/remote repositories", anfe );
}
return openJar( previousArtifact.getFile() );
}