aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-base/archiva-repository-layer
diff options
context:
space:
mode:
authorBrett Porter <brett@apache.org>2007-09-28 03:17:11 +0000
committerBrett Porter <brett@apache.org>2007-09-28 03:17:11 +0000
commite50371591df708ced25391eec1ae1d0f27cf39aa (patch)
tree37b6536b4f2fd9e8655f2fa7aabc77a286508830 /archiva-base/archiva-repository-layer
parentbc5df1bd8a86691788fbfd00b15911fb96e890ff (diff)
downloadarchiva-e50371591df708ced25391eec1ae1d0f27cf39aa.tar.gz
archiva-e50371591df708ced25391eec1ae1d0f27cf39aa.zip
[MRM-528] run the correct consumers
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@580205 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-base/archiva-repository-layer')
-rw-r--r--archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumers.java52
-rw-r--r--archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/functors/ConsumerWantsFilePredicate.java15
-rw-r--r--archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumerUtilTest.java59
3 files changed, 90 insertions, 36 deletions
diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumers.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumers.java
index 6876a7294..a253a2c05 100644
--- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumers.java
+++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumers.java
@@ -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 );
+*/
}
}
+
}
diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/functors/ConsumerWantsFilePredicate.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/functors/ConsumerWantsFilePredicate.java
index 799985165..2d154294c 100644
--- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/functors/ConsumerWantsFilePredicate.java
+++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/functors/ConsumerWantsFilePredicate.java
@@ -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.
diff --git a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumerUtilTest.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumerUtilTest.java
index 2f2a751bb..707cac441 100644
--- a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumerUtilTest.java
+++ b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumerUtilTest.java
@@ -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();
}
}