|
Lines 19-33
package org.eclipse.gemini.web.internal.url;
Link Here
|
| 19 |
import java.io.File; |
19 |
import java.io.File; |
| 20 |
import java.io.FileInputStream; |
20 |
import java.io.FileInputStream; |
| 21 |
import java.io.IOException; |
21 |
import java.io.IOException; |
|
|
22 |
import java.io.InputStream; |
| 22 |
import java.net.URI; |
23 |
import java.net.URI; |
| 23 |
import java.net.URISyntaxException; |
24 |
import java.net.URISyntaxException; |
| 24 |
import java.net.URL; |
25 |
import java.net.URL; |
|
|
26 |
import java.net.URLDecoder; |
| 27 |
import java.util.Collection; |
| 28 |
import java.util.Enumeration; |
| 25 |
import java.util.HashSet; |
29 |
import java.util.HashSet; |
| 26 |
import java.util.Set; |
30 |
import java.util.Set; |
| 27 |
import java.util.jar.Attributes; |
31 |
import java.util.jar.Attributes; |
| 28 |
import java.util.jar.JarEntry; |
32 |
import java.util.jar.JarEntry; |
|
|
33 |
import java.util.jar.JarFile; |
| 29 |
import java.util.jar.JarInputStream; |
34 |
import java.util.jar.JarInputStream; |
| 30 |
import java.util.jar.Manifest; |
35 |
import java.util.jar.Manifest; |
|
|
36 |
import java.util.zip.ZipEntry; |
| 31 |
|
37 |
|
| 32 |
import org.slf4j.Logger; |
38 |
import org.slf4j.Logger; |
| 33 |
import org.slf4j.LoggerFactory; |
39 |
import org.slf4j.LoggerFactory; |
|
Lines 59-64
final class WebBundleScanner {
Link Here
|
| 59 |
private final Object monitor = new Object(); |
65 |
private final Object monitor = new Object(); |
| 60 |
|
66 |
|
| 61 |
private final URL source; |
67 |
private final URL source; |
|
|
68 |
private final String localSourcePath; |
| 69 |
private final Collection<ZipEntry> sourceZipEntries = new HashSet<ZipEntry>(); |
| 62 |
|
70 |
|
| 63 |
private final WebBundleScannerCallback callBack; |
71 |
private final WebBundleScannerCallback callBack; |
| 64 |
|
72 |
|
|
Lines 81-86
final class WebBundleScanner {
Link Here
|
| 81 |
this.source = source; |
89 |
this.source = source; |
| 82 |
this.callBack = callBack; |
90 |
this.callBack = callBack; |
| 83 |
this.findClassesInNestedJars = findClassesInNestedJars; |
91 |
this.findClassesInNestedJars = findClassesInNestedJars; |
|
|
92 |
this.localSourcePath = getLocalSourcePath(source); |
| 84 |
} |
93 |
} |
| 85 |
|
94 |
|
| 86 |
/** |
95 |
/** |
|
Lines 92-97
final class WebBundleScanner {
Link Here
|
| 92 |
void scanWar() throws IOException { |
101 |
void scanWar() throws IOException { |
| 93 |
synchronized (this.monitor) { |
102 |
synchronized (this.monitor) { |
| 94 |
this.scannedJars.clear(); |
103 |
this.scannedJars.clear(); |
|
|
104 |
this.sourceZipEntries.clear(); |
| 95 |
if (isDirectory()) { |
105 |
if (isDirectory()) { |
| 96 |
scanWarDirectory(); |
106 |
scanWarDirectory(); |
| 97 |
} else { |
107 |
} else { |
|
Lines 208-221
final class WebBundleScanner {
Link Here
|
| 208 |
} |
218 |
} |
| 209 |
} |
219 |
} |
| 210 |
} |
220 |
} |
| 211 |
|
221 |
|
| 212 |
JarEntry entry; |
222 |
if (this.findClassesInNestedJars) { |
| 213 |
while ((entry = jis.getNextJarEntry()) != null) { |
223 |
JarEntry entry; |
| 214 |
String entryName = entry.getName(); |
224 |
while ((entry = jis.getNextJarEntry()) != null) { |
| 215 |
if (entryName.endsWith(CLASS_SUFFIX)) { |
225 |
String entryName = entry.getName(); |
| 216 |
notifyClassFound(entryName); |
226 |
if (entryName.endsWith(CLASS_SUFFIX)) { |
| 217 |
} |
227 |
notifyClassFound(entryName); |
| 218 |
} |
228 |
} |
|
|
229 |
} |
| 230 |
} |
| 219 |
} |
231 |
} |
| 220 |
|
232 |
|
| 221 |
private static Path getNormalisedDirectoryPath(String jarEntryName) { |
233 |
private static Path getNormalisedDirectoryPath(String jarEntryName) { |
|
Lines 246-253
final class WebBundleScanner {
Link Here
|
| 246 |
throw new IllegalStateException("Unexpected URISyntaxException.", e); |
258 |
throw new IllegalStateException("Unexpected URISyntaxException.", e); |
| 247 |
} |
259 |
} |
| 248 |
} |
260 |
} |
|
|
261 |
|
| 262 |
private void scanNestedJarInWarFile(final String jarPath) throws IOException { |
| 263 |
if (this.localSourcePath == null) { |
| 264 |
scanNestedJarInWarFileWithStream(jarPath); |
| 265 |
return; |
| 266 |
} |
| 267 |
|
| 268 |
scanNestedJarInWarFileWithZipFile(jarPath, this.localSourcePath); |
| 269 |
} |
| 270 |
|
| 271 |
private String getLocalSourcePath(final URL url) { |
| 272 |
if (!FILE_SCHEME.equals(url.getProtocol())) { |
| 273 |
return null; |
| 274 |
} |
| 275 |
return URLDecoder.decode(url.getPath()); |
| 276 |
} |
| 249 |
|
277 |
|
| 250 |
private void scanNestedJarInWarFile(String jarPath) throws IOException { |
278 |
private void scanNestedJarInWarFileWithStream(String jarPath) throws IOException { |
| 251 |
JarInputStream jis = new JarInputStream(this.source.openStream()); |
279 |
JarInputStream jis = new JarInputStream(this.source.openStream()); |
| 252 |
try { |
280 |
try { |
| 253 |
JarEntry entry; |
281 |
JarEntry entry; |
|
Lines 263-275
final class WebBundleScanner {
Link Here
|
| 263 |
} finally { |
291 |
} finally { |
| 264 |
IOUtils.closeQuietly(jis); |
292 |
IOUtils.closeQuietly(jis); |
| 265 |
} |
293 |
} |
| 266 |
|
294 |
} |
|
|
295 |
|
| 296 |
private void scanNestedJarInWarFileWithZipFile(String jarPath, String localSourcePath) throws IOException { |
| 297 |
JarFile jarFile = null; |
| 298 |
try { |
| 299 |
InputStream foundInputStream = null; |
| 300 |
String foundZipEntryName = null; |
| 301 |
if (sourceZipEntries.isEmpty()) {//then search and cache all entries |
| 302 |
jarFile = new JarFile(localSourcePath); |
| 303 |
Enumeration<JarEntry> jarFileEntries = jarFile.entries(); |
| 304 |
while (jarFileEntries.hasMoreElements()) { |
| 305 |
final ZipEntry zipEntry = jarFileEntries.nextElement(); |
| 306 |
// 1. cache |
| 307 |
sourceZipEntries.add(zipEntry); |
| 308 |
// 2. search if it is not found still |
| 309 |
if ((foundZipEntryName == null) && jarPath.endsWith(zipEntry.getName())) { |
| 310 |
foundZipEntryName = zipEntry.getName(); |
| 311 |
foundInputStream = jarFile.getInputStream(zipEntry); |
| 312 |
} |
| 313 |
} |
| 314 |
} else {//search entry in cache |
| 315 |
for (ZipEntry zipEntry: sourceZipEntries) { |
| 316 |
if (jarPath.endsWith(zipEntry.getName())) { |
| 317 |
jarFile = new JarFile(localSourcePath); |
| 318 |
foundZipEntryName = zipEntry.getName(); |
| 319 |
foundInputStream = jarFile.getInputStream(zipEntry); |
| 320 |
break; |
| 321 |
} |
| 322 |
|
| 323 |
} |
| 324 |
} |
| 325 |
|
| 326 |
if ((foundZipEntryName != null) && driveCallBackIfNewJarFound(foundZipEntryName)) { |
| 327 |
JarInputStream nestedJis = new JarInputStream(foundInputStream); |
| 328 |
doScanNestedJar(foundZipEntryName, nestedJis); |
| 329 |
} |
| 330 |
} finally {//quiet close |
| 331 |
if (jarFile != null) { |
| 332 |
try { |
| 333 |
jarFile.close(); |
| 334 |
} catch (IOException _) {} |
| 335 |
} |
| 336 |
} |
| 267 |
} |
337 |
} |
| 268 |
|
338 |
|
| 269 |
private void notifyClassFound(String entryName) { |
339 |
private void notifyClassFound(String entryName) { |
| 270 |
if (this.findClassesInNestedJars) { |
340 |
this.callBack.classFound(entryName); |
| 271 |
this.callBack.classFound(entryName); |
|
|
| 272 |
} |
| 273 |
} |
341 |
} |
| 274 |
|
342 |
|
| 275 |
private boolean isDirectory() { |
343 |
private boolean isDirectory() { |