From 1e760c7354cf76a820bf05aa29881ca9154757fc Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Thu, 26 Sep 2002 08:13:58 +0000 Subject: [PATCH] Make use the not deprecated methods of ExecTask. PR: 12468 Submitted by: Jesse Stockall git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273356 13f79535-47bb-0310-9956-ffa450edef68 --- .../tools/ant/taskdefs/optional/Cab.java | 58 ++++++++----------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java b/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java index d7bb2166c..798885d2e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java @@ -79,6 +79,7 @@ import org.apache.tools.ant.util.FileUtils; * Create a CAB archive. * * @author Roger Vaughn rvaughn@seaconinc.com + * @author Jesse Stockall */ public class Cab extends MatchingTask { @@ -143,13 +144,13 @@ public class Cab extends MatchingTask { */ protected void checkConfiguration() throws BuildException { if (baseDir == null) { - throw new BuildException("basedir attribute must be set!"); + throw new BuildException("basedir attribute must be set!", getLocation()); } if (!baseDir.exists()) { - throw new BuildException("basedir does not exist!"); + throw new BuildException("basedir does not exist!", getLocation()); } if (cabFile == null) { - throw new BuildException("cabfile attribute must be set!"); + throw new BuildException("cabfile attribute must be set!" , getLocation()); } } @@ -182,31 +183,6 @@ public class Cab extends MatchingTask { return upToDate; } - /** - * Create the cabarc command line to use. - */ - protected Commandline createCommand(File listFile) { - Commandline command = new Commandline(); - command.setExecutable("cabarc"); - command.createArgument().setValue("-r"); - command.createArgument().setValue("-p"); - - if (!doCompress) { - command.createArgument().setValue("-m"); - command.createArgument().setValue("none"); - } - - if (cmdOptions != null) { - command.createArgument().setLine(cmdOptions); - } - - command.createArgument().setValue("n"); - command.createArgument().setFile(cabFile); - command.createArgument().setValue("@" + listFile.getAbsolutePath()); - - return command; - } - /** * Creates a list file. This temporary file contains a list of all files * to be included in the cab, one file per line. @@ -286,7 +262,7 @@ public class Cab extends MatchingTask { sb.append("\n").append(cabFile.getAbsolutePath()).append("\n"); try { - Process p = Execute.launch(getProject(), + Process p = Execute.launch(getProject(), new String[] {"listcab"}, null, baseDir, true); OutputStream out = p.getOutputStream(); @@ -301,7 +277,7 @@ public class Cab extends MatchingTask { LogOutputStream errLog = new LogOutputStream(this, Project.MSG_ERR); StreamPumper outPump = new StreamPumper(p.getInputStream(), outLog); StreamPumper errPump = new StreamPumper(p.getErrorStream(), errLog); - + // Pump streams asynchronously (new Thread(outPump)).start(); (new Thread(errPump)).start(); @@ -327,7 +303,7 @@ public class Cab extends MatchingTask { } } catch (IOException ex) { String msg = "Problem creating " + cabFile + " " + ex.getMessage(); - throw new BuildException(msg); + throw new BuildException(msg, getLocation()); } } else { try { @@ -344,7 +320,23 @@ public class Cab extends MatchingTask { exec.setOutput(outFile); } - exec.setCommand(createCommand(listFile)); + exec.setExecutable("cabarc"); + exec.createArg().setValue("-r"); + exec.createArg().setValue("-p"); + + if (!doCompress) { + exec.createArg().setValue("-m"); + exec.createArg().setValue("none"); + } + + if (cmdOptions != null) { + exec.createArg().setLine(cmdOptions); + } + + exec.createArg().setValue("n"); + exec.createArg().setFile(cabFile); + exec.createArg().setValue("@" + listFile.getAbsolutePath()); + exec.execute(); if (outFile != null) { @@ -354,7 +346,7 @@ public class Cab extends MatchingTask { listFile.delete(); } catch (IOException ioe) { String msg = "Problem creating " + cabFile + " " + ioe.getMessage(); - throw new BuildException(msg); + throw new BuildException(msg, getLocation()); } } }