mirror of https://github.com/apache/archiva.git
[MRM-528] run the correct consumers
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@580205 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bc5df1bd8a
commit
e50371591d
|
@ -85,6 +85,8 @@ public interface RepositoryContentConsumer extends BaseConsumer
|
||||||
* NOTE: If the consumer opted to batch up processing requests in the {@link #processFile(String)} event
|
* NOTE: If the consumer opted to batch up processing requests in the {@link #processFile(String)} event
|
||||||
* this would be the last opportunity to drain any processing queue's.
|
* this would be the last opportunity to drain any processing queue's.
|
||||||
* </p>
|
* </p>
|
||||||
|
*
|
||||||
|
* @todo! this is never called by the RepositoryScannerInstance
|
||||||
*/
|
*/
|
||||||
public void completeScan();
|
public void completeScan();
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,15 +24,17 @@ import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.collections.Predicate;
|
import org.apache.commons.collections.Predicate;
|
||||||
import org.apache.commons.collections.functors.IfClosure;
|
import org.apache.commons.collections.functors.IfClosure;
|
||||||
import org.apache.commons.collections.functors.OrPredicate;
|
import org.apache.commons.collections.functors.OrPredicate;
|
||||||
import org.apache.maven.archiva.common.utils.PathUtil;
|
import org.apache.maven.archiva.common.utils.BaseFile;
|
||||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||||
import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
|
import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
|
||||||
import org.apache.maven.archiva.consumers.ConsumerException;
|
|
||||||
import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
|
import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
|
||||||
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
|
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
|
||||||
import org.apache.maven.archiva.consumers.RepositoryContentConsumer;
|
import org.apache.maven.archiva.consumers.RepositoryContentConsumer;
|
||||||
import org.apache.maven.archiva.consumers.functors.PermanentConsumerPredicate;
|
import org.apache.maven.archiva.consumers.functors.PermanentConsumerPredicate;
|
||||||
import org.apache.maven.archiva.model.ArchivaRepository;
|
import org.apache.maven.archiva.model.ArchivaRepository;
|
||||||
|
import org.apache.maven.archiva.repository.scanner.functors.ConsumerProcessFileClosure;
|
||||||
|
import org.apache.maven.archiva.repository.scanner.functors.ConsumerWantsFilePredicate;
|
||||||
|
import org.apache.maven.archiva.repository.scanner.functors.TriggerBeginScanClosure;
|
||||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
|
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
|
||||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
|
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
|
||||||
|
@ -213,32 +215,38 @@ public class RepositoryContentConsumers
|
||||||
public void executeConsumers( ArchivaRepository repository, File localFile )
|
public void executeConsumers( ArchivaRepository repository, File localFile )
|
||||||
{
|
{
|
||||||
// Run the repository consumers
|
// Run the repository consumers
|
||||||
for ( RepositoryContentConsumer consumer : availableKnownConsumers )
|
|
||||||
{
|
|
||||||
consumeFile( consumer, repository, localFile );
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( RepositoryContentConsumer consumer : availableInvalidConsumers )
|
|
||||||
{
|
|
||||||
consumeFile( consumer, repository, localFile );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void consumeFile( RepositoryContentConsumer consumer, ArchivaRepository repository, File localFile )
|
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
consumer.beginScan( repository );
|
Closure triggerBeginScan = new TriggerBeginScanClosure( repository, getLogger() );
|
||||||
consumer.processFile( PathUtil.getRelative( repository.getUrl().getPath(), localFile ) );
|
|
||||||
}
|
CollectionUtils.forAllDo( availableKnownConsumers, triggerBeginScan );
|
||||||
catch ( ConsumerException e )
|
CollectionUtils.forAllDo( availableInvalidConsumers, triggerBeginScan );
|
||||||
{
|
|
||||||
getLogger().error( "Error processing file: " + localFile, e );
|
// yuck. In case you can't read this, it says
|
||||||
// ignore, let next repo scan handle it
|
// "process the file if the consumer has it in the includes list, and not in the excludes list"
|
||||||
|
BaseFile baseFile = new BaseFile( repository.getUrl().getPath(), localFile );
|
||||||
|
ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate();
|
||||||
|
predicate.setBasefile( baseFile );
|
||||||
|
ConsumerProcessFileClosure closure = new ConsumerProcessFileClosure( getLogger() );
|
||||||
|
closure.setBasefile( baseFile );
|
||||||
|
predicate.setCaseSensitive( false );
|
||||||
|
Closure processIfWanted = IfClosure.getInstance( predicate, closure );
|
||||||
|
|
||||||
|
CollectionUtils.forAllDo( availableKnownConsumers, processIfWanted );
|
||||||
|
|
||||||
|
if ( predicate.getWantedFileCount() <= 0 )
|
||||||
|
{
|
||||||
|
// Nothing known processed this file. It is invalid!
|
||||||
|
CollectionUtils.forAllDo( availableInvalidConsumers, closure );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
consumer.completeScan();
|
/* TODO: This is never called by the repository scanner instance, so not calling here either - but it probably should be?
|
||||||
|
CollectionUtils.forAllDo( availableKnownConsumers, triggerCompleteScan );
|
||||||
|
CollectionUtils.forAllDo( availableInvalidConsumers, triggerCompleteScan );
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ import org.apache.maven.archiva.consumers.RepositoryContentConsumer;
|
||||||
import org.codehaus.plexus.util.SelectorUtils;
|
import org.codehaus.plexus.util.SelectorUtils;
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ConsumerWantsFilePredicate
|
* ConsumerWantsFilePredicate
|
||||||
|
@ -87,15 +87,12 @@ public class ConsumerWantsFilePredicate
|
||||||
|
|
||||||
private boolean wantsFile( RepositoryContentConsumer consumer, String relativePath )
|
private boolean wantsFile( RepositoryContentConsumer consumer, String relativePath )
|
||||||
{
|
{
|
||||||
Iterator it;
|
|
||||||
|
|
||||||
// Test excludes first.
|
// Test excludes first.
|
||||||
if ( consumer.getExcludes() != null )
|
List<String> excludes = consumer.getExcludes();
|
||||||
|
if ( excludes != null )
|
||||||
{
|
{
|
||||||
it = consumer.getExcludes().iterator();
|
for ( String pattern : excludes )
|
||||||
while ( it.hasNext() )
|
|
||||||
{
|
{
|
||||||
String pattern = (String) it.next();
|
|
||||||
if ( SelectorUtils.matchPath( pattern, relativePath, isCaseSensitive ) )
|
if ( SelectorUtils.matchPath( pattern, relativePath, isCaseSensitive ) )
|
||||||
{
|
{
|
||||||
// Definately does NOT WANT FILE.
|
// Definately does NOT WANT FILE.
|
||||||
|
@ -105,10 +102,8 @@ public class ConsumerWantsFilePredicate
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now test includes.
|
// Now test includes.
|
||||||
it = consumer.getIncludes().iterator();
|
for ( String pattern : consumer.getIncludes() )
|
||||||
while ( it.hasNext() )
|
|
||||||
{
|
{
|
||||||
String pattern = (String) it.next();
|
|
||||||
if ( SelectorUtils.matchPath( pattern, relativePath, isCaseSensitive ) )
|
if ( SelectorUtils.matchPath( pattern, relativePath, isCaseSensitive ) )
|
||||||
{
|
{
|
||||||
// Specifically WANTS FILE.
|
// Specifically WANTS FILE.
|
||||||
|
|
|
@ -109,7 +109,7 @@ public class RepositoryContentConsumerUtilTest
|
||||||
public void testExecution()
|
public void testExecution()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
MockControl knownControl = MockControl.createControl( KnownRepositoryContentConsumer.class );
|
MockControl knownControl = MockControl.createNiceControl( KnownRepositoryContentConsumer.class );
|
||||||
RepositoryContentConsumers consumers = lookupRepositoryConsumerUtil();
|
RepositoryContentConsumers consumers = lookupRepositoryConsumerUtil();
|
||||||
KnownRepositoryContentConsumer knownConsumer = (KnownRepositoryContentConsumer) knownControl.getMock();
|
KnownRepositoryContentConsumer knownConsumer = (KnownRepositoryContentConsumer) knownControl.getMock();
|
||||||
consumers.setAvailableKnownConsumers( Collections.singletonList( knownConsumer ) );
|
consumers.setAvailableKnownConsumers( Collections.singletonList( knownConsumer ) );
|
||||||
|
@ -123,18 +123,69 @@ public class RepositoryContentConsumerUtilTest
|
||||||
File testFile = getTestFile( "target/test-repo/path/to/test-file.txt" );
|
File testFile = getTestFile( "target/test-repo/path/to/test-file.txt" );
|
||||||
|
|
||||||
knownConsumer.beginScan( repo );
|
knownConsumer.beginScan( repo );
|
||||||
|
knownConsumer.getExcludes();
|
||||||
|
knownControl.setReturnValue( Collections.EMPTY_LIST );
|
||||||
|
knownConsumer.getIncludes();
|
||||||
|
knownControl.setReturnValue( Collections.singletonList( "**/*.txt" ) );
|
||||||
knownConsumer.processFile( "path/to/test-file.txt" );
|
knownConsumer.processFile( "path/to/test-file.txt" );
|
||||||
knownConsumer.completeScan();
|
// knownConsumer.completeScan();
|
||||||
knownControl.replay();
|
knownControl.replay();
|
||||||
|
|
||||||
invalidConsumer.beginScan( repo );
|
invalidConsumer.beginScan( repo );
|
||||||
invalidConsumer.processFile( "path/to/test-file.txt" );
|
// invalidConsumer.completeScan();
|
||||||
invalidConsumer.completeScan();
|
|
||||||
invalidControl.replay();
|
invalidControl.replay();
|
||||||
|
|
||||||
consumers.executeConsumers( repo, testFile );
|
consumers.executeConsumers( repo, testFile );
|
||||||
|
|
||||||
knownControl.verify();
|
knownControl.verify();
|
||||||
invalidControl.verify();
|
invalidControl.verify();
|
||||||
|
|
||||||
|
knownControl.reset();
|
||||||
|
invalidControl.reset();
|
||||||
|
|
||||||
|
File notIncludedTestFile = getTestFile( "target/test-repo/path/to/test-file.xml" );
|
||||||
|
|
||||||
|
knownConsumer.beginScan( repo );
|
||||||
|
knownConsumer.getExcludes();
|
||||||
|
knownControl.setReturnValue( Collections.EMPTY_LIST );
|
||||||
|
knownConsumer.getIncludes();
|
||||||
|
knownControl.setReturnValue( Collections.singletonList( "**/*.txt" ) );
|
||||||
|
// knownConsumer.completeScan();
|
||||||
|
knownControl.replay();
|
||||||
|
|
||||||
|
invalidConsumer.beginScan( repo );
|
||||||
|
invalidConsumer.processFile( "path/to/test-file.xml" );
|
||||||
|
invalidConsumer.getId();
|
||||||
|
invalidControl.setReturnValue( "invalid" );
|
||||||
|
// invalidConsumer.completeScan();
|
||||||
|
invalidControl.replay();
|
||||||
|
|
||||||
|
consumers.executeConsumers( repo, notIncludedTestFile );
|
||||||
|
|
||||||
|
knownControl.verify();
|
||||||
|
invalidControl.verify();
|
||||||
|
|
||||||
|
knownControl.reset();
|
||||||
|
invalidControl.reset();
|
||||||
|
|
||||||
|
File excludedTestFile = getTestFile( "target/test-repo/path/to/test-file.txt" );
|
||||||
|
|
||||||
|
knownConsumer.beginScan( repo );
|
||||||
|
knownConsumer.getExcludes();
|
||||||
|
knownControl.setReturnValue( Collections.singletonList( "**/test-file.txt" ) );
|
||||||
|
// knownConsumer.completeScan();
|
||||||
|
knownControl.replay();
|
||||||
|
|
||||||
|
invalidConsumer.beginScan( repo );
|
||||||
|
invalidConsumer.processFile( "path/to/test-file.txt" );
|
||||||
|
invalidConsumer.getId();
|
||||||
|
invalidControl.setReturnValue( "invalid" );
|
||||||
|
// invalidConsumer.completeScan();
|
||||||
|
invalidControl.replay();
|
||||||
|
|
||||||
|
consumers.executeConsumers( repo, excludedTestFile );
|
||||||
|
|
||||||
|
knownControl.verify();
|
||||||
|
invalidControl.verify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue