@@ -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 ) ) | |||
{ |
@@ -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 ); | |||
@@ -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; | |||
} |
@@ -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 ); | |||
} | |||
} | |||
} |
@@ -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( ) ); | |||
} | |||
} |
@@ -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 ) |
@@ -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 | |||
{ |
@@ -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()); |
@@ -86,6 +86,11 @@ | |||
</exclusion> | |||
</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> |
@@ -1386,6 +1386,7 @@ public class JcrMetadataRepository | |||
return aClass == Session.class; | |||
} | |||
@SuppressWarnings( "unchecked" ) | |||
@Override | |||
public <T> T obtainAccess( Class<T> aClass ) | |||
throws MetadataRepositoryException |