import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import java.util.Map.Entry;
+import java.util.Properties;
/**
* DefaultRepositoryProxyConnectors
* @throws ProxyException if there was a problem fetching the artifact.
*/
public File fetchFromProxies( ManagedRepositoryContent repository, ArtifactReference artifact )
- throws ProxyException
{
File localFile = toLocalFile( repository, artifact );
getLogger().debug( "Artifact " + Keys.toKey( artifact ) + " not updated on repository \""
+ targetRepository.getRepository().getId() + "\"." );
}
+ catch ( ProxyException e )
+ {
+ getLogger().warn( "Transfer error from repository \"" + targetRepository.getRepository().getId() +
+ "\" for artifact " + Keys.toKey( artifact ) + ", continuing to next repository. Error message: " +
+ e.getMessage() );
+ getLogger().debug( "Full stack trace", e );
+ }
}
getLogger().debug( "Exhausted all target repositories, artifact " + Keys.toKey( artifact ) + " not found." );
* @return the (local) metadata file that was fetched/merged/updated, or null if no metadata file exists.
*/
public File fetchFromProxies( ManagedRepositoryContent repository, VersionedReference metadata )
- throws ProxyException
{
File localFile = toLocalFile( repository, metadata );
File localRepoFile = toLocalRepoFile( repository, targetRepository, targetPath );
long originalMetadataTimestamp = getLastModified( localRepoFile );
-
+
try
{
transferFile( connector, targetRepository, targetPath, localRepoFile, requestProperties );
+ " not updated on remote repository \""
+ targetRepository.getRepository().getId() + "\"." );
}
+ catch ( ProxyException e )
+ {
+ getLogger().warn( "Transfer error from repository \"" + targetRepository.getRepository().getId() +
+ "\" for versioned Metadata " + Keys.toKey( metadata ) +
+ ", continuing to next repository. Error message: " + e.getMessage() );
+ getLogger().debug( "Full stack trace", e );
+ }
}
if ( hasBeenUpdated( localFile, originalTimestamp ) )
return file.lastModified();
}
-
+
private boolean hasBeenUpdated( File file, long originalLastModified )
{
if ( !file.exists() || !file.isFile() )
{
return false;
}
-
+
long currentLastModified = getLastModified( file );
return ( currentLastModified > originalLastModified );
}
* @throws ProxyException if there was a problem fetching the metadata file.
*/
public File fetchFromProxies( ManagedRepositoryContent repository, ProjectReference metadata )
- throws NotFoundException, NotModifiedException, ProxyException
{
File localFile = toLocalFile( repository, metadata );
try
{
transferFile( connector, targetRepository, targetPath, localRepoFile, requestProperties );
-
+
if ( hasBeenUpdated( localRepoFile, originalMetadataTimestamp ) )
{
metadataNeedsUpdating = true;
+ " not updated on remote repository \""
+ targetRepository.getRepository().getId() + "\"." );
}
-
+ catch ( ProxyException e )
+ {
+ getLogger().warn( "Transfer error from repository \"" + targetRepository.getRepository().getId() +
+ "\" for project metadata " + Keys.toKey( metadata ) +
+ ", continuing to next repository. Error message: " + e.getMessage() );
+ getLogger().debug( "Full stack trace", e );
+ }
+
}
if ( hasBeenUpdated( localFile, originalTimestamp ) )
}
private File toLocalFile( ManagedRepositoryContent repository, ArtifactReference artifact )
- throws ProxyException
{
return repository.toFile( artifact );
}
private File toLocalFile( ManagedRepositoryContent repository, ProjectReference metadata )
- throws ProxyException
{
String sourcePath = metadataTools.toPath( metadata );
return new File( repository.getRepoRoot(), sourcePath );
}
private File toLocalFile( ManagedRepositoryContent repository, VersionedReference metadata )
- throws ProxyException
{
String sourcePath = metadataTools.toPath( metadata );
return new File( repository.getRepoRoot(), sourcePath );
*/
private File transferFile( ProxyConnector connector, RemoteRepositoryContent remoteRepository, String remotePath,
File localFile, Properties requestProperties )
- throws NotFoundException, NotModifiedException, ProxyException
+ throws ProxyException, NotModifiedException
{
String url = remoteRepository.getURL().getUrl() + remotePath;
requestProperties.setProperty( "url", url );
catch ( NotModifiedException e )
{
// Do not cache url here.
- throw e;
+ throw e;
}
catch ( ProxyException e )
{
*/
private File transferSimpleFile( Wagon wagon, RemoteRepositoryContent remoteRepository, String remotePath,
File localFile )
- throws NotFoundException, NotModifiedException, ProxyException
+ throws ProxyException
{
assert ( remotePath != null );
throw new NotModifiedException( "Not downloaded, as local file is newer than remote side: "
+ localFile.getAbsolutePath() );
}
-
+
if ( temp.exists() )
{
getLogger().debug( "Downloaded successfully." );
AuthenticationInfo authInfo = null;
String username = remoteRepository.getRepository().getUsername();
String password = remoteRepository.getRepository().getPassword();
-
+
if ( StringUtils.isNotBlank( username ) && StringUtils.isNotBlank( password ) )
{
getLogger().debug( "Using username " + username + " to connect to remote repository "
import org.apache.maven.archiva.repository.metadata.RepositoryMetadataException;
import org.apache.maven.archiva.repository.metadata.RepositoryMetadataReader;
import org.apache.maven.archiva.repository.metadata.RepositoryMetadataWriter;
+import org.apache.maven.wagon.TransferFailedException;
import org.custommonkey.xmlunit.DetailedDiff;
import org.custommonkey.xmlunit.Diff;
* present in the repository.
*
* Test Case Naming is as follows.
- *
+ *
* <code>
* public void testGet[Release|Snapshot|Project]Metadata[Not]Proxied[Not|On]Local[Not|On|Multiple]Remote
* </code>
- *
+ *
* <pre>
* Which should leave the following matrix of test cases.
- *
+ *
* Metadata | Proxied | Local | Remote
* ----------+----------+-------+---------
* Release | Not | Not | n/a (1)
* Project | | On | Not
* Project | | On | On
* Project | | On | Multiple
- *
+ *
* (1) If it isn't proxied, no point in having a remote.
* </pre>
*
*/
private MetadataTools metadataTools;
+ // TODO: same test for other fetch* methods
+ public void testFetchFromTwoProxiesWhenFirstConnectionFails()
+ throws Exception
+ {
+ // Project metadata that does not exist locally, but has multiple versions in remote repos
+ String requestedResource = "org/apache/maven/test/get-default-layout/maven-metadata.xml";
+ setupTestableManagedRepository( requestedResource );
+
+ saveRemoteRepositoryConfig( "badproxied1", "Bad Proxied 1", "test://bad.machine.com/repo/", "default" );
+
+ // Configure Connector (usually done within archiva.xml configuration)
+ saveConnector( ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
+ SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
+ saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
+ SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
+
+ assertResourceNotFound( requestedResource );
+ assertNoRepoMetadata( "badproxied1", requestedResource );
+ assertNoRepoMetadata( ID_PROXIED2, requestedResource );
+
+ // ensure that a hard failure in the first proxy connector is skipped and the second repository checked
+ File expectedFile = new File( managedDefaultDir.getAbsoluteFile(),
+ metadataTools.getRepositorySpecificName( "badproxied1", requestedResource ) );
+ wagonMock.get( requestedResource, new File( expectedFile.getParentFile(), expectedFile.getName() + ".tmp" ) );
+ wagonMockControl.setThrowable( new TransferFailedException( "can't connect" ) );
+
+ wagonMockControl.replay();
+
+ assertFetchProject( requestedResource );
+
+ wagonMockControl.verify();
+
+ assertProjectMetadataContents( requestedResource, new String[] { "1.0.1" }, "1.0.1", "1.0.1" );
+ assertNoRepoMetadata( "badproxied1", requestedResource );
+ assertRepoProjectMetadata( ID_PROXIED2, requestedResource, new String[] { "1.0.1" } );
+ }
+
/**
* Attempt to get the project metadata for non-existant artifact.
- *
+ *
* Expected result: the maven-metadata.xml file is not created on the managed repository, nor returned
* to the requesting client.
*/
/**
* A request for a release maven-metadata.xml file that does not exist locally, and the managed
* repository has no proxied repositories set up.
- *
+ *
* Expected result: the maven-metadata.xml file is not created on the managed repository, nor returned
* to the requesting client.
*/
/**
* A request for a maven-metadata.xml file that does exist locally, and the managed
* repository has no proxied repositories set up.
- *
+ *
* Expected result: the maven-metadata.xml file is updated locally, based off of the managed repository
* information, and then returned to the client.
*/
/**
* A request for a release maven-metadata.xml file that does not exist on the managed repository, but
* exists on multiple remote repositories.
- *
+ *
* Expected result: the maven-metadata.xml file is downloaded from the remote into the repository specific
* file location on the managed repository, a merge of the contents to the requested
* maven-metadata.xml is performed, and then the merged maven-metadata.xml file is
/**
* A request for a maven-metadata.xml file that does not exist locally, nor does it exist in a remote
* proxied repository.
- *
+ *
* Expected result: the maven-metadata.xml file is created locally, based off of managed repository
* information, and then return to the client.
*/
/**
* A request for a maven-metadata.xml file that does not exist on the managed repository, but
* exists on 1 remote repository.
- *
+ *
* Expected result: the maven-metadata.xml file is downloaded from the remote into the repository specific
* file location on the managed repository, a merge of the contents to the requested
* maven-metadata.xml is performed, and then the merged maven-metadata.xml file is
/**
* A request for a maven-metadata.xml file that exists in the managed repository, but
* not on any remote repository.
- *
+ *
* Expected result: the maven-metadata.xml file does not exist on the remote proxied repository and
* is not downloaded. There is no repository specific metadata file on the managed
* repository. The managed repository maven-metadata.xml is returned to the
/**
* A request for a maven-metadata.xml file that exists in the managed repository, and on multiple
* remote repositories.
- *
+ *
* Expected result: the maven-metadata.xml file on the remote proxied repository is downloaded
* and merged into the contents of the existing managed repository copy of
* the maven-metadata.xml file.
/**
* A request for a maven-metadata.xml file that exists in the managed repository, and on one
* remote repository.
- *
+ *
* Expected result: the maven-metadata.xml file on the remote proxied repository is downloaded
* and merged into the contents of the existing managed repository copy of
* the maven-metadata.xml file.
/**
* Transfer the metadata file.
- *
+ *
* @param requestedResource the requested resource
- * @throws Exception
+ * @throws Exception
*/
private void assertFetchProject( String requestedResource )
throws Exception
/**
* Transfer the metadata file, not expected to succeed.
- *
+ *
* @param requestedResource the requested resource
- * @throws Exception
+ * @throws Exception
*/
private void assertFetchProjectFailed( String requestedResource )
throws Exception
/**
* Transfer the metadata file.
- *
+ *
* @param requestedResource the requested resource
- * @throws Exception
+ * @throws Exception
*/
private void assertFetchVersioned( String requestedResource )
throws Exception
/**
* Transfer the metadata file, not expected to succeed.
- *
+ *
* @param requestedResource the requested resource
- * @throws Exception
+ * @throws Exception
*/
private void assertFetchVersionedFailed( String requestedResource )
throws Exception
/**
* Test for the existance of the requestedResource in the default managed repository.
- *
+ *
* @param requestedResource the requested resource
- * @throws Exception
+ * @throws Exception
*/
private void assertResourceExists( String requestedResource )
throws Exception
/**
* Ensures that the requested resource is not present in the managed repository.
- *
+ *
* @param requestedResource the requested resource
- * @throws Exception
+ * @throws Exception
*/
private void assertNoMetadata( String requestedResource )
throws Exception
}
/**
- * Ensures that the proxied repository specific maven metadata file does NOT exist in the
+ * Ensures that the proxied repository specific maven metadata file does NOT exist in the
* managed repository.
* @param proxiedRepoId the proxied repository id to validate with.
* @param requestedResource the resource requested.
/**
* Test for the existance of the requestedResource in the default managed repository, and if it exists,
* does it contain the specified list of expected versions?
- *
+ *
* @param requestedResource the requested resource
- * @throws Exception
+ * @throws Exception
*/
private void assertProjectMetadataContents( String requestedResource, String expectedVersions[],
String latestVersion, String releaseVersion )
/**
* Test for the existance of the requestedResource in the default managed repository, and if it exists,
* does it contain the expected release maven-metadata.xml contents?
- *
+ *
* @param requestedResource the requested resource
- * @throws Exception
+ * @throws Exception
*/
private void assertReleaseMetadataContents( String requestedResource )
throws Exception
/**
* Test for the existance of the snapshot metadata in the default managed repository, and if it exists,
* does it contain the expected release maven-metadata.xml contents?
- *
+ *
* @param requestedResource the requested resource
* @param expectedDate the date in "yyyyMMdd" format
* @param expectedTime the time in "hhmmss" format
* @param expectedBuildnumber the build number
- *
- * @throws Exception
+ *
+ * @throws Exception
*/
private void assertSnapshotMetadataContents( String requestedResource, String expectedDate, String expectedTime,
int expectedBuildnumber )
}
/**
- * Test for the existance of the proxied repository specific snapshot metadata in the default managed
+ * Test for the existance of the proxied repository specific snapshot metadata in the default managed
* repository, and if it exists, does it contain the expected release maven-metadata.xml contents?
- *
+ *
* @param proxiedRepoId the repository id of the proxied repository.
* @param requestedResource the requested resource
* @param expectedDate the date in "yyyyMMdd" format
* @param expectedTime the time in "hhmmss" format
* @param expectedBuildnumber the build number
- *
- * @throws Exception
+ *
+ * @throws Exception
*/
private void assertRepoSnapshotMetadataContents( String proxiedRepoId, String requestedResource,
String expectedDate, String expectedTime, int expectedBuildnumber )
/**
* Ensures that the repository specific maven metadata file exists, and contains the appropriate
* list of expected versions within.
- *
+ *
* @param proxiedRepoId
* @param requestedResource
*/
/**
* Test for the non-existance of the requestedResource in the default managed repository.
- *
+ *
* @param requestedResource the requested resource
- * @throws Exception
+ * @throws Exception
*/
private void assertResourceNotFound( String requestedResource )
throws Exception