1 | |
package org.apache.maven.archiva.repository.scanner; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.io.File; |
23 | |
import java.util.ArrayList; |
24 | |
import java.util.Date; |
25 | |
import java.util.HashMap; |
26 | |
import java.util.List; |
27 | |
import java.util.Map; |
28 | |
|
29 | |
import org.apache.archiva.repository.scanner.functors.TriggerScanCompletedClosure; |
30 | |
import org.apache.commons.collections.Closure; |
31 | |
import org.apache.commons.collections.CollectionUtils; |
32 | |
import org.apache.commons.collections.functors.IfClosure; |
33 | |
import org.apache.maven.archiva.common.utils.BaseFile; |
34 | |
import org.apache.maven.archiva.configuration.ArchivaConfiguration; |
35 | |
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; |
36 | |
import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration; |
37 | |
import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer; |
38 | |
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; |
39 | |
import org.apache.maven.archiva.repository.scanner.functors.ConsumerProcessFileClosure; |
40 | |
import org.apache.maven.archiva.repository.scanner.functors.ConsumerWantsFilePredicate; |
41 | |
import org.apache.maven.archiva.repository.scanner.functors.TriggerBeginScanClosure; |
42 | |
import org.springframework.beans.BeansException; |
43 | |
import org.springframework.context.ApplicationContext; |
44 | |
import org.springframework.context.ApplicationContextAware; |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
public class RepositoryContentConsumers |
52 | |
implements ApplicationContextAware |
53 | |
{ |
54 | |
private ApplicationContext applicationContext; |
55 | |
|
56 | |
private ArchivaConfiguration archivaConfiguration; |
57 | |
|
58 | |
private List<KnownRepositoryContentConsumer> selectedKnownConsumers; |
59 | |
|
60 | |
private List<InvalidRepositoryContentConsumer> selectedInvalidConsumers; |
61 | |
|
62 | |
public RepositoryContentConsumers( ArchivaConfiguration archivaConfiguration ) |
63 | 0 | { |
64 | 0 | this.archivaConfiguration = archivaConfiguration; |
65 | 0 | } |
66 | |
|
67 | |
public void setApplicationContext( ApplicationContext applicationContext ) |
68 | |
throws BeansException |
69 | |
{ |
70 | 0 | this.applicationContext = applicationContext; |
71 | 0 | } |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
public List<String> getSelectedKnownConsumerIds() |
86 | |
{ |
87 | 0 | RepositoryScanningConfiguration scanning = archivaConfiguration.getConfiguration().getRepositoryScanning(); |
88 | 0 | return scanning.getKnownContentConsumers(); |
89 | |
} |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
public List<String> getSelectedInvalidConsumerIds() |
104 | |
{ |
105 | 0 | RepositoryScanningConfiguration scanning = archivaConfiguration.getConfiguration().getRepositoryScanning(); |
106 | 0 | return scanning.getInvalidContentConsumers(); |
107 | |
} |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
public Map<String, KnownRepositoryContentConsumer> getSelectedKnownConsumersMap() |
116 | |
{ |
117 | 0 | Map<String, KnownRepositoryContentConsumer> consumerMap = new HashMap<String, KnownRepositoryContentConsumer>(); |
118 | |
|
119 | 0 | for ( KnownRepositoryContentConsumer consumer : getSelectedKnownConsumers() ) |
120 | |
{ |
121 | 0 | consumerMap.put( consumer.getId(), consumer ); |
122 | |
} |
123 | |
|
124 | 0 | return consumerMap; |
125 | |
} |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
public Map<String, InvalidRepositoryContentConsumer> getSelectedInvalidConsumersMap() |
134 | |
{ |
135 | 0 | Map<String, InvalidRepositoryContentConsumer> consumerMap = |
136 | |
new HashMap<String, InvalidRepositoryContentConsumer>(); |
137 | |
|
138 | 0 | for ( InvalidRepositoryContentConsumer consumer : getSelectedInvalidConsumers() ) |
139 | |
{ |
140 | 0 | consumerMap.put( consumer.getId(), consumer ); |
141 | |
} |
142 | |
|
143 | 0 | return consumerMap; |
144 | |
} |
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
public synchronized List<KnownRepositoryContentConsumer> getSelectedKnownConsumers() |
153 | |
{ |
154 | 0 | if ( selectedKnownConsumers == null ) |
155 | |
{ |
156 | 0 | List<KnownRepositoryContentConsumer> ret = new ArrayList<KnownRepositoryContentConsumer>(); |
157 | |
|
158 | 0 | List<String> knownSelected = getSelectedKnownConsumerIds(); |
159 | |
|
160 | 0 | for ( KnownRepositoryContentConsumer consumer : getAvailableKnownConsumers() ) |
161 | |
{ |
162 | 0 | if ( knownSelected.contains( consumer.getId() ) || consumer.isPermanent() ) |
163 | |
{ |
164 | 0 | ret.add( consumer ); |
165 | |
} |
166 | |
} |
167 | 0 | this.selectedKnownConsumers = ret; |
168 | |
} |
169 | 0 | return selectedKnownConsumers; |
170 | |
} |
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
public synchronized List<InvalidRepositoryContentConsumer> getSelectedInvalidConsumers() |
179 | |
{ |
180 | 0 | if ( selectedInvalidConsumers == null ) |
181 | |
{ |
182 | 0 | List<InvalidRepositoryContentConsumer> ret = new ArrayList<InvalidRepositoryContentConsumer>(); |
183 | |
|
184 | 0 | List<String> invalidSelected = getSelectedInvalidConsumerIds(); |
185 | |
|
186 | 0 | for ( InvalidRepositoryContentConsumer consumer : getAvailableInvalidConsumers() ) |
187 | |
{ |
188 | 0 | if ( invalidSelected.contains( consumer.getId() ) || consumer.isPermanent() ) |
189 | |
{ |
190 | 0 | ret.add( consumer ); |
191 | |
} |
192 | |
} |
193 | 0 | selectedInvalidConsumers = ret; |
194 | |
} |
195 | 0 | return selectedInvalidConsumers; |
196 | |
} |
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
@SuppressWarnings("unchecked") |
206 | |
public List<KnownRepositoryContentConsumer> getAvailableKnownConsumers() |
207 | |
{ |
208 | 0 | return new ArrayList<KnownRepositoryContentConsumer>( applicationContext.getBeansOfType( KnownRepositoryContentConsumer.class ).values() ); |
209 | |
} |
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
@SuppressWarnings("unchecked") |
219 | |
public List<InvalidRepositoryContentConsumer> getAvailableInvalidConsumers() |
220 | |
{ |
221 | 0 | return new ArrayList<InvalidRepositoryContentConsumer>( applicationContext.getBeansOfType( InvalidRepositoryContentConsumer.class ).values() ); |
222 | |
} |
223 | |
|
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
public void executeConsumers( ManagedRepositoryConfiguration repository, File localFile, boolean updateRelatedArtifacts ) |
235 | |
{ |
236 | |
|
237 | |
try |
238 | |
{ |
239 | 0 | Closure triggerBeginScan = new TriggerBeginScanClosure( repository, getStartTime(), false ); |
240 | |
|
241 | 0 | List<KnownRepositoryContentConsumer> selectedKnownConsumers = getSelectedKnownConsumers(); |
242 | |
|
243 | |
|
244 | |
|
245 | 0 | if( updateRelatedArtifacts == false ) |
246 | |
{ |
247 | 0 | List<KnownRepositoryContentConsumer> clone = new ArrayList<KnownRepositoryContentConsumer>(); |
248 | 0 | clone.addAll( selectedKnownConsumers ); |
249 | |
|
250 | 0 | for( KnownRepositoryContentConsumer consumer : clone ) |
251 | |
{ |
252 | 0 | if( consumer.getId().equals( "create-missing-checksums" ) || |
253 | |
consumer.getId().equals( "metadata-updater" ) ) |
254 | |
{ |
255 | 0 | selectedKnownConsumers.remove( consumer ); |
256 | |
} |
257 | |
} |
258 | |
} |
259 | |
|
260 | 0 | List<InvalidRepositoryContentConsumer> selectedInvalidConsumers = getSelectedInvalidConsumers(); |
261 | 0 | CollectionUtils.forAllDo( selectedKnownConsumers, triggerBeginScan ); |
262 | 0 | CollectionUtils.forAllDo( selectedInvalidConsumers, triggerBeginScan ); |
263 | |
|
264 | |
|
265 | |
|
266 | 0 | BaseFile baseFile = new BaseFile( repository.getLocation(), localFile ); |
267 | 0 | ConsumerWantsFilePredicate predicate = new ConsumerWantsFilePredicate(); |
268 | 0 | predicate.setBasefile( baseFile ); |
269 | 0 | predicate.setCaseSensitive( false ); |
270 | |
|
271 | 0 | ConsumerProcessFileClosure closure = new ConsumerProcessFileClosure(); |
272 | 0 | closure.setBasefile( baseFile ); |
273 | 0 | closure.setExecuteOnEntireRepo( false ); |
274 | |
|
275 | 0 | Closure processIfWanted = IfClosure.getInstance( predicate, closure ); |
276 | |
|
277 | 0 | CollectionUtils.forAllDo( selectedKnownConsumers, processIfWanted ); |
278 | |
|
279 | 0 | if ( predicate.getWantedFileCount() <= 0 ) |
280 | |
{ |
281 | |
|
282 | 0 | CollectionUtils.forAllDo( selectedInvalidConsumers, closure ); |
283 | |
} |
284 | |
|
285 | 0 | TriggerScanCompletedClosure scanCompletedClosure = new TriggerScanCompletedClosure( repository, false ); |
286 | |
|
287 | 0 | CollectionUtils.forAllDo( selectedKnownConsumers, scanCompletedClosure ); |
288 | |
} |
289 | |
finally |
290 | 0 | { |
291 | |
|
292 | |
|
293 | |
|
294 | |
|
295 | |
|
296 | 0 | } |
297 | 0 | } |
298 | |
|
299 | |
public void setSelectedKnownConsumers( List<KnownRepositoryContentConsumer> selectedKnownConsumers ) |
300 | |
{ |
301 | 0 | this.selectedKnownConsumers = selectedKnownConsumers; |
302 | 0 | } |
303 | |
|
304 | |
public void setSelectedInvalidConsumers( List<InvalidRepositoryContentConsumer> selectedInvalidConsumers ) |
305 | |
{ |
306 | 0 | this.selectedInvalidConsumers = selectedInvalidConsumers; |
307 | 0 | } |
308 | |
|
309 | |
protected Date getStartTime() |
310 | |
{ |
311 | 0 | return new Date( System.currentTimeMillis() ); |
312 | |
} |
313 | |
|
314 | |
public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration ) |
315 | |
{ |
316 | 0 | this.archivaConfiguration = archivaConfiguration; |
317 | 0 | } |
318 | |
} |