Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 216459 Details for
Bug 379112
Performance issue on large WAR deployment
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch and test
patch.txt (text/plain), 9.90 KB, created by
Radoslav Ivanov
on 2012-05-30 06:19:00 EDT
(
hide
)
Description:
Patch and test
Filename:
MIME Type:
Creator:
Radoslav Ivanov
Created:
2012-05-30 06:19:00 EDT
Size:
9.90 KB
patch
obsolete
>diff --git a/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/url/WebBundleScanner.java b/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/url/WebBundleScanner.java >index bbdb962..9fd28c5 100644 >--- a/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/url/WebBundleScanner.java >+++ b/org.eclipse.gemini.web.core/src/main/java/org/eclipse/gemini/web/internal/url/WebBundleScanner.java >@@ -19,15 +19,21 @@ package org.eclipse.gemini.web.internal.url; > import java.io.File; > import java.io.FileInputStream; > import java.io.IOException; >+import java.io.InputStream; > import java.net.URI; > import java.net.URISyntaxException; > import java.net.URL; >+import java.net.URLDecoder; >+import java.util.Collection; >+import java.util.Enumeration; > import java.util.HashSet; > import java.util.Set; > import java.util.jar.Attributes; > import java.util.jar.JarEntry; >+import java.util.jar.JarFile; > import java.util.jar.JarInputStream; > import java.util.jar.Manifest; >+import java.util.zip.ZipEntry; > > import org.slf4j.Logger; > import org.slf4j.LoggerFactory; >@@ -59,6 +65,8 @@ final class WebBundleScanner { > private final Object monitor = new Object(); > > private final URL source; >+ private final String localSourcePath; >+ private final Collection<ZipEntry> sourceZipEntries = new HashSet<ZipEntry>(); > > private final WebBundleScannerCallback callBack; > >@@ -81,6 +89,7 @@ final class WebBundleScanner { > this.source = source; > this.callBack = callBack; > this.findClassesInNestedJars = findClassesInNestedJars; >+ this.localSourcePath = getLocalSourcePath(source); > } > > /** >@@ -92,6 +101,7 @@ final class WebBundleScanner { > void scanWar() throws IOException { > synchronized (this.monitor) { > this.scannedJars.clear(); >+ this.sourceZipEntries.clear(); > if (isDirectory()) { > scanWarDirectory(); > } else { >@@ -208,14 +218,16 @@ final class WebBundleScanner { > } > } > } >- >- JarEntry entry; >- while ((entry = jis.getNextJarEntry()) != null) { >- String entryName = entry.getName(); >- if (entryName.endsWith(CLASS_SUFFIX)) { >- notifyClassFound(entryName); >- } >- } >+ >+ if (this.findClassesInNestedJars) { >+ JarEntry entry; >+ while ((entry = jis.getNextJarEntry()) != null) { >+ String entryName = entry.getName(); >+ if (entryName.endsWith(CLASS_SUFFIX)) { >+ notifyClassFound(entryName); >+ } >+ } >+ } > } > > private static Path getNormalisedDirectoryPath(String jarEntryName) { >@@ -246,8 +258,24 @@ final class WebBundleScanner { > throw new IllegalStateException("Unexpected URISyntaxException.", e); > } > } >+ >+ private void scanNestedJarInWarFile(final String jarPath) throws IOException { >+ if (this.localSourcePath == null) { >+ scanNestedJarInWarFileWithStream(jarPath); >+ return; >+ } >+ >+ scanNestedJarInWarFileWithZipFile(jarPath, this.localSourcePath); >+ } >+ >+ private String getLocalSourcePath(final URL url) { >+ if (!FILE_SCHEME.equals(url.getProtocol())) { >+ return null; >+ } >+ return URLDecoder.decode(url.getPath()); >+ } > >- private void scanNestedJarInWarFile(String jarPath) throws IOException { >+ private void scanNestedJarInWarFileWithStream(String jarPath) throws IOException { > JarInputStream jis = new JarInputStream(this.source.openStream()); > try { > JarEntry entry; >@@ -263,13 +291,53 @@ final class WebBundleScanner { > } finally { > IOUtils.closeQuietly(jis); > } >- >+ } >+ >+ private void scanNestedJarInWarFileWithZipFile(String jarPath, String localSourcePath) throws IOException { >+ JarFile jarFile = null; >+ try { >+ InputStream foundInputStream = null; >+ String foundZipEntryName = null; >+ if (sourceZipEntries.isEmpty()) {//then search and cache all entries >+ jarFile = new JarFile(localSourcePath); >+ Enumeration<JarEntry> jarFileEntries = jarFile.entries(); >+ while (jarFileEntries.hasMoreElements()) { >+ final ZipEntry zipEntry = jarFileEntries.nextElement(); >+ // 1. cache >+ sourceZipEntries.add(zipEntry); >+ // 2. search if it is not found still >+ if ((foundZipEntryName == null) && jarPath.endsWith(zipEntry.getName())) { >+ foundZipEntryName = zipEntry.getName(); >+ foundInputStream = jarFile.getInputStream(zipEntry); >+ } >+ } >+ } else {//search entry in cache >+ for (ZipEntry zipEntry: sourceZipEntries) { >+ if (jarPath.endsWith(zipEntry.getName())) { >+ jarFile = new JarFile(localSourcePath); >+ foundZipEntryName = zipEntry.getName(); >+ foundInputStream = jarFile.getInputStream(zipEntry); >+ break; >+ } >+ >+ } >+ } >+ >+ if ((foundZipEntryName != null) && driveCallBackIfNewJarFound(foundZipEntryName)) { >+ JarInputStream nestedJis = new JarInputStream(foundInputStream); >+ doScanNestedJar(foundZipEntryName, nestedJis); >+ } >+ } finally {//quiet close >+ if (jarFile != null) { >+ try { >+ jarFile.close(); >+ } catch (IOException _) {} >+ } >+ } > } > >- private void notifyClassFound(String entryName) { >- if (this.findClassesInNestedJars) { >- this.callBack.classFound(entryName); >- } >+ private void notifyClassFound(String entryName) { >+ this.callBack.classFound(entryName); > } > > private boolean isDirectory() { >diff --git a/org.eclipse.gemini.web.core/src/test/java/org/eclipse/gemini/web/internal/url/WebBundleScannerTests.java b/org.eclipse.gemini.web.core/src/test/java/org/eclipse/gemini/web/internal/url/WebBundleScannerTests.java >index 7d5ea97..33da9e7 100644 >--- a/org.eclipse.gemini.web.core/src/test/java/org/eclipse/gemini/web/internal/url/WebBundleScannerTests.java >+++ b/org.eclipse.gemini.web.core/src/test/java/org/eclipse/gemini/web/internal/url/WebBundleScannerTests.java >@@ -21,6 +21,7 @@ import static org.easymock.EasyMock.verify; > > import java.io.File; > import java.io.IOException; >+import java.net.URL; > > import org.easymock.EasyMock; > import org.junit.Test; >@@ -33,19 +34,31 @@ import org.eclipse.virgo.util.io.PathReference; > public class WebBundleScannerTests { > > private static final File WAR_FILE = new File("target/resources/simple-war.war"); >+ private static final File WAR_CLASSPATHDEPS = new File("../org.eclipse.gemini.web.test/src/test/resources/classpathdeps.war"); >+ >+ @Test >+ public void testScanClasspathDeps() throws IOException { >+ final WebBundleScannerCallback callback = EasyMock.createMock(WebBundleScannerCallback.class); >+ >+ setExpectationsClasspathDeps(callback); >+ >+ scan(WAR_CLASSPATHDEPS.toURI().toURL(), callback); >+ } > > @Test > public void testScanLib() throws IOException { > WebBundleScannerCallback callback = EasyMock.createMock(WebBundleScannerCallback.class); > > setExpectations(callback); >- >- replay(callback); >- >- WebBundleScanner scanner = new WebBundleScanner(WAR_FILE.toURI().toURL(), callback); >- scanner.scanWar(); > >- verify(callback); >+ scan(WAR_FILE.toURI().toURL(), callback); >+ } >+ >+ private void setExpectationsClasspathDeps(WebBundleScannerCallback callback) { >+ callback.jarFound("WEB-INF/lib/jar1.jar"); >+ callback.jarFound("j2/jar2.jar"); >+ callback.jarFound("j3/jar3.jar"); >+ callback.jarFound("j4/jar4.jar"); > } > > private void setExpectations(WebBundleScannerCallback callback) { >@@ -89,12 +102,7 @@ public class WebBundleScannerTests { > > setExpectationsIncludingNestedJars(callback); > >- replay(callback); >- >- WebBundleScanner scanner = new WebBundleScanner(WAR_FILE.toURL(), callback, true); >- scanner.scanWar(); >- >- verify(callback); >+ scan(WAR_FILE.toURL(), callback, true); > } > > @Test >@@ -105,12 +113,7 @@ public class WebBundleScannerTests { > > setExpectations(callback); > >- replay(callback); >- >- WebBundleScanner scanner = new WebBundleScanner(pr.toURI().toURL(), callback); >- scanner.scanWar(); >- >- verify(callback); >+ scan(pr.toURI().toURL(), callback); > } finally { > pr.delete(true); > } >@@ -124,17 +127,25 @@ public class WebBundleScannerTests { > > setExpectationsIncludingNestedJars(callback); > >- replay(callback); >- >- WebBundleScanner scanner = new WebBundleScanner(pr.toURI().toURL(), callback, true); >- scanner.scanWar(); >- >- verify(callback); >+ scan(pr.toURI().toURL(), callback, true); > } finally { > pr.delete(true); > } > } > >+ private void scan(final URL url, final WebBundleScannerCallback callback) throws IOException { >+ this.scan(url, callback, false); >+ } >+ >+ private void scan(final URL url, final WebBundleScannerCallback callback, final boolean findClassesInNestedJars) throws IOException { >+ replay(callback); >+ >+ final WebBundleScanner scanner = new WebBundleScanner(url, callback, findClassesInNestedJars); >+ scanner.scanWar(); >+ >+ verify(callback); >+ } >+ > private PathReference unpackToDir() throws IOException { > String tmpDir = System.getProperty("java.io.tmpdir"); > PathReference dest = new PathReference(new File(tmpDir, "unpack-" + System.currentTimeMillis()));
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
milesg78
:
iplog+
Actions:
View
|
Diff
Attachments on
bug 379112
:
215391
|
215639
|
216458
| 216459