Coverage Report - org.apache.maven.archiva.repository.scanner.DefaultRepositoryScanner
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultRepositoryScanner
0%
0/36
0%
0/10
0
 
 1  
 package org.apache.maven.archiva.repository.scanner;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *  http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.io.File;
 23  
 import java.util.ArrayList;
 24  
 import java.util.LinkedHashSet;
 25  
 import java.util.List;
 26  
 import java.util.Set;
 27  
 
 28  
 import org.apache.commons.collections.CollectionUtils;
 29  
 import org.apache.maven.archiva.configuration.FileTypes;
 30  
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
 31  
 import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
 32  
 import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
 33  
 import org.apache.maven.archiva.consumers.RepositoryContentConsumer;
 34  
 import org.apache.maven.archiva.repository.RepositoryException;
 35  
 import org.codehaus.plexus.util.DirectoryWalker;
 36  
 
 37  
 import javax.swing.*;
 38  
 
 39  
 /**
 40  
  * DefaultRepositoryScanner
 41  
  *
 42  
  * @version $Id: DefaultRepositoryScanner.java 1042633 2010-12-06 13:27:53Z brett $
 43  
  * @plexus.component role="org.apache.maven.archiva.repository.scanner.RepositoryScanner"
 44  
  */
 45  0
 public class DefaultRepositoryScanner
 46  
     implements RepositoryScanner
 47  
 {
 48  
     /**
 49  
      * @plexus.requirement
 50  
      */
 51  
     private FileTypes filetypes;
 52  
 
 53  
     /**
 54  
      * @plexus.requirement
 55  
      */
 56  
     private RepositoryContentConsumers consumerUtil;
 57  
 
 58  0
     private Set<RepositoryScannerInstance> inProgressScans = new LinkedHashSet<RepositoryScannerInstance>();
 59  
 
 60  
     public RepositoryScanStatistics scan( ManagedRepositoryConfiguration repository, long changesSince )
 61  
         throws RepositoryException
 62  
     {
 63  0
         List<KnownRepositoryContentConsumer> knownContentConsumers = consumerUtil.getSelectedKnownConsumers();
 64  0
         List<InvalidRepositoryContentConsumer> invalidContentConsumers = consumerUtil.getSelectedInvalidConsumers();
 65  0
         List<String> ignoredPatterns = filetypes.getFileTypePatterns( FileTypes.IGNORED );
 66  
 
 67  0
         return scan( repository, knownContentConsumers, invalidContentConsumers, ignoredPatterns, changesSince );
 68  
     }
 69  
 
 70  
     public RepositoryScanStatistics scan( ManagedRepositoryConfiguration repository,
 71  
                                           List<KnownRepositoryContentConsumer> knownContentConsumers,
 72  
                                           List<InvalidRepositoryContentConsumer> invalidContentConsumers,
 73  
                                           List<String> ignoredContentPatterns, long changesSince )
 74  
         throws RepositoryException
 75  
     {
 76  0
         if ( repository == null )
 77  
         {
 78  0
             throw new IllegalArgumentException( "Unable to operate on a null repository." );
 79  
         }
 80  
 
 81  0
         File repositoryBase = new File( repository.getLocation() );
 82  
 
 83  0
         if ( !repositoryBase.exists() )
 84  
         {
 85  0
             throw new UnsupportedOperationException( "Unable to scan a repository, directory "
 86  
                 + repositoryBase.getPath() + " does not exist." );
 87  
         }
 88  
 
 89  0
         if ( !repositoryBase.isDirectory() )
 90  
         {
 91  0
             throw new UnsupportedOperationException( "Unable to scan a repository, path "
 92  
                 + repositoryBase.getPath() + " is not a directory." );
 93  
         }
 94  
 
 95  
         // Setup Includes / Excludes.
 96  
 
 97  0
         List<String> allExcludes = new ArrayList<String>();
 98  0
         List<String> allIncludes = new ArrayList<String>();
 99  
 
 100  0
         if ( CollectionUtils.isNotEmpty( ignoredContentPatterns ) )
 101  
         {
 102  0
             allExcludes.addAll( ignoredContentPatterns );
 103  
         }
 104  
 
 105  
         // Scan All Content. (intentional)
 106  0
         allIncludes.add( "**/*" );
 107  
 
 108  
         // Setup Directory Walker
 109  0
         DirectoryWalker dirWalker = new DirectoryWalker();
 110  
 
 111  0
         dirWalker.setBaseDir( repositoryBase );
 112  
 
 113  0
         dirWalker.setIncludes( allIncludes );
 114  0
         dirWalker.setExcludes( allExcludes );
 115  
 
 116  
         // Setup the Scan Instance
 117  0
         RepositoryScannerInstance scannerInstance = new RepositoryScannerInstance( repository, knownContentConsumers,
 118  
                                                                                    invalidContentConsumers, changesSince );
 119  
 
 120  0
         inProgressScans.add( scannerInstance );
 121  
 
 122  0
         dirWalker.addDirectoryWalkListener( scannerInstance );
 123  
 
 124  
         // Execute scan.
 125  0
         dirWalker.scan();
 126  
 
 127  0
         RepositoryScanStatistics stats = scannerInstance.getStatistics();
 128  
 
 129  0
         stats.setKnownConsumers( gatherIds( knownContentConsumers ) );
 130  0
         stats.setInvalidConsumers( gatherIds( invalidContentConsumers ) );
 131  
 
 132  0
         inProgressScans.remove( scannerInstance );
 133  
 
 134  0
         return stats;
 135  
     }
 136  
 
 137  
     private List<String> gatherIds( List<? extends RepositoryContentConsumer> consumers )
 138  
     {
 139  0
         List<String> ids = new ArrayList<String>();
 140  0
         for ( RepositoryContentConsumer consumer : consumers )
 141  
         {
 142  0
             ids.add( consumer.getId() );
 143  
         }
 144  0
         return ids;
 145  
     }
 146  
 
 147  
     public Set<RepositoryScannerInstance> getInProgressScans()
 148  
     {
 149  0
         return inProgressScans;
 150  
     }
 151  
 }