@@ -77,7 +77,8 @@ public abstract class AbstractArchiver
7777 /**
7878 * A list of the following objects:
7979 * <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>
8182 * <li>Instances of {@link PlexusIoResourceCollection}, which are converted into an {@link Iterator} over instances
8283 * of {@link ArchiveEntry} by {@link #getResources()}.
8384 * </ul>
@@ -107,7 +108,8 @@ public abstract class AbstractArchiver
107108 // On lunix-like systems, we replace windows backslashes with forward slashes
108109 private final boolean replacePathSlashesToJavaPaths = File .separatorChar == '/' ;
109110
110- private final List <Closeable > closeables = new ArrayList <Closeable >( );
111+ private final List <Closeable > closeables = new ArrayList <Closeable >();
112+
111113 /**
112114 * since 2.2 is on by default
113115 *
@@ -118,30 +120,36 @@ public abstract class AbstractArchiver
118120 // contextualized.
119121 private ArchiverManager archiverManager ;
120122
121- private static class ResourceCollectionWithModes
123+ private static class AddedResourceCollection
122124 {
123125 private final PlexusIoResourceCollection resources ;
126+
124127 private final int forcedFileMode ;
128+
125129 private final int forcedDirectoryMode ;
126130
127- public ResourceCollectionWithModes ( PlexusIoResourceCollection resources , int forcedFileMode ,
128- int forcedDirMode )
131+ public AddedResourceCollection ( PlexusIoResourceCollection resources , int forcedFileMode , int forcedDirMode )
129132 {
130133 this .resources = resources ;
131134 this .forcedFileMode = forcedFileMode ;
132135 this .forcedDirectoryMode = forcedDirMode ;
133136 }
134137
135- private int maybeOverridden (int suggestedMode , boolean isDir ){
136- if (isDir ){
138+ private int maybeOverridden ( int suggestedMode , boolean isDir )
139+ {
140+ if ( isDir )
141+ {
137142 return forcedDirectoryMode >= 0 ? forcedDirectoryMode : suggestedMode ;
138- } else {
143+ }
144+ else
145+ {
139146 return forcedFileMode >= 0 ? forcedFileMode : suggestedMode ;
140147
141148 }
142149 }
143150
144151 }
152+
145153 /**
146154 * @since 1.1
147155 */
@@ -376,8 +384,8 @@ public void addSymlink( String symlinkName, String symlinkDestination )
376384 public void addSymlink ( String symlinkName , int permissions , String symlinkDestination )
377385 throws ArchiverException
378386 {
379- doAddResource ( ArchiveEntry . createSymlinkEntry ( symlinkName , permissions , symlinkDestination ,
380- getDirectoryMode () ) );
387+ doAddResource (
388+ ArchiveEntry . createSymlinkEntry ( symlinkName , permissions , symlinkDestination , getDirectoryMode () ) );
381389 }
382390
383391 protected ArchiveEntry asArchiveEntry ( @ Nonnull final PlexusIoResource resource , final String destFileName ,
@@ -391,52 +399,34 @@ protected ArchiveEntry asArchiveEntry( @Nonnull final PlexusIoResource resource,
391399
392400 if ( resource .isFile () )
393401 {
394- return ArchiveEntry .createFileEntry ( destFileName , resource , permissions , collection ,
395- getDirectoryMode () );
402+ return ArchiveEntry .createFileEntry ( destFileName , resource , permissions , collection , getDirectoryMode () );
396403 }
397404 else
398405 {
399406 return ArchiveEntry .createDirectoryEntry ( destFileName , resource , permissions , getDirectoryMode () );
400407 }
401408 }
402409
403- private int maybeOverridden (int suggestedMode , boolean isDir ){
404- if (isDir ){
410+ private int maybeOverridden ( int suggestedMode , boolean isDir )
411+ {
412+ if ( isDir )
413+ {
405414 return forcedDirectoryMode >= 0 ? forcedDirectoryMode : suggestedMode ;
406- } else {
407- return forcedFileMode >= 0 ? forcedFileMode : suggestedMode ;
408-
409415 }
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
420417 {
421- final PlexusIoResourceAttributes attrs = ( ( ResourceAttributeSupplier ) resource ). getAttributes () ;
418+ return forcedFileMode >= 0 ? forcedFileMode : suggestedMode ;
422419
423- if ( attrs != null )
424- {
425- fromResource = attrs .getOctalMode ();
426- }
427420 }
428-
429- return asArchiveEntry ( resource , destFileName , maybeOverridden (fromResource , resource .isDirectory ()), collection );
430421 }
431422
432- protected ArchiveEntry asArchiveEntry ( final ResourceCollectionWithModes collection ,
433- final PlexusIoResource resource )
423+ private ArchiveEntry asArchiveEntry ( final AddedResourceCollection collection , final PlexusIoResource resource )
434424 throws ArchiverException
435425 {
436426 final String destFileName = collection .resources .getName ( resource );
437427
438428 int fromResource = -1 ;
439- if ( resource instanceof ResourceAttributeSupplier )
429+ if ( resource instanceof ResourceAttributeSupplier )
440430 {
441431 final PlexusIoResourceAttributes attrs = ( (ResourceAttributeSupplier ) resource ).getAttributes ();
442432
@@ -446,8 +436,9 @@ protected ArchiveEntry asArchiveEntry( final ResourceCollectionWithModes collect
446436 }
447437 }
448438
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 );
451442 }
452443
453444
@@ -518,7 +509,7 @@ public ResourceIterator getResources()
518509 {
519510 private final Iterator addedResourceIter = resources .iterator ();
520511
521- private ResourceCollectionWithModes currentResourceCollection ;
512+ private AddedResourceCollection currentResourceCollection ;
522513
523514 private Iterator ioResourceIter ;
524515
@@ -541,9 +532,9 @@ public boolean hasNext()
541532 {
542533 nextEntry = (ArchiveEntry ) o ;
543534 }
544- else if ( o instanceof ResourceCollectionWithModes )
535+ else if ( o instanceof AddedResourceCollection )
545536 {
546- currentResourceCollection = (ResourceCollectionWithModes ) o ;
537+ currentResourceCollection = (AddedResourceCollection ) o ;
547538
548539 try
549540 {
@@ -584,7 +575,7 @@ else if ( o instanceof ResourceCollectionWithModes )
584575 }
585576 }
586577
587- if ( nextEntry != null && seenEntries .contains ( normalizedForDuplicateCheck (nextEntry ) ))
578+ if ( nextEntry != null && seenEntries .contains ( normalizedForDuplicateCheck ( nextEntry ) ) )
588579 {
589580 final String path = nextEntry .getName ();
590581
@@ -632,7 +623,7 @@ public ArchiveEntry next()
632623 final ArchiveEntry next = nextEntry ;
633624 nextEntry = null ;
634625
635- seenEntries .add ( normalizedForDuplicateCheck (next ) );
626+ seenEntries .add ( normalizedForDuplicateCheck ( next ) );
636627
637628 return next ;
638629 }
@@ -642,8 +633,9 @@ public void remove()
642633 throw new UnsupportedOperationException ( "Does not support iterator" );
643634 }
644635
645- private String normalizedForDuplicateCheck (ArchiveEntry entry ){
646- return entry .getName ().replace ( '\\' , '/' );
636+ private String normalizedForDuplicateCheck ( ArchiveEntry entry )
637+ {
638+ return entry .getName ().replace ( '\\' , '/' );
647639 }
648640
649641 };
@@ -767,8 +759,9 @@ protected PlexusIoResourceCollection asResourceCollection( final ArchivedFileSet
767759 "Error adding archived file-set. PlexusIoResourceCollection not found for: " + archiveFile , e );
768760 }
769761
770- if (resources instanceof EncodingSupported ) {
771- ((EncodingSupported )resources ).setEncoding ( charset );
762+ if ( resources instanceof EncodingSupported )
763+ {
764+ ( (EncodingSupported ) resources ).setEncoding ( charset );
772765 }
773766
774767 if ( resources instanceof PlexusIoArchivedResourceCollection )
@@ -815,10 +808,11 @@ protected PlexusIoResourceCollection asResourceCollection( final ArchivedFileSet
815808 public void addResources ( final PlexusIoResourceCollection collection )
816809 throws ArchiverException
817810 {
818- doAddResource ( new ResourceCollectionWithModes ( collection , forcedFileMode , forcedDirectoryMode ));
811+ doAddResource ( new AddedResourceCollection ( collection , forcedFileMode , forcedDirectoryMode ) );
819812 }
820813
821- private void doAddResource (Object item ){
814+ private void doAddResource ( Object item )
815+ {
822816 resources .add ( item );
823817 }
824818
@@ -956,11 +950,11 @@ protected boolean isUptodate()
956950 {
957951 l = ( (ArchiveEntry ) o ).getResource ().getLastModified ();
958952 }
959- else if ( o instanceof ResourceCollectionWithModes )
953+ else if ( o instanceof AddedResourceCollection )
960954 {
961955 try
962956 {
963- l = ( (ResourceCollectionWithModes ) o ).resources .getLastModified ();
957+ l = ( (AddedResourceCollection ) o ).resources .getLastModified ();
964958 }
965959 catch ( final IOException e )
966960 {
@@ -1096,11 +1090,15 @@ protected void validate()
10961090
10971091 protected abstract String getArchiveType ();
10981092
1099- private void addCloseable (Object maybeCloseable ){
1100- if (maybeCloseable instanceof Closeable )
1093+ private void addCloseable ( Object maybeCloseable )
1094+ {
1095+ if ( maybeCloseable instanceof Closeable )
1096+ {
11011097 closeables .add ( (Closeable ) maybeCloseable );
1098+ }
11021099
11031100 }
1101+
11041102 private void closeIterators ()
11051103 {
11061104 for ( Closeable closeable : closeables )
@@ -1109,6 +1107,7 @@ private void closeIterators()
11091107 }
11101108
11111109 }
1110+
11121111 protected abstract void close ()
11131112 throws IOException ;
11141113
0 commit comments