@@ -79,16 +79,11 @@ public abstract class AbstractZipArchiver
7979
8080 protected String archiveType = "zip" ;
8181
82- /*
83- * Whether the original compression of entries coming from a ZIP
84- * archive should be kept (for example when updating an archive).
85- */
86- //not used: private boolean keepCompression = false;
8782 private boolean doFilesonly = false ;
8883
8984 protected final Hashtable <String , String > entries = new Hashtable <String , String >();
9085
91- protected final Hashtable < String , String > addedDirs = new Hashtable < String , String > ();
86+ protected final AddedDirs addedDirs = new AddedDirs ();
9287
9388 private static final long EMPTY_CRC = new CRC32 ().getValue ();
9489
@@ -363,7 +358,7 @@ protected final void addResources( ResourceIterator resources, ParallelScatterZi
363358 name = name + "/" ;
364359 }
365360
366- addParentDirs ( entry , null , name , zOut , "" );
361+ addParentDirs ( entry , null , name , zOut );
367362
368363 if ( entry .getResource ().isFile () )
369364 {
@@ -384,29 +379,12 @@ protected final void addResources( ResourceIterator resources, ParallelScatterZi
384379 * be impossible and is not really supported.
385380 */
386381 @ SuppressWarnings ( { "JavaDoc" } )
387- private void addParentDirs ( ArchiveEntry archiveEntry , File baseDir , String entry , ParallelScatterZipCreator zOut ,
388- String prefix )
382+ private void addParentDirs (ArchiveEntry archiveEntry , File baseDir , String entry , ParallelScatterZipCreator zOut )
389383 throws IOException
390384 {
391385 if ( !doFilesonly && getIncludeEmptyDirs () )
392386 {
393- Stack <String > directories = new Stack <String >();
394-
395- // Don't include the last entry itself if it's
396- // a dir; it will be added on its own.
397- int slashPos = entry .length () - ( entry .endsWith ( "/" ) ? 1 : 0 );
398-
399- while ( ( slashPos = entry .lastIndexOf ( '/' , slashPos - 1 ) ) != -1 )
400- {
401- String dir = entry .substring ( 0 , slashPos + 1 );
402-
403- if ( addedDirs .contains ( prefix + dir ) )
404- {
405- break ;
406- }
407-
408- directories .push ( dir );
409- }
387+ Stack <String > directories = addedDirs .asStringStack (entry );
410388
411389 while ( !directories .isEmpty () )
412390 {
@@ -423,12 +401,12 @@ private void addParentDirs( ArchiveEntry archiveEntry, File baseDir, String entr
423401 // the
424402 // At this point we could do something like read the atr
425403 final PlexusIoResource res = new AnonymousResource ( f );
426- zipDir ( res , zOut , prefix + dir , archiveEntry .getDefaultDirMode (), encoding );
404+ zipDir ( res , zOut , dir , archiveEntry .getDefaultDirMode (), encoding );
427405 }
428406 }
429407 }
430408
431- /**
409+ /**
432410 * Adds a new entry to the archive, takes care of duplicates as well.
433411 *
434412 * @param in the stream to read data for the entry from.
@@ -544,15 +522,12 @@ protected void zipDir( PlexusIoResource dir, ParallelScatterZipCreator zOut, Str
544522 String encodingToUse )
545523 throws IOException
546524 {
547- if ( addedDirs .get ( vPath ) != null )
525+ if ( addedDirs .update ( vPath ) )
548526 {
549- // don't add directories we've already added.
550- // no warning if we try, it is harmless in and of itself
551527 return ;
552528 }
553529
554- getLogger ().debug ( "adding directory " + vPath );
555- addedDirs .put ( vPath , vPath );
530+ getLogger ().debug ("adding directory " + vPath );
556531
557532 if ( !skipWriting )
558533 {
0 commit comments