import org.apache.maven.wagon.authorization.AuthorizationException;
import org.apache.maven.wagon.observers.ChecksumObserver;
import org.codehaus.plexus.logging.AbstractLogEnabled;
-import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.FileUtils;
import java.io.File;
import java.io.FileInputStream;
{
tries++;
- getLogger().info( "trying " + path + " from " + repository.getId() );
+ getLogger().info( "Trying " + path + " from " + repository.getId() + "...");
wagon.get( path, temp );
}
disconnectWagon( wagon );
- if ( !temp.renameTo( target ) )
- {
- getLogger().warn( "Unable to rename tmp file to its final name... resorting to copy command." );
-
- try
- {
- FileUtils.copyFile( temp, target );
- }
- catch ( IOException e )
- {
- throw new ProxyException( "Cannot copy tmp file to its final location", e );
- }
- finally
- {
- temp.delete();
- }
- }
+ copyTempToTarget( temp, target );
return target;
}
* @return true when the checksum succeeds and false when the checksum failed.
*/
private boolean doChecksumCheck( Map checksumMap, String path, Wagon wagon )
+ throws ProxyException
{
releaseChecksums( wagon, checksumMap );
for ( Iterator checksums = checksumMap.keySet().iterator(); checksums.hasNext(); )
try
{
- File tempChecksumFile = new File( checksumFile.getAbsolutePath() + "." + checksumExt );
+ File tempChecksumFile = new File( checksumFile.getAbsolutePath() + ".tmp" );
wagon.get( checksumPath, tempChecksumFile );
{
remoteChecksum = remoteChecksum.substring( 0, remoteChecksum.indexOf( ' ' ) );
}
- return remoteChecksum.toUpperCase().equals( checksum.getActualChecksum().toUpperCase() );
+
+ boolean checksumCheck = false;
+ if ( remoteChecksum.toUpperCase().equals( checksum.getActualChecksum().toUpperCase() ) )
+ {
+ copyTempToTarget( tempChecksumFile, checksumFile );
+
+ checksumCheck = true;
+ }
+ return checksumCheck;
}
catch ( ChecksumFailedException e )
{
}
catch ( TransferFailedException e )
{
- getLogger().warn( "An error occurred during the download of " + checksumPath + ": " + e.getMessage() );
+ getLogger().debug( "An error occurred during the download of " + checksumPath + ": " + e.getMessage(), e );
// do nothing try the next checksum
}
catch ( ResourceDoesNotExistException e )
{
- getLogger().warn( "An error occurred during the download of " + checksumPath + ": " + e.getMessage() );
+ getLogger().debug( "An error occurred during the download of " + checksumPath + ": " + e.getMessage(), e );
// do nothing try the next checksum
}
catch ( AuthorizationException e )
{
- getLogger().warn( "An error occurred during the download of " + checksumPath + ": " + e.getMessage() );
+ getLogger().debug( "An error occurred during the download of " + checksumPath + ": " + e.getMessage(), e );
// do nothing try the next checksum
}
catch ( IOException e )
{
- getLogger().info( "An error occurred while reading the temporary checksum file." );
+ getLogger().debug( "An error occurred while reading the temporary checksum file.", e );
return false;
}
}
- getLogger().info( "Skipping checksum validation for " + path + ": No remote checksums available." );
+ getLogger().debug( "Skipping checksum validation for " + path + ": No remote checksums available." );
return true;
}
return text;
}
+ private void copyTempToTarget( File temp, File target )
+ throws ProxyException
+ {
+ if ( target.exists() && !target.delete() )
+ {
+ throw new ProxyException( "Unable to overwrite existing target file: " + target.getAbsolutePath() );
+ }
+
+ if ( !temp.renameTo( target ) )
+ {
+ getLogger().warn( "Unable to rename tmp file to its final name... resorting to copy command." );
+
+ try
+ {
+ FileUtils.copyFile( temp, target );
+ }
+ catch ( IOException e )
+ {
+ throw new ProxyException( "Cannot copy tmp file to its final location", e );
+ }
+ finally
+ {
+ temp.delete();
+ }
+ }
+ }
+
/**
* Used to disconnect the wagonManager from its repository
*
}
}
- public void testCache()
+ public void testArtifactDownload()
throws Exception
{
+ //test download
File file = proxy.get( "/commons-logging/commons-logging/1.0/commons-logging-1.0.jar" );
assertTrue( "File must be downloaded.", file.exists() );
assertTrue( "Downloaded file should be present in the cache.",
file.getAbsolutePath().startsWith( proxy.getConfiguration().getRepositoryCachePath() ) );
+ //test cache
file = proxy.get( "/commons-logging/commons-logging/1.0/commons-logging-1.0.jar" );
- file = proxy.get( "/not-standard/repository/file.txt" );
+ try
+ {
+ file = proxy.get( "/commons-logging/commons-logging/2.0/commons-logging-2.0.jar" );
+ fail( "Expected ResourceDoesNotExistException exception not thrown" );
+ }
+ catch ( ResourceDoesNotExistException e )
+ {
+ assertTrue( true );
+ }
+ }
+
+ public void testArtifactChecksum()
+ throws Exception
+ {
+ //force the downlod from the remote repository, use getRemoteFile()
+ File file = proxy.getRemoteFile( "/commons-logging/commons-logging/1.0/commons-logging-1.0.jar.md5" );
assertTrue( "File must be downloaded.", file.exists() );
assertTrue( "Downloaded file should be present in the cache.",
file.getAbsolutePath().startsWith( proxy.getConfiguration().getRepositoryCachePath() ) );
+ }
- file = proxy.get( "/checksumed-md5/repository/file.txt" );
+ public void testNonArtifactWithNoChecksum()
+ throws Exception
+ {
+ File file = proxy.get( "/not-standard/repository/file.txt" );
+ assertTrue( "File must be downloaded.", file.exists() );
+ assertTrue( "Downloaded file should be present in the cache.",
+ file.getAbsolutePath().startsWith( proxy.getConfiguration().getRepositoryCachePath() ) );
+ }
+
+ public void testNonArtifactWithMD5Checksum()
+ throws Exception
+ {
+ File file = proxy.get( "/checksumed-md5/repository/file.txt" );
+ assertTrue( "File must be downloaded.", file.exists() );
+ assertTrue( "Downloaded file should be present in the cache.",
+ file.getAbsolutePath().startsWith( proxy.getConfiguration().getRepositoryCachePath() ) );
+ }
+
+ public void testNonArtifactWithSHA1Checksum()
+ throws Exception
+ {
+ File file = proxy.get( "/checksumed-sha1/repository/file.txt" );
assertTrue( "File must be downloaded.", file.exists() );
assertTrue( "Downloaded file should be present in the cache.",
file.getAbsolutePath().startsWith( proxy.getConfiguration().getRepositoryCachePath() ) );