1818
1919import org .apache .commons .compress .archivers .zip .ZipArchiveEntry ;
2020import org .apache .commons .compress .archivers .zip .ZipFile ;
21+ import org .codehaus .plexus .components .io .functions .SymlinkDestinationSupplier ;
2122import org .codehaus .plexus .components .io .resources .AbstractPlexusIoArchiveResourceCollection ;
2223import org .codehaus .plexus .components .io .resources .EncodingSupported ;
2324import org .codehaus .plexus .components .io .resources .PlexusIoResource ;
@@ -79,6 +80,59 @@ public URL getResource( String name )
7980 private static class ZipFileResourceIterator
8081 implements Iterator <PlexusIoResource >, Closeable
8182 {
83+ private class ZipFileResource
84+ extends PlexusIoURLResource
85+ {
86+ private ZipFileResource ( ZipArchiveEntry entry )
87+ {
88+ super ( entry .getName (), entry .getTime () == -1 ? PlexusIoResource .UNKNOWN_MODIFICATION_DATE : entry .getTime (),
89+ entry .isDirectory () ? PlexusIoResource .UNKNOWN_RESOURCE_SIZE : entry .getSize (),
90+ !entry .isDirectory (), entry .isDirectory (), true );
91+ }
92+
93+ public URL getURL ()
94+ throws IOException
95+ {
96+ String spec = getName ();
97+ if ( spec .startsWith ( "/" ) )
98+ {
99+ // Code path for PLXCOMP-170. Note that urlClassloader does not seem to produce correct
100+ // urls for this. Which again means files loaded via this path cannot have file names
101+ // requiring url encoding
102+ spec = "./" + spec ;
103+ return new URL ( url , spec );
104+ }
105+ return urlClassLoader .getResource ( spec );
106+ }
107+ }
108+
109+ private class ZipFileSymlinkResource
110+ extends ZipFileResource
111+ implements SymlinkDestinationSupplier
112+ {
113+ private final ZipArchiveEntry entry ;
114+
115+ private ZipFileSymlinkResource ( ZipArchiveEntry entry )
116+ {
117+ super ( entry );
118+
119+ this .entry = entry ;
120+ }
121+
122+ @ Override
123+ public String getSymlinkDestination ()
124+ throws IOException
125+ {
126+ return zipFile .getUnixSymlink ( entry );
127+ }
128+
129+ @ Override
130+ public boolean isSymbolicLink ()
131+ {
132+ return true ;
133+ }
134+ }
135+
82136 private final Enumeration <ZipArchiveEntry > en ;
83137
84138 private final URL url ;
@@ -103,28 +157,10 @@ public boolean hasNext()
103157 public PlexusIoResource next ()
104158 {
105159 final ZipArchiveEntry entry = en .nextElement ();
106- long l = entry .getTime ();
107- final long lastModified = l == -1 ? PlexusIoResource .UNKNOWN_MODIFICATION_DATE : l ;
108- final boolean dir = entry .isDirectory ();
109- final long size = dir ? PlexusIoResource .UNKNOWN_RESOURCE_SIZE : entry .getSize ();
110160
111- return new PlexusIoURLResource ( entry .getName (), lastModified , size , !dir , dir , true )
112- {
113- public URL getURL ()
114- throws IOException
115- {
116- String spec = getName ();
117- if ( spec .startsWith ( "/" ) )
118- {
119- // Code path for PLXCOMP-170. Note that urlClassloader does not seem to produce correct
120- // urls for this. Which again means files loaded via this path cannot have file names
121- // requiring url encoding
122- spec = "./" + spec ;
123- return new URL ( url , spec );
124- }
125- return urlClassLoader .getResource ( spec );
126- }
127- };
161+ return entry .isUnixSymlink ()
162+ ? new ZipFileSymlinkResource ( entry )
163+ : new ZipFileResource ( entry );
128164 }
129165
130166 public void remove ()
0 commit comments