]> source.dussan.org Git - archiva.git/commitdiff
[MRM-528] must only use the enabled consumers
authorBrett Porter <brett@apache.org>
Mon, 29 Oct 2007 08:24:12 +0000 (08:24 +0000)
committerBrett Porter <brett@apache.org>
Mon, 29 Oct 2007 08:24:12 +0000 (08:24 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@589542 13f79535-47bb-0310-9956-ffa450edef68

archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumers.java
archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/scanner/RepositoryContentConsumersTest.java

index e51fb354c0b3a7a8cdd2bafbfc15e56c765d92f2..4b8ad89f1f106cdecf0e31a9afa2fd24ac834c1f 100644 (file)
@@ -65,6 +65,10 @@ public class RepositoryContentConsumers
      */
     private List<InvalidRepositoryContentConsumer> availableInvalidConsumers;
 
+    private List<KnownRepositoryContentConsumer> selectedKnownConsumers;
+
+    private List<InvalidRepositoryContentConsumer> selectedInvalidConsumers;
+
     /**
      * <p>
      * Get the list of Ids associated with those {@link KnownRepositoryContentConsumer} that have
@@ -113,14 +117,9 @@ public class RepositoryContentConsumers
     {
         Map<String, KnownRepositoryContentConsumer> consumerMap = new HashMap<String, KnownRepositoryContentConsumer>();
 
-        List<String> 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<String, InvalidRepositoryContentConsumer> consumerMap = new HashMap<String, InvalidRepositoryContentConsumer>();
 
-        List<String> 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<KnownRepositoryContentConsumer> getSelectedKnownConsumers()
+    public synchronized List<KnownRepositoryContentConsumer> getSelectedKnownConsumers()
     {
-        List<KnownRepositoryContentConsumer> ret = new ArrayList<KnownRepositoryContentConsumer>();
+        if ( selectedKnownConsumers == null )
+        {
+            List<KnownRepositoryContentConsumer> ret = new ArrayList<KnownRepositoryContentConsumer>();
 
-        List<String> knownSelected = getSelectedKnownConsumerIds();
+            List<String> 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<InvalidRepositoryContentConsumer> getSelectedInvalidConsumers()
+    public synchronized List<InvalidRepositoryContentConsumer> getSelectedInvalidConsumers()
     {
-        List<InvalidRepositoryContentConsumer> ret = new ArrayList<InvalidRepositoryContentConsumer>();
+        if ( selectedInvalidConsumers == null )
+        {
+            List<InvalidRepositoryContentConsumer> ret = new ArrayList<InvalidRepositoryContentConsumer>();
 
-        List<String> invalidSelected = getSelectedInvalidConsumerIds();
+            List<String> 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<KnownRepositoryContentConsumer> selectedKnownConsumers = getSelectedKnownConsumers();
+            List<InvalidRepositoryContentConsumer> 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<KnownRepositoryContentConsumer> selectedKnownConsumers )
+    {
+        this.selectedKnownConsumers = selectedKnownConsumers;
+    }
+
+    public void setSelectedInvalidConsumers( List<InvalidRepositoryContentConsumer> selectedInvalidConsumers )
+    {
+        this.selectedInvalidConsumers = selectedInvalidConsumers;
+    }
 }
index d0ee6e2d2c803e3cba01709791483d430cd137af..f4ad33e5b28bb47dd2ee0ee5299208be23ecf5c2 100644 (file)
@@ -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();