git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@580205 13f79535-47bb-0310-9956-ffa450edef68tags/archiva-1.0-beta-3
@@ -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 | |||
* this would be the last opportunity to drain any processing queue's. | |||
* </p> | |||
* | |||
* @todo! this is never called by the RepositoryScannerInstance | |||
*/ | |||
public void completeScan(); | |||
} |
@@ -24,15 +24,17 @@ import org.apache.commons.collections.CollectionUtils; | |||
import org.apache.commons.collections.Predicate; | |||
import org.apache.commons.collections.functors.IfClosure; | |||
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.RepositoryScanningConfiguration; | |||
import org.apache.maven.archiva.consumers.ConsumerException; | |||
import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer; | |||
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; | |||
import org.apache.maven.archiva.consumers.RepositoryContentConsumer; | |||
import org.apache.maven.archiva.consumers.functors.PermanentConsumerPredicate; | |||
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.personality.plexus.lifecycle.phase.Initializable; | |||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; | |||
@@ -213,32 +215,38 @@ public class RepositoryContentConsumers | |||
public void executeConsumers( ArchivaRepository repository, File localFile ) | |||
{ | |||
// Run the repository consumers | |||
for ( RepositoryContentConsumer consumer : availableKnownConsumers ) | |||
try | |||
{ | |||
consumeFile( consumer, repository, localFile ); | |||
} | |||
Closure triggerBeginScan = new TriggerBeginScanClosure( repository, getLogger() ); | |||
for ( RepositoryContentConsumer consumer : availableInvalidConsumers ) | |||
{ | |||
consumeFile( consumer, repository, localFile ); | |||
} | |||
} | |||
CollectionUtils.forAllDo( availableKnownConsumers, triggerBeginScan ); | |||
CollectionUtils.forAllDo( availableInvalidConsumers, triggerBeginScan ); | |||
private void consumeFile( RepositoryContentConsumer consumer, ArchivaRepository repository, File localFile ) | |||
{ | |||
try | |||
{ | |||
consumer.beginScan( repository ); | |||
consumer.processFile( PathUtil.getRelative( repository.getUrl().getPath(), localFile ) ); | |||
} | |||
catch ( ConsumerException e ) | |||
{ | |||
getLogger().error( "Error processing file: " + localFile, e ); | |||
// ignore, let next repo scan handle it | |||
// yuck. In case you can't read this, it says | |||
// "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 | |||
{ | |||
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.StringUtils; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
/** | |||
* ConsumerWantsFilePredicate | |||
@@ -87,15 +87,12 @@ public class ConsumerWantsFilePredicate | |||
private boolean wantsFile( RepositoryContentConsumer consumer, String relativePath ) | |||
{ | |||
Iterator it; | |||
// Test excludes first. | |||
if ( consumer.getExcludes() != null ) | |||
List<String> excludes = consumer.getExcludes(); | |||
if ( excludes != null ) | |||
{ | |||
it = consumer.getExcludes().iterator(); | |||
while ( it.hasNext() ) | |||
for ( String pattern : excludes ) | |||
{ | |||
String pattern = (String) it.next(); | |||
if ( SelectorUtils.matchPath( pattern, relativePath, isCaseSensitive ) ) | |||
{ | |||
// Definately does NOT WANT FILE. | |||
@@ -105,10 +102,8 @@ public class ConsumerWantsFilePredicate | |||
} | |||
// Now test includes. | |||
it = consumer.getIncludes().iterator(); | |||
while ( it.hasNext() ) | |||
for ( String pattern : consumer.getIncludes() ) | |||
{ | |||
String pattern = (String) it.next(); | |||
if ( SelectorUtils.matchPath( pattern, relativePath, isCaseSensitive ) ) | |||
{ | |||
// Specifically WANTS FILE. |
@@ -109,7 +109,7 @@ public class RepositoryContentConsumerUtilTest | |||
public void testExecution() | |||
throws Exception | |||
{ | |||
MockControl knownControl = MockControl.createControl( KnownRepositoryContentConsumer.class ); | |||
MockControl knownControl = MockControl.createNiceControl( KnownRepositoryContentConsumer.class ); | |||
RepositoryContentConsumers consumers = lookupRepositoryConsumerUtil(); | |||
KnownRepositoryContentConsumer knownConsumer = (KnownRepositoryContentConsumer) knownControl.getMock(); | |||
consumers.setAvailableKnownConsumers( Collections.singletonList( knownConsumer ) ); | |||
@@ -123,18 +123,69 @@ public class RepositoryContentConsumerUtilTest | |||
File testFile = getTestFile( "target/test-repo/path/to/test-file.txt" ); | |||
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.completeScan(); | |||
// knownConsumer.completeScan(); | |||
knownControl.replay(); | |||
invalidConsumer.beginScan( repo ); | |||
invalidConsumer.processFile( "path/to/test-file.txt" ); | |||
invalidConsumer.completeScan(); | |||
// invalidConsumer.completeScan(); | |||
invalidControl.replay(); | |||
consumers.executeConsumers( repo, testFile ); | |||
knownControl.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(); | |||
} | |||
} |