correctly deploy checksums
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@180069 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e72c8822e5
commit
4a8f37a827
@ -41,6 +41,7 @@ import org.apache.maven.wagon.Wagon;
|
|||||||
import org.apache.maven.wagon.authentication.AuthenticationException;
|
import org.apache.maven.wagon.authentication.AuthenticationException;
|
||||||
import org.apache.maven.wagon.authentication.AuthenticationInfo;
|
import org.apache.maven.wagon.authentication.AuthenticationInfo;
|
||||||
import org.apache.maven.wagon.authorization.AuthorizationException;
|
import org.apache.maven.wagon.authorization.AuthorizationException;
|
||||||
|
import org.apache.maven.wagon.events.TransferListener;
|
||||||
import org.apache.maven.wagon.observers.ChecksumObserver;
|
import org.apache.maven.wagon.observers.ChecksumObserver;
|
||||||
import org.apache.maven.wagon.providers.file.FileWagon;
|
import org.apache.maven.wagon.providers.file.FileWagon;
|
||||||
import org.apache.maven.wagon.providers.ftp.FtpWagon;
|
import org.apache.maven.wagon.providers.ftp.FtpWagon;
|
||||||
@ -65,8 +66,10 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -437,7 +440,7 @@ public class DefaultArtifactDeployer
|
|||||||
|
|
||||||
private void deployFile( Repository repository, File src, String dest, Project project )
|
private void deployFile( Repository repository, File src, String dest, Project project )
|
||||||
throws ResourceDoesNotExistException, MalformedURLException, NoSuchAlgorithmException, TransferFailedException,
|
throws ResourceDoesNotExistException, MalformedURLException, NoSuchAlgorithmException, TransferFailedException,
|
||||||
ConnectionException, AuthenticationException, AuthorizationException
|
ConnectionException, AuthenticationException, AuthorizationException, MavenException
|
||||||
{
|
{
|
||||||
deployFiles( repository, Collections.singletonList( src ), Collections.singletonList( dest ), null, project );
|
deployFiles( repository, Collections.singletonList( src ), Collections.singletonList( dest ), null, project );
|
||||||
}
|
}
|
||||||
@ -445,7 +448,7 @@ public class DefaultArtifactDeployer
|
|||||||
private void deployFiles( Repository repository, List srcFiles, List destFiles,
|
private void deployFiles( Repository repository, List srcFiles, List destFiles,
|
||||||
AuthenticationInfo authenticationInfo, Project project )
|
AuthenticationInfo authenticationInfo, Project project )
|
||||||
throws ConnectionException, AuthenticationException, ResourceDoesNotExistException, TransferFailedException,
|
throws ConnectionException, AuthenticationException, ResourceDoesNotExistException, TransferFailedException,
|
||||||
AuthorizationException, MalformedURLException, NoSuchAlgorithmException
|
AuthorizationException, MalformedURLException, NoSuchAlgorithmException, MavenException
|
||||||
{
|
{
|
||||||
|
|
||||||
if ( srcFiles.size() != destFiles.size() )
|
if ( srcFiles.size() != destFiles.size() )
|
||||||
@ -455,9 +458,17 @@ public class DefaultArtifactDeployer
|
|||||||
}
|
}
|
||||||
|
|
||||||
Wagon wagon = getWagon( repository.getProtocol(), project, repository.getId() );
|
Wagon wagon = getWagon( repository.getProtocol(), project, repository.getId() );
|
||||||
wagon.addTransferListener( new UploadMeter() );
|
|
||||||
wagon.addTransferListener( new ChecksumObserver() );
|
TransferListener uploadMonitor = new UploadMeter();
|
||||||
wagon.addTransferListener( new ChecksumObserver( "SHA-1" ) );
|
|
||||||
|
Map checksums = new HashMap( 2 );
|
||||||
|
|
||||||
|
ChecksumObserver observer = new ChecksumObserver( "MD5" );
|
||||||
|
checksums.put( "md5", observer );
|
||||||
|
wagon.addTransferListener( observer );
|
||||||
|
observer = new ChecksumObserver( "SHA-1" );
|
||||||
|
checksums.put( "sha1", observer );
|
||||||
|
wagon.addTransferListener( observer );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -466,10 +477,40 @@ public class DefaultArtifactDeployer
|
|||||||
Iterator destIterator = destFiles.iterator();
|
Iterator destIterator = destFiles.iterator();
|
||||||
while ( srcIterator.hasNext() )
|
while ( srcIterator.hasNext() )
|
||||||
{
|
{
|
||||||
|
wagon.addTransferListener( uploadMonitor );
|
||||||
|
|
||||||
File srcFile = (File) srcIterator.next();
|
File srcFile = (File) srcIterator.next();
|
||||||
String destFile = (String) destIterator.next();
|
String destFile = (String) destIterator.next();
|
||||||
wagon.put( srcFile, destFile );
|
wagon.put( srcFile, destFile );
|
||||||
|
|
||||||
|
wagon.removeTransferListener( uploadMonitor );
|
||||||
|
|
||||||
|
Map sums = new HashMap( 2 );
|
||||||
|
for ( Iterator i = checksums.keySet().iterator(); i.hasNext(); )
|
||||||
|
{
|
||||||
|
// store first - a later put will modify them
|
||||||
|
String extension = (String) i.next();
|
||||||
|
observer = (ChecksumObserver) checksums.get( extension );
|
||||||
|
sums.put( extension, observer.getActualChecksum() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for ( Iterator i = checksums.keySet().iterator(); i.hasNext(); )
|
||||||
|
{
|
||||||
|
String extension = (String) i.next();
|
||||||
|
observer = (ChecksumObserver) checksums.get( extension );
|
||||||
|
|
||||||
|
// TODO: shouldn't need a file intermediatary - improve wagon to take a stream
|
||||||
|
File temp = File.createTempFile( "maven-artifact", null );
|
||||||
|
temp.deleteOnExit();
|
||||||
|
FileUtils.fileWrite( temp.getAbsolutePath(), (String) sums.get( extension ) );
|
||||||
|
|
||||||
|
wagon.put( temp, destFile + "." + extension );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch ( IOException e )
|
||||||
|
{
|
||||||
|
throw new MavenException( "Error creating temporary file to transfer checksums", e );
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user