Browse Source

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
master
Conor MacNeill 25 years ago
parent
commit
53588f1250
1 changed files with 17 additions and 8 deletions
  1. +17
    -8
      src/main/org/apache/tools/ant/taskdefs/Expand.java

+ 17
- 8
src/main/org/apache/tools/ant/taskdefs/Expand.java View File

@@ -76,19 +76,21 @@ public class Expand extends Task {
public void execute() throws BuildException { public void execute() throws BuildException {
Touch touch = (Touch) project.createTask("touch"); Touch touch = (Touch) project.createTask("touch");
touch.setTarget(target); touch.setTarget(target);
File srcF=project.resolveFile(source);
File dir=project.resolveFile(dest);
ZipInputStream zis = null;
try { try {
File srcF=project.resolveFile(source);
File dir=project.resolveFile(dest);
log("Expanding: " + srcF + " into " + dir, Project.MSG_INFO); log("Expanding: " + srcF + " into " + dir, Project.MSG_INFO);
// code from WarExpand // code from WarExpand
ZipInputStream zis = new ZipInputStream(new FileInputStream(srcF));
zis = new ZipInputStream(new FileInputStream(srcF));
ZipEntry ze = null; ZipEntry ze = null;
while ((ze = zis.getNextEntry()) != null) { while ((ze = zis.getNextEntry()) != null) {
File f = new File(dir, project.translatePath(ze.getName()));
try { try {
File f = new File(dir, project.translatePath(ze.getName()));
log("expand-file " + ze.getName() , Project.MSG_VERBOSE ); log("expand-file " + ze.getName() , Project.MSG_VERBOSE );
// create intermediary directories - sometimes zip don't add them // create intermediary directories - sometimes zip don't add them
File dirF=new File(f.getParent()); File dirF=new File(f.getParent());
@@ -115,12 +117,19 @@ public class Expand extends Task {
} }


} catch( FileNotFoundException ex ) { } catch( FileNotFoundException ex ) {
System.out.println("FileNotFoundException: " + ze.getName() );
log("Unable to expand to file " + f.getPath(), Project.MSG_WARN);
} }
} }
log("</log:expand>", Project.MSG_VERBOSE );
log("expand complete", Project.MSG_VERBOSE );
} catch (IOException ioe) { } catch (IOException ioe) {
ioe.printStackTrace();
throw new BuildException("Error while expanding " + srcF.getPath(), ioe);
} finally {
if (zis != null) {
try {
zis.close();
}
catch (IOException e) {}
}
} }
} }




Loading…
Cancel
Save