1 package org.apache.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.archiva.admin.model.beans.ManagedRepository;
23 import org.apache.archiva.configuration.ArchivaConfiguration;
24 import org.apache.archiva.configuration.ConfigurationNames;
25 import org.apache.archiva.configuration.FileTypes;
26 import org.apache.archiva.consumers.AbstractMonitoredConsumer;
27 import org.apache.archiva.consumers.ConsumerException;
28 import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
29 import org.apache.archiva.redback.components.registry.Registry;
30 import org.apache.archiva.redback.components.registry.RegistryListener;
31 import org.springframework.context.annotation.Scope;
32 import org.springframework.stereotype.Service;
34 import javax.annotation.PostConstruct;
35 import javax.inject.Inject;
37 import java.util.ArrayList;
38 import java.util.Date;
39 import java.util.List;
46 @Service( "knownRepositoryContentConsumer#auto-remove" )
48 public class AutoRemoveConsumer
49 extends AbstractMonitoredConsumer
50 implements KnownRepositoryContentConsumer, RegistryListener
53 * default-value="auto-remove"
55 private String id = "auto-remove";
58 * default-value="Automatically Remove File from Filesystem."
60 private String description = "Automatically Remove File from Filesystem.";
66 private ArchivaConfiguration configuration;
72 private FileTypes filetypes;
74 private File repositoryDir;
76 private List<String> includes = new ArrayList<String>( 0 );
83 public String getDescription()
85 return this.description;
88 public boolean isPermanent()
93 public void beginScan( ManagedRepository repository, Date whenGathered )
94 throws ConsumerException
96 this.repositoryDir = new File( repository.getLocation() );
99 public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo )
100 throws ConsumerException
102 beginScan( repository, whenGathered );
105 public void completeScan()
110 public void completeScan( boolean executeOnEntireRepo )
115 public List<String> getExcludes()
120 public List<String> getIncludes()
125 public void processFile( String path )
126 throws ConsumerException
128 File file = new File( this.repositoryDir, path );
131 triggerConsumerInfo( "(Auto) Removing File: " + file.getAbsolutePath() );
136 public void processFile( String path, boolean executeOnEntireRepo )
137 throws ConsumerException
142 public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
144 if ( ConfigurationNames.isRepositoryScanning( propertyName ) )
150 public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
155 private void initIncludes()
157 includes = new ArrayList<String>( filetypes.getFileTypePatterns( FileTypes.AUTO_REMOVE ) );
161 public void initialize()
163 configuration.addChangeListener( this );