]> source.dussan.org Git - archiva.git/commitdiff
Multicatch and override
authorEric Barboni <skygo@apache.org>
Fri, 11 Apr 2014 21:29:44 +0000 (23:29 +0200)
committerEric Barboni <skygo@apache.org>
Fri, 11 Apr 2014 21:29:44 +0000 (23:29 +0200)
archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java
archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/ProxyConnectorOrderComparator.java
archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/MockRepositoryArchivaTaskScheduler.java
archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java
archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestRepositorySessionFactory.java
archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/AbstractProxyTestCase.java
archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/HttpProxyTransferTest.java
archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java
archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/WagonDelegate.java

index 1d2ff6e7dae9e7735b5c04c080bec9151a69fe83..c4b8b0f11dc9faabee73f512fb8cfd8e3f413004 100644 (file)
@@ -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<String, List<ProxyConnector>> proxyConnectorMap = new HashMap<>();
 
-    private Map<String, ProxyInfo> networkProxyMap = new ConcurrentHashMap<String, ProxyInfo>();
+    private Map<String, ProxyInfo> 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<ProxyConnector> connectors = getProxyConnectors( repository );
-        Map<String, Exception> previousExceptions = new LinkedHashMap<String, Exception>();
+        Map<String, Exception> 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<ProxyConnector> 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 */
index de3b9c84c2e76ff93a112ee1204849a3eb60d753..8acb4ee525d30021a2d6abebfcc8caed5baca378 100644 (file)
@@ -38,6 +38,7 @@ public class ProxyConnectorOrderComparator
         return INSTANCE;
     }
 
+    @Override
     public int compare( ProxyConnector o1, ProxyConnector o2 )
     {
         if ( o1 == null && o2 == null )
index fa8b00c8ede3486e92901cc411f9d8a83763fd43..2b8b9ab6345c79f69ffd037c11c95eedfac7d672 100644 (file)
@@ -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
     {
index 533951968c53005e95458caee590bd39e057dee3..1e575224d904a6a74c1dd31b32b90431308f0cc2 100644 (file)
@@ -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<String> getArtifactVersions( String repoId, String namespace, String projectId,
                                                    String projectVersion )
     {
         return Collections.emptyList();
     }
 
+    @Override
     public Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId,
                                                                      String projectVersion )
     {
         return Collections.emptyList();
     }
 
+    @Override
     public Collection<String> getRootNamespaces( String repoId )
     {
         return Collections.emptyList();
     }
 
+    @Override
     public Collection<String> getNamespaces( String repoId, String namespace )
     {
         return Collections.emptyList();
     }
 
+    @Override
     public Collection<String> getProjects( String repoId, String namespace )
     {
         return Collections.emptyList();
     }
 
+    @Override
     public Collection<String> 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<String> 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<ArtifactMetadata> getArtifactsByDateRange( String repoId, Date startTime, Date endTime )
     {
         return Collections.emptyList();
     }
 
+    @Override
     public Collection<String> getRepositories()
     {
         return Collections.emptyList();
     }
 
+    @Override
     public List<ArtifactMetadata> 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<ArtifactMetadata> 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>T obtainAccess( Class<T> aClass )
     {
         return null;  //To change body of implemented methods use File | Settings | File Templates.
     }
 
+    @Override
     public List<ArtifactMetadata> 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
     {
index 38a421ac12305152b2f2e6ee7d5b1c2eef1b0770..61aeeb3844f5144f2645ece163e2414c22840f2b 100644 (file)
@@ -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 );
index e3f39d2ecaa75cee855b2305a8dfeeb515dcdbc9..7470d05be62cc45baf3ebc1920de5035a29bf11e 100644 (file)
@@ -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;
index b8647c6a3ceb30ce0cb6a60494f1a92745f0eb07..b96a261ed00955359312cb1e46ffc5cae1ef266a 100644 (file)
@@ -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
index 20490acf5dd54f8f361f921785ded8ffd12be206..7cd49a6520b064b12ff8a158eb85f6b540f4cade 100644 (file)
@@ -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
index 71cd32262e2f39af507ff9e209efe69fbbe6afe3..56edc448dc9bbe36f4c74f7c65683b60b3576643 100644 (file)
@@ -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<String> 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 );