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 ;
@@ -79,6 +80,59 @@ public URL getResource( String name )
79
80
private static class ZipFileResourceIterator
80
81
implements Iterator <PlexusIoResource >, Closeable
81
82
{
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
+
82
136
private final Enumeration <ZipArchiveEntry > en ;
83
137
84
138
private final URL url ;
@@ -103,28 +157,10 @@ public boolean hasNext()
103
157
public PlexusIoResource next ()
104
158
{
105
159
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 ();
110
160
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 );
128
164
}
129
165
130
166
public void remove ()
0 commit comments