18
18
19
19
import org .apache .commons .compress .archivers .zip .ZipArchiveEntry ;
20
20
import org .apache .commons .compress .archivers .zip .ZipFile ;
21
+ import org .codehaus .plexus .components .io .functions .SymlinkDestinationSupplier ;
21
22
import org .codehaus .plexus .components .io .resources .AbstractPlexusIoArchiveResourceCollection ;
22
23
import org .codehaus .plexus .components .io .resources .EncodingSupported ;
23
24
import org .codehaus .plexus .components .io .resources .PlexusIoResource ;
@@ -86,6 +87,59 @@ public URL getResource( String name )
86
87
private static class ZipFileResourceIterator
87
88
implements Iterator <PlexusIoResource >, Closeable
88
89
{
90
+ private class ZipFileResource
91
+ extends PlexusIoURLResource
92
+ {
93
+ private ZipFileResource ( ZipArchiveEntry entry )
94
+ {
95
+ super ( entry .getName (), entry .getTime () == -1 ? PlexusIoResource .UNKNOWN_MODIFICATION_DATE : entry .getTime (),
96
+ entry .isDirectory () ? PlexusIoResource .UNKNOWN_RESOURCE_SIZE : entry .getSize (),
97
+ !entry .isDirectory (), entry .isDirectory (), true );
98
+ }
99
+
100
+ public URL getURL ()
101
+ throws IOException
102
+ {
103
+ String spec = getName ();
104
+ if ( spec .startsWith ( "/" ) )
105
+ {
106
+ // Code path for PLXCOMP-170. Note that urlClassloader does not seem to produce correct
107
+ // urls for this. Which again means files loaded via this path cannot have file names
108
+ // requiring url encoding
109
+ spec = "./" + spec ;
110
+ return new URL ( url , spec );
111
+ }
112
+ return urlClassLoader .getResource ( spec );
113
+ }
114
+ }
115
+
116
+ private class ZipFileSymlinkResource
117
+ extends ZipFileResource
118
+ implements SymlinkDestinationSupplier
119
+ {
120
+ private final ZipArchiveEntry entry ;
121
+
122
+ private ZipFileSymlinkResource ( ZipArchiveEntry entry )
123
+ {
124
+ super ( entry );
125
+
126
+ this .entry = entry ;
127
+ }
128
+
129
+ @ Override
130
+ public String getSymlinkDestination ()
131
+ throws IOException
132
+ {
133
+ return zipFile .getUnixSymlink ( entry );
134
+ }
135
+
136
+ @ Override
137
+ public boolean isSymbolicLink ()
138
+ {
139
+ return true ;
140
+ }
141
+ }
142
+
89
143
private final Enumeration <ZipArchiveEntry > en ;
90
144
91
145
private final URL url ;
@@ -110,28 +164,10 @@ public boolean hasNext()
110
164
public PlexusIoResource next ()
111
165
{
112
166
final ZipArchiveEntry entry = en .nextElement ();
113
- long l = entry .getTime ();
114
- final long lastModified = l == -1 ? PlexusIoResource .UNKNOWN_MODIFICATION_DATE : l ;
115
- final boolean dir = entry .isDirectory ();
116
- final long size = dir ? PlexusIoResource .UNKNOWN_RESOURCE_SIZE : entry .getSize ();
117
167
118
- return new PlexusIoURLResource ( entry .getName (), lastModified , size , !dir , dir , true )
119
- {
120
- public URL getURL ()
121
- throws IOException
122
- {
123
- String spec = getName ();
124
- if ( spec .startsWith ( "/" ) )
125
- {
126
- // Code path for PLXCOMP-170. Note that urlClassloader does not seem to produce correct
127
- // urls for this. Which again means files loaded via this path cannot have file names
128
- // requiring url encoding
129
- spec = "./" + spec ;
130
- return new URL ( url , spec );
131
- }
132
- return urlClassLoader .getResource ( spec );
133
- }
134
- };
168
+ return entry .isUnixSymlink ()
169
+ ? new ZipFileSymlinkResource ( entry )
170
+ : new ZipFileResource ( entry );
135
171
}
136
172
137
173
public void remove ()
0 commit comments