You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2008/07/09 03:09:57 UTC
svn commit: r675074 - in
/maven/components/branches/maven-2.0.x/maven-artifact-manager/src:
main/java/org/apache/maven/artifact/manager/
test/java/org/apache/maven/artifact/manager/
test/resources/org/apache/maven/artifact/manager/
Author: brett
Date: Tue Jul 8 18:09:56 2008
New Revision: 675074
URL: http://svn.apache.org/viewvc?rev=675074&view=rev
Log:
[MARTIFACT-28] if an artifact has an md5 but no sha1, a null pointer exception results. add other tests from trunk.
Merged from: r674388
Added:
maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/StringWagon.java
- copied, changed from r674556, maven/artifact/trunk/src/test/java/org/apache/maven/artifact/manager/StringWagon.java
maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/WagonString.java
- copied unchanged from r674556, maven/artifact/trunk/src/test/java/org/apache/maven/artifact/manager/WagonString.java
Modified:
maven/components/branches/maven-2.0.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java
maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java
maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/resources/org/apache/maven/artifact/manager/DefaultWagonManagerTest.xml
Modified: maven/components/branches/maven-2.0.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java?rev=675074&r1=675073&r2=675074&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java (original)
+++ maven/components/branches/maven-2.0.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java Tue Jul 8 18:09:56 2008
@@ -465,39 +465,68 @@
wagon.get( remotePath, temp );
downloaded = true;
}
+ }
+ catch ( NoSuchAlgorithmException e )
+ {
+ throw new TransferFailedException( "Unable to add checksum methods: " + e.getMessage(), e );
+ }
+ finally
+ {
+ if ( md5ChecksumObserver != null )
+ {
+ wagon.removeTransferListener( md5ChecksumObserver );
+ }
+ if ( sha1ChecksumObserver != null )
+ {
+ wagon.removeTransferListener( sha1ChecksumObserver );
+ }
+ }
- if ( downloaded )
+ if ( downloaded )
+ {
+ // keep the checksum files from showing up on the download monitor...
+ if ( downloadMonitor != null )
{
- if ( sha1ChecksumObserver != null )
- {
- wagon.removeTransferListener( sha1ChecksumObserver );
- }
+ wagon.removeTransferListener( downloadMonitor );
+ }
- if ( md5ChecksumObserver != null )
+ // try to verify the SHA-1 checksum for this file.
+ try
+ {
+ verifyChecksum( sha1ChecksumObserver, destination, temp, remotePath, ".sha1", wagon );
+ }
+ catch ( ChecksumFailedException e )
+ {
+ // if we catch a ChecksumFailedException, it means the transfer/read succeeded, but the checksum
+ // doesn't match. This could be a problem with the server (ibiblio HTTP-200 error page), so we'll
+ // try this up to two times. On the second try, we'll handle it as a bona-fide error, based on the
+ // repository's checksum checking policy.
+ if ( firstRun )
{
- wagon.removeTransferListener( md5ChecksumObserver );
+ getLogger().warn( "*** CHECKSUM FAILED - " + e.getMessage() + " - RETRYING" );
+ retry = true;
}
-
- // keep the checksum files from showing up on the download monitor...
- if ( downloadMonitor != null )
+ else
{
- wagon.removeTransferListener( downloadMonitor );
+ handleChecksumFailure( checksumPolicy, e.getMessage(), e.getCause() );
}
+ }
+ catch ( ResourceDoesNotExistException sha1TryException )
+ {
+ getLogger().debug( "SHA1 not found, trying MD5", sha1TryException );
- // try to verify the SHA-1 checksum for this file.
+ // if this IS NOT a ChecksumFailedException, it was a problem with transfer/read of the checksum
+ // file...we'll try again with the MD5 checksum.
try
{
- verifyChecksum( sha1ChecksumObserver, destination, temp, remotePath, ".sha1", wagon );
+ verifyChecksum( md5ChecksumObserver, destination, temp, remotePath, ".md5", wagon );
}
catch ( ChecksumFailedException e )
{
- // if we catch a ChecksumFailedException, it means the transfer/read succeeded, but the checksum
- // doesn't match. This could be a problem with the server (ibiblio HTTP-200 error page), so we'll
- // try this up to two times. On the second try, we'll handle it as a bona-fide error, based on the
- // repository's checksum checking policy.
+ // if we also fail to verify based on the MD5 checksum, and the checksum transfer/read
+ // succeeded, then we need to determine whether to retry or handle it as a failure.
if ( firstRun )
{
- getLogger().warn( "*** CHECKSUM FAILED - " + e.getMessage() + " - RETRYING" );
retry = true;
}
else
@@ -505,63 +534,23 @@
handleChecksumFailure( checksumPolicy, e.getMessage(), e.getCause() );
}
}
- catch ( ResourceDoesNotExistException sha1TryException )
+ catch ( ResourceDoesNotExistException md5TryException )
{
- getLogger().debug( "SHA1 not found, trying MD5", sha1TryException );
-
- // if this IS NOT a ChecksumFailedException, it was a problem with transfer/read of the checksum
- // file...we'll try again with the MD5 checksum.
- try
- {
- verifyChecksum( md5ChecksumObserver, destination, temp, remotePath, ".md5", wagon );
- }
- catch ( ChecksumFailedException e )
- {
- // if we also fail to verify based on the MD5 checksum, and the checksum transfer/read
- // succeeded, then we need to determine whether to retry or handle it as a failure.
- if ( firstRun )
- {
- retry = true;
- }
- else
- {
- handleChecksumFailure( checksumPolicy, e.getMessage(), e.getCause() );
- }
- }
- catch ( ResourceDoesNotExistException md5TryException )
- {
- // this was a failed transfer, and we don't want to retry.
- handleChecksumFailure( checksumPolicy, "Error retrieving checksum file for " + remotePath,
- md5TryException );
- }
- }
-
- // reinstate the download monitor...
- if ( downloadMonitor != null )
- {
- wagon.addTransferListener( downloadMonitor );
+ // this was a failed transfer, and we don't want to retry.
+ handleChecksumFailure( checksumPolicy, "Error retrieving checksum file for " + remotePath,
+ md5TryException );
}
}
- // unset the firstRun flag, so we don't get caught in an infinite loop...
- firstRun = false;
- }
- catch ( NoSuchAlgorithmException e )
- {
- throw new TransferFailedException( "Unable to add checksum methods: " + e.getMessage(), e );
- }
- finally
- {
- if ( sha1ChecksumObserver != null )
- {
- wagon.removeTransferListener( sha1ChecksumObserver );
- }
-
- if ( md5ChecksumObserver != null )
+ // reinstate the download monitor...
+ if ( downloadMonitor != null )
{
- wagon.removeTransferListener( md5ChecksumObserver );
+ wagon.addTransferListener( downloadMonitor );
}
}
+
+ // unset the firstRun flag, so we don't get caught in an infinite loop...
+ firstRun = false;
}
}
catch ( ConnectionException e )
Modified: maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java?rev=675074&r1=675073&r2=675074&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java (original)
+++ maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java Tue Jul 8 18:09:56 2008
@@ -19,14 +19,31 @@
* under the License.
*/
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
+import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.wagon.ResourceDoesNotExistException;
+import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.wagon.UnsupportedProtocolException;
import org.apache.maven.wagon.Wagon;
+import org.apache.maven.wagon.authorization.AuthorizationException;
+import org.apache.maven.wagon.events.TransferListener;
+import org.apache.maven.wagon.observers.Debug;
import org.apache.maven.wagon.repository.Repository;
import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.easymock.MockControl;
/**
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
@@ -36,16 +53,57 @@
extends PlexusTestCase
{
- private WagonManager wagonManager;
+ private DefaultWagonManager wagonManager;
+
+ private TransferListener transferListener = new Debug();
+
+ private ArtifactFactory artifactFactory;
protected void setUp()
throws Exception
{
super.setUp();
- wagonManager = (WagonManager) lookup( WagonManager.ROLE );
+ wagonManager = (DefaultWagonManager) lookup( WagonManager.ROLE );
+
+ artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
}
+ private Artifact createTestPomArtifact( String directory )
+ throws IOException
+ {
+ File testData = getTestFile( directory );
+ FileUtils.deleteDirectory( testData );
+ testData.mkdirs();
+
+ Artifact artifact = artifactFactory.createProjectArtifact( "test", "test", "1.0" );
+ artifact.setFile( new File( testData, "test-1.0.pom" ) );
+ assertFalse( artifact.getFile().exists() );
+ return artifact;
+ }
+
+ public void testGetArtifactSha1MissingMd5Present()
+ throws IOException, UnsupportedProtocolException, TransferFailedException, ResourceDoesNotExistException
+ {
+ Artifact artifact = createTestPomArtifact( "target/test-data/get-remote-artifact" );
+
+ ArtifactRepository repo = createNoOpRepo();
+
+ StringWagon wagon = (StringWagon) wagonManager.getWagon( "noop" );
+ wagon.addExpectedContent( repo.getLayout().pathOf( artifact ), "expected" );
+ wagon.addExpectedContent( repo.getLayout().pathOf( artifact ) + ".md5", "bad_checksum" );
+
+ wagonManager.getArtifact( artifact, repo );
+
+ assertTrue( artifact.getFile().exists() );
+ }
+
+ private ArtifactRepository createNoOpRepo()
+ {
+ ArtifactRepository repo =
+ new DefaultArtifactRepository( "id", "noop://url", new ArtifactRepositoryLayoutStub() );
+ return repo;
+ }
/**
* checks the handling of urls
@@ -53,27 +111,26 @@
public void testExternalURL()
{
DefaultWagonManager mgr = new DefaultWagonManager();
- assertTrue(mgr.isExternalRepo( getRepo( "foo", "http://somehost" ) ));
- assertTrue(mgr.isExternalRepo( getRepo( "foo", "http://somehost:9090/somepath" ) ));
- assertTrue(mgr.isExternalRepo( getRepo( "foo", "ftp://somehost" ) ));
- assertTrue(mgr.isExternalRepo( getRepo( "foo", "http://192.168.101.1" ) ));
- assertTrue(mgr.isExternalRepo( getRepo( "foo", "http://" ) ));
- //these are local
- assertFalse(mgr.isExternalRepo( getRepo( "foo", "http://localhost:8080" ) ));
- assertFalse(mgr.isExternalRepo( getRepo( "foo", "http://127.0.0.1:9090" ) ));
- assertFalse(mgr.isExternalRepo( getRepo( "foo", "file://localhost/somepath" ) ));
- assertFalse(mgr.isExternalRepo( getRepo( "foo", "file://localhost/D:/somepath" ) ));
- assertFalse(mgr.isExternalRepo( getRepo( "foo", "http://localhost" ) ));
- assertFalse(mgr.isExternalRepo( getRepo( "foo", "http://127.0.0.1" ) ));
- assertFalse(mgr.isExternalRepo( getRepo( "foo", "file:///somepath" ) ));
- assertFalse(mgr.isExternalRepo( getRepo( "foo", "file://D:/somepath" ) ));
-
- //not a proper url so returns false;
- assertFalse(mgr.isExternalRepo( getRepo( "foo", "192.168.101.1" ) ));
- assertFalse(mgr.isExternalRepo( getRepo( "foo", "" ) ));
+ assertTrue( mgr.isExternalRepo( getRepo( "foo", "http://somehost" ) ) );
+ assertTrue( mgr.isExternalRepo( getRepo( "foo", "http://somehost:9090/somepath" ) ) );
+ assertTrue( mgr.isExternalRepo( getRepo( "foo", "ftp://somehost" ) ) );
+ assertTrue( mgr.isExternalRepo( getRepo( "foo", "http://192.168.101.1" ) ) );
+ assertTrue( mgr.isExternalRepo( getRepo( "foo", "http://" ) ) );
+ // these are local
+ assertFalse( mgr.isExternalRepo( getRepo( "foo", "http://localhost:8080" ) ) );
+ assertFalse( mgr.isExternalRepo( getRepo( "foo", "http://127.0.0.1:9090" ) ) );
+ assertFalse( mgr.isExternalRepo( getRepo( "foo", "file://localhost/somepath" ) ) );
+ assertFalse( mgr.isExternalRepo( getRepo( "foo", "file://localhost/D:/somepath" ) ) );
+ assertFalse( mgr.isExternalRepo( getRepo( "foo", "http://localhost" ) ) );
+ assertFalse( mgr.isExternalRepo( getRepo( "foo", "http://127.0.0.1" ) ) );
+ assertFalse( mgr.isExternalRepo( getRepo( "foo", "file:///somepath" ) ) );
+ assertFalse( mgr.isExternalRepo( getRepo( "foo", "file://D:/somepath" ) ) );
+
+ // not a proper url so returns false;
+ assertFalse( mgr.isExternalRepo( getRepo( "foo", "192.168.101.1" ) ) );
+ assertFalse( mgr.isExternalRepo( getRepo( "foo", "" ) ) );
}
-
/**
* Check that lookups with exact matches work and that no matches don't corrupt the repo.
*/
@@ -81,20 +138,19 @@
{
wagonManager.addMirror( "a", "a", "http://a" );
wagonManager.addMirror( "b", "b", "http://b" );
-
+
ArtifactRepository repo = null;
- repo = wagonManager.getMirrorRepository( getRepo("a","http://a.a" ));
+ repo = wagonManager.getMirrorRepository( getRepo( "a", "http://a.a" ) );
assertEquals( "http://a", repo.getUrl() );
-
- repo = wagonManager.getMirrorRepository( getRepo("b","http://a.a" ));
+
+ repo = wagonManager.getMirrorRepository( getRepo( "b", "http://a.a" ) );
assertEquals( "http://b", repo.getUrl() );
-
- repo = wagonManager.getMirrorRepository( getRepo("c","http://c.c") );
+
+ repo = wagonManager.getMirrorRepository( getRepo( "c", "http://c.c" ) );
assertEquals( "http://c.c", repo.getUrl() );
-
-
+
}
-
+
/**
* Check that wildcards don't override exact id matches.
*/
@@ -103,107 +159,104 @@
wagonManager.addMirror( "a", "a", "http://a" );
wagonManager.addMirror( "b", "b", "http://b" );
wagonManager.addMirror( "c", "*", "http://wildcard" );
-
+
ArtifactRepository repo = null;
- repo = wagonManager.getMirrorRepository( getRepo("a","http://a.a" ));
+ repo = wagonManager.getMirrorRepository( getRepo( "a", "http://a.a" ) );
assertEquals( "http://a", repo.getUrl() );
-
- repo = wagonManager.getMirrorRepository( getRepo("b","http://a.a" ));
+
+ repo = wagonManager.getMirrorRepository( getRepo( "b", "http://a.a" ) );
assertEquals( "http://b", repo.getUrl() );
-
- repo = wagonManager.getMirrorRepository( getRepo("c","http://c.c") );
- assertEquals( "http://wildcard", repo.getUrl() );
-
+
+ repo = wagonManager.getMirrorRepository( getRepo( "c", "http://c.c" ) );
+ assertEquals( "http://wildcard", repo.getUrl() );
+
}
/**
- * Check that patterns are processed correctly
- * Valid patterns:
- * * = everything
- * external:* = everything not on the localhost and not file based.
- * repo,repo1 = repo or repo1
- * *,!repo1 = everything except repo1
- *
+ * Check that patterns are processed correctly Valid patterns: * = everything external:* = everything not on the
+ * localhost and not file based. repo,repo1 = repo or repo1 *,!repo1 = everything except repo1
*/
public void testPatterns()
{
DefaultWagonManager mgr = new DefaultWagonManager();
-
- assertTrue(mgr.matchPattern( getRepo("a"), "*" ));
- assertTrue(mgr.matchPattern( getRepo("a"), "*," ));
- assertTrue(mgr.matchPattern( getRepo("a"), ",*," ));
- assertTrue(mgr.matchPattern( getRepo("a"), "*," ));
-
- assertTrue(mgr.matchPattern( getRepo("a"), "a" ));
- assertTrue(mgr.matchPattern( getRepo("a"), "a," ));
- assertTrue(mgr.matchPattern( getRepo("a"), ",a," ));
- assertTrue(mgr.matchPattern( getRepo("a"), "a," ));
-
- assertFalse(mgr.matchPattern( getRepo("b"), "a" ));
- assertFalse(mgr.matchPattern( getRepo("b"), "a," ));
- assertFalse(mgr.matchPattern( getRepo("b"), ",a" ));
- assertFalse(mgr.matchPattern( getRepo("b"), ",a," ));
-
- assertTrue(mgr.matchPattern( getRepo("a"), "a,b" ));
- assertTrue(mgr.matchPattern( getRepo("b"), "a,b" ));
-
- assertFalse(mgr.matchPattern( getRepo("c"), "a,b" ));
-
- assertTrue(mgr.matchPattern( getRepo("a"), "*" ));
- assertTrue(mgr.matchPattern( getRepo("a"), "*,b" ));
- assertTrue(mgr.matchPattern( getRepo("a"), "*,!b" ));
-
- assertFalse(mgr.matchPattern( getRepo("a"), "*,!a" ));
- assertFalse(mgr.matchPattern( getRepo("a"), "!a,*" ));
-
- assertTrue(mgr.matchPattern( getRepo("c"), "*,!a" ));
- assertTrue(mgr.matchPattern( getRepo("c"), "!a,*" ));
-
- assertFalse(mgr.matchPattern( getRepo("c"), "!a,!c" ));
- assertFalse(mgr.matchPattern( getRepo("d"), "!a,!c*" ));
+
+ assertTrue( mgr.matchPattern( getRepo( "a" ), "*" ) );
+ assertTrue( mgr.matchPattern( getRepo( "a" ), "*," ) );
+ assertTrue( mgr.matchPattern( getRepo( "a" ), ",*," ) );
+ assertTrue( mgr.matchPattern( getRepo( "a" ), "*," ) );
+
+ assertTrue( mgr.matchPattern( getRepo( "a" ), "a" ) );
+ assertTrue( mgr.matchPattern( getRepo( "a" ), "a," ) );
+ assertTrue( mgr.matchPattern( getRepo( "a" ), ",a," ) );
+ assertTrue( mgr.matchPattern( getRepo( "a" ), "a," ) );
+
+ assertFalse( mgr.matchPattern( getRepo( "b" ), "a" ) );
+ assertFalse( mgr.matchPattern( getRepo( "b" ), "a," ) );
+ assertFalse( mgr.matchPattern( getRepo( "b" ), ",a" ) );
+ assertFalse( mgr.matchPattern( getRepo( "b" ), ",a," ) );
+
+ assertTrue( mgr.matchPattern( getRepo( "a" ), "a,b" ) );
+ assertTrue( mgr.matchPattern( getRepo( "b" ), "a,b" ) );
+
+ assertFalse( mgr.matchPattern( getRepo( "c" ), "a,b" ) );
+
+ assertTrue( mgr.matchPattern( getRepo( "a" ), "*" ) );
+ assertTrue( mgr.matchPattern( getRepo( "a" ), "*,b" ) );
+ assertTrue( mgr.matchPattern( getRepo( "a" ), "*,!b" ) );
+
+ assertFalse( mgr.matchPattern( getRepo( "a" ), "*,!a" ) );
+ assertFalse( mgr.matchPattern( getRepo( "a" ), "!a,*" ) );
+
+ assertTrue( mgr.matchPattern( getRepo( "c" ), "*,!a" ) );
+ assertTrue( mgr.matchPattern( getRepo( "c" ), "!a,*" ) );
+
+ assertFalse( mgr.matchPattern( getRepo( "c" ), "!a,!c" ) );
+ assertFalse( mgr.matchPattern( getRepo( "d" ), "!a,!c*" ) );
}
-
+
/**
- * make sure the external if is fully exercised. We can assume file and ips are also handled because they
- * have a separate test above.
+ * make sure the external if is fully exercised. We can assume file and ips are also handled because they have a
+ * separate test above.
*/
public void testPatternsWithExternal()
{
DefaultWagonManager mgr = new DefaultWagonManager();
- assertTrue( mgr.matchPattern( getRepo( "a","http://localhost" ), "*" ) );
- assertFalse( mgr.matchPattern( getRepo( "a","http://localhost" ), "external:*" ) );
-
- assertTrue( mgr.matchPattern( getRepo( "a","http://localhost" ), "external:*,a" ) );
- assertFalse( mgr.matchPattern( getRepo( "a","http://localhost" ), "external:*,!a" ) );
- assertTrue( mgr.matchPattern( getRepo( "a","http://localhost" ), "a,external:*" ) );
- assertFalse( mgr.matchPattern( getRepo( "a","http://localhost" ), "!a,external:*" ) );
-
- assertFalse( mgr.matchPattern( getRepo( "c","http://localhost" ), "!a,external:*" ) );
- assertTrue( mgr.matchPattern( getRepo( "c","http://somehost" ), "!a,external:*" ) );
+ assertTrue( mgr.matchPattern( getRepo( "a", "http://localhost" ), "*" ) );
+ assertFalse( mgr.matchPattern( getRepo( "a", "http://localhost" ), "external:*" ) );
+
+ assertTrue( mgr.matchPattern( getRepo( "a", "http://localhost" ), "external:*,a" ) );
+ assertFalse( mgr.matchPattern( getRepo( "a", "http://localhost" ), "external:*,!a" ) );
+ assertTrue( mgr.matchPattern( getRepo( "a", "http://localhost" ), "a,external:*" ) );
+ assertFalse( mgr.matchPattern( getRepo( "a", "http://localhost" ), "!a,external:*" ) );
+
+ assertFalse( mgr.matchPattern( getRepo( "c", "http://localhost" ), "!a,external:*" ) );
+ assertTrue( mgr.matchPattern( getRepo( "c", "http://somehost" ), "!a,external:*" ) );
}
+
/**
* Build an ArtifactRepository object.
+ *
* @param id
* @param url
* @return
*/
- private ArtifactRepository getRepo (String id, String url)
+ private ArtifactRepository getRepo( String id, String url )
{
- return (ArtifactRepository) new DefaultArtifactRepository(id,url,new DefaultRepositoryLayout());
+ return new DefaultArtifactRepository( id, url, new DefaultRepositoryLayout() );
}
-
+
/**
* Build an ArtifactRepository object.
+ *
* @param id
- * @param url
* @return
*/
- private ArtifactRepository getRepo (String id)
+ private ArtifactRepository getRepo( String id )
{
- return getRepo(id,"http://something");
+ return getRepo( id, "http://something" );
}
-
+
public void testDefaultWagonManager()
throws Exception
{
@@ -215,6 +268,8 @@
assertWagon( "c" );
+ assertWagon( "noop" );
+
try
{
assertWagon( "d" );
@@ -223,7 +278,7 @@
}
catch ( UnsupportedProtocolException e )
{
- //ok
+ // ok
assertTrue( true );
}
}
@@ -247,7 +302,7 @@
}
catch ( UnsupportedProtocolException e )
{
- //ok
+ // ok
assertTrue( true );
}
}
@@ -261,21 +316,193 @@
repository.setProtocol( null );
- Wagon wagon = (Wagon) wagonManager.getWagon( repository );
+ Wagon wagon = wagonManager.getWagon( repository );
fail( "Expected :" + UnsupportedProtocolException.class.getName() );
}
catch ( UnsupportedProtocolException e )
{
- //ok
+ // ok
assertTrue( true );
}
}
+ /**
+ * Checks the verification of checksums.
+ */
+ public void testChecksumVerification()
+ throws Exception
+ {
+ ArtifactRepositoryPolicy policy =
+ new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS,
+ ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL );
+ ArtifactRepository repo =
+ new DefaultArtifactRepository( "id", "string://url", new ArtifactRepositoryLayoutStub(), policy, policy );
+
+ File tmpFile = File.createTempFile( "mvn-cs-test", ".temp" );
+ File sha1File = new File( tmpFile.getPath() + ".sha1" );
+ File md5File = new File( tmpFile.getPath() + ".md5" );
+
+ try
+ {
+ Artifact artifact =
+ new DefaultArtifact( "sample.group", "sample-art", VersionRange.createFromVersion( "1.0" ), "scope",
+ "jar", "classifier", null );
+ artifact.setFile( tmpFile );
+
+ {
+ Xpp3Dom path = new Xpp3Dom( "path" );
+ path.setValue( "lower-case-checksum" );
+ Xpp3Dom sha1 = new Xpp3Dom( "path.sha1" );
+ sha1.setValue( "2a25dc564a3b34f68237fc849066cbc7bb7a36a1" );
+ Xpp3Dom resourceStrings = new Xpp3Dom( "resourceStrings" );
+ resourceStrings.addChild( path );
+ resourceStrings.addChild( sha1 );
+ Xpp3Dom conf = new Xpp3Dom( "configuration" );
+ conf.addChild( resourceStrings );
+
+ wagonManager.addConfiguration( repo.getId(), conf );
+
+ try
+ {
+ wagonManager.getArtifact( artifact, repo );
+ }
+ catch ( ChecksumFailedException e )
+ {
+ fail( "Checksum verification did not pass: " + e.getMessage() );
+ }
+ }
+
+ {
+ Xpp3Dom path = new Xpp3Dom( "path" );
+ path.setValue( "upper-case-checksum" );
+ Xpp3Dom sha1 = new Xpp3Dom( "path.sha1" );
+ sha1.setValue( "B7BB97D7D0B9244398D9B47296907F73313663E6" );
+ Xpp3Dom resourceStrings = new Xpp3Dom( "resourceStrings" );
+ resourceStrings.addChild( path );
+ resourceStrings.addChild( sha1 );
+ Xpp3Dom conf = new Xpp3Dom( "configuration" );
+ conf.addChild( resourceStrings );
+
+ wagonManager.addConfiguration( repo.getId(), conf );
+
+ try
+ {
+ wagonManager.getArtifact( artifact, repo );
+ }
+ catch ( ChecksumFailedException e )
+ {
+ fail( "Checksum verification did not pass: " + e.getMessage() );
+ }
+ }
+
+ {
+ Xpp3Dom path = new Xpp3Dom( "path" );
+ path.setValue( "expected-failure" );
+ Xpp3Dom sha1 = new Xpp3Dom( "path.sha1" );
+ sha1.setValue( "b7bb97d7d0b9244398d9b47296907f73313663e6" );
+ Xpp3Dom resourceStrings = new Xpp3Dom( "resourceStrings" );
+ resourceStrings.addChild( path );
+ resourceStrings.addChild( sha1 );
+ Xpp3Dom conf = new Xpp3Dom( "configuration" );
+ conf.addChild( resourceStrings );
+
+ wagonManager.addConfiguration( repo.getId(), conf );
+
+ try
+ {
+ wagonManager.getArtifact( artifact, repo );
+ fail( "Checksum verification did not fail" );
+ }
+ catch ( ChecksumFailedException e )
+ {
+ // expected
+ }
+ }
+
+ {
+ Xpp3Dom path = new Xpp3Dom( "path" );
+ path.setValue( "lower-case-checksum" );
+ Xpp3Dom md5 = new Xpp3Dom( "path.md5" );
+ md5.setValue( "50b2cf50a103a965efac62b983035cac" );
+ Xpp3Dom resourceStrings = new Xpp3Dom( "resourceStrings" );
+ resourceStrings.addChild( path );
+ resourceStrings.addChild( md5 );
+ Xpp3Dom conf = new Xpp3Dom( "configuration" );
+ conf.addChild( resourceStrings );
+
+ wagonManager.addConfiguration( repo.getId(), conf );
+
+ try
+ {
+ wagonManager.getArtifact( artifact, repo );
+ }
+ catch ( ChecksumFailedException e )
+ {
+ fail( "Checksum verification did not pass: " + e.getMessage() );
+ }
+ }
+
+ {
+ Xpp3Dom path = new Xpp3Dom( "path" );
+ path.setValue( "upper-case-checksum" );
+ Xpp3Dom md5 = new Xpp3Dom( "path.md5" );
+ md5.setValue( "842F568FCCFEB7E534DC72133D42FFDC" );
+ Xpp3Dom resourceStrings = new Xpp3Dom( "resourceStrings" );
+ resourceStrings.addChild( path );
+ resourceStrings.addChild( md5 );
+ Xpp3Dom conf = new Xpp3Dom( "configuration" );
+ conf.addChild( resourceStrings );
+
+ wagonManager.addConfiguration( repo.getId(), conf );
+
+ try
+ {
+ wagonManager.getArtifact( artifact, repo );
+ }
+ catch ( ChecksumFailedException e )
+ {
+ fail( "Checksum verification did not pass: " + e.getMessage() );
+ }
+ }
+
+ {
+ Xpp3Dom path = new Xpp3Dom( "path" );
+ path.setValue( "expected-failure" );
+ Xpp3Dom md5 = new Xpp3Dom( "path.md5" );
+ md5.setValue( "b7bb97d7d0b9244398d9b47296907f73313663e6" );
+ Xpp3Dom resourceStrings = new Xpp3Dom( "resourceStrings" );
+ resourceStrings.addChild( path );
+ resourceStrings.addChild( md5 );
+ Xpp3Dom conf = new Xpp3Dom( "configuration" );
+ conf.addChild( resourceStrings );
+
+ wagonManager.addConfiguration( repo.getId(), conf );
+
+ try
+ {
+ wagonManager.getArtifact( artifact, repo );
+ fail( "Checksum verification did not fail" );
+ }
+ catch ( ChecksumFailedException e )
+ {
+ // expected
+ }
+ }
+
+ }
+ finally
+ {
+ tmpFile.delete();
+ sha1File.delete();
+ md5File.delete();
+ }
+ }
+
private void assertWagon( String protocol )
throws Exception
{
- Wagon wagon = (Wagon) wagonManager.getWagon( protocol );
+ Wagon wagon = wagonManager.getWagon( protocol );
assertNotNull( "Check wagon, protocol=" + protocol, wagon );
}
@@ -308,4 +535,23 @@
assertEquals( "Check configuration for wagon, protocol=" + protocol, s, wagon.getConfigurableField() );
}
+ private final class ArtifactRepositoryLayoutStub
+ implements ArtifactRepositoryLayout
+ {
+ public String pathOfRemoteRepositoryMetadata( ArtifactMetadata metadata )
+ {
+ return "path";
+ }
+
+ public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )
+ {
+ return "path";
+ }
+
+ public String pathOf( Artifact artifact )
+ {
+ return "path";
+ }
+ }
+
}
Copied: maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/StringWagon.java (from r674556, maven/artifact/trunk/src/test/java/org/apache/maven/artifact/manager/StringWagon.java)
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/StringWagon.java?p2=maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/StringWagon.java&p1=maven/artifact/trunk/src/test/java/org/apache/maven/artifact/manager/StringWagon.java&r1=674556&r2=675074&rev=675074&view=diff
==============================================================================
--- maven/artifact/trunk/src/test/java/org/apache/maven/artifact/manager/StringWagon.java (original)
+++ maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/java/org/apache/maven/artifact/manager/StringWagon.java Tue Jul 8 18:09:56 2008
@@ -37,7 +37,7 @@
public class StringWagon
extends StreamWagon
{
- private Map<String, String> expectedContent = new HashMap<String, String>();
+ private Map expectedContent = new HashMap();
public void addExpectedContent( String resourceName, String expectedContent )
{
@@ -49,19 +49,17 @@
return new String[] { "noop" };
}
- @Override
public void closeConnection()
throws ConnectionException
{
}
- @Override
public void fillInputData( InputData inputData )
throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
{
Resource resource = inputData.getResource();
- String content = expectedContent.get( resource.getName() );
+ String content = (String) expectedContent.get( resource.getName() );
if ( content != null )
{
@@ -75,14 +73,12 @@
}
}
- @Override
public void fillOutputData( OutputData outputData )
throws TransferFailedException
{
outputData.setOutputStream( new StringOutputStream() );
}
- @Override
protected void openConnectionInternal()
throws ConnectionException, AuthenticationException
{
Modified: maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/resources/org/apache/maven/artifact/manager/DefaultWagonManagerTest.xml
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/resources/org/apache/maven/artifact/manager/DefaultWagonManagerTest.xml?rev=675074&r1=675073&r2=675074&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/resources/org/apache/maven/artifact/manager/DefaultWagonManagerTest.xml (original)
+++ maven/components/branches/maven-2.0.x/maven-artifact-manager/src/test/resources/org/apache/maven/artifact/manager/DefaultWagonManagerTest.xml Tue Jul 8 18:09:56 2008
@@ -40,8 +40,18 @@
<implementation>org.apache.maven.artifact.manager.WagonC</implementation>
</component>
<component>
+ <role>org.apache.maven.wagon.Wagon</role>
+ <role-hint>noop</role-hint>
+ <implementation>org.apache.maven.artifact.manager.StringWagon</implementation>
+ </component>
+ <component>
+ <role>org.apache.maven.wagon.Wagon</role>
+ <role-hint>string</role-hint>
+ <implementation>org.apache.maven.artifact.manager.WagonString</implementation>
+ </component>
+ <component>
<role>org.apache.maven.artifact.repository.authentication.AuthenticationInfoProvider</role>
<implementation>org.apache.maven.artifact.repository.authentication.DummyAuthenticationInfoProvider</implementation>
</component>
</components>
-</plexus>
\ No newline at end of file
+</plexus>