3 import java.util.ArrayList;
7 import org.apache.archiva.configuration.ArchivaConfiguration;
8 import org.apache.archiva.configuration.FileTypes;
9 import org.apache.archiva.consumers.AbstractMonitoredConsumer;
10 import org.apache.archiva.consumers.ConsumerException;
11 import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
12 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
13 import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
14 import org.apache.archiva.redback.components.registry.Registry;
15 import org.apache.archiva.redback.components.registry.RegistryListener;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19 import javax.annotation.PostConstruct;
20 import javax.inject.Inject;
21 import org.springframework.context.annotation.Scope;
22 import org.springframework.stereotype.Service;
23 import org.apache.archiva.admin.model.beans.ManagedRepository;
26 * <code>SimpleArtifactConsumer</code>
29 @Service("knownRepositoryContentConsumer#simple")
31 public class SimpleArtifactConsumer
32 extends AbstractMonitoredConsumer
33 implements KnownRepositoryContentConsumer, RegistryListener, Initializable
36 private Logger log = LoggerFactory.getLogger( SimpleArtifactConsumer.class );
39 * default-value="simple-artifact-consumer"
41 private String id = "simple-artifact-consumer";
46 private String description = "Simple consumer to illustrate how to consume the contents of a repository.";
52 private FileTypes filetypes;
58 private ArchivaConfiguration configuration;
60 private List propertyNameTriggers = new ArrayList();
62 private List includes = new ArrayList();
64 /** current repository being scanned */
65 private ManagedRepository repository;
67 public void beginScan( ManagedRepository repository )
68 throws ConsumerException
70 this.repository = repository;
71 log.info( "Beginning scan of repository [" + this.repository.getId() + "]" );
74 public void beginScan( ManagedRepository repository, Date whenGathered )
75 throws ConsumerException
77 this.repository = repository;
78 log.info( "Beginning scan of repository [" + this.repository.getId() + "]" );
81 public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo )
82 throws ConsumerException
84 this.repository = repository;
85 log.info( "Beginning scan of repository [" + this.repository.getId() + "]" );
88 public void processFile( String path )
89 throws ConsumerException
91 log.info( "Processing entry [" + path + "] from repository [" + this.repository.getId() + "]" );
94 public void processFile( String path, boolean executeOnEntireRepo )
95 throws ConsumerException
97 log.info( "Processing entry [" + path + "] from repository [" + this.repository.getId() + "]" );
100 public void completeScan()
102 log.info( "Finished scan of repository [" + this.repository.getId() + "]" );
105 public void completeScan( boolean executeOnEntireRepo )
107 log.info( "Finished scan of repository [" + this.repository.getId() + "]" );
112 * Used by archiva to determine if the consumer wishes to process all of a repository's entries or just those that
113 * have been modified since the last scan.
115 * @return boolean true if the consumer wishes to process all entries on each scan, false for only those modified
116 * since the last scan
118 public boolean isProcessUnmodified()
120 return super.isProcessUnmodified();
123 public void afterConfigurationChange( org.apache.archiva.redback.components.registry.Registry registry, String propertyName, Object propertyValue )
125 if ( propertyNameTriggers.contains( propertyName ) )
131 public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
136 private void initIncludes()
139 includes.addAll( filetypes.getFileTypePatterns( FileTypes.INDEXABLE_CONTENT ) );
143 public void initialize()
144 throws InitializationException
146 propertyNameTriggers = new ArrayList();
147 propertyNameTriggers.add( "repositoryScanning" );
148 propertyNameTriggers.add( "fileTypes" );
149 propertyNameTriggers.add( "fileType" );
150 propertyNameTriggers.add( "patterns" );
151 propertyNameTriggers.add( "pattern" );
153 configuration.addChangeListener( this );
158 public String getId()
163 public String getDescription()
165 return this.description;
168 public List getExcludes()
173 public List getIncludes()
175 return this.includes;
178 public boolean isPermanent()