From: Brett Porter Date: Mon, 29 Oct 2007 08:24:12 +0000 (+0000) Subject: [MRM-528] must only use the enabled consumers X-Git-Tag: archiva-1.0-beta-3~4 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b2c335626a4df68de2771dd1423a9a2bac8b74df;p=archiva.git [MRM-528] must only use the enabled consumers git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@589542 13f79535-47bb-0310-9956-ffa450edef68 --- 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 e51fb354c..4b8ad89f1 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 @@ -65,6 +65,10 @@ public class RepositoryContentConsumers */ private List availableInvalidConsumers; + private List selectedKnownConsumers; + + private List selectedInvalidConsumers; + /** *

* Get the list of Ids associated with those {@link KnownRepositoryContentConsumer} that have @@ -113,14 +117,9 @@ public class RepositoryContentConsumers { Map consumerMap = new HashMap(); - List knownSelected = getSelectedKnownConsumerIds(); - - for ( KnownRepositoryContentConsumer consumer : availableKnownConsumers ) + for ( KnownRepositoryContentConsumer consumer : getSelectedKnownConsumers() ) { - if ( knownSelected.contains( consumer.getId() ) || consumer.isPermanent() ) - { - consumerMap.put( consumer.getId(), consumer ); - } + consumerMap.put( consumer.getId(), consumer ); } return consumerMap; @@ -136,14 +135,9 @@ public class RepositoryContentConsumers { Map consumerMap = new HashMap(); - List invalidSelected = getSelectedInvalidConsumerIds(); - - for ( InvalidRepositoryContentConsumer consumer : availableInvalidConsumers ) + for ( InvalidRepositoryContentConsumer consumer : getSelectedInvalidConsumers() ) { - if ( invalidSelected.contains( consumer.getId() ) || consumer.isPermanent() ) - { - consumerMap.put( consumer.getId(), consumer ); - } + consumerMap.put( consumer.getId(), consumer ); } return consumerMap; @@ -156,21 +150,24 @@ public class RepositoryContentConsumers * @return the list of {@link KnownRepositoryContentConsumer} that have been selected * by the active configuration. */ - public List getSelectedKnownConsumers() + public synchronized List getSelectedKnownConsumers() { - List ret = new ArrayList(); + if ( selectedKnownConsumers == null ) + { + List ret = new ArrayList(); - List knownSelected = getSelectedKnownConsumerIds(); + List knownSelected = getSelectedKnownConsumerIds(); - for ( KnownRepositoryContentConsumer consumer : availableKnownConsumers ) - { - if ( knownSelected.contains( consumer.getId() ) || consumer.isPermanent() ) + for ( KnownRepositoryContentConsumer consumer : availableKnownConsumers ) { - ret.add( consumer ); + if ( knownSelected.contains( consumer.getId() ) || consumer.isPermanent() ) + { + ret.add( consumer ); + } } + this.selectedKnownConsumers = ret; } - - return ret; + return selectedKnownConsumers; } /** @@ -180,21 +177,24 @@ public class RepositoryContentConsumers * @return the list of {@link InvalidRepositoryContentConsumer} that have been selected * by the active configuration. */ - public List getSelectedInvalidConsumers() + public synchronized List getSelectedInvalidConsumers() { - List ret = new ArrayList(); + if ( selectedInvalidConsumers == null ) + { + List ret = new ArrayList(); - List invalidSelected = getSelectedInvalidConsumerIds(); + List invalidSelected = getSelectedInvalidConsumerIds(); - for ( InvalidRepositoryContentConsumer consumer : availableInvalidConsumers ) - { - if ( invalidSelected.contains( consumer.getId() ) || consumer.isPermanent() ) + for ( InvalidRepositoryContentConsumer consumer : availableInvalidConsumers ) { - ret.add( consumer ); + if ( invalidSelected.contains( consumer.getId() ) || consumer.isPermanent() ) + { + ret.add( consumer ); + } } + selectedInvalidConsumers = ret; } - - return ret; + return selectedInvalidConsumers; } /** @@ -263,8 +263,10 @@ public class RepositoryContentConsumers { Closure triggerBeginScan = new TriggerBeginScanClosure( repository, getLogger() ); - CollectionUtils.forAllDo( availableKnownConsumers, triggerBeginScan ); - CollectionUtils.forAllDo( availableInvalidConsumers, triggerBeginScan ); + List selectedKnownConsumers = getSelectedKnownConsumers(); + List selectedInvalidConsumers = getSelectedInvalidConsumers(); + CollectionUtils.forAllDo( selectedKnownConsumers, triggerBeginScan ); + CollectionUtils.forAllDo( selectedInvalidConsumers, triggerBeginScan ); // 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" @@ -276,12 +278,12 @@ public class RepositoryContentConsumers predicate.setCaseSensitive( false ); Closure processIfWanted = IfClosure.getInstance( predicate, closure ); - CollectionUtils.forAllDo( availableKnownConsumers, processIfWanted ); + CollectionUtils.forAllDo( selectedKnownConsumers, processIfWanted ); if ( predicate.getWantedFileCount() <= 0 ) { // Nothing known processed this file. It is invalid! - CollectionUtils.forAllDo( availableInvalidConsumers, closure ); + CollectionUtils.forAllDo( selectedInvalidConsumers, closure ); } } finally @@ -293,4 +295,13 @@ public class RepositoryContentConsumers } } + public void setSelectedKnownConsumers( List selectedKnownConsumers ) + { + this.selectedKnownConsumers = selectedKnownConsumers; + } + + public void setSelectedInvalidConsumers( List selectedInvalidConsumers ) + { + this.selectedInvalidConsumers = selectedInvalidConsumers; + } } diff --git a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumersTest.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumersTest.java index d0ee6e2d2..f4ad33e5b 100644 --- a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumersTest.java +++ b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumersTest.java @@ -190,26 +190,35 @@ public class RepositoryContentConsumersTest { MockControl knownControl = MockControl.createNiceControl( KnownRepositoryContentConsumer.class ); RepositoryContentConsumers consumers = lookupRepositoryConsumers(); - KnownRepositoryContentConsumer knownConsumer = (KnownRepositoryContentConsumer) knownControl.getMock(); - consumers.setAvailableKnownConsumers( Collections.singletonList( knownConsumer ) ); + KnownRepositoryContentConsumer selectedKnownConsumer = (KnownRepositoryContentConsumer) knownControl.getMock(); + KnownRepositoryContentConsumer unselectedKnownConsumer = + (KnownRepositoryContentConsumer) MockControl.createNiceControl( + KnownRepositoryContentConsumer.class ).getMock(); + consumers.setAvailableKnownConsumers( Arrays.asList( selectedKnownConsumer, unselectedKnownConsumer ) ); + consumers.setSelectedKnownConsumers( Collections.singletonList( selectedKnownConsumer ) ); MockControl invalidControl = MockControl.createControl( InvalidRepositoryContentConsumer.class ); - InvalidRepositoryContentConsumer invalidConsumer = (InvalidRepositoryContentConsumer) invalidControl.getMock(); - consumers.setAvailableInvalidConsumers( Collections.singletonList( invalidConsumer ) ); + InvalidRepositoryContentConsumer selectedInvalidConsumer = + (InvalidRepositoryContentConsumer) invalidControl.getMock(); + InvalidRepositoryContentConsumer unselectedInvalidConsumer = + (InvalidRepositoryContentConsumer) MockControl.createControl( + InvalidRepositoryContentConsumer.class ).getMock(); + consumers.setAvailableInvalidConsumers( Arrays.asList( selectedInvalidConsumer, unselectedInvalidConsumer ) ); + consumers.setSelectedInvalidConsumers( Collections.singletonList( selectedInvalidConsumer ) ); ManagedRepositoryConfiguration repo = createRepository( "id", "name", getTestFile( "target/test-repo" ) ); File testFile = getTestFile( "target/test-repo/path/to/test-file.txt" ); - knownConsumer.beginScan( repo ); - knownConsumer.getExcludes(); + selectedKnownConsumer.beginScan( repo ); + selectedKnownConsumer.getExcludes(); knownControl.setReturnValue( Collections.EMPTY_LIST ); - knownConsumer.getIncludes(); + selectedKnownConsumer.getIncludes(); knownControl.setReturnValue( Collections.singletonList( "**/*.txt" ) ); - knownConsumer.processFile( _OS( "path/to/test-file.txt" ) ); + selectedKnownConsumer.processFile( _OS( "path/to/test-file.txt" ) ); // knownConsumer.completeScan(); knownControl.replay(); - invalidConsumer.beginScan( repo ); + selectedInvalidConsumer.beginScan( repo ); // invalidConsumer.completeScan(); invalidControl.replay(); @@ -223,17 +232,17 @@ public class RepositoryContentConsumersTest File notIncludedTestFile = getTestFile( "target/test-repo/path/to/test-file.xml" ); - knownConsumer.beginScan( repo ); - knownConsumer.getExcludes(); + selectedKnownConsumer.beginScan( repo ); + selectedKnownConsumer.getExcludes(); knownControl.setReturnValue( Collections.EMPTY_LIST ); - knownConsumer.getIncludes(); + selectedKnownConsumer.getIncludes(); knownControl.setReturnValue( Collections.singletonList( "**/*.txt" ) ); // knownConsumer.completeScan(); knownControl.replay(); - invalidConsumer.beginScan( repo ); - invalidConsumer.processFile( _OS( "path/to/test-file.xml" ) ); - invalidConsumer.getId(); + selectedInvalidConsumer.beginScan( repo ); + selectedInvalidConsumer.processFile( _OS( "path/to/test-file.xml" ) ); + selectedInvalidConsumer.getId(); invalidControl.setReturnValue( "invalid" ); // invalidConsumer.completeScan(); invalidControl.replay(); @@ -248,15 +257,15 @@ public class RepositoryContentConsumersTest File excludedTestFile = getTestFile( "target/test-repo/path/to/test-file.txt" ); - knownConsumer.beginScan( repo ); - knownConsumer.getExcludes(); + selectedKnownConsumer.beginScan( repo ); + selectedKnownConsumer.getExcludes(); knownControl.setReturnValue( Collections.singletonList( "**/test-file.txt" ) ); // knownConsumer.completeScan(); knownControl.replay(); - invalidConsumer.beginScan( repo ); - invalidConsumer.processFile( _OS( "path/to/test-file.txt" ) ); - invalidConsumer.getId(); + selectedInvalidConsumer.beginScan( repo ); + selectedInvalidConsumer.processFile( _OS( "path/to/test-file.txt" ) ); + selectedInvalidConsumer.getId(); invalidControl.setReturnValue( "invalid" ); // invalidConsumer.completeScan(); invalidControl.replay();