From 53588f1250f43815d4c92de79c326dd3665fb83c Mon Sep 17 00:00:00 2001 From: Conor MacNeill Date: Sat, 8 Jul 2000 02:58:38 +0000 Subject: [PATCH] Close ZIP files after expand operation is complete. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267745 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/taskdefs/Expand.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/Expand.java b/src/main/org/apache/tools/ant/taskdefs/Expand.java index 558ed97fd..7f758971f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Expand.java +++ b/src/main/org/apache/tools/ant/taskdefs/Expand.java @@ -76,19 +76,21 @@ public class Expand extends Task { public void execute() throws BuildException { Touch touch = (Touch) project.createTask("touch"); touch.setTarget(target); - + + File srcF=project.resolveFile(source); + File dir=project.resolveFile(dest); + + ZipInputStream zis = null; try { - File srcF=project.resolveFile(source); - File dir=project.resolveFile(dest); log("Expanding: " + srcF + " into " + dir, Project.MSG_INFO); // code from WarExpand - ZipInputStream zis = new ZipInputStream(new FileInputStream(srcF)); + zis = new ZipInputStream(new FileInputStream(srcF)); ZipEntry ze = null; while ((ze = zis.getNextEntry()) != null) { + File f = new File(dir, project.translatePath(ze.getName())); try { - File f = new File(dir, project.translatePath(ze.getName())); log("expand-file " + ze.getName() , Project.MSG_VERBOSE ); // create intermediary directories - sometimes zip don't add them File dirF=new File(f.getParent()); @@ -115,12 +117,19 @@ public class Expand extends Task { } } catch( FileNotFoundException ex ) { - System.out.println("FileNotFoundException: " + ze.getName() ); + log("Unable to expand to file " + f.getPath(), Project.MSG_WARN); } } - log("", Project.MSG_VERBOSE ); + log("expand complete", Project.MSG_VERBOSE ); } catch (IOException ioe) { - ioe.printStackTrace(); + throw new BuildException("Error while expanding " + srcF.getPath(), ioe); + } finally { + if (zis != null) { + try { + zis.close(); + } + catch (IOException e) {} + } } }