* ConsumerWantsFilePredicate
*/
public class ConsumerWantsFilePredicate
- implements Predicate
+ implements Predicate<RepositoryContentConsumer>
{
private BaseFile basefile;
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
}
}
@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;
}
}
}
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;
}
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 )
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 ) )
}
// Now test includes.
- for ( String pattern : consumer.getIncludes() )
+ for ( String pattern : consumer.getIncludes( ) )
{
if ( SelectorUtils.matchPath( pattern, relativePath, isCaseSensitive ) )
{
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;
// Run the repository consumers
try
{
- Closure triggerBeginScan = new TriggerBeginScanClosure( repository, getStartTime(), false );
+ Closure<RepositoryContentConsumer> triggerBeginScan = new TriggerBeginScanClosure( repository, getStartTime(), false );
selectedKnownConsumers = getSelectedKnownConsumers();
closure.setBasefile( baseFile );
closure.setExecuteOnEntireRepo( false );
- Closure processIfWanted = IfClosure.ifClosure( predicate, closure );
+ Closure<RepositoryContentConsumer> processIfWanted = IfClosure.ifClosure( predicate, closure );
IterableUtils.forEach( selectedKnownConsumers, processIfWanted );
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;
}
this.basefile = basefile;
}
- public boolean isExecuteOnEntireRepo()
+ public boolean isExecuteOnEntireRepo( )
{
return executeOnEntireRepo;
}
this.consumerCounts = consumerCounts;
}
- public Logger getLogger()
+ public Logger getLogger( )
{
return log;
}
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;
{
this.repository = repository;
}
-
+
public TriggerBeginScanClosure( ManagedRepository repository, Date whenGathered )
{
this( repository );
}
@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 );
}
}
}
* TriggerScanCompletedClosure
*/
public class TriggerScanCompletedClosure
- implements Closure
+ implements Closure<RepositoryContentConsumer>
{
private Logger log = LoggerFactory.getLogger( TriggerScanCompletedClosure.class );
}
@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( ) );
}
}
*/
@Inject
@Named(value = "taskQueue#indexing")
- private TaskQueue indexingQueue;
+ private TaskQueue<ArtifactIndexingTask> indexingQueue;
@Override
public void queueTask( ArtifactIndexingTask task )
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Locale;
+import java.util.function.Function;
/**
* Maven2 managed repository implementation.
return CAPABILITIES;
}
+
+ @SuppressWarnings( "unchecked" )
@Override
public <T extends RepositoryFeature<T>> RepositoryFeature<T> getFeature( Class<T> clazz ) throws UnsupportedFeatureException
{
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
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());
</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>
return aClass == Session.class;
}
+ @SuppressWarnings( "unchecked" )
@Override
public <T> T obtainAccess( Class<T> aClass )
throws MetadataRepositoryException