1 package org.apache.maven.archiva.consumers.core;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
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;
37 import java.util.ArrayList;
38 import java.util.Date;
39 import java.util.List;
45 * @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
46 * role-hint="auto-remove"
47 * instantiation-strategy="per-lookup"
49 public class AutoRemoveConsumer
50 extends AbstractMonitoredConsumer
51 implements KnownRepositoryContentConsumer, RegistryListener, Initializable
54 * @plexus.configuration default-value="auto-remove"
59 * @plexus.configuration default-value="Automatically Remove File from Filesystem."
61 private String description;
66 private ArchivaConfiguration configuration;
71 private FileTypes filetypes;
73 private File repositoryDir;
75 private List<String> includes = new ArrayList<String>();
82 public String getDescription()
84 return this.description;
87 public boolean isPermanent()
92 public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered )
93 throws ConsumerException
95 this.repositoryDir = new File( repository.getLocation() );
98 public void completeScan()
103 public List<String> getExcludes()
108 public List<String> getIncludes()
113 public void processFile( String path )
114 throws ConsumerException
116 File file = new File( this.repositoryDir, path );
119 triggerConsumerInfo( "(Auto) Removing File: " + file.getAbsolutePath() );
124 public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
126 if ( ConfigurationNames.isRepositoryScanning( propertyName ) )
132 public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
137 private void initIncludes()
141 includes.addAll( filetypes.getFileTypePatterns( FileTypes.AUTO_REMOVE ) );
144 public void initialize()
145 throws InitializationException
147 configuration.addChangeListener( this );