diff options
author | Martin Stockhammer <martin_s@apache.org> | 2018-04-02 10:28:31 +0200 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2018-04-02 10:46:34 +0200 |
commit | 0f400d66a309e76d55a15e965cb551bfcf7b0b3d (patch) | |
tree | 1ded14450ab088458c290e6095290dad46c919e9 | |
parent | d422c877838b7893f7f34344e6a60665a2537073 (diff) | |
download | archiva-0f400d66a309e76d55a15e965cb551bfcf7b0b3d.tar.gz archiva-0f400d66a309e76d55a15e965cb551bfcf7b0b3d.zip |
Adding generics and reducing compiler warnings
10 files changed, 108 insertions, 100 deletions
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/functors/ConsumerWantsFilePredicate.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/functors/ConsumerWantsFilePredicate.java index 53267dc13..7011aadcc 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/functors/ConsumerWantsFilePredicate.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/functors/ConsumerWantsFilePredicate.java @@ -37,7 +37,7 @@ import java.util.List; * ConsumerWantsFilePredicate */ public class ConsumerWantsFilePredicate - implements Predicate + implements Predicate<RepositoryContentConsumer> { private BaseFile basefile; @@ -49,12 +49,12 @@ public class ConsumerWantsFilePredicate private ManagedRepository managedRepository; - private Logger logger = LoggerFactory.getLogger( getClass() ); + private Logger logger = LoggerFactory.getLogger( getClass( ) ); /** * @deprecated use constructor with ManagedRepository */ - public ConsumerWantsFilePredicate() + public ConsumerWantsFilePredicate( ) { // no-op } @@ -65,28 +65,25 @@ public class ConsumerWantsFilePredicate } @Override - public boolean evaluate( Object object ) + public boolean evaluate( RepositoryContentConsumer object ) { boolean satisfies = false; - if ( object instanceof RepositoryContentConsumer ) + RepositoryContentConsumer consumer = (RepositoryContentConsumer) object; + if ( wantsFile( consumer, FilenameUtils.separatorsToUnix( basefile.getRelativePath( ) ) ) ) { - RepositoryContentConsumer consumer = (RepositoryContentConsumer) object; - if ( wantsFile( consumer, FilenameUtils.separatorsToUnix( basefile.getRelativePath() ) ) ) - { - satisfies = true; + satisfies = true; - // regardless of the timestamp, we record that it was wanted so it doesn't get counted as invalid - wantedFileCount++; + // regardless of the timestamp, we record that it was wanted so it doesn't get counted as invalid + wantedFileCount++; - if ( !consumer.isProcessUnmodified() ) + if ( !consumer.isProcessUnmodified( ) ) + { + // Timestamp finished points to the last successful scan, not this current one. + if ( basefile.lastModified( ) < changesSince ) { - // Timestamp finished points to the last successful scan, not this current one. - if ( basefile.lastModified() < changesSince ) - { - // Skip file as no change has occurred. - satisfies = false; - } + // Skip file as no change has occurred. + satisfies = false; } } } @@ -94,17 +91,17 @@ public class ConsumerWantsFilePredicate return satisfies; } - public BaseFile getBasefile() + public BaseFile getBasefile( ) { return basefile; } - public int getWantedFileCount() + public int getWantedFileCount( ) { return wantedFileCount; } - public boolean isCaseSensitive() + public boolean isCaseSensitive( ) { return isCaseSensitive; } @@ -123,7 +120,7 @@ public class ConsumerWantsFilePredicate private boolean wantsFile( RepositoryContentConsumer consumer, String relativePath ) { // Test excludes first. - List<String> excludes = consumer.getExcludes(); + List<String> excludes = consumer.getExcludes( ); if ( excludes != null ) { for ( String pattern : excludes ) @@ -139,18 +136,24 @@ public class ConsumerWantsFilePredicate if ( managedRepository != null ) { String indexDirectory; - if (managedRepository.supportsFeature( IndexCreationFeature.class )) { - IndexCreationFeature icf = managedRepository.getFeature( IndexCreationFeature.class ).get(); - if (icf.getIndexPath()==null) { - indexDirectory=".index"; - } else + if ( managedRepository.supportsFeature( IndexCreationFeature.class ) ) + { + IndexCreationFeature icf = managedRepository.getFeature( IndexCreationFeature.class ).get( ); + if ( icf.getIndexPath( ) == null ) + { + indexDirectory = ".index"; + } + else { indexDirectory = ( icf.getIndexPath( ).getScheme( ) == null ? Paths.get( icf.getIndexPath( ).getPath( ) ) : Paths.get( icf.getIndexPath( ) ) ).toString( ); } - } else { + } + else + { indexDirectory = ".index"; } - if (StringUtils.isEmpty( indexDirectory )) { + if ( StringUtils.isEmpty( indexDirectory ) ) + { indexDirectory = ".index"; } if ( StringUtils.startsWith( relativePath, indexDirectory ) ) @@ -161,7 +164,7 @@ public class ConsumerWantsFilePredicate } // Now test includes. - for ( String pattern : consumer.getIncludes() ) + for ( String pattern : consumer.getIncludes( ) ) { if ( SelectorUtils.matchPath( pattern, relativePath, isCaseSensitive ) ) { diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryContentConsumers.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryContentConsumers.java index b561c112b..0cbc0aa6a 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryContentConsumers.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryContentConsumers.java @@ -26,6 +26,7 @@ import org.apache.archiva.common.utils.PathUtil; 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.consumers.functors.ConsumerWantsFilePredicate; import org.apache.archiva.redback.components.registry.RegistryListener; import org.apache.archiva.repository.ManagedRepository; @@ -275,7 +276,7 @@ public class RepositoryContentConsumers // Run the repository consumers try { - Closure triggerBeginScan = new TriggerBeginScanClosure( repository, getStartTime(), false ); + Closure<RepositoryContentConsumer> triggerBeginScan = new TriggerBeginScanClosure( repository, getStartTime(), false ); selectedKnownConsumers = getSelectedKnownConsumers(); @@ -312,7 +313,7 @@ public class RepositoryContentConsumers closure.setBasefile( baseFile ); closure.setExecuteOnEntireRepo( false ); - Closure processIfWanted = IfClosure.ifClosure( predicate, closure ); + Closure<RepositoryContentConsumer> processIfWanted = IfClosure.ifClosure( predicate, closure ); IterableUtils.forEach( selectedKnownConsumers, processIfWanted ); diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/ConsumerProcessFileClosure.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/ConsumerProcessFileClosure.java index 6cd9b21cf..68728741b 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/ConsumerProcessFileClosure.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/ConsumerProcessFileClosure.java @@ -28,62 +28,59 @@ import org.slf4j.LoggerFactory; import java.util.Map; /** - * ConsumerProcessFileClosure - * + * ConsumerProcessFileClosure */ public class ConsumerProcessFileClosure - implements Closure + implements Closure<RepositoryContentConsumer> { private Logger log = LoggerFactory.getLogger( ConsumerProcessFileClosure.class ); - + private BaseFile basefile; private boolean executeOnEntireRepo; - private Map<String,Long> consumerTimings; - - private Map<String,Long> consumerCounts; + private Map<String, Long> consumerTimings; + + private Map<String, Long> consumerCounts; @Override - public void execute( Object input ) + public void execute( RepositoryContentConsumer input ) { - if ( input instanceof RepositoryContentConsumer ) + RepositoryContentConsumer consumer = (RepositoryContentConsumer) input; + + String id = consumer.getId( ); + try { - RepositoryContentConsumer consumer = (RepositoryContentConsumer) input; + log.debug( "Sending to consumer: {}", id ); + + long startTime = System.currentTimeMillis( ); + consumer.processFile( basefile.getRelativePath( ), executeOnEntireRepo ); + long endTime = System.currentTimeMillis( ); - String id = consumer.getId(); - try + if ( consumerTimings != null ) { - log.debug( "Sending to consumer: {}", id ); - - long startTime = System.currentTimeMillis(); - consumer.processFile( basefile.getRelativePath(), executeOnEntireRepo ); - long endTime = System.currentTimeMillis(); - - if ( consumerTimings != null ) - { - Long value = consumerTimings.get( id ); - consumerTimings.put( id, ( value != null ? value : 0 ) + endTime - startTime ); - } - - if ( consumerCounts != null ) - { - Long value = consumerCounts.get( id ); - consumerCounts.put( id, ( value != null ? value : 0 ) + 1 ); - } + Long value = consumerTimings.get( id ); + consumerTimings.put( id, ( value != null ? value : 0 ) + endTime - startTime ); } - catch ( Exception e ) + + if ( consumerCounts != null ) { - /* Intentionally Catch all exceptions. - * So that the discoverer processing can continue. - */ - log.error( "Consumer [{}] had an error when processing file [" - + "{}]: {}", id, basefile.getAbsolutePath(), e.getMessage(), e ); + Long value = consumerCounts.get( id ); + consumerCounts.put( id, ( value != null ? value : 0 ) + 1 ); } } + catch ( Exception e ) + { + /* Intentionally Catch all exceptions. + * So that the discoverer processing can continue. + */ + log.error( "Consumer [{}] had an error when processing file [" + + "{}]: {}", id, basefile.getAbsolutePath( ), e.getMessage( ), e ); + } + } - public BaseFile getBasefile() + public BaseFile getBasefile( ) { return basefile; } @@ -93,7 +90,7 @@ public class ConsumerProcessFileClosure this.basefile = basefile; } - public boolean isExecuteOnEntireRepo() + public boolean isExecuteOnEntireRepo( ) { return executeOnEntireRepo; } @@ -113,7 +110,7 @@ public class ConsumerProcessFileClosure this.consumerCounts = consumerCounts; } - public Logger getLogger() + public Logger getLogger( ) { return log; } diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerBeginScanClosure.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerBeginScanClosure.java index 8bd6d8e9a..209f29c71 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerBeginScanClosure.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerBeginScanClosure.java @@ -29,17 +29,15 @@ import org.slf4j.LoggerFactory; import java.util.Date; /** - * TriggerBeginScanClosure - * - * + * TriggerBeginScanClosure */ public class TriggerBeginScanClosure - implements Closure + implements Closure<RepositoryContentConsumer> { private Logger log = LoggerFactory.getLogger( TriggerBeginScanClosure.class ); - + private ManagedRepository repository; - + private Date whenGathered; private boolean executeOnEntireRepo = true; @@ -48,7 +46,7 @@ public class TriggerBeginScanClosure { this.repository = repository; } - + public TriggerBeginScanClosure( ManagedRepository repository, Date whenGathered ) { this( repository ); @@ -62,20 +60,17 @@ public class TriggerBeginScanClosure } @Override - public void execute( Object input ) + public void execute( RepositoryContentConsumer input ) { - if ( input instanceof RepositoryContentConsumer ) + RepositoryContentConsumer consumer = (RepositoryContentConsumer) input; + + try + { + consumer.beginScan( repository, whenGathered, executeOnEntireRepo ); + } + catch ( ConsumerException e ) { - RepositoryContentConsumer consumer = (RepositoryContentConsumer) input; - - try - { - consumer.beginScan( repository, whenGathered, executeOnEntireRepo ); - } - catch ( ConsumerException e ) - { - log.warn( "Consumer [{}] cannot begin: {}",consumer.getId(), e.getMessage(), e ); - } + log.warn( "Consumer [{}] cannot begin: {}", consumer.getId( ), e.getMessage( ), e ); } } } diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerScanCompletedClosure.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerScanCompletedClosure.java index 79909f8f9..4a52ea8df 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerScanCompletedClosure.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/TriggerScanCompletedClosure.java @@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory; * TriggerScanCompletedClosure */ public class TriggerScanCompletedClosure - implements Closure + implements Closure<RepositoryContentConsumer> { private Logger log = LoggerFactory.getLogger( TriggerScanCompletedClosure.class ); @@ -49,13 +49,10 @@ public class TriggerScanCompletedClosure } @Override - public void execute( Object input ) + public void execute( RepositoryContentConsumer input ) { - if ( input instanceof RepositoryContentConsumer ) - { - RepositoryContentConsumer consumer = (RepositoryContentConsumer) input; - consumer.completeScan( executeOnEntireRepo ); - log.debug( "Consumer [{}] completed for repository [{}]", consumer.getId(), repository.getId() ); - } + RepositoryContentConsumer consumer = (RepositoryContentConsumer) input; + consumer.completeScan( executeOnEntireRepo ); + log.debug( "Consumer [{}] completed for repository [{}]", consumer.getId( ), repository.getId( ) ); } } diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/IndexingArchivaTaskScheduler.java b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/IndexingArchivaTaskScheduler.java index 3d658107b..14cbfe30c 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/IndexingArchivaTaskScheduler.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/IndexingArchivaTaskScheduler.java @@ -45,7 +45,7 @@ public class IndexingArchivaTaskScheduler */ @Inject @Named(value = "taskQueue#indexing") - private TaskQueue indexingQueue; + private TaskQueue<ArtifactIndexingTask> indexingQueue; @Override public void queueTask( ArtifactIndexingTask task ) diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java index 7b9279f2b..ea55b7c5e 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenManagedRepository.java @@ -38,6 +38,7 @@ import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; import java.util.Locale; +import java.util.function.Function; /** * Maven2 managed repository implementation. @@ -85,6 +86,8 @@ public class MavenManagedRepository extends AbstractManagedRepository return CAPABILITIES; } + + @SuppressWarnings( "unchecked" ) @Override public <T extends RepositoryFeature<T>> RepositoryFeature<T> getFeature( Class<T> clazz ) throws UnsupportedFeatureException { diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java index 62057b033..79a9fb9e6 100644 --- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/repository/maven2/MavenRepositoryProvider.java @@ -57,7 +57,9 @@ import java.time.Duration; import java.time.Period; import java.time.temporal.ChronoUnit; import java.util.HashSet; +import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; /** * Provider for the maven2 repository implementations @@ -242,8 +244,12 @@ public class MavenRepositoryProvider implements RepositoryProvider { remoteIndexFeature.setDownloadRemoteIndexOnStartup(false); } } - repo.setExtraHeaders(cfg.getExtraHeaders()); - repo.setExtraParameters(cfg.getExtraParameters()); + for ( Object key : cfg.getExtraHeaders().keySet() ) { + repo.addExtraHeader( key.toString(), cfg.getExtraHeaders().get(key).toString() ); + } + for ( Object key : cfg.getExtraParameters().keySet() ) { + repo.addExtraParameter( key.toString(), cfg.getExtraParameters().get(key).toString() ); + } PasswordCredentials credentials = new PasswordCredentials("", new char[0]); if (cfg.getPassword() != null && cfg.getUsername() != null) { credentials.setPassword(cfg.getPassword().toCharArray()); diff --git a/archiva-modules/plugins/metadata-store-jcr/pom.xml b/archiva-modules/plugins/metadata-store-jcr/pom.xml index 609011387..299a29ac8 100644 --- a/archiva-modules/plugins/metadata-store-jcr/pom.xml +++ b/archiva-modules/plugins/metadata-store-jcr/pom.xml @@ -87,6 +87,11 @@ </exclusions> </dependency> <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.scr.annotations</artifactId> + <version>RELEASE</version> + </dependency> + <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> </dependency> diff --git a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java index 978602ad2..1231a1463 100644 --- a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java +++ b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java @@ -1386,6 +1386,7 @@ public class JcrMetadataRepository return aClass == Session.class; } + @SuppressWarnings( "unchecked" ) @Override public <T> T obtainAccess( Class<T> aClass ) throws MetadataRepositoryException |