@@ -77,7 +77,8 @@ public abstract class AbstractArchiver
77
77
/**
78
78
* A list of the following objects:
79
79
* <ul>
80
- * <li>Instances of {@link ArchiveEntry}, which are passed back by {@link #getResources()} without modifications.</li>
80
+ * <li>Instances of {@link ArchiveEntry}, which are passed back by {@link #getResources()} without modifications
81
+ * .</li>
81
82
* <li>Instances of {@link PlexusIoResourceCollection}, which are converted into an {@link Iterator} over instances
82
83
* of {@link ArchiveEntry} by {@link #getResources()}.
83
84
* </ul>
@@ -107,7 +108,8 @@ public abstract class AbstractArchiver
107
108
// On lunix-like systems, we replace windows backslashes with forward slashes
108
109
private final boolean replacePathSlashesToJavaPaths = File .separatorChar == '/' ;
109
110
110
- private final List <Closeable > closeables = new ArrayList <Closeable >( );
111
+ private final List <Closeable > closeables = new ArrayList <Closeable >();
112
+
111
113
/**
112
114
* since 2.2 is on by default
113
115
*
@@ -118,30 +120,36 @@ public abstract class AbstractArchiver
118
120
// contextualized.
119
121
private ArchiverManager archiverManager ;
120
122
121
- private static class ResourceCollectionWithModes
123
+ private static class AddedResourceCollection
122
124
{
123
125
private final PlexusIoResourceCollection resources ;
126
+
124
127
private final int forcedFileMode ;
128
+
125
129
private final int forcedDirectoryMode ;
126
130
127
- public ResourceCollectionWithModes ( PlexusIoResourceCollection resources , int forcedFileMode ,
128
- int forcedDirMode )
131
+ public AddedResourceCollection ( PlexusIoResourceCollection resources , int forcedFileMode , int forcedDirMode )
129
132
{
130
133
this .resources = resources ;
131
134
this .forcedFileMode = forcedFileMode ;
132
135
this .forcedDirectoryMode = forcedDirMode ;
133
136
}
134
137
135
- private int maybeOverridden (int suggestedMode , boolean isDir ){
136
- if (isDir ){
138
+ private int maybeOverridden ( int suggestedMode , boolean isDir )
139
+ {
140
+ if ( isDir )
141
+ {
137
142
return forcedDirectoryMode >= 0 ? forcedDirectoryMode : suggestedMode ;
138
- } else {
143
+ }
144
+ else
145
+ {
139
146
return forcedFileMode >= 0 ? forcedFileMode : suggestedMode ;
140
147
141
148
}
142
149
}
143
150
144
151
}
152
+
145
153
/**
146
154
* @since 1.1
147
155
*/
@@ -376,8 +384,8 @@ public void addSymlink( String symlinkName, String symlinkDestination )
376
384
public void addSymlink ( String symlinkName , int permissions , String symlinkDestination )
377
385
throws ArchiverException
378
386
{
379
- doAddResource ( ArchiveEntry . createSymlinkEntry ( symlinkName , permissions , symlinkDestination ,
380
- getDirectoryMode () ) );
387
+ doAddResource (
388
+ ArchiveEntry . createSymlinkEntry ( symlinkName , permissions , symlinkDestination , getDirectoryMode () ) );
381
389
}
382
390
383
391
protected ArchiveEntry asArchiveEntry ( @ Nonnull final PlexusIoResource resource , final String destFileName ,
@@ -391,52 +399,34 @@ protected ArchiveEntry asArchiveEntry( @Nonnull final PlexusIoResource resource,
391
399
392
400
if ( resource .isFile () )
393
401
{
394
- return ArchiveEntry .createFileEntry ( destFileName , resource , permissions , collection ,
395
- getDirectoryMode () );
402
+ return ArchiveEntry .createFileEntry ( destFileName , resource , permissions , collection , getDirectoryMode () );
396
403
}
397
404
else
398
405
{
399
406
return ArchiveEntry .createDirectoryEntry ( destFileName , resource , permissions , getDirectoryMode () );
400
407
}
401
408
}
402
409
403
- private int maybeOverridden (int suggestedMode , boolean isDir ){
404
- if (isDir ){
410
+ private int maybeOverridden ( int suggestedMode , boolean isDir )
411
+ {
412
+ if ( isDir )
413
+ {
405
414
return forcedDirectoryMode >= 0 ? forcedDirectoryMode : suggestedMode ;
406
- } else {
407
- return forcedFileMode >= 0 ? forcedFileMode : suggestedMode ;
408
-
409
415
}
410
- }
411
-
412
- protected ArchiveEntry asArchiveEntry ( final PlexusIoResourceCollection collection ,
413
- final PlexusIoResource resource )
414
- throws ArchiverException
415
- {
416
- final String destFileName = collection .getName ( resource );
417
-
418
- int fromResource = -1 ;
419
- if ( resource instanceof ResourceAttributeSupplier )
416
+ else
420
417
{
421
- final PlexusIoResourceAttributes attrs = ( ( ResourceAttributeSupplier ) resource ). getAttributes () ;
418
+ return forcedFileMode >= 0 ? forcedFileMode : suggestedMode ;
422
419
423
- if ( attrs != null )
424
- {
425
- fromResource = attrs .getOctalMode ();
426
- }
427
420
}
428
-
429
- return asArchiveEntry ( resource , destFileName , maybeOverridden (fromResource , resource .isDirectory ()), collection );
430
421
}
431
422
432
- protected ArchiveEntry asArchiveEntry ( final ResourceCollectionWithModes collection ,
433
- final PlexusIoResource resource )
423
+ private ArchiveEntry asArchiveEntry ( final AddedResourceCollection collection , final PlexusIoResource resource )
434
424
throws ArchiverException
435
425
{
436
426
final String destFileName = collection .resources .getName ( resource );
437
427
438
428
int fromResource = -1 ;
439
- if ( resource instanceof ResourceAttributeSupplier )
429
+ if ( resource instanceof ResourceAttributeSupplier )
440
430
{
441
431
final PlexusIoResourceAttributes attrs = ( (ResourceAttributeSupplier ) resource ).getAttributes ();
442
432
@@ -446,8 +436,9 @@ protected ArchiveEntry asArchiveEntry( final ResourceCollectionWithModes collect
446
436
}
447
437
}
448
438
449
- return asArchiveEntry ( resource , destFileName , collection .maybeOverridden ( fromResource ,
450
- resource .isDirectory () ), collection .resources );
439
+ return asArchiveEntry ( resource , destFileName ,
440
+ collection .maybeOverridden ( fromResource , resource .isDirectory () ),
441
+ collection .resources );
451
442
}
452
443
453
444
@@ -518,7 +509,7 @@ public ResourceIterator getResources()
518
509
{
519
510
private final Iterator addedResourceIter = resources .iterator ();
520
511
521
- private ResourceCollectionWithModes currentResourceCollection ;
512
+ private AddedResourceCollection currentResourceCollection ;
522
513
523
514
private Iterator ioResourceIter ;
524
515
@@ -541,9 +532,9 @@ public boolean hasNext()
541
532
{
542
533
nextEntry = (ArchiveEntry ) o ;
543
534
}
544
- else if ( o instanceof ResourceCollectionWithModes )
535
+ else if ( o instanceof AddedResourceCollection )
545
536
{
546
- currentResourceCollection = (ResourceCollectionWithModes ) o ;
537
+ currentResourceCollection = (AddedResourceCollection ) o ;
547
538
548
539
try
549
540
{
@@ -584,7 +575,7 @@ else if ( o instanceof ResourceCollectionWithModes )
584
575
}
585
576
}
586
577
587
- if ( nextEntry != null && seenEntries .contains ( normalizedForDuplicateCheck (nextEntry ) ))
578
+ if ( nextEntry != null && seenEntries .contains ( normalizedForDuplicateCheck ( nextEntry ) ) )
588
579
{
589
580
final String path = nextEntry .getName ();
590
581
@@ -632,7 +623,7 @@ public ArchiveEntry next()
632
623
final ArchiveEntry next = nextEntry ;
633
624
nextEntry = null ;
634
625
635
- seenEntries .add ( normalizedForDuplicateCheck (next ) );
626
+ seenEntries .add ( normalizedForDuplicateCheck ( next ) );
636
627
637
628
return next ;
638
629
}
@@ -642,8 +633,9 @@ public void remove()
642
633
throw new UnsupportedOperationException ( "Does not support iterator" );
643
634
}
644
635
645
- private String normalizedForDuplicateCheck (ArchiveEntry entry ){
646
- return entry .getName ().replace ( '\\' , '/' );
636
+ private String normalizedForDuplicateCheck ( ArchiveEntry entry )
637
+ {
638
+ return entry .getName ().replace ( '\\' , '/' );
647
639
}
648
640
649
641
};
@@ -767,8 +759,9 @@ protected PlexusIoResourceCollection asResourceCollection( final ArchivedFileSet
767
759
"Error adding archived file-set. PlexusIoResourceCollection not found for: " + archiveFile , e );
768
760
}
769
761
770
- if (resources instanceof EncodingSupported ) {
771
- ((EncodingSupported )resources ).setEncoding ( charset );
762
+ if ( resources instanceof EncodingSupported )
763
+ {
764
+ ( (EncodingSupported ) resources ).setEncoding ( charset );
772
765
}
773
766
774
767
if ( resources instanceof PlexusIoArchivedResourceCollection )
@@ -815,10 +808,11 @@ protected PlexusIoResourceCollection asResourceCollection( final ArchivedFileSet
815
808
public void addResources ( final PlexusIoResourceCollection collection )
816
809
throws ArchiverException
817
810
{
818
- doAddResource ( new ResourceCollectionWithModes ( collection , forcedFileMode , forcedDirectoryMode ));
811
+ doAddResource ( new AddedResourceCollection ( collection , forcedFileMode , forcedDirectoryMode ) );
819
812
}
820
813
821
- private void doAddResource (Object item ){
814
+ private void doAddResource ( Object item )
815
+ {
822
816
resources .add ( item );
823
817
}
824
818
@@ -956,11 +950,11 @@ protected boolean isUptodate()
956
950
{
957
951
l = ( (ArchiveEntry ) o ).getResource ().getLastModified ();
958
952
}
959
- else if ( o instanceof ResourceCollectionWithModes )
953
+ else if ( o instanceof AddedResourceCollection )
960
954
{
961
955
try
962
956
{
963
- l = ( (ResourceCollectionWithModes ) o ).resources .getLastModified ();
957
+ l = ( (AddedResourceCollection ) o ).resources .getLastModified ();
964
958
}
965
959
catch ( final IOException e )
966
960
{
@@ -1096,11 +1090,15 @@ protected void validate()
1096
1090
1097
1091
protected abstract String getArchiveType ();
1098
1092
1099
- private void addCloseable (Object maybeCloseable ){
1100
- if (maybeCloseable instanceof Closeable )
1093
+ private void addCloseable ( Object maybeCloseable )
1094
+ {
1095
+ if ( maybeCloseable instanceof Closeable )
1096
+ {
1101
1097
closeables .add ( (Closeable ) maybeCloseable );
1098
+ }
1102
1099
1103
1100
}
1101
+
1104
1102
private void closeIterators ()
1105
1103
{
1106
1104
for ( Closeable closeable : closeables )
@@ -1109,6 +1107,7 @@ private void closeIterators()
1109
1107
}
1110
1108
1111
1109
}
1110
+
1112
1111
protected abstract void close ()
1113
1112
throws IOException ;
1114
1113
0 commit comments