Coverage Report - org.apache.maven.archiva.consumers.core.AutoRemoveConsumer
 
Classes in this File Line Coverage Branch Coverage Complexity
AutoRemoveConsumer
0%
0/31
0%
0/4
0
 
 1  
 package org.apache.maven.archiva.consumers.core;
 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 org.apache.commons.collections.CollectionUtils;
 23  
 import org.apache.commons.lang.StringUtils;
 24  
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
 25  
 import org.apache.maven.archiva.configuration.ConfigurationNames;
 26  
 import org.apache.maven.archiva.configuration.FileTypes;
 27  
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
 28  
 import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
 29  
 import org.apache.maven.archiva.consumers.ConsumerException;
 30  
 import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
 31  
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
 32  
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
 33  
 import org.codehaus.plexus.registry.Registry;
 34  
 import org.codehaus.plexus.registry.RegistryListener;
 35  
 
 36  
 import java.io.File;
 37  
 import java.util.ArrayList;
 38  
 import java.util.Date;
 39  
 import java.util.List;
 40  
 
 41  
 /**
 42  
  * AutoRemoveConsumer
 43  
  *
 44  
  * @version $Id: AutoRemoveConsumer.java 1041824 2010-12-03 14:11:05Z brett $
 45  
  * @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
 46  
  * role-hint="auto-remove"
 47  
  * instantiation-strategy="per-lookup"
 48  
  */
 49  0
 public class AutoRemoveConsumer
 50  
     extends AbstractMonitoredConsumer
 51  
     implements KnownRepositoryContentConsumer, RegistryListener, Initializable
 52  
 {
 53  
     /**
 54  
      * @plexus.configuration default-value="auto-remove"
 55  
      */
 56  
     private String id;
 57  
 
 58  
     /**
 59  
      * @plexus.configuration default-value="Automatically Remove File from Filesystem."
 60  
      */
 61  
     private String description;
 62  
 
 63  
     /**
 64  
      * @plexus.requirement
 65  
      */
 66  
     private ArchivaConfiguration configuration;
 67  
 
 68  
     /**
 69  
      * @plexus.requirement
 70  
      */
 71  
     private FileTypes filetypes;
 72  
 
 73  
     private File repositoryDir;
 74  
     
 75  0
     private List<String> includes = new ArrayList<String>();
 76  
 
 77  
     public String getId()
 78  
     {
 79  0
         return this.id;
 80  
     }
 81  
 
 82  
     public String getDescription()
 83  
     {
 84  0
         return this.description;
 85  
     }
 86  
 
 87  
     public boolean isPermanent()
 88  
     {
 89  0
         return false;
 90  
     }
 91  
 
 92  
     public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered )
 93  
         throws ConsumerException
 94  
     {
 95  0
         this.repositoryDir = new File( repository.getLocation() );
 96  0
     }
 97  
 
 98  
     public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
 99  
         throws ConsumerException
 100  
     {
 101  0
         beginScan( repository, whenGathered );
 102  0
     }
 103  
 
 104  
     public void completeScan()
 105  
     {
 106  
         /* do nothing */
 107  0
     }
 108  
 
 109  
     public void completeScan( boolean executeOnEntireRepo )
 110  
     {
 111  0
         completeScan();
 112  0
     }
 113  
 
 114  
     public List<String> getExcludes()
 115  
     {
 116  0
         return null;
 117  
     }
 118  
 
 119  
     public List<String> getIncludes()
 120  
     {
 121  0
         return includes;
 122  
     }
 123  
 
 124  
     public void processFile( String path )
 125  
         throws ConsumerException
 126  
     {
 127  0
         File file = new File( this.repositoryDir, path );
 128  0
         if ( file.exists() )
 129  
         {
 130  0
             triggerConsumerInfo( "(Auto) Removing File: " + file.getAbsolutePath() );
 131  0
             file.delete();
 132  
         }
 133  0
     }
 134  
 
 135  
     public void processFile( String path, boolean executeOnEntireRepo )
 136  
         throws ConsumerException
 137  
     {
 138  0
         processFile( path );    
 139  0
     }
 140  
 
 141  
     public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
 142  
     {                
 143  0
         if ( ConfigurationNames.isRepositoryScanning( propertyName ) )
 144  
         {
 145  0
             initIncludes();
 146  
         }
 147  0
     }
 148  
 
 149  
     public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
 150  
     {
 151  
         /* do nothing */
 152  0
     }
 153  
 
 154  
     private void initIncludes()
 155  
     {
 156  0
         includes.clear();
 157  
 
 158  0
         includes.addAll( filetypes.getFileTypePatterns( FileTypes.AUTO_REMOVE ) );
 159  0
     }
 160  
 
 161  
     public void initialize()
 162  
         throws InitializationException
 163  
     {     
 164  0
         configuration.addChangeListener( this );
 165  
 
 166  0
         initIncludes();
 167  0
     }
 168  
 }