kinman 2002/12/02 14:26:23
Modified: jasper2/src/share/org/apache/jasper/compiler
TldLocationsCache.java
Log:
- Patch by petr.jiricka@netbeans.com (Petr Jiricka)
Fix 14854: Allow redeploying tag libraries from the same jar,
do not lock the jar files on Windows
Revision Changes Path
1.9 +50 -24 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/TldLocationsCache.java
Index: TldLocationsCache.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/TldLocationsCache.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- TldLocationsCache.java 9 Oct 2002 18:25:39 -0000 1.8
+++ TldLocationsCache.java 2 Dec 2002 22:26:23 -0000 1.9
@@ -134,15 +134,30 @@
private boolean initialized;
private ServletContext ctxt;
+ private boolean redeployMode;
//*********************************************************************
// Constructor and Initilizations
public TldLocationsCache(ServletContext ctxt) {
+ this(ctxt, false);
+ }
+
+ /** Constructs a new instance of TldLocationsCache.
+ * @param ctxt the servlet context of the web application in which Jasper
+ * is running
+ * @param redeployMode if true, then the compiler will allow redeploying
+ * a tag library from the same jar, at the expense of slowing down the server
+ * a bit. Note that this may only work on JDK 1.3.1_01a and later, because
+ * of JDK bug 4211817 fixed in this release.
+ * If redeployMode is false, a faster but less capable mode will be used.
+ */
+ public TldLocationsCache(ServletContext ctxt, boolean redeployMode) {
this.ctxt = ctxt;
- mappings = new Hashtable();
- tlds = new Hashtable();
- initialized = false;
+ this.redeployMode = redeployMode;
+ mappings = new Hashtable();
+ tlds = new Hashtable();
+ initialized = false;
}
private void init() {
@@ -247,6 +262,9 @@
url = new URL("jar:" + url.toString() + "!/");
JarURLConnection conn =
(JarURLConnection) url.openConnection();
+ if (redeployMode) {
+ conn.setUseCaches(false);
+ }
jarFile = conn.getJarFile();
Enumeration entries = jarFile.entries();
while (entries.hasMoreElements()) {
@@ -255,32 +273,40 @@
if (!name.startsWith("META-INF/")) continue;
if (!name.endsWith(".tld")) continue;
stream = jarFile.getInputStream(entry);
- String uri = parseTldForUri(resourcePath, stream);
- if (uri != null) {
- mappings.put(uri, new String[]{ resourcePath, name });
+ try {
+ String uri = parseTldForUri(resourcePath, stream);
+ if (uri != null) {
+ mappings.put(uri, new String[]{ resourcePath, name });
+ }
+ }
+ finally {
+ if (stream != null) {
+ try {
+ stream.close();
+ } catch (Throwable t) {}
+ }
}
}
- // FIXME @@@
- // -- it seems that the JarURLConnection class caches JarFile
- // objects for particular URLs, and there is no way to get
- // it to release the cached entry, so
- // there's no way to redeploy from the same JAR file. Wierd.
} catch (Exception ex) {
- if (stream != null) {
- try {
- stream.close();
- } catch (Throwable t) {
- // ignore
- }
- }
- if (jarFile != null) {
- try {
- jarFile.close();
- } catch (Throwable t) {
- // ignore
- }
+ if (!redeployMode) {
+ // if not in redeploy mode, close the jar in case of an error
+ if (jarFile != null) {
+ try {
+ jarFile.close();
+ } catch (Throwable t) { /* ignore */ }
+ }
}
throw new JasperException(ex);
+ }
+ finally {
+ if (redeployMode) {
+ // if in redeploy mode, always close the jar
+ if (jarFile != null) {
+ try {
+ jarFile.close();
+ } catch (Throwable t) { /* ignore */ }
+ }
+ }
}
}
--
To unsubscribe, e-mail: <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>
|