You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2016/09/26 12:56:41 UTC
tomee git commit: TOMEE-1935 Fixes #47 patch from SvetlinZarev to
close JarFile
Repository: tomee
Updated Branches:
refs/heads/master 31a308994 -> 40794d0d9
TOMEE-1935 Fixes #47 patch from SvetlinZarev to close JarFile
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/40794d0d
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/40794d0d
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/40794d0d
Branch: refs/heads/master
Commit: 40794d0d9c8e32bf7ef3b377ea0857f2b84ca463
Parents: 31a3089
Author: rmannibucau <rm...@apache.org>
Authored: Mon Sep 26 14:56:32 2016 +0200
Committer: rmannibucau <rm...@apache.org>
Committed: Mon Sep 26 14:56:32 2016 +0200
----------------------------------------------------------------------
.../apache/openejb/config/DeploymentLoader.java | 49 +++++++++++---------
.../openejb/config/rules/CheckClassLoading.java | 29 ++++++------
2 files changed, 41 insertions(+), 37 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/40794d0d/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java b/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
index 0611997..3515c13 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
@@ -319,24 +319,25 @@ public class DeploymentLoader implements DeploymentFilterable {
try {
final File file = URLs.toFile(url);
if (file.getName().endsWith(".jar")) {
- final JarFile jarFile = new JarFile(file);
+ try (JarFile jarFile = new JarFile(file)) {
- // TODO: better management of altdd
- String name = (ALTDD != null ? ALTDD + "." : "") + "ra.xml";
+ // TODO: better management of altdd
+ String name = (ALTDD != null ? ALTDD + "." : "") + "ra.xml";
- JarEntry entry = jarFile.getJarEntry(name);
- if (entry == null) {
- name = "META-INF/" + name;
- entry = jarFile.getJarEntry(name);
- }
- if (entry == null) {
- continue;
- }
+ JarEntry entry = jarFile.getJarEntry(name);
+ if (entry == null) {
+ name = "META-INF/" + name;
+ entry = jarFile.getJarEntry(name);
+ }
+ if (entry == null) {
+ continue;
+ }
- final String jarLocation = file.getAbsolutePath();
- final ConnectorModule connectorModule = createConnectorModule(jarLocation, jarLocation, webModule.getClassLoader(), null);
- if (connectorModule != null) {
- appModule.getConnectorModules().add(connectorModule);
+ final String jarLocation = file.getAbsolutePath();
+ final ConnectorModule connectorModule = createConnectorModule(jarLocation, jarLocation, webModule.getClassLoader(), null);
+ if (connectorModule != null) {
+ appModule.getConnectorModules().add(connectorModule);
+ }
}
}
} catch (final Exception e) {
@@ -1775,8 +1776,7 @@ public class DeploymentLoader implements DeploymentFilterable {
if (warFile.isFile()) { // only to discover module type so xml file filtering is enough
final URL jarURL = new URL("jar", "", -1, warFile.toURI().toURL() + "!/");
- try {
- final JarFile jarFile = new JarFile(warFile);
+ try (JarFile jarFile = new JarFile(warFile)) {
for (final JarEntry entry : Collections.list(jarFile.entries())) {
final String entryName = entry.getName();
if (!entry.isDirectory() && entryName.startsWith("WEB-INF/")
@@ -2086,12 +2086,15 @@ public class DeploymentLoader implements DeploymentFilterable {
cls = EjbModule.class;
// if it is a war just throw an error
try {
- final File ar = URLs.toFile(urls);
- if (!ar.isDirectory() && !ar.getName().endsWith("ar")) { // guess no archive extension, check it is not a hidden war
- final JarFile war = new JarFile(ar);
- final ZipEntry entry = war.getEntry("WEB-INF/");
- if (entry != null) {
- logger.warning("you deployed " + urls.toExternalForm() + ", it seems it is a war with no extension, please rename it");
+ if(logger.isWarningEnabled()) {
+ final File ar = URLs.toFile(urls);
+ if (!ar.isDirectory() && !ar.getName().endsWith("ar")) { // guess no archive extension, check it is not a hidden war
+ try (JarFile war = new JarFile(ar)) {
+ final ZipEntry entry = war.getEntry("WEB-INF/");
+ if (entry != null) {
+ logger.warning("you deployed " + urls.toExternalForm() + ", it seems it is a war with no extension, please rename it");
+ }
+ }
}
}
} catch (final Exception ignored) {
http://git-wip-us.apache.org/repos/asf/tomee/blob/40794d0d/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckClassLoading.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckClassLoading.java b/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckClassLoading.java
index bb17b3e..dd3d8ae 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckClassLoading.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/rules/CheckClassLoading.java
@@ -167,24 +167,25 @@ public class CheckClassLoading extends ValidationBase {
final List<String> files = new ArrayList<String>();
- final JarFile file = new JarFile(archive);
- final Enumeration<JarEntry> entries = file.entries();
- while (entries.hasMoreElements()) {
- final JarEntry entry = entries.nextElement();
- final String name = entry.getName();
- for (final String ext : extensions) {
- if (name.endsWith(ext)) {
- if (CLASS_EXT.equals(ext)) {
- files.add(name.replace("/", "."));
- } else {
- files.add(name);
+ try (JarFile file = new JarFile(archive)) {
+ final Enumeration<JarEntry> entries = file.entries();
+ while (entries.hasMoreElements()) {
+ final JarEntry entry = entries.nextElement();
+ final String name = entry.getName();
+ for (final String ext : extensions) {
+ if (name.endsWith(ext)) {
+ if (CLASS_EXT.equals(ext)) {
+ files.add(name.replace("/", "."));
+ } else {
+ files.add(name);
+ }
+ break;
}
- break;
}
}
- }
- return files;
+ return files;
+ }
}
}