From 83df105260c3fe5c2a7f6fb90230426074cb37ae Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Sun, 1 Apr 2018 19:40:26 +0200 Subject: [PATCH] Reducing compiler warnings --- .../ProxyConnectorSelectionPredicate.java | 4 +- .../core/MetadataUpdaterConsumer.java | 33 +------------ ...eanupReleasedSnapshotsRepositoryPurge.java | 46 ++----------------- .../indexer/maven/MavenIndexContext.java | 1 + .../maven/search/MavenRepositorySearch.java | 3 +- .../DefaultRepositoryProxyConnectors.java | 2 +- .../DefaultProxyConnectorAdmin.java | 4 +- .../RepositoryContentConsumersTest.java | 34 ++++++++------ .../archiva-scheduler-indexing/pom.xml | 1 - .../TemporaryGroupIndexSessionCleaner.java | 2 +- .../repository/storage/maven2/MockWagon.java | 1 + .../index/mock/MavenIndexContextMock.java | 1 + .../maven2/MavenRepositoryProviderTest.java | 4 +- .../metadata/MetadataToolsTest.java | 1 + 14 files changed, 40 insertions(+), 97 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/functors/ProxyConnectorSelectionPredicate.java b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/functors/ProxyConnectorSelectionPredicate.java index 4cc234a10..209f75ad5 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/functors/ProxyConnectorSelectionPredicate.java +++ b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/functors/ProxyConnectorSelectionPredicate.java @@ -29,7 +29,7 @@ import org.apache.commons.lang.StringUtils; * */ public class ProxyConnectorSelectionPredicate - implements Predicate + implements Predicate { private String sourceId; @@ -42,7 +42,7 @@ public class ProxyConnectorSelectionPredicate } @Override - public boolean evaluate( Object object ) + public boolean evaluate( ProxyConnectorConfiguration object ) { boolean satisfies = false; diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/MetadataUpdaterConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/MetadataUpdaterConsumer.java index aef12a553..1689eeec9 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/MetadataUpdaterConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/MetadataUpdaterConsumer.java @@ -213,17 +213,9 @@ public class MetadataUpdaterConsumer log.debug( "Skipping uptodate metadata: {}", this.metadataTools.toPath( projectRef ) ); return; } - - metadataTools.updateMetadata( this.repository, projectRef ); + metadataTools.updateMetadata( this.repository, metadataPath ); log.debug( "Updated metadata: {}", this.metadataTools.toPath( projectRef ) ); } - catch ( LayoutException e ) - { - log.warn( "Unable to convert path [{}] to an internal project reference: ", path, e ); - triggerConsumerWarning( TYPE_METADATA_BAD_INTERNAL_REF, - "Unable to convert path [" + path + "] to an internal project reference: " - + e.getMessage( ) ); - } catch ( RepositoryMetadataException e ) { log.error( "Unable to write project metadat for artifact [{}]:", path, e ); @@ -236,13 +228,6 @@ public class MetadataUpdaterConsumer triggerConsumerWarning( TYPE_METADATA_IO, "Project metadata not written due to IO warning: " + e.getMessage( ) ); } - catch ( ContentNotFoundException e ) - { - log.warn( "Project metadata not written because no versions were found to update: ", e ); - triggerConsumerWarning( TYPE_METADATA_IO, - "Project metadata not written because no versions were found to update: " - + e.getMessage( ) ); - } } private void updateVersionMetadata( ArtifactReference artifact, String path ) @@ -265,16 +250,9 @@ public class MetadataUpdaterConsumer return; } - metadataTools.updateMetadata( this.repository, versionRef ); + metadataTools.updateMetadata( this.repository, metadataPath ); log.debug( "Updated metadata: {}", this.metadataTools.toPath( versionRef ) ); } - catch ( LayoutException e ) - { - log.warn( "Unable to convert path [{}] to an internal version reference: ", path, e ); - triggerConsumerWarning( TYPE_METADATA_BAD_INTERNAL_REF, - "Unable to convert path [" + path + "] to an internal version reference: " - + e.getMessage( ) ); - } catch ( RepositoryMetadataException e ) { log.error( "Unable to write version metadata for artifact [{}]: ", path, e ); @@ -287,13 +265,6 @@ public class MetadataUpdaterConsumer triggerConsumerWarning( TYPE_METADATA_IO, "Version metadata not written due to IO warning: " + e.getMessage( ) ); } - catch ( ContentNotFoundException e ) - { - log.warn( "Version metadata not written because no versions were found to update: ", e ); - triggerConsumerWarning( TYPE_METADATA_IO, - "Version metadata not written because no versions were found to update: " - + e.getMessage( ) ); - } } /* diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java index ce6dc2803..f30bf6a4f 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/repository/CleanupReleasedSnapshotsRepositoryPurge.java @@ -166,7 +166,7 @@ public class CleanupReleasedSnapshotsRepositoryPurge if ( needsMetadataUpdate ) { - updateMetadata( artifactRef ); + updateMetadata( path ); } } catch ( LayoutException e ) @@ -183,57 +183,17 @@ public class CleanupReleasedSnapshotsRepositoryPurge } } - private void updateMetadata( ArtifactReference artifact ) + private void updateMetadata( String path ) { - VersionedReference versionRef = new VersionedReference( ); - versionRef.setGroupId( artifact.getGroupId( ) ); - versionRef.setArtifactId( artifact.getArtifactId( ) ); - versionRef.setVersion( artifact.getVersion( ) ); - - ProjectReference projectRef = new ProjectReference( ); - projectRef.setGroupId( artifact.getGroupId( ) ); - projectRef.setArtifactId( artifact.getArtifactId( ) ); try { - metadataTools.updateMetadata( repository, versionRef ); - } - catch ( ContentNotFoundException e ) - { - // Ignore. (Just means we have no snapshot versions left to reference). + metadataTools.updateMetadata( repository, path ); } catch ( RepositoryMetadataException e ) - { - // Ignore. - } - catch ( IOException e ) - { - // Ignore. - } - catch ( LayoutException e ) { // Ignore. } - try - { - metadataTools.updateMetadata( repository, projectRef ); - } - catch ( ContentNotFoundException e ) - { - // Ignore. (Just means we have no snapshot versions left to reference). - } - catch ( RepositoryMetadataException e ) - { - // Ignore. - } - catch ( IOException e ) - { - // Ignore. - } - catch ( LayoutException e ) - { - // Ignore. - } } } diff --git a/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexContext.java b/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexContext.java index 37f602f79..e031922fb 100644 --- a/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexContext.java +++ b/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexContext.java @@ -108,6 +108,7 @@ public class MavenIndexContext implements ArchivaIndexingContext { return IndexingContext.class.equals(clazz); } + @SuppressWarnings( "unchecked" ) @Override public T getBaseContext(Class clazz) throws UnsupportedOperationException { if (IndexingContext.class.equals(clazz)) { diff --git a/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearch.java b/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearch.java index 5d0698fb6..6a7c9fd83 100644 --- a/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearch.java +++ b/archiva-modules/archiva-base/archiva-maven2-indexer/src/main/java/org/apache/archiva/indexer/maven/search/MavenRepositorySearch.java @@ -145,6 +145,7 @@ public class MavenRepositorySearch /** * @see RepositorySearch#search(String, SearchFields, SearchResultLimits) */ + @SuppressWarnings( "deprecation" ) @Override public SearchResults search( String principal, SearchFields searchFields, SearchResultLimits limits ) throws RepositorySearchException @@ -325,7 +326,7 @@ public class MavenRepositorySearch FlatSearchResponse response = indexer.searchFlat( request ); - if ( response == null || response.getTotalHits() == 0 ) + if ( response == null || response.getTotalHitsCount() == 0 ) { SearchResults results = new SearchResults(); results.setLimits( limits ); 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 ebb5463a3..94fb690ae 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 @@ -144,7 +144,7 @@ public class DefaultRepositoryProxyConnectors @Inject @Named(value = "archivaTaskScheduler#repository") - private ArchivaTaskScheduler scheduler; + private ArchivaTaskScheduler scheduler; @Inject private RepositoryRegistry repositoryRegistry; diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/proxyconnector/DefaultProxyConnectorAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/proxyconnector/DefaultProxyConnectorAdmin.java index 52943c1c0..18cf3a3a0 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/proxyconnector/DefaultProxyConnectorAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/proxyconnector/DefaultProxyConnectorAdmin.java @@ -29,7 +29,7 @@ import org.apache.archiva.configuration.ProxyConnectorConfiguration; import org.apache.archiva.configuration.functors.ProxyConnectorSelectionPredicate; import org.apache.archiva.metadata.model.facets.AuditEvent; import org.apache.archiva.repository.RepositoryRegistry; -import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.IterableUtils; import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Service; @@ -205,7 +205,7 @@ public class DefaultProxyConnectorAdmin } ProxyConnectorSelectionPredicate selectedProxy = new ProxyConnectorSelectionPredicate( sourceId, targetId ); - return (ProxyConnectorConfiguration) CollectionUtils.find( configuration.getProxyConnectors(), selectedProxy ); + return IterableUtils.find( configuration.getProxyConnectors(), selectedProxy ); } protected ProxyConnectorConfiguration getProxyConnectorConfiguration( ProxyConnector proxyConnector ) diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java index 6148fe58e..2537a62ab 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java @@ -23,6 +23,7 @@ import junit.framework.TestCase; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; import org.apache.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.consumers.RepositoryContentConsumer; import org.apache.archiva.repository.BasicManagedRepository; import org.apache.archiva.repository.BasicRemoteRepository; import org.apache.archiva.repository.ManagedRepository; @@ -59,6 +60,7 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.function.Function; import static org.easymock.EasyMock.*; @@ -347,16 +349,20 @@ public class RepositoryContentConsumersTest return path; } - private static Map convertToMap( List objects ) + private static Map convertToMap( List objects) { - HashMap map = new HashMap(); - for ( Object o : objects ) + HashMap map = new HashMap<>(); + for ( T o : objects ) { - map.put( o, o ); + map.put( o.toString(), o ); } return map; } + private static Function,Map> getConversionFunction(Class type) { + return ts -> convertToMap( ts ); + } + public class MockApplicationContext implements ApplicationContext { @@ -445,23 +451,25 @@ public class RepositoryContentConsumersTest throw new UnsupportedOperationException( "Not supported yet." ); } + @SuppressWarnings( "unchecked" ) @Override - public Map getBeansOfType( Class type ) + public Map getBeansOfType( Class type ) throws BeansException { - if ( type == KnownRepositoryContentConsumer.class ) - { - return convertToMap( knownRepositoryContentConsumer ); + List list = null; + if (type == KnownRepositoryContentConsumer.class) { + list = (List) knownRepositoryContentConsumer; + } else if (type == InvalidRepositoryContentConsumer.class) { + list = (List) invalidRepositoryContentConsumers; } - if ( type == InvalidRepositoryContentConsumer.class ) - { - return convertToMap( invalidRepositoryContentConsumers ); + if (list!=null) { + return getConversionFunction( type ).apply( list ); } throw new UnsupportedOperationException( "Should not have been called" ); } @Override - public Map getBeansOfType( Class type, boolean includeNonSingletons, boolean allowEagerInit ) + public Map getBeansOfType( Class type, boolean includeNonSingletons, boolean allowEagerInit ) throws BeansException { throw new UnsupportedOperationException( "Not supported yet." ); @@ -487,7 +495,7 @@ public class RepositoryContentConsumersTest } @Override - public Object getBean( String name, Class requiredType ) + public T getBean( String name, Class requiredType ) throws BeansException { throw new UnsupportedOperationException( "Not supported yet." ); diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/pom.xml b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/pom.xml index 66e6e5efb..170140dcc 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/pom.xml +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/pom.xml @@ -227,7 +227,6 @@ org.apache.archiva.scheduler;version=${project.version}, org.apache.commons.io;version="[1.4,2)", org.apache.commons.lang*;version="[2.4,3)", - org.apache.lucene*;version="[3,4)", org.springframework*;version="[3,4)", org.apache.archiva.redback.components.taskqueue*, org.apache.maven.index*, diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/TemporaryGroupIndexSessionCleaner.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/TemporaryGroupIndexSessionCleaner.java index a9ccb8db3..02c4125a4 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/TemporaryGroupIndexSessionCleaner.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/TemporaryGroupIndexSessionCleaner.java @@ -68,7 +68,7 @@ public class TemporaryGroupIndexSessionCleaner @Override public void sessionDestroyed( HttpSessionEvent httpSessionEvent ) { - Map tempFilesPerKey = + @SuppressWarnings( "unchecked" ) Map tempFilesPerKey = (Map) httpSessionEvent.getSession().getAttribute( TEMPORARY_INDEX_SESSION_KEY ); diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/MockWagon.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/MockWagon.java index b85889a75..f28f77798 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/MockWagon.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/MockWagon.java @@ -147,6 +147,7 @@ public class MockWagon } + @Deprecated @Override public void openConnection() throws ConnectionException, AuthenticationException diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/index/mock/MavenIndexContextMock.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/index/mock/MavenIndexContextMock.java index d5f323c5e..e0db09597 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/index/mock/MavenIndexContextMock.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/index/mock/MavenIndexContextMock.java @@ -108,6 +108,7 @@ public class MavenIndexContextMock implements ArchivaIndexingContext { return IndexingContext.class.equals(clazz); } + @SuppressWarnings( "unchecked" ) @Override public T getBaseContext(Class clazz) throws UnsupportedOperationException { if (IndexingContext.class.equals(clazz)) { diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/maven2/MavenRepositoryProviderTest.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/maven2/MavenRepositoryProviderTest.java index 8731c7c5a..9030f6581 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/maven2/MavenRepositoryProviderTest.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/maven2/MavenRepositoryProviderTest.java @@ -154,11 +154,11 @@ public class MavenRepositoryProviderTest repo.setUrl( "https://repo.maven.apache.org/maven2/test" ); repo.setDownloadRemoteIndex( true ); repo.setDownloadRemoteIndexOnStartup( true ); - Map header = new HashMap( ); + Map header = new HashMap<>( ); header.put("header1","value1"); header.put("header2","value2"); repo.setExtraHeaders( header ); - Map params = new HashMap( ); + Map params = new HashMap<>( ); params.put("param1","pval1"); params.put("param2","pval2"); repo.setExtraParameters( params ); diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/metadata/MetadataToolsTest.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/metadata/MetadataToolsTest.java index e1be3e449..5271cc63e 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/metadata/MetadataToolsTest.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/repository/metadata/MetadataToolsTest.java @@ -60,6 +60,7 @@ import static org.junit.Assert.*; /** * MetadataToolsTest */ +@SuppressWarnings( "deprecation" ) @ContextConfiguration ( { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-metadata-tools-test.xml" } ) public class MetadataToolsTest -- 2.39.5