Repository: tomee
Updated Branches:
  refs/heads/master 80b788d46 -> 04c0e98e9


TOMEE-1960, closing JarFile - thanks Kaloyan Spiridonov


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/04c0e98e
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/04c0e98e
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/04c0e98e

Branch: refs/heads/master
Commit: 04c0e98e9e58110e6da47070caf4f88ae72ad3d8
Parents: 80b788d
Author: rmannibucau <rmannibu...@apache.org>
Authored: Fri Oct 14 17:21:28 2016 +0200
Committer: rmannibucau <rmannibu...@apache.org>
Committed: Fri Oct 14 17:21:28 2016 +0200

----------------------------------------------------------------------
 .../tomee/catalina/TomcatWebAppBuilder.java     |  9 ++--
 .../org/apache/tomee/installer/Installer.java   | 49 +++++++++-----------
 .../apache/tomee/loader/OpenEJBListener.java    |  3 +-
 3 files changed, 27 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/04c0e98e/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
----------------------------------------------------------------------
diff --git 
a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
 
b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
index 1553219..e834e83 100644
--- 
a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
+++ 
b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
@@ -471,10 +471,11 @@ public class TomcatWebAppBuilder implements 
WebAppBuilder, ContextListener, Pare
                         logger.info("using context file " + 
cXml.getAbsolutePath());
                     }
                 } else { // war
-                    final JarFile warAsJar = new JarFile(war);
-                    final JarEntry entry = 
warAsJar.getJarEntry(Constants.ApplicationContextXml);
-                    if (entry != null) {
-                        contextXmlUrl = new URL("jar:" + 
war.getAbsoluteFile().toURI().toURL().toExternalForm() + "!/" + 
Constants.ApplicationContextXml);
+                    try (final JarFile warAsJar = new JarFile(war)) {
+                        final JarEntry entry = 
warAsJar.getJarEntry(Constants.ApplicationContextXml);
+                        if (entry != null) {
+                            contextXmlUrl = new URL("jar:" + 
war.getAbsoluteFile().toURI().toURL().toExternalForm() + "!/" + 
Constants.ApplicationContextXml);
+                        }
                     }
                 }
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/04c0e98e/tomee/tomee-common/src/main/java/org/apache/tomee/installer/Installer.java
----------------------------------------------------------------------
diff --git 
a/tomee/tomee-common/src/main/java/org/apache/tomee/installer/Installer.java 
b/tomee/tomee-common/src/main/java/org/apache/tomee/installer/Installer.java
index 1581045..301dfd5 100644
--- a/tomee/tomee-common/src/main/java/org/apache/tomee/installer/Installer.java
+++ b/tomee/tomee-common/src/main/java/org/apache/tomee/installer/Installer.java
@@ -598,29 +598,24 @@ public class Installer implements InstallerInterface {
             // the core jar contains the config files
             return;
         }
-        final JarFile coreJar;
-        try {
-            coreJar = new JarFile(openejbCoreJar);
-        } catch (final IOException e) {
-            return;
-        }
-
-        //
-        // conf/tomee.xml
-        //
-        final File openEjbXmlFile = new File(confDir, "tomee.xml");
-        if (!openEjbXmlFile.exists()) {
-            // read in the openejb.xml file from the openejb core jar
-            final String openEjbXml = Installers.readEntry(coreJar, 
"default.openejb.conf", alerts);
-            if (openEjbXml != null) {
-                if (Installers.writeAll(openEjbXmlFile, 
openEjbXml.replace("<openejb>", "<tomee>").replace("</openejb>", "</tomee>"), 
alerts)) {
-                    alerts.addInfo("Copy tomee.xml to conf");
+        try (final JarFile coreJar = new JarFile(openejbCoreJar)) {
+            //
+            // conf/tomee.xml
+            //
+            final File openEjbXmlFile = new File(confDir, "tomee.xml");
+            if (!openEjbXmlFile.exists()) {
+                // read in the openejb.xml file from the openejb core jar
+                final String openEjbXml = Installers.readEntry(coreJar, 
"default.openejb.conf", alerts);
+                if (openEjbXml != null) {
+                    if (Installers.writeAll(openEjbXmlFile, 
openEjbXml.replace("<openejb>", "<tomee>").replace("</openejb>", "</tomee>"), 
alerts)) {
+                        alerts.addInfo("Copy tomee.xml to conf");
+                    }
                 }
             }
+        } catch (final IOException e) {
+            return;
         }
 
-
-        //
         // conf/logging.properties
         // now we are using tomcat one of jdk one by default
         //
@@ -809,16 +804,14 @@ public class Installer implements InstallerInterface {
         //
         // conf/web.xml
         //
-        final JarFile openejbTomcatCommonJar;
-        try {
-            openejbTomcatCommonJar = new 
JarFile(paths.geOpenEJBTomcatCommonJar());
+        try (final JarFile openejbTomcatCommonJar = new 
JarFile(paths.geOpenEJBTomcatCommonJar())) {
+            final File webXmlFile = new File(confDir, "web.xml");
+            final String webXml = Installers.readEntry(openejbTomcatCommonJar, 
"conf/web.xml", alerts);
+            if (Installers.writeAll(webXmlFile, webXml, alerts)) {
+                alerts.addInfo("Set jasper in production mode in TomEE 
web.xml");
+            }
         } catch (final IOException e) {
-            return;
-        }
-        final File webXmlFile = new File(confDir, "web.xml");
-        final String webXml = Installers.readEntry(openejbTomcatCommonJar, 
"conf/web.xml", alerts);
-        if (Installers.writeAll(webXmlFile, webXml, alerts)) {
-            alerts.addInfo("Set jasper in production mode in TomEE web.xml");
+            // no-op
         }
     }
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/04c0e98e/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/OpenEJBListener.java
----------------------------------------------------------------------
diff --git 
a/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/OpenEJBListener.java 
b/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/OpenEJBListener.java
index 3eb0e9a..b76d35d 100644
--- 
a/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/OpenEJBListener.java
+++ 
b/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/OpenEJBListener.java
@@ -141,8 +141,7 @@ public class OpenEJBListener implements LifecycleListener {
 
     private static boolean isTomEEWar(final File file) {
         final String name = file.getName();
-        try {
-            final JarFile jarFile = new JarFile(file);
+        try (final JarFile jarFile = new JarFile(file)) {
             return jarFile.getEntry("lib") != null
                     && (name.startsWith("tomee") || name.startsWith("openejb")
                     && name.endsWith(".war"));

Reply via email to