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.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
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 private Logger log = LoggerFactory.getLogger( AutoRemoveConsumer.class );
58 * default-value="auto-remove"
60 private String id = "auto-remove";
63 * default-value="Automatically Remove File from Filesystem."
65 private String description = "Automatically Remove File from Filesystem.";
71 private ArchivaConfiguration configuration;
77 private FileTypes filetypes;
79 private File repositoryDir;
81 private List<String> includes = new ArrayList<>( 0 );
90 public String getDescription()
92 return this.description;
96 public void beginScan( ManagedRepository repository, Date whenGathered )
97 throws ConsumerException
99 this.repositoryDir = new File( repository.getLocation() );
103 public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo )
104 throws ConsumerException
106 beginScan( repository, whenGathered );
110 public void completeScan()
116 public void completeScan( boolean executeOnEntireRepo )
122 public List<String> getExcludes()
128 public List<String> getIncludes()
134 public void processFile( String path )
135 throws ConsumerException
137 File file = new File( this.repositoryDir, path );
140 log.info( "(Auto) Removing File: {}", file.getAbsolutePath() );
141 triggerConsumerInfo( "(Auto) Removing File: " + file.getAbsolutePath() );
147 public void processFile( String path, boolean executeOnEntireRepo )
148 throws ConsumerException
154 public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
156 if ( ConfigurationNames.isRepositoryScanning( propertyName ) )
163 public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
168 private void initIncludes()
170 includes = new ArrayList<>( filetypes.getFileTypePatterns( FileTypes.AUTO_REMOVE ) );
174 public void initialize()
176 configuration.addChangeListener( this );