You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ep...@apache.org on 2006/02/09 04:19:37 UTC
svn commit: r376168 - in
/maven/repository-manager/trunk/maven-repository-proxy/src:
main/java/org/apache/maven/repository/proxy/
test/java/org/apache/maven/repository/proxy/
test/remote-repo1/checksumed-sha1/repository/
test/remote-repo1/commons-loggi...
Author: epunzalan
Date: Wed Feb 8 19:19:34 2006
New Revision: 376168
URL: http://svn.apache.org/viewcvs?rev=376168&view=rev
Log:
MRM-43
More junit coverage
Added:
maven/repository-manager/trunk/maven-repository-proxy/src/test/remote-repo1/commons-logging/commons-logging/1.0/commons-logging-1.0.jar.md5
Modified:
maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java
maven/repository-manager/trunk/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/DefaultProxyManagerTest.java
maven/repository-manager/trunk/maven-repository-proxy/src/test/remote-repo1/checksumed-sha1/repository/file.txt.sha1
Modified: maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java?rev=376168&r1=376167&r2=376168&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java (original)
+++ maven/repository-manager/trunk/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java Wed Feb 8 19:19:34 2006
@@ -33,8 +33,8 @@
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;
@@ -218,7 +218,7 @@
{
tries++;
- getLogger().info( "trying " + path + " from " + repository.getId() );
+ getLogger().info( "Trying " + path + " from " + repository.getId() + "...");
wagon.get( path, temp );
@@ -238,23 +238,7 @@
}
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;
}
@@ -371,6 +355,7 @@
* @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(); )
@@ -382,7 +367,7 @@
try
{
- File tempChecksumFile = new File( checksumFile.getAbsolutePath() + "." + checksumExt );
+ File tempChecksumFile = new File( checksumFile.getAbsolutePath() + ".tmp" );
wagon.get( checksumPath, tempChecksumFile );
@@ -391,7 +376,15 @@
{
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 )
{
@@ -399,27 +392,27 @@
}
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;
}
@@ -459,6 +452,33 @@
}
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();
+ }
+ }
}
/**
Modified: maven/repository-manager/trunk/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/DefaultProxyManagerTest.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/DefaultProxyManagerTest.java?rev=376168&r1=376167&r2=376168&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/DefaultProxyManagerTest.java (original)
+++ maven/repository-manager/trunk/maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/DefaultProxyManagerTest.java Wed Feb 8 19:19:34 2006
@@ -62,22 +62,61 @@
}
}
- 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() ) );
+ }
+
+ 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() ) );
+ }
- file = proxy.get( "/checksumed-md5/repository/file.txt" );
+ 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() ) );
Modified: maven/repository-manager/trunk/maven-repository-proxy/src/test/remote-repo1/checksumed-sha1/repository/file.txt.sha1
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-proxy/src/test/remote-repo1/checksumed-sha1/repository/file.txt.sha1?rev=376168&r1=376167&r2=376168&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-proxy/src/test/remote-repo1/checksumed-sha1/repository/file.txt.sha1 (original)
+++ maven/repository-manager/trunk/maven-repository-proxy/src/test/remote-repo1/checksumed-sha1/repository/file.txt.sha1 Wed Feb 8 19:19:34 2006
@@ -1 +1 @@
-ABCDE
\ No newline at end of file
+afb037c2bd96fe1ef1cfd220e82682d088d60d3e
\ No newline at end of file
Added: maven/repository-manager/trunk/maven-repository-proxy/src/test/remote-repo1/commons-logging/commons-logging/1.0/commons-logging-1.0.jar.md5
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-proxy/src/test/remote-repo1/commons-logging/commons-logging/1.0/commons-logging-1.0.jar.md5?rev=376168&view=auto
==============================================================================
--- maven/repository-manager/trunk/maven-repository-proxy/src/test/remote-repo1/commons-logging/commons-logging/1.0/commons-logging-1.0.jar.md5 (added)
+++ maven/repository-manager/trunk/maven-repository-proxy/src/test/remote-repo1/commons-logging/commons-logging/1.0/commons-logging-1.0.jar.md5 Wed Feb 8 19:19:34 2006
@@ -0,0 +1 @@
+240b26992977c9ad119efb91cb21f8f8
\ No newline at end of file