From d44d957734badacce74293846d11b3b736b9a478 Mon Sep 17 00:00:00 2001 From: Eric Barboni Date: Fri, 11 Apr 2014 23:29:44 +0200 Subject: [PATCH] Multicatch and override --- .../DefaultRepositoryProxyConnectors.java | 43 ++++++------------- .../proxy/ProxyConnectorOrderComparator.java | 1 + .../MockRepositoryArchivaTaskScheduler.java | 4 ++ .../repository/TestMetadataRepository.java | 35 +++++++++++++++ .../TestRepositorySessionFactory.java | 2 +- .../archiva/proxy/AbstractProxyTestCase.java | 1 - .../archiva/proxy/HttpProxyTransferTest.java | 1 + .../archiva/proxy/MockConfiguration.java | 7 +++ .../apache/archiva/proxy/WagonDelegate.java | 28 ++++++++++++ 9 files changed, 91 insertions(+), 31 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java index 1d2ff6e7d..c4b8b0f11 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java @@ -87,7 +87,6 @@ import javax.inject.Inject; import javax.inject.Named; import java.io.File; import java.io.IOException; -import java.io.RandomAccessFile; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -136,7 +135,7 @@ public class DefaultRepositoryProxyConnectors private Map> proxyConnectorMap = new HashMap<>(); - private Map networkProxyMap = new ConcurrentHashMap(); + private Map networkProxyMap = new ConcurrentHashMap<>(); @Inject private WagonFactory wagonFactory; @@ -302,6 +301,7 @@ public class DefaultRepositoryProxyConnectors return proxyConnectorRuleConfigurations; } + @Override public File fetchFromProxies( ManagedRepositoryContent repository, ArtifactReference artifact ) throws ProxyDownloadException { @@ -313,7 +313,7 @@ public class DefaultRepositoryProxyConnectors requestProperties.setProperty( "managedRepositoryId", repository.getId() ); List connectors = getProxyConnectors( repository ); - Map previousExceptions = new LinkedHashMap(); + Map previousExceptions = new LinkedHashMap<>(); for ( ProxyConnector connector : connectors ) { if ( connector.isDisabled() ) @@ -354,12 +354,7 @@ public class DefaultRepositoryProxyConnectors log.debug( "Artifact {} not updated on repository \"{}\".", Keys.toKey( artifact ), targetRepository.getRepository().getId() ); } - catch ( ProxyException e ) - { - validatePolicies( this.downloadErrorPolicies, connector.getPolicies(), requestProperties, artifact, - targetRepository, localFile, e, previousExceptions ); - } - catch ( RepositoryAdminException e ) + catch ( ProxyException | RepositoryAdminException e ) { validatePolicies( this.downloadErrorPolicies, connector.getPolicies(), requestProperties, artifact, targetRepository, localFile, e, previousExceptions ); @@ -377,6 +372,7 @@ public class DefaultRepositoryProxyConnectors return null; } + @Override public File fetchFromProxies( ManagedRepositoryContent repository, String path ) { File localFile = new File( repository.getRepoRoot(), path ); @@ -450,6 +446,7 @@ public class DefaultRepositoryProxyConnectors return null; } + @Override public File fetchMetatadaFromProxies( ManagedRepositoryContent repository, String logicalPath ) { File localFile = new File( repository.getRepoRoot(), logicalPath ); @@ -496,14 +493,7 @@ public class DefaultRepositoryProxyConnectors targetRepository.getRepository().getId(), e ); } - catch ( ProxyException e ) - { - log.warn( - "Transfer error from repository {} for versioned Metadata {}, continuing to next repository. Error message: {}", - targetRepository.getRepository().getId(), logicalPath, e.getMessage() ); - log.debug( "Full stack trace", e ); - } - catch ( RepositoryAdminException e ) + catch ( ProxyException | RepositoryAdminException e ) { log.warn( "Transfer error from repository {} for versioned Metadata {}, continuing to next repository. Error message: {}", @@ -550,6 +540,7 @@ public class DefaultRepositoryProxyConnectors * @param repository * @throws ProxyException * @throws NotModifiedException + * @throws org.apache.archiva.admin.model.RepositoryAdminException */ protected void transferResources( ProxyConnector connector, RemoteRepositoryContent remoteRepository, File tmpMd5, File tmpSha1, File tmpResource, String url, String remotePath, File resource, @@ -669,6 +660,7 @@ public class DefaultRepositoryProxyConnectors /** * Test if the provided ManagedRepositoryContent has any proxies configured for it. */ + @Override public boolean hasProxies( ManagedRepositoryContent repository ) { synchronized ( this.proxyConnectorMap ) @@ -700,12 +692,7 @@ public class DefaultRepositoryProxyConnectors return false; } - if ( !file.isFile() ) - { - return false; - } - - return true; + return file.isFile(); } /** @@ -1204,12 +1191,7 @@ public class DefaultRepositoryProxyConnectors wagon.connect( wagonRepository, authInfo, networkProxy ); connected = true; } - catch ( ConnectionException e ) - { - log.warn( "Could not connect to {}: {}", remoteRepository.getRepository().getName(), e.getMessage() ); - connected = false; - } - catch ( AuthenticationException e ) + catch ( ConnectionException | AuthenticationException e ) { log.warn( "Could not connect to {}: {}", remoteRepository.getRepository().getName(), e.getMessage() ); connected = false; @@ -1256,6 +1238,7 @@ public class DefaultRepositoryProxyConnectors /** * TODO: Ensure that list is correctly ordered based on configuration. See MRM-477 */ + @Override public List getProxyConnectors( ManagedRepositoryContent repository ) { synchronized ( this.proxyConnectorMap ) @@ -1271,6 +1254,7 @@ public class DefaultRepositoryProxyConnectors } } + @Override public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue ) { if ( ConfigurationNames.isNetworkProxy( propertyName ) || ConfigurationNames.isManagedRepositories( @@ -1304,6 +1288,7 @@ public class DefaultRepositoryProxyConnectors } + @Override public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue ) { /* do nothing */ diff --git a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/ProxyConnectorOrderComparator.java b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/ProxyConnectorOrderComparator.java index de3b9c84c..8acb4ee52 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/ProxyConnectorOrderComparator.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/ProxyConnectorOrderComparator.java @@ -38,6 +38,7 @@ public class ProxyConnectorOrderComparator return INSTANCE; } + @Override public int compare( ProxyConnector o1, ProxyConnector o2 ) { if ( o1 == null && o2 == null ) diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/MockRepositoryArchivaTaskScheduler.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/MockRepositoryArchivaTaskScheduler.java index fa8b00c8e..2b8b9ab63 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/MockRepositoryArchivaTaskScheduler.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/MockRepositoryArchivaTaskScheduler.java @@ -30,22 +30,26 @@ import org.springframework.stereotype.Service; public class MockRepositoryArchivaTaskScheduler implements RepositoryArchivaTaskScheduler { + @Override public boolean isProcessingRepositoryTask( String repositoryId ) { return false; } + @Override public boolean isProcessingRepositoryTask( RepositoryTask task ) { return false; } + @Override public void queueTask( RepositoryTask task ) throws TaskQueueException { // no op } + @Override public boolean unQueueTask( RepositoryTask task ) throws TaskQueueException { diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java index 533951968..1e575224d 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java @@ -37,157 +37,187 @@ import java.util.List; public class TestMetadataRepository implements MetadataRepository { + @Override public ProjectMetadata getProject( String repoId, String namespace, String projectId ) { return null; } + @Override public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId, String projectVersion ) { return null; } + @Override public Collection getArtifactVersions( String repoId, String namespace, String projectId, String projectVersion ) { return Collections.emptyList(); } + @Override public Collection getProjectReferences( String repoId, String namespace, String projectId, String projectVersion ) { return Collections.emptyList(); } + @Override public Collection getRootNamespaces( String repoId ) { return Collections.emptyList(); } + @Override public Collection getNamespaces( String repoId, String namespace ) { return Collections.emptyList(); } + @Override public Collection getProjects( String repoId, String namespace ) { return Collections.emptyList(); } + @Override public Collection getProjectVersions( String repoId, String namespace, String projectId ) { return Collections.emptyList(); } + @Override public void updateProject( String repoId, ProjectMetadata project ) { // no op } + @Override public void updateArtifact( String repoId, String namespace, String projectId, String projectVersion, ArtifactMetadata artifactMeta ) { // no op } + @Override public void updateProjectVersion( String repoId, String namespace, String projectId, ProjectVersionMetadata versionMetadata ) { // no op } + @Override public void updateNamespace( String repoId, String namespace ) { // no op } + @Override public List getMetadataFacets( String repodId, String facetId ) { return Collections.emptyList(); } + @Override public MetadataFacet getMetadataFacet( String repositoryId, String facetId, String name ) { return null; } + @Override public void addMetadataFacet( String repositoryId, MetadataFacet metadataFacet ) { // no op } + @Override public void removeMetadataFacets( String repositoryId, String facetId ) { // no op } + @Override public void removeMetadataFacet( String repoId, String facetId, String name ) { // no op } + @Override public List getArtifactsByDateRange( String repoId, Date startTime, Date endTime ) { return Collections.emptyList(); } + @Override public Collection getRepositories() { return Collections.emptyList(); } + @Override public List getArtifactsByChecksum( String repoId, String checksum ) { return Collections.emptyList(); } + @Override public void removeArtifact( String repositoryId, String namespace, String project, String version, String id ) { // no op } + @Override public void removeRepository( String repoId ) { // no op } + @Override public Collection getArtifacts( String repoId, String namespace, String projectId, String projectVersion ) { return Collections.emptyList(); } + @Override public void save() { // no op } + @Override public void close() { // no op } + @Override public void revert() { // no op } + @Override public boolean canObtainAccess( Class aClass ) { return false; } + @Override public T obtainAccess( Class aClass ) { return null; //To change body of implemented methods use File | Settings | File Templates. } + @Override public List getArtifacts( String repositoryId ) { return Collections.emptyList(); } + @Override public void removeArtifact( String repositoryId, String namespace, String project, String version, MetadataFacet metadataFacet ) throws MetadataRepositoryException @@ -195,30 +225,35 @@ public class TestMetadataRepository throw new UnsupportedOperationException(); } + @Override public void removeArtifact( ArtifactMetadata artifactMetadata, String baseVersion ) throws MetadataRepositoryException { throw new UnsupportedOperationException(); } + @Override public void removeNamespace( String repositoryId, String namespace ) throws MetadataRepositoryException { } + @Override public void removeProjectVersion( String repoId, String namespace, String projectId, String projectVersion ) throws MetadataRepositoryException { } + @Override public void removeProject( String repositoryId, String namespace, String projectId ) throws MetadataRepositoryException { throw new UnsupportedOperationException(); } + @Override public boolean hasMetadataFacet( String repositoryId, String facetId ) throws MetadataRepositoryException { diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestRepositorySessionFactory.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestRepositorySessionFactory.java index 38a421ac1..61aeeb384 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestRepositorySessionFactory.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestRepositorySessionFactory.java @@ -1,7 +1,6 @@ package org.apache.archiva.metadata.repository; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Configurable; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Startable; import org.springframework.stereotype.Service; @@ -29,6 +28,7 @@ public class TestRepositorySessionFactory { private MetadataResolver resolver; + @Override public RepositorySession createSession() { return new RepositorySession( new TestMetadataRepository(), resolver ); diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java index e3f39d2ec..7470d05be 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java @@ -38,7 +38,6 @@ import org.apache.archiva.proxy.model.RepositoryProxyConnectors; import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.ArrayUtils; import org.apache.maven.index.NexusIndexer; import org.apache.maven.index.context.IndexingContext; import org.apache.maven.wagon.Wagon; diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java index b8647c6a3..b96a261ed 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java @@ -138,6 +138,7 @@ public class HttpProxyTransferTest Handler handler = new AbstractHandler() { + @Override public void handle( String s, Request request, HttpServletRequest httpServletRequest, HttpServletResponse response ) throws IOException, ServletException diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java index 20490acf5..7cd49a652 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java @@ -82,16 +82,19 @@ public class MockConfiguration } ); } + @Override public void addChangeListener( org.apache.archiva.redback.components.registry.RegistryListener listener ) { registryListeners.add( listener ); } + @Override public Configuration getConfiguration() { return configuration; } + @Override public void save( Configuration configuration ) throws RegistryException { @@ -113,21 +116,25 @@ public class MockConfiguration } } + @Override public void addListener( ConfigurationListener listener ) { configListeners.add( listener ); } + @Override public void removeListener( ConfigurationListener listener ) { configListeners.remove( listener ); } + @Override public boolean isDefaulted() { return false; } + @Override public void reload() { // no op diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/WagonDelegate.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/WagonDelegate.java index 71cd32262..56edc448d 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/WagonDelegate.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/WagonDelegate.java @@ -54,6 +54,7 @@ public class WagonDelegate private String contentToGet; + @Override public void get( String resourceName, File destination ) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException { @@ -62,6 +63,7 @@ public class WagonDelegate create( destination ); } + @Override public boolean getIfNewer( String resourceName, File destination, long timestamp ) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException { @@ -72,18 +74,21 @@ public class WagonDelegate return result; } + @Override public void put( File source, String destination ) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException { delegate.put( source, destination ); } + @Override public void putDirectory( File sourceDirectory, String destinationDirectory ) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException { delegate.putDirectory( sourceDirectory, destinationDirectory ); } + @Override public boolean resourceExists( String resourceName ) throws TransferFailedException, AuthorizationException { @@ -91,72 +96,85 @@ public class WagonDelegate } @SuppressWarnings ("unchecked") + @Override public List getFileList( String destinationDirectory ) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException { return delegate.getFileList( destinationDirectory ); } + @Override public boolean supportsDirectoryCopy() { return delegate.supportsDirectoryCopy(); } + @Override public void setTimeout( int val ) { // ignore } + @Override public int getTimeout() { return 0; } + @Override public void setReadTimeout( int timeoutValue ) { // ignore } + @Override public int getReadTimeout() { return 0; } + @Override public Repository getRepository() { return delegate.getRepository(); } + @Override public void connect( Repository source ) throws ConnectionException, AuthenticationException { delegate.connect( source ); } + @Override public void connect( Repository source, ProxyInfo proxyInfo ) throws ConnectionException, AuthenticationException { delegate.connect( source, proxyInfo ); } + @Override public void connect( Repository source, ProxyInfoProvider proxyInfoProvider ) throws ConnectionException, AuthenticationException { delegate.connect( source, proxyInfoProvider ); } + @Override public void connect( Repository source, AuthenticationInfo authenticationInfo ) throws ConnectionException, AuthenticationException { delegate.connect( source, authenticationInfo ); } + @Override public void connect( Repository source, AuthenticationInfo authenticationInfo, ProxyInfo proxyInfo ) throws ConnectionException, AuthenticationException { delegate.connect( source, authenticationInfo, proxyInfo ); } + @Override public void connect( Repository source, AuthenticationInfo authenticationInfo, ProxyInfoProvider proxyInfoProvider ) throws ConnectionException, AuthenticationException { @@ -164,53 +182,63 @@ public class WagonDelegate } @SuppressWarnings ("deprecation") + @Override public void openConnection() throws ConnectionException, AuthenticationException { delegate.openConnection(); } + @Override public void disconnect() throws ConnectionException { delegate.disconnect(); } + @Override public void addSessionListener( SessionListener listener ) { delegate.addSessionListener( listener ); } + @Override public void removeSessionListener( SessionListener listener ) { delegate.removeSessionListener( listener ); } + @Override public boolean hasSessionListener( SessionListener listener ) { return delegate.hasSessionListener( listener ); } + @Override public void addTransferListener( TransferListener listener ) { delegate.addTransferListener( listener ); } + @Override public void removeTransferListener( TransferListener listener ) { delegate.removeTransferListener( listener ); } + @Override public boolean hasTransferListener( TransferListener listener ) { return delegate.hasTransferListener( listener ); } + @Override public boolean isInteractive() { return delegate.isInteractive(); } + @Override public void setInteractive( boolean interactive ) { delegate.setInteractive( interactive ); -- 2.39.5