]> source.dussan.org Git - archiva.git/blob
3fc27507c1fd26e7502b3fc620db50cfc7030e93
[archiva.git] /
1 package $package;
2
3 import java.util.ArrayList;
4 import java.util.Date;
5 import java.util.List;
6
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;
16
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;
24
25 /**
26  * <code>SimpleArtifactConsumer</code>
27  * 
28  */
29 @Service("knownRepositoryContentConsumer#simple")
30 @Scope("prototype")
31 public class SimpleArtifactConsumer
32     extends AbstractMonitoredConsumer
33     implements KnownRepositoryContentConsumer, RegistryListener, Initializable
34 {
35
36     private Logger log = LoggerFactory.getLogger( SimpleArtifactConsumer.class );
37
38     /**
39      * default-value="simple-artifact-consumer"
40      */
41     private String id = "simple-artifact-consumer";
42
43     /**
44      *
45      */
46     private String description = "Simple consumer to illustrate how to consume the contents of a repository.";
47
48     /**
49      *
50      */
51     @Inject
52     private FileTypes filetypes;
53
54     /**
55      *
56      */
57     @Inject
58     private ArchivaConfiguration configuration;
59
60     private List propertyNameTriggers = new ArrayList();
61
62     private List includes = new ArrayList();
63
64     /** current repository being scanned */
65     private ManagedRepository repository;
66
67     public void beginScan( ManagedRepository repository )
68         throws ConsumerException
69     {
70         this.repository = repository;
71         log.info( "Beginning scan of repository [" + this.repository.getId() + "]" );
72     }
73
74     public void beginScan( ManagedRepository repository, Date whenGathered )
75         throws ConsumerException
76     {
77         this.repository = repository;
78         log.info( "Beginning scan of repository [" + this.repository.getId() + "]" );
79     }
80
81     public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo )
82         throws ConsumerException
83     {
84         this.repository = repository;
85         log.info( "Beginning scan of repository [" + this.repository.getId() + "]" );
86     }
87
88     public void processFile( String path )
89         throws ConsumerException
90     {
91         log.info( "Processing entry [" + path + "] from repository [" + this.repository.getId() + "]" );
92     }
93
94     public void processFile( String path, boolean executeOnEntireRepo )
95         throws ConsumerException
96     {
97         log.info( "Processing entry [" + path + "] from repository [" + this.repository.getId() + "]" );
98     }
99
100     public void completeScan()
101     {
102         log.info( "Finished scan of repository [" + this.repository.getId() + "]" );
103     }
104
105     public void completeScan( boolean executeOnEntireRepo )
106     {
107         log.info( "Finished scan of repository [" + this.repository.getId() + "]" );
108     }
109
110
111     /**
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.
114      * 
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
117      */
118     public boolean isProcessUnmodified()
119     {
120         return super.isProcessUnmodified();
121     }
122
123     public void afterConfigurationChange( org.apache.archiva.redback.components.registry.Registry registry, String propertyName, Object propertyValue )
124     {
125         if ( propertyNameTriggers.contains( propertyName ) )
126         {
127             initIncludes();
128         }
129     }
130
131     public void beforeConfigurationChange( Registry registry, String propertyName, Object propertyValue )
132     {
133         /* do nothing */
134     }
135
136     private void initIncludes()
137     {
138         includes.clear();
139         includes.addAll( filetypes.getFileTypePatterns( FileTypes.INDEXABLE_CONTENT ) );
140     }
141
142     @PostConstruct
143     public void initialize()
144         throws InitializationException
145     {
146         propertyNameTriggers = new ArrayList();
147         propertyNameTriggers.add( "repositoryScanning" );
148         propertyNameTriggers.add( "fileTypes" );
149         propertyNameTriggers.add( "fileType" );
150         propertyNameTriggers.add( "patterns" );
151         propertyNameTriggers.add( "pattern" );
152
153         configuration.addChangeListener( this );
154
155         initIncludes();
156     }
157
158     public String getId()
159     {
160         return this.id;
161     }
162
163     public String getDescription()
164     {
165         return this.description;
166     }
167
168     public List getExcludes()
169     {
170         return null;
171     }
172
173     public List getIncludes()
174     {
175         return this.includes;
176     }
177
178     public boolean isPermanent()
179     {
180         return false;
181     }
182 }