{
range = VersionRange.createFromVersionSpec( comparisonVersion );
}
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 );
}