From 773a2273edbbe2976362a6698ad57fd4df51ceca Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Mon, 3 Feb 2003 15:41:18 +0000 Subject: [PATCH] Close original archive after checking for old manifest in - otherwise the file may still be locked on Windows and friends when we try to rename it. Submitted by: Antoine Levy-Lambert git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273965 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/org/apache/tools/ant/taskdefs/Jar.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/Jar.java b/src/main/org/apache/tools/ant/taskdefs/Jar.java index 463d19f8c..7e9ed483d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Jar.java +++ b/src/main/org/apache/tools/ant/taskdefs/Jar.java @@ -163,8 +163,9 @@ public class Jar extends Zip { public void setDestFile(File jarFile) { super.setDestFile(jarFile); if (jarFile.exists()) { + ZipFile zf = null; try { - ZipFile zf = new ZipFile(jarFile); + zf = new ZipFile(jarFile); // must not use getEntry as "well behaving" applications // must accept the manifest in any capitalization @@ -174,13 +175,22 @@ public class Jar extends Zip { if (ze.getName().equalsIgnoreCase("META-INF/MANIFEST.MF")) { originalManifest = getManifest(new InputStreamReader(zf - .getInputStream(ze))); + .getInputStream(ze))); } } } catch (Throwable t) { log("error while reading original manifest: " + t.getMessage(), Project.MSG_WARN); + } finally { + if (zf != null) { + try { + zf.close(); + } catch (IOException e) { + // XXX - log an error? throw an exception? + } + } } + } }