1 | |
package org.apache.maven.plugin.assembly.archive.archiver; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import org.apache.maven.plugin.assembly.filter.ContainerDescriptorHandler; |
23 | |
import org.codehaus.plexus.archiver.ArchiveFinalizer; |
24 | |
import org.codehaus.plexus.archiver.ArchivedFileSet; |
25 | |
import org.codehaus.plexus.archiver.Archiver; |
26 | |
import org.codehaus.plexus.archiver.ArchiverException; |
27 | |
import org.codehaus.plexus.archiver.FileSet; |
28 | |
import org.codehaus.plexus.archiver.FinalizerEnabled; |
29 | |
import org.codehaus.plexus.archiver.ResourceIterator; |
30 | |
import org.codehaus.plexus.archiver.util.DefaultArchivedFileSet; |
31 | |
import org.codehaus.plexus.archiver.util.DefaultFileSet; |
32 | |
import org.codehaus.plexus.components.io.fileselectors.FileInfo; |
33 | |
import org.codehaus.plexus.components.io.fileselectors.FileSelector; |
34 | |
import org.codehaus.plexus.components.io.resources.PlexusIoResource; |
35 | |
import org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection; |
36 | |
import org.codehaus.plexus.logging.Logger; |
37 | |
|
38 | |
import java.io.File; |
39 | |
import java.io.FileInputStream; |
40 | |
import java.io.IOException; |
41 | |
import java.io.InputStream; |
42 | |
import java.util.ArrayList; |
43 | |
import java.util.Arrays; |
44 | |
import java.util.HashSet; |
45 | |
import java.util.Iterator; |
46 | |
import java.util.List; |
47 | |
import java.util.Map; |
48 | |
import java.util.Set; |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
public class AssemblyProxyArchiver |
62 | |
implements Archiver |
63 | |
{ |
64 | |
|
65 | 3 | private static final String[] STR_TEMPLATE = new String[0]; |
66 | |
|
67 | |
private final Archiver delegate; |
68 | |
|
69 | |
private String rootPrefix; |
70 | |
|
71 | |
private FileSelector[] selectors; |
72 | |
|
73 | 27 | private final ThreadLocal<Boolean> inPublicApi = new ThreadLocal<Boolean>(); |
74 | |
|
75 | |
private final Logger logger; |
76 | |
|
77 | |
private final boolean dryRun; |
78 | |
|
79 | |
private boolean forced; |
80 | |
|
81 | 27 | private final Set<String> seenPaths = new HashSet<String>(); |
82 | |
|
83 | |
private final String assemblyWorkPath; |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
private boolean useJvmChmod; |
89 | |
|
90 | |
public AssemblyProxyArchiver( final String rootPrefix, final Archiver delegate, |
91 | |
final List<ContainerDescriptorHandler> containerDescriptorHandlers, |
92 | |
final List<FileSelector> extraSelectors, |
93 | |
final List<ArchiveFinalizer> extraFinalizers, final File assemblyWorkDir, |
94 | |
final Logger logger, final boolean dryRun ) |
95 | 27 | { |
96 | 27 | this.rootPrefix = rootPrefix; |
97 | 27 | this.delegate = delegate; |
98 | |
|
99 | 27 | assemblyWorkPath = assemblyWorkDir.getAbsolutePath() |
100 | |
.replace( '\\', '/' ); |
101 | |
|
102 | 27 | this.logger = logger; |
103 | 27 | this.dryRun = dryRun; |
104 | |
|
105 | 27 | if ( !"".equals( rootPrefix ) && !rootPrefix.endsWith( "/" ) ) |
106 | |
{ |
107 | 3 | this.rootPrefix += "/"; |
108 | |
} |
109 | |
|
110 | 27 | final List<FileSelector> selectors = new ArrayList<FileSelector>(); |
111 | |
|
112 | 27 | final boolean isFinalizerEnabled = ( delegate instanceof FinalizerEnabled ); |
113 | |
|
114 | 27 | if ( containerDescriptorHandlers != null ) |
115 | |
{ |
116 | 3 | for ( final Iterator<ContainerDescriptorHandler> it = containerDescriptorHandlers.iterator(); it.hasNext(); ) |
117 | |
{ |
118 | 3 | final ContainerDescriptorHandler handler = it.next(); |
119 | |
|
120 | 3 | selectors.add( handler ); |
121 | |
|
122 | 3 | if ( isFinalizerEnabled ) |
123 | |
{ |
124 | 0 | ( (FinalizerEnabled) delegate ).addArchiveFinalizer( handler ); |
125 | |
} |
126 | 3 | } |
127 | |
} |
128 | |
|
129 | 27 | if ( extraSelectors != null ) |
130 | |
{ |
131 | 21 | for ( final Iterator<FileSelector> it = extraSelectors.iterator(); it.hasNext(); ) |
132 | |
{ |
133 | 9 | final FileSelector selector = it.next(); |
134 | 9 | selectors.add( selector ); |
135 | 9 | } |
136 | |
} |
137 | |
|
138 | 27 | if ( ( extraFinalizers != null ) && isFinalizerEnabled ) |
139 | |
{ |
140 | 9 | for ( final Iterator<ArchiveFinalizer> it = extraFinalizers.iterator(); it.hasNext(); ) |
141 | |
{ |
142 | 3 | ( (FinalizerEnabled) delegate ).addArchiveFinalizer( it.next() ); |
143 | |
} |
144 | |
} |
145 | |
|
146 | 27 | if ( !selectors.isEmpty() ) |
147 | |
{ |
148 | 12 | this.selectors = selectors.toArray( new FileSelector[selectors.size()] ); |
149 | |
} |
150 | 27 | } |
151 | |
|
152 | |
public void addArchivedFileSet( final File archiveFile, final String prefix, final String[] includes, |
153 | |
final String[] excludes ) |
154 | |
throws ArchiverException |
155 | |
{ |
156 | 0 | final String archiveKey = getArchiveKey( archiveFile, prefix ); |
157 | 0 | if ( seenPaths.contains( archiveKey ) ) |
158 | |
{ |
159 | 0 | warn( "Archive: " + archiveFile + " has already been added. Skipping." ); |
160 | 0 | return; |
161 | |
} |
162 | |
|
163 | 0 | inPublicApi.set( Boolean.TRUE ); |
164 | |
try |
165 | |
{ |
166 | 0 | final DefaultArchivedFileSet fs = new DefaultArchivedFileSet(); |
167 | |
|
168 | 0 | fs.setArchive( archiveFile ); |
169 | 0 | fs.setIncludes( includes ); |
170 | 0 | fs.setExcludes( excludes ); |
171 | 0 | fs.setPrefix( rootPrefix + prefix ); |
172 | 0 | fs.setFileSelectors( selectors ); |
173 | |
|
174 | 0 | debug( "Adding archived file-set in: " + archiveFile + " to archive location: " + fs.getPrefix() ); |
175 | |
|
176 | 0 | if ( dryRun ) |
177 | |
{ |
178 | 0 | debug( "DRY RUN: Skipping delegated call to: " + getMethodName() ); |
179 | |
} |
180 | |
else |
181 | |
{ |
182 | 0 | delegate.addArchivedFileSet( fs ); |
183 | 0 | seenPaths.add( archiveKey ); |
184 | |
} |
185 | |
} |
186 | |
finally |
187 | |
{ |
188 | 0 | inPublicApi.set( null ); |
189 | 0 | } |
190 | 0 | } |
191 | |
|
192 | |
private String getArchiveKey( final File archiveFile, final String prefix ) |
193 | |
{ |
194 | 0 | return archiveFile.getAbsolutePath() + ":" + prefix; |
195 | |
} |
196 | |
|
197 | |
private void debug( final String message ) |
198 | |
{ |
199 | 12 | if ( ( logger != null ) && logger.isDebugEnabled() ) |
200 | |
{ |
201 | 12 | logger.debug( message ); |
202 | |
} |
203 | 12 | } |
204 | |
|
205 | |
private void warn( final String message ) |
206 | |
{ |
207 | 0 | if ( ( logger != null ) && logger.isWarnEnabled() ) |
208 | |
{ |
209 | 0 | logger.warn( message ); |
210 | |
} |
211 | 0 | } |
212 | |
|
213 | |
public void addArchivedFileSet( final File archiveFile, final String prefix ) |
214 | |
throws ArchiverException |
215 | |
{ |
216 | 0 | final String archiveKey = getArchiveKey( archiveFile, prefix ); |
217 | 0 | if ( seenPaths.contains( archiveKey ) ) |
218 | |
{ |
219 | 0 | warn( "Archive: " + archiveFile + " has already been added. Skipping." ); |
220 | 0 | return; |
221 | |
} |
222 | |
|
223 | 0 | inPublicApi.set( Boolean.TRUE ); |
224 | |
try |
225 | |
{ |
226 | 0 | final DefaultArchivedFileSet fs = new DefaultArchivedFileSet(); |
227 | |
|
228 | 0 | fs.setArchive( archiveFile ); |
229 | 0 | fs.setPrefix( rootPrefix + prefix ); |
230 | 0 | fs.setFileSelectors( selectors ); |
231 | |
|
232 | 0 | debug( "Adding archived file-set in: " + archiveFile + " to archive location: " + fs.getPrefix() ); |
233 | |
|
234 | 0 | if ( dryRun ) |
235 | |
{ |
236 | 0 | debug( "DRY RUN: Skipping delegated call to: " + getMethodName() ); |
237 | |
} |
238 | |
else |
239 | |
{ |
240 | 0 | delegate.addArchivedFileSet( fs ); |
241 | 0 | seenPaths.add( archiveKey ); |
242 | |
} |
243 | |
} |
244 | |
finally |
245 | |
{ |
246 | 0 | inPublicApi.set( null ); |
247 | 0 | } |
248 | 0 | } |
249 | |
|
250 | |
public void addArchivedFileSet( final File archiveFile, final String[] includes, final String[] excludes ) |
251 | |
throws ArchiverException |
252 | |
{ |
253 | 0 | final String archiveKey = getArchiveKey( archiveFile, "" ); |
254 | 0 | if ( seenPaths.contains( archiveKey ) ) |
255 | |
{ |
256 | 0 | warn( "Archive: " + archiveFile + " has already been added. Skipping." ); |
257 | 0 | return; |
258 | |
} |
259 | |
|
260 | 0 | inPublicApi.set( Boolean.TRUE ); |
261 | |
try |
262 | |
{ |
263 | 0 | final DefaultArchivedFileSet fs = new DefaultArchivedFileSet(); |
264 | |
|
265 | 0 | fs.setArchive( archiveFile ); |
266 | 0 | fs.setIncludes( includes ); |
267 | 0 | fs.setExcludes( excludes ); |
268 | 0 | fs.setPrefix( rootPrefix ); |
269 | 0 | fs.setFileSelectors( selectors ); |
270 | |
|
271 | 0 | debug( "Adding archived file-set in: " + archiveFile + " to archive location: " + fs.getPrefix() ); |
272 | |
|
273 | 0 | if ( dryRun ) |
274 | |
{ |
275 | 0 | debug( "DRY RUN: Skipping delegated call to: " + getMethodName() ); |
276 | |
} |
277 | |
else |
278 | |
{ |
279 | 0 | delegate.addArchivedFileSet( fs ); |
280 | 0 | seenPaths.add( archiveKey ); |
281 | |
} |
282 | |
} |
283 | |
finally |
284 | |
{ |
285 | 0 | inPublicApi.set( null ); |
286 | 0 | } |
287 | 0 | } |
288 | |
|
289 | |
public void addArchivedFileSet( final File archiveFile ) |
290 | |
throws ArchiverException |
291 | |
{ |
292 | 0 | final String archiveKey = getArchiveKey( archiveFile, "" ); |
293 | 0 | if ( seenPaths.contains( archiveKey ) ) |
294 | |
{ |
295 | 0 | warn( "Archive: " + archiveFile + " has already been added. Skipping." ); |
296 | 0 | return; |
297 | |
} |
298 | |
|
299 | 0 | inPublicApi.set( Boolean.TRUE ); |
300 | |
try |
301 | |
{ |
302 | 0 | final DefaultArchivedFileSet fs = new DefaultArchivedFileSet(); |
303 | |
|
304 | 0 | fs.setArchive( archiveFile ); |
305 | 0 | fs.setPrefix( rootPrefix ); |
306 | 0 | fs.setFileSelectors( selectors ); |
307 | |
|
308 | 0 | debug( "Adding archived file-set in: " + archiveFile + " to archive location: " + fs.getPrefix() ); |
309 | |
|
310 | 0 | if ( dryRun ) |
311 | |
{ |
312 | 0 | debug( "DRY RUN: Skipping delegated call to: " + getMethodName() ); |
313 | |
} |
314 | |
else |
315 | |
{ |
316 | 0 | delegate.addArchivedFileSet( fs ); |
317 | 0 | seenPaths.add( archiveKey ); |
318 | |
} |
319 | |
} |
320 | |
finally |
321 | |
{ |
322 | 0 | inPublicApi.set( null ); |
323 | 0 | } |
324 | 0 | } |
325 | |
|
326 | |
public void addDirectory( final File directory, final String prefix, final String[] includes, |
327 | |
final String[] excludes ) |
328 | |
throws ArchiverException |
329 | |
{ |
330 | 0 | inPublicApi.set( Boolean.TRUE ); |
331 | |
try |
332 | |
{ |
333 | 0 | final DefaultFileSet fs = new DefaultFileSet(); |
334 | |
|
335 | 0 | fs.setDirectory( directory ); |
336 | 0 | fs.setIncludes( includes ); |
337 | 0 | fs.setExcludes( excludes ); |
338 | 0 | fs.setPrefix( rootPrefix + prefix ); |
339 | 0 | fs.setFileSelectors( selectors ); |
340 | |
|
341 | 0 | debug( "Adding directory file-set in: " + directory + " to archive location: " + fs.getPrefix() ); |
342 | |
|
343 | 0 | if ( dryRun ) |
344 | |
{ |
345 | 0 | debug( "DRY RUN: Skipping delegated call to: " + getMethodName() ); |
346 | |
} |
347 | |
else |
348 | |
{ |
349 | 0 | doAddFileSet( fs ); |
350 | |
} |
351 | |
} |
352 | |
finally |
353 | |
{ |
354 | 0 | inPublicApi.set( null ); |
355 | 0 | } |
356 | 0 | } |
357 | |
|
358 | |
public void addDirectory( final File directory, final String prefix ) |
359 | |
throws ArchiverException |
360 | |
{ |
361 | 0 | inPublicApi.set( Boolean.TRUE ); |
362 | |
try |
363 | |
{ |
364 | 0 | final DefaultFileSet fs = new DefaultFileSet(); |
365 | |
|
366 | 0 | fs.setDirectory( directory ); |
367 | 0 | fs.setPrefix( rootPrefix + prefix ); |
368 | 0 | fs.setFileSelectors( selectors ); |
369 | |
|
370 | 0 | debug( "Adding directory file-set in: " + directory + " to archive location: " + fs.getPrefix() ); |
371 | |
|
372 | 0 | if ( dryRun ) |
373 | |
{ |
374 | 0 | debug( "DRY RUN: Skipping delegated call to: " + getMethodName() ); |
375 | |
} |
376 | |
else |
377 | |
{ |
378 | 0 | doAddFileSet( fs ); |
379 | |
} |
380 | |
} |
381 | |
finally |
382 | |
{ |
383 | 0 | inPublicApi.set( null ); |
384 | 0 | } |
385 | 0 | } |
386 | |
|
387 | |
public void addDirectory( final File directory, final String[] includes, final String[] excludes ) |
388 | |
throws ArchiverException |
389 | |
{ |
390 | 0 | inPublicApi.set( Boolean.TRUE ); |
391 | |
try |
392 | |
{ |
393 | 0 | final DefaultFileSet fs = new DefaultFileSet(); |
394 | |
|
395 | 0 | fs.setDirectory( directory ); |
396 | 0 | fs.setIncludes( includes ); |
397 | 0 | fs.setExcludes( excludes ); |
398 | 0 | fs.setPrefix( rootPrefix ); |
399 | 0 | fs.setFileSelectors( selectors ); |
400 | |
|
401 | 0 | debug( "Adding directory file-set in: " + directory + " to archive location: " + fs.getPrefix() ); |
402 | |
|
403 | 0 | if ( dryRun ) |
404 | |
{ |
405 | 0 | debug( "DRY RUN: Skipping delegated call to: " + getMethodName() ); |
406 | |
} |
407 | |
else |
408 | |
{ |
409 | 0 | doAddFileSet( fs ); |
410 | |
} |
411 | |
} |
412 | |
finally |
413 | |
{ |
414 | 0 | inPublicApi.set( null ); |
415 | 0 | } |
416 | 0 | } |
417 | |
|
418 | |
public void addDirectory( final File directory ) |
419 | |
throws ArchiverException |
420 | |
{ |
421 | 3 | inPublicApi.set( Boolean.TRUE ); |
422 | |
try |
423 | |
{ |
424 | 3 | final DefaultFileSet fs = new DefaultFileSet(); |
425 | |
|
426 | 3 | fs.setDirectory( directory ); |
427 | 3 | fs.setPrefix( rootPrefix ); |
428 | 3 | fs.setFileSelectors( selectors ); |
429 | |
|
430 | 3 | debug( "Adding directory file-set in: " + directory + " to archive location: " + fs.getPrefix() ); |
431 | |
|
432 | 3 | if ( dryRun ) |
433 | |
{ |
434 | 0 | debug( "DRY RUN: Skipping delegated call to: " + getMethodName() ); |
435 | |
} |
436 | |
else |
437 | |
{ |
438 | 3 | doAddFileSet( fs ); |
439 | |
} |
440 | |
} |
441 | |
finally |
442 | |
{ |
443 | 3 | inPublicApi.set( null ); |
444 | 3 | } |
445 | 3 | } |
446 | |
|
447 | |
public void addFile( final File inputFile, final String destFileName, final int permissions ) |
448 | |
throws ArchiverException |
449 | |
{ |
450 | 0 | if ( acceptFile( inputFile ) ) |
451 | |
{ |
452 | 0 | inPublicApi.set( Boolean.TRUE ); |
453 | |
try |
454 | |
{ |
455 | 0 | debug( "Adding file: " + inputFile + " to archive location: " + rootPrefix + destFileName ); |
456 | |
|
457 | 0 | if ( dryRun ) |
458 | |
{ |
459 | 0 | debug( "DRY RUN: Skipping delegated call to: " + getMethodName() ); |
460 | |
} |
461 | |
else |
462 | |
{ |
463 | 0 | delegate.addFile( inputFile, rootPrefix + destFileName, permissions ); |
464 | |
} |
465 | |
} |
466 | |
finally |
467 | |
{ |
468 | 0 | inPublicApi.set( null ); |
469 | 0 | } |
470 | |
} |
471 | 0 | } |
472 | |
|
473 | |
public void addFile( final File inputFile, final String destFileName ) |
474 | |
throws ArchiverException |
475 | |
{ |
476 | 3 | if ( acceptFile( inputFile ) ) |
477 | |
{ |
478 | 3 | inPublicApi.set( Boolean.TRUE ); |
479 | |
try |
480 | |
{ |
481 | 3 | debug( "Adding file: " + inputFile + " to archive location: " + rootPrefix + destFileName ); |
482 | |
|
483 | 3 | if ( dryRun ) |
484 | |
{ |
485 | 0 | debug( "DRY RUN: Skipping delegated call to: " + getMethodName() ); |
486 | |
} |
487 | |
else |
488 | |
{ |
489 | 3 | delegate.addFile( inputFile, rootPrefix + destFileName ); |
490 | |
} |
491 | |
} |
492 | |
finally |
493 | |
{ |
494 | 3 | inPublicApi.set( null ); |
495 | 3 | } |
496 | |
} |
497 | 3 | } |
498 | |
|
499 | |
public void createArchive() |
500 | |
throws ArchiverException, IOException |
501 | |
{ |
502 | 6 | inPublicApi.set( Boolean.TRUE ); |
503 | |
try |
504 | |
{ |
505 | 6 | if ( dryRun ) |
506 | |
{ |
507 | 0 | debug( "DRY RUN: Skipping delegated call to: " + getMethodName() ); |
508 | |
} |
509 | |
else |
510 | |
{ |
511 | 6 | delegate.setForced( forced ); |
512 | 6 | delegate.createArchive(); |
513 | |
} |
514 | |
} |
515 | |
finally |
516 | |
{ |
517 | 6 | inPublicApi.set( null ); |
518 | 6 | } |
519 | 6 | } |
520 | |
|
521 | |
public int getDefaultDirectoryMode() |
522 | |
{ |
523 | 0 | inPublicApi.set( Boolean.TRUE ); |
524 | |
try |
525 | |
{ |
526 | 0 | return delegate.getDefaultDirectoryMode(); |
527 | |
} |
528 | |
finally |
529 | |
{ |
530 | 0 | inPublicApi.set( null ); |
531 | |
} |
532 | |
} |
533 | |
|
534 | |
public int getDefaultFileMode() |
535 | |
{ |
536 | 0 | inPublicApi.set( Boolean.TRUE ); |
537 | |
try |
538 | |
{ |
539 | 0 | return delegate.getDefaultFileMode(); |
540 | |
} |
541 | |
finally |
542 | |
{ |
543 | 0 | inPublicApi.set( null ); |
544 | |
} |
545 | |
} |
546 | |
|
547 | |
public File getDestFile() |
548 | |
{ |
549 | 0 | inPublicApi.set( Boolean.TRUE ); |
550 | |
try |
551 | |
{ |
552 | 0 | return delegate.getDestFile(); |
553 | |
} |
554 | |
finally |
555 | |
{ |
556 | 0 | inPublicApi.set( null ); |
557 | |
} |
558 | |
} |
559 | |
|
560 | |
@SuppressWarnings( { "rawtypes", "deprecation" } ) |
561 | |
public Map getFiles() |
562 | |
{ |
563 | 0 | inPublicApi.set( Boolean.TRUE ); |
564 | |
try |
565 | |
{ |
566 | 0 | return delegate.getFiles(); |
567 | |
} |
568 | |
finally |
569 | |
{ |
570 | 0 | inPublicApi.set( null ); |
571 | |
} |
572 | |
} |
573 | |
|
574 | |
public boolean getIncludeEmptyDirs() |
575 | |
{ |
576 | 0 | inPublicApi.set( Boolean.TRUE ); |
577 | |
try |
578 | |
{ |
579 | 0 | return delegate.getIncludeEmptyDirs(); |
580 | |
} |
581 | |
finally |
582 | |
{ |
583 | 0 | inPublicApi.set( null ); |
584 | |
} |
585 | |
} |
586 | |
|
587 | |
public boolean isForced() |
588 | |
{ |
589 | 0 | inPublicApi.set( Boolean.TRUE ); |
590 | |
try |
591 | |
{ |
592 | 0 | return delegate.isForced(); |
593 | |
} |
594 | |
finally |
595 | |
{ |
596 | 0 | inPublicApi.set( null ); |
597 | |
} |
598 | |
} |
599 | |
|
600 | |
public boolean isSupportingForced() |
601 | |
{ |
602 | 0 | inPublicApi.set( Boolean.TRUE ); |
603 | |
try |
604 | |
{ |
605 | 0 | return delegate.isSupportingForced(); |
606 | |
} |
607 | |
finally |
608 | |
{ |
609 | 0 | inPublicApi.set( null ); |
610 | |
} |
611 | |
} |
612 | |
|
613 | |
public void setDefaultDirectoryMode( final int mode ) |
614 | |
{ |
615 | 0 | inPublicApi.set( Boolean.TRUE ); |
616 | |
try |
617 | |
{ |
618 | 0 | delegate.setDefaultDirectoryMode( mode ); |
619 | |
} |
620 | |
finally |
621 | |
{ |
622 | 0 | inPublicApi.set( null ); |
623 | 0 | } |
624 | 0 | } |
625 | |
|
626 | |
public void setDefaultFileMode( final int mode ) |
627 | |
{ |
628 | 0 | inPublicApi.set( Boolean.TRUE ); |
629 | |
try |
630 | |
{ |
631 | 0 | delegate.setDefaultFileMode( mode ); |
632 | |
} |
633 | |
finally |
634 | |
{ |
635 | 0 | inPublicApi.set( null ); |
636 | 0 | } |
637 | 0 | } |
638 | |
|
639 | |
public void setDestFile( final File destFile ) |
640 | |
{ |
641 | 3 | inPublicApi.set( Boolean.TRUE ); |
642 | |
try |
643 | |
{ |
644 | 3 | delegate.setDestFile( destFile ); |
645 | |
} |
646 | |
finally |
647 | |
{ |
648 | 3 | inPublicApi.set( null ); |
649 | 3 | } |
650 | 3 | } |
651 | |
|
652 | |
public void setForced( final boolean forced ) |
653 | |
{ |
654 | 27 | inPublicApi.set( Boolean.TRUE ); |
655 | |
try |
656 | |
{ |
657 | 27 | this.forced = forced; |
658 | 27 | delegate.setForced( forced ); |
659 | |
} |
660 | |
finally |
661 | |
{ |
662 | 27 | inPublicApi.set( null ); |
663 | 27 | } |
664 | 27 | } |
665 | |
|
666 | |
public void setIncludeEmptyDirs( final boolean includeEmptyDirs ) |
667 | |
{ |
668 | 0 | inPublicApi.set( Boolean.TRUE ); |
669 | |
try |
670 | |
{ |
671 | 0 | delegate.setIncludeEmptyDirs( includeEmptyDirs ); |
672 | |
} |
673 | |
finally |
674 | |
{ |
675 | 0 | inPublicApi.set( null ); |
676 | 0 | } |
677 | 0 | } |
678 | |
|
679 | |
public void setDotFileDirectory( final File dotFileDirectory ) |
680 | |
{ |
681 | 0 | throw new UnsupportedOperationException( "Undocumented feature of plexus-archiver; this is not yet supported." ); |
682 | |
} |
683 | |
|
684 | |
public void addArchivedFileSet( final ArchivedFileSet fileSet ) |
685 | |
throws ArchiverException |
686 | |
{ |
687 | 0 | final String archiveKey = getArchiveKey( fileSet.getArchive(), "" ); |
688 | 0 | if ( seenPaths.contains( archiveKey ) ) |
689 | |
{ |
690 | 0 | warn( "Archive: " + fileSet.getArchive() + " has already been added. Skipping." ); |
691 | 0 | return; |
692 | |
} |
693 | |
|
694 | 0 | inPublicApi.set( Boolean.TRUE ); |
695 | |
try |
696 | |
{ |
697 | 0 | final PrefixedArchivedFileSet fs = new PrefixedArchivedFileSet( fileSet, rootPrefix, selectors ); |
698 | |
|
699 | 0 | debug( "Adding archived file-set in: " + fileSet.getArchive() + " to archive location: " + fs.getPrefix() ); |
700 | |
|
701 | 0 | if ( dryRun ) |
702 | |
{ |
703 | 0 | debug( "DRY RUN: Skipping delegated call to: " + getMethodName() ); |
704 | |
} |
705 | |
else |
706 | |
{ |
707 | 0 | delegate.addArchivedFileSet( fs ); |
708 | 0 | seenPaths.add( archiveKey ); |
709 | |
} |
710 | |
} |
711 | |
finally |
712 | |
{ |
713 | 0 | inPublicApi.set( null ); |
714 | 0 | } |
715 | 0 | } |
716 | |
|
717 | |
public void addFileSet( final FileSet fileSet ) |
718 | |
throws ArchiverException |
719 | |
{ |
720 | 6 | inPublicApi.set( Boolean.TRUE ); |
721 | |
try |
722 | |
{ |
723 | 6 | final PrefixedFileSet fs = new PrefixedFileSet( fileSet, rootPrefix, selectors ); |
724 | |
|
725 | 6 | debug( "Adding file-set in: " + fileSet.getDirectory() + " to archive location: " + fs.getPrefix() ); |
726 | |
|
727 | 6 | if ( dryRun ) |
728 | |
{ |
729 | 0 | debug( "DRY RUN: Skipping delegated call to: " + getMethodName() ); |
730 | |
} |
731 | |
else |
732 | |
{ |
733 | 6 | doAddFileSet( fs ); |
734 | |
} |
735 | |
} |
736 | |
finally |
737 | |
{ |
738 | 6 | inPublicApi.set( null ); |
739 | 6 | } |
740 | 6 | } |
741 | |
|
742 | |
private void doAddFileSet( final FileSet fs ) |
743 | |
throws ArchiverException |
744 | |
{ |
745 | 9 | final String fsPath = fs.getDirectory() |
746 | |
.getAbsolutePath() |
747 | |
.replace( '\\', '/' ); |
748 | |
|
749 | 9 | if ( fsPath.equals( assemblyWorkPath ) ) |
750 | |
{ |
751 | 3 | logger.debug( "SKIPPING fileset with source directory matching assembly working-directory: " + fsPath ); |
752 | 3 | return; |
753 | |
} |
754 | 6 | else if ( assemblyWorkPath.startsWith( fsPath ) ) |
755 | |
{ |
756 | 3 | final List<String> newEx = new ArrayList<String>(); |
757 | 3 | if ( fs.getExcludes() != null ) |
758 | |
{ |
759 | 0 | newEx.addAll( Arrays.asList( fs.getExcludes() ) ); |
760 | |
} |
761 | |
|
762 | 3 | final String workDirExclude = assemblyWorkPath.substring( fsPath.length() + 1 ); |
763 | |
|
764 | 3 | logger.debug( "Adding exclude for assembly working-directory: " + workDirExclude |
765 | |
+ "\nFile-Set source directory: " + fsPath ); |
766 | |
|
767 | 3 | newEx.add( workDirExclude ); |
768 | |
|
769 | 3 | final List<String> newIn = new ArrayList<String>(); |
770 | 3 | if ( fs.getIncludes() != null ) |
771 | |
{ |
772 | 0 | for ( final String include : fs.getIncludes() ) |
773 | |
{ |
774 | 0 | if ( !include.startsWith( workDirExclude ) ) |
775 | |
{ |
776 | 0 | newIn.add( include ); |
777 | |
} |
778 | |
} |
779 | |
} |
780 | |
|
781 | 3 | final DefaultFileSet dfs = new DefaultFileSet(); |
782 | |
|
783 | 3 | dfs.setCaseSensitive( fs.isCaseSensitive() ); |
784 | 3 | dfs.setDirectory( fs.getDirectory() ); |
785 | 3 | dfs.setExcludes( newEx.toArray( STR_TEMPLATE ) ); |
786 | 3 | dfs.setFileSelectors( fs.getFileSelectors() ); |
787 | 3 | dfs.setIncludes( newIn.toArray( STR_TEMPLATE ) ); |
788 | 3 | dfs.setIncludingEmptyDirectories( fs.isIncludingEmptyDirectories() ); |
789 | 3 | dfs.setPrefix( fs.getPrefix() ); |
790 | 3 | dfs.setUsingDefaultExcludes( fs.isUsingDefaultExcludes() ); |
791 | |
|
792 | 3 | delegate.addFileSet( dfs ); |
793 | 3 | } |
794 | |
else |
795 | |
{ |
796 | 3 | delegate.addFileSet( fs ); |
797 | |
} |
798 | 6 | } |
799 | |
|
800 | |
private String getMethodName() |
801 | |
{ |
802 | 0 | final NullPointerException npe = new NullPointerException(); |
803 | 0 | final StackTraceElement[] trace = npe.getStackTrace(); |
804 | |
|
805 | 0 | final StackTraceElement methodElement = trace[1]; |
806 | |
|
807 | 0 | return methodElement.getMethodName() + " (archiver line: " + methodElement.getLineNumber() + ")"; |
808 | |
} |
809 | |
|
810 | |
private boolean acceptFile( final File inputFile ) |
811 | |
throws ArchiverException |
812 | |
{ |
813 | 3 | if ( Boolean.TRUE != inPublicApi.get() ) |
814 | |
{ |
815 | 3 | if ( selectors != null ) |
816 | |
{ |
817 | 3 | final FileInfo fileInfo = new DefaultFileInfo( inputFile ); |
818 | |
|
819 | 6 | for ( int i = 0; i < selectors.length; i++ ) |
820 | |
{ |
821 | 3 | final FileSelector selector = selectors[i]; |
822 | |
|
823 | |
try |
824 | |
{ |
825 | 3 | if ( !selector.isSelected( fileInfo ) ) |
826 | |
{ |
827 | 0 | return false; |
828 | |
} |
829 | |
} |
830 | 0 | catch ( final IOException e ) |
831 | |
{ |
832 | 0 | throw new ArchiverException( "Error processing file: " + inputFile + " using selector: " |
833 | |
+ selectors[i], e ); |
834 | 3 | } |
835 | |
} |
836 | |
} |
837 | |
} |
838 | |
|
839 | 3 | return true; |
840 | |
} |
841 | |
|
842 | |
private static final class DefaultFileInfo |
843 | |
implements FileInfo |
844 | |
{ |
845 | |
|
846 | |
private final File inputFile; |
847 | |
|
848 | |
DefaultFileInfo( final File inputFile ) |
849 | 3 | { |
850 | 3 | this.inputFile = inputFile; |
851 | 3 | } |
852 | |
|
853 | |
public InputStream getContents() |
854 | |
throws IOException |
855 | |
{ |
856 | 0 | return new FileInputStream( inputFile ); |
857 | |
} |
858 | |
|
859 | |
public String getName() |
860 | |
{ |
861 | 3 | return inputFile.getName(); |
862 | |
} |
863 | |
|
864 | |
public boolean isDirectory() |
865 | |
{ |
866 | 0 | return inputFile.isDirectory(); |
867 | |
} |
868 | |
|
869 | |
public boolean isFile() |
870 | |
{ |
871 | 3 | return inputFile.isFile(); |
872 | |
} |
873 | |
|
874 | |
} |
875 | |
|
876 | |
public void addResource( final PlexusIoResource resource, final String destFileName, final int permissions ) |
877 | |
throws ArchiverException |
878 | |
{ |
879 | 0 | inPublicApi.set( Boolean.TRUE ); |
880 | |
try |
881 | |
{ |
882 | 0 | delegate.addResource( resource, destFileName, permissions ); |
883 | |
} |
884 | |
finally |
885 | |
{ |
886 | 0 | inPublicApi.set( null ); |
887 | 0 | } |
888 | 0 | } |
889 | |
|
890 | |
public void addResources( final PlexusIoResourceCollection resources ) |
891 | |
throws ArchiverException |
892 | |
{ |
893 | 0 | inPublicApi.set( Boolean.TRUE ); |
894 | |
try |
895 | |
{ |
896 | 0 | delegate.addResources( resources ); |
897 | |
} |
898 | |
finally |
899 | |
{ |
900 | 0 | inPublicApi.set( null ); |
901 | 0 | } |
902 | 0 | } |
903 | |
|
904 | |
public ResourceIterator getResources() |
905 | |
throws ArchiverException |
906 | |
{ |
907 | 0 | return delegate.getResources(); |
908 | |
} |
909 | |
|
910 | |
public String getDuplicateBehavior() |
911 | |
{ |
912 | 0 | return delegate.getDuplicateBehavior(); |
913 | |
} |
914 | |
|
915 | |
public void setDuplicateBehavior( final String duplicate ) |
916 | |
{ |
917 | 0 | inPublicApi.set( Boolean.TRUE ); |
918 | |
try |
919 | |
{ |
920 | 0 | delegate.setDuplicateBehavior( duplicate ); |
921 | |
} |
922 | |
finally |
923 | |
{ |
924 | 0 | inPublicApi.set( null ); |
925 | 0 | } |
926 | 0 | } |
927 | |
|
928 | |
public int getDirectoryMode() |
929 | |
{ |
930 | 0 | return delegate.getDirectoryMode(); |
931 | |
} |
932 | |
|
933 | |
public int getFileMode() |
934 | |
{ |
935 | 0 | return delegate.getFileMode(); |
936 | |
} |
937 | |
|
938 | |
public int getOverrideDirectoryMode() |
939 | |
{ |
940 | 0 | return delegate.getOverrideDirectoryMode(); |
941 | |
} |
942 | |
|
943 | |
public int getOverrideFileMode() |
944 | |
{ |
945 | 0 | return delegate.getOverrideFileMode(); |
946 | |
} |
947 | |
|
948 | |
public void setDirectoryMode( final int mode ) |
949 | |
{ |
950 | 0 | inPublicApi.set( Boolean.TRUE ); |
951 | |
try |
952 | |
{ |
953 | 0 | delegate.setDirectoryMode( mode ); |
954 | |
} |
955 | |
finally |
956 | |
{ |
957 | 0 | inPublicApi.set( null ); |
958 | 0 | } |
959 | 0 | } |
960 | |
|
961 | |
public void setFileMode( final int mode ) |
962 | |
{ |
963 | 0 | inPublicApi.set( Boolean.TRUE ); |
964 | |
try |
965 | |
{ |
966 | 0 | delegate.setFileMode( mode ); |
967 | |
} |
968 | |
finally |
969 | |
{ |
970 | 0 | inPublicApi.set( null ); |
971 | 0 | } |
972 | 0 | } |
973 | |
|
974 | |
public boolean isUseJvmChmod() |
975 | |
{ |
976 | 0 | return useJvmChmod; |
977 | |
} |
978 | |
|
979 | |
public void setUseJvmChmod( final boolean useJvmChmod ) |
980 | |
{ |
981 | 15 | this.useJvmChmod = useJvmChmod; |
982 | 15 | } |
983 | |
|
984 | |
public boolean isIgnorePermissions() |
985 | |
{ |
986 | 0 | return delegate.isIgnorePermissions(); |
987 | |
} |
988 | |
|
989 | |
public void setIgnorePermissions( final boolean ignorePermissions ) |
990 | |
{ |
991 | 15 | delegate.setIgnorePermissions( ignorePermissions ); |
992 | 15 | } |
993 | |
|
994 | |
} |