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 java.util.ArrayList;
23 import java.util.Date;
24 import java.util.List;
26 import org.apache.archiva.configuration.ArchivaConfiguration;
27 import org.apache.archiva.configuration.FileTypes;
28 import org.apache.archiva.consumers.AbstractMonitoredConsumer;
29 import org.apache.archiva.consumers.ConsumerException;
30 import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
31 import org.apache.archiva.redback.components.registry.Registry;
32 import org.apache.archiva.redback.components.registry.RegistryListener;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import javax.annotation.PostConstruct;
37 import javax.inject.Inject;
38 import org.springframework.context.annotation.Scope;
39 import org.springframework.stereotype.Service;
40 import org.apache.archiva.admin.model.beans.ManagedRepository;
43 * <code>SimpleArtifactConsumer</code>
46 @Service("knownRepositoryContentConsumer#simple")
48 public class SimpleArtifactConsumer
49 extends AbstractMonitoredConsumer
50 implements KnownRepositoryContentConsumer, RegistryListener
53 private Logger log = LoggerFactory.getLogger( SimpleArtifactConsumer.class );
56 * default-value="simple-artifact-consumer"
58 private String id = "simple-artifact-consumer";
63 private String description = "Simple consumer to illustrate how to consume the contents of a repository.";
69 private FileTypes filetypes;
75 private ArchivaConfiguration configuration;
77 private List<String> propertyNameTriggers = new ArrayList<>();
79 private List<String> includes = new ArrayList<>();
81 /** current repository being scanned */
82 private ManagedRepository repository;
84 public void beginScan( ManagedRepository repository )
85 throws ConsumerException
87 this.repository = repository;
88 log.info( "Beginning scan of repository [" + this.repository.getId() + "]" );
91 public void beginScan( ManagedRepository repository, Date whenGathered )
92 throws ConsumerException
94 this.repository = repository;
95 log.info( "Beginning scan of repository [" + this.repository.getId() + "]" );
98 public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo )
99 throws ConsumerException
101 this.repository = repository;
102 log.info( "Beginning scan of repository [" + this.repository.getId() + "]" );
105 public void processFile( String path )
106 throws ConsumerException
108 log.info( "Processing entry [" + path + "] from repository [" + this.repository.getId() + "]" );
111 public void processFile( String path, boolean executeOnEntireRepo )
112 throws ConsumerException
114 log.info( "Processing entry [" + path + "] from repository [" + this.repository.getId() + "]" );
117 public void completeScan()
119 log.info( "Finished scan of repository [" + this.repository.getId() + "]" );
122 public void completeScan( boolean executeOnEntireRepo )
124 log.info( "Finished scan of repository [" + this.repository.getId() + "]" );
129 * Used by archiva to determine if the consumer wishes to process all of a repository's entries or just those that
130 * have been modified since the last scan.
132 * @return boolean true if the consumer wishes to process all entries on each scan, false for only those modified
133 * since the last scan
135 public boolean isProcessUnmodified()
137 return super.isProcessUnmodified();
140 public void afterConfigurationChange( org.apache.archiva.redback.components.registry.Registry registry, String propertyName, Object propertyValue )
142 if ( propertyNameTriggers.contains( propertyName ) )
148 public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
153 private void initIncludes()
156 includes.addAll( filetypes.getFileTypePatterns( FileTypes.INDEXABLE_CONTENT ) );
160 public void initialize()
162 propertyNameTriggers = new ArrayList<>();
163 propertyNameTriggers.add( "repositoryScanning" );
164 propertyNameTriggers.add( "fileTypes" );
165 propertyNameTriggers.add( "fileType" );
166 propertyNameTriggers.add( "patterns" );
167 propertyNameTriggers.add( "pattern" );
169 configuration.addChangeListener( this );
174 public String getId()
179 public String getDescription()
181 return this.description;
184 public List<String> getExcludes()
189 public List<String> getIncludes()
191 return this.includes;
194 public boolean isPermanent()