File resource = new File( targetRepository.getLocation(), artifactPath );
File workingDirectory = createWorkingDirectory( targetRepository.getLocation() );
try
{
Wagon wagon = null;
try
{
String protocol = getProtocol( remoteRepository.getUrl() );
wagon = wagonFactory.getWagon( "wagon#" + protocol );
if ( wagon == null )
{
throw new RuntimeException( "Unsupported remote repository protocol: " + protocol );
}
boolean connected = connectToRepository( wagon, remoteRepository );
if ( connected )
{
tmpResource = new File( workingDirectory, filename );
if ( VersionUtil.isSnapshot( version ) )
{
// get the metadata first!
File tmpMetadataResource = new File( workingDirectory, METADATA_FILENAME );
String metadataPath = StringUtils.substringBeforeLast( artifactPath, "/" ) + "/" + METADATA_FILENAME;
wagon.get( metadataPath, tmpMetadataResource );
log.debug( "Successfully downloaded metadata." );
MavenRepositoryMetadata metadata = MavenRepositoryMetadataReader.read( tmpMetadataResource );
// re-adjust to timestamp if present, otherwise retain the original -SNAPSHOT filename
MavenRepositoryMetadata.Snapshot snapshotVersion = metadata.getSnapshotVersion();
String timestampVersion = version;
if ( snapshotVersion != null )
{
timestampVersion =
timestampVersion.substring( 0, timestampVersion.length() - 8 ); // remove SNAPSHOT from end
timestampVersion =
timestampVersion + snapshotVersion.getTimestamp() + "-" + snapshotVersion.getBuildNumber();
filename = artifactId + "-" + timestampVersion + ".pom";
artifactPath = pathTranslator.toPath( groupId, artifactId, version, filename );
log.debug( "New artifactPath : " + artifactPath );
}
}
log.info( "Retrieving " + artifactPath + " from " + remoteRepository.getName() );
wagon.get( artifactPath, tmpResource );
log.debug( "Downloaded successfully." );
tmpSha1 =
transferChecksum( wagon, remoteRepository, artifactPath, tmpResource, workingDirectory, ".sha1" );
tmpMd5 =
transferChecksum( wagon, remoteRepository, artifactPath, tmpResource, workingDirectory, ".md5" );
}
}
finally
{
if ( wagon != null )
{
try
{
wagon.disconnect();
}
catch ( ConnectionException e )
{
log.warn( "Unable to disconnect wagon.", e );
}