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.registry.Registry;
32 import org.codehaus.plexus.registry.RegistryListener;
33 import org.springframework.context.annotation.Scope;
34 import org.springframework.stereotype.Service;
36 import javax.annotation.PostConstruct;
37 import javax.inject.Inject;
39 import java.util.ArrayList;
40 import java.util.Date;
41 import java.util.List;
48 @Service("knownRepositoryContentConsumer#auto-remove")
50 public class AutoRemoveConsumer
51 extends AbstractMonitoredConsumer
52 implements KnownRepositoryContentConsumer, RegistryListener
55 * plexus.configuration default-value="auto-remove"
57 private String id = "auto-remove";
60 * plexus.configuration default-value="Automatically Remove File from Filesystem."
62 private String description = "Automatically Remove File from Filesystem.";
68 private ArchivaConfiguration configuration;
74 private FileTypes filetypes;
76 private File repositoryDir;
78 private List<String> includes = new ArrayList<String>();
85 public String getDescription()
87 return this.description;
90 public boolean isPermanent()
95 public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered )
96 throws ConsumerException
98 this.repositoryDir = new File( repository.getLocation() );
101 public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo )
102 throws ConsumerException
104 beginScan( repository, whenGathered );
107 public void completeScan()
112 public void completeScan( boolean executeOnEntireRepo )
117 public List<String> getExcludes()
122 public List<String> getIncludes()
127 public void processFile( String path )
128 throws ConsumerException
130 File file = new File( this.repositoryDir, path );
133 triggerConsumerInfo( "(Auto) Removing File: " + file.getAbsolutePath() );
138 public void processFile( String path, boolean executeOnEntireRepo )
139 throws ConsumerException
144 public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
146 if ( ConfigurationNames.isRepositoryScanning( propertyName ) )
152 public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
157 private void initIncludes()
161 includes.addAll( filetypes.getFileTypePatterns( FileTypes.AUTO_REMOVE ) );
165 public void initialize()
167 configuration.addChangeListener( this );