From 233ae85c5f835679681ece8d58a279b6bcf50550 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Thu, 25 Apr 2002 12:14:51 +0000 Subject: [PATCH] Don't tell people we'd execute a given command line when we really do something completely different. I hope this will cut down the "Ant swallows my quotes" reports to those that are real problems in Ant and not just problems of communication. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272573 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/DefaultLogger.java | 30 ++-- .../tools/ant/taskdefs/AbstractCvsTask.java | 13 +- .../apache/tools/ant/taskdefs/ExecTask.java | 6 +- .../apache/tools/ant/taskdefs/Execute.java | 13 +- .../apache/tools/ant/taskdefs/ExecuteOn.java | 5 +- .../org/apache/tools/ant/taskdefs/Java.java | 4 +- .../apache/tools/ant/taskdefs/Javadoc.java | 2 +- .../compilers/DefaultCompilerAdapter.java | 4 +- .../tools/ant/taskdefs/optional/ANTLR.java | 4 +- .../tools/ant/taskdefs/optional/Javah.java | 2 +- .../tools/ant/taskdefs/optional/Rpm.java | 2 +- .../taskdefs/optional/ccm/CCMCreateTask.java | 2 +- .../taskdefs/optional/clearcase/CCUpdate.java | 14 +- .../taskdefs/optional/dotnet/NetCommand.java | 4 +- .../optional/ejb/BorlandDeploymentTool.java | 2 +- .../ant/taskdefs/optional/javacc/JJTree.java | 2 +- .../optional/jdepend/JDependTask.java | 2 +- .../compilers/DefaultJspCompilerAdapter.java | 3 +- .../taskdefs/optional/junit/JUnitTask.java | 2 +- .../metamata/AbstractMetamataTask.java | 2 +- .../taskdefs/optional/metamata/MParse.java | 2 +- .../taskdefs/optional/perforce/P4Base.java | 2 +- .../ant/taskdefs/optional/pvcs/Pvcs.java | 2 +- .../taskdefs/optional/sitraka/CovMerge.java | 2 +- .../taskdefs/optional/sitraka/CovReport.java | 2 +- .../taskdefs/optional/sitraka/Coverage.java | 2 +- .../ant/taskdefs/rmic/DefaultRmicAdapter.java | 2 +- .../apache/tools/ant/types/Commandline.java | 129 +++++++++++++++++- .../tools/ant/types/CommandlineJava.java | 23 ++++ 29 files changed, 220 insertions(+), 64 deletions(-) diff --git a/src/main/org/apache/tools/ant/DefaultLogger.java b/src/main/org/apache/tools/ant/DefaultLogger.java index 795871891..86bd7b9b4 100644 --- a/src/main/org/apache/tools/ant/DefaultLogger.java +++ b/src/main/org/apache/tools/ant/DefaultLogger.java @@ -55,6 +55,7 @@ package org.apache.tools.ant; import java.io.PrintStream; +import java.util.StringTokenizer; import org.apache.tools.ant.util.StringUtils; import org.apache.tools.ant.util.DateUtils; @@ -248,21 +249,34 @@ public class DefaultLogger implements BuildLogger { if (priority <= msgOutputLevel) { StringBuffer message = new StringBuffer(); - // Print out the name of the task if we're in one - if (event.getTask() != null) { + if (event.getTask() != null && !emacsMode) { + // Print out the name of the task if we're in one String name = event.getTask().getTaskName(); + String label = "[" + name + "] "; + int size = LEFT_COLUMN_SIZE - label.length(); + StringBuffer tmp = new StringBuffer(size); + for (int i = 0; i < size; i++) { + tmp.append(" "); + } + tmp.append(label); + label = tmp.toString(); - if (!emacsMode) { - String label = "[" + name + "] "; - int size = LEFT_COLUMN_SIZE - label.length(); - for (int i = 0; i < size; i++) { - message.append(" "); + StringTokenizer tok = new StringTokenizer(event.getMessage(), + "\r\n", false); + boolean first = true; + while (tok.hasMoreTokens()) { + if (!first) { + message.append(StringUtils.LINE_SEP); } + first = false; message.append(label); + message.append(tok.nextToken()); } + + } else { + message.append(event.getMessage()); } - message.append(event.getMessage()); String msg = message.toString(); if (priority != Project.MSG_ERR) { printMessage(msg, out, priority); diff --git a/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java b/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java index a31f1d1fb..73915ca41 100644 --- a/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java @@ -321,8 +321,7 @@ public abstract class AbstractCvsTask extends Task { try { String actualCommandLine = executeToString(exe); - log("running cvs command: " + actualCommandLine, - Project.MSG_DEBUG); + log(actualCommandLine, Project.MSG_VERBOSE); int retCode = exe.execute(); log("retCode=" + retCode, Project.MSG_DEBUG); /*Throw an exception if cvs exited with error. (Iulian)*/ @@ -400,13 +399,9 @@ public abstract class AbstractCvsTask extends Task { private String executeToString(Execute execute){ - StringBuffer stringBuffer = new StringBuffer(250); - String[] commandLine = execute.getCommandline(); - for (int i = 0; i < commandLine.length; i++){ - - stringBuffer.append(commandLine[i]); - stringBuffer.append(" "); - } + StringBuffer stringBuffer = + new StringBuffer(Commandline.describeCommand(execute + .getCommandline())); String newLine = StringUtils.LINE_SEP; String[] variableArray = execute.getEnvironment(); diff --git a/src/main/org/apache/tools/ant/taskdefs/ExecTask.java b/src/main/org/apache/tools/ant/taskdefs/ExecTask.java index 00962fc2d..fb0170bbd 100644 --- a/src/main/org/apache/tools/ant/taskdefs/ExecTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/ExecTask.java @@ -303,9 +303,6 @@ public class ExecTask extends Task { if (dir == null) { dir = project.getBaseDir(); } - // show the command - log(cmdl.toString(), Project.MSG_VERBOSE); - Execute exe = new Execute(createHandler(), createWatchdog()); exe.setAntRun(getProject()); exe.setWorkingDirectory(dir); @@ -363,6 +360,9 @@ public class ExecTask extends Task { * overidden by subclasses */ protected void runExec(Execute exe) throws BuildException { + // show the command + log(cmdl.describeCommand(), Project.MSG_VERBOSE); + exe.setCommandline(cmdl.getCommandline()); try { runExecute(exe); diff --git a/src/main/org/apache/tools/ant/taskdefs/Execute.java b/src/main/org/apache/tools/ant/taskdefs/Execute.java index 86e2016ae..847d6bdb4 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Execute.java +++ b/src/main/org/apache/tools/ant/taskdefs/Execute.java @@ -63,7 +63,6 @@ import org.apache.tools.ant.taskdefs.condition.Os; import java.io.File; import java.io.IOException; - import java.io.BufferedReader; import java.io.StringReader; import java.io.ByteArrayOutputStream; @@ -507,7 +506,8 @@ public class Execute { public static void runCommand(Task task, String[] cmdline) throws BuildException { try { - task.log(Commandline.toString(cmdline), Project.MSG_VERBOSE); + task.log(Commandline.describeCommand(cmdline), + Project.MSG_VERBOSE); Execute exe = new Execute(new LogStreamHandler(task, Project.MSG_INFO, Project.MSG_ERR)); @@ -542,7 +542,8 @@ public class Execute { throws IOException { if (project != null) { project.log("Execute:CommandLauncher: " + - Commandline.toString(cmd), Project.MSG_DEBUG); + Commandline.describeCommand(cmd), + Project.MSG_DEBUG); } return Runtime.getRuntime().exec(cmd, env); } @@ -588,7 +589,8 @@ public class Execute { } if (project != null) { project.log("Execute:Java11CommandLauncher: " + - Commandline.toString(newcmd), Project.MSG_DEBUG); + Commandline.describeCommand(newcmd), + Project.MSG_DEBUG); } return Runtime.getRuntime().exec(newcmd, env); } @@ -615,7 +617,8 @@ public class Execute { try { if (project != null) { project.log("Execute:Java13CommandLauncher: " + - Commandline.toString(cmd), Project.MSG_DEBUG); + Commandline.describeCommand(cmd), + Project.MSG_DEBUG); } Object[] arguments = { cmd, env, workingDir }; return (Process) _execWithCWD.invoke(Runtime.getRuntime(), diff --git a/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java b/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java index 6792b4faa..98dfea151 100644 --- a/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java +++ b/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java @@ -240,7 +240,7 @@ public class ExecuteOn extends ExecTask { fileNames.copyInto(s); for (int j = 0; j < s.length; j++) { String[] command = getCommandline(s[j], base); - log("Executing " + Commandline.toString(command), + log(Commandline.describeCommand(command), Project.MSG_VERBOSE); exe.setCommandline(command); runExecute(exe); @@ -256,8 +256,7 @@ public class ExecuteOn extends ExecTask { File[] b = new File[baseDirs.size()]; baseDirs.copyInto(b); String[] command = getCommandline(s, b); - log("Executing " + Commandline.toString(command), - Project.MSG_VERBOSE); + log(Commandline.describeCommand(command), Project.MSG_VERBOSE); exe.setCommandline(command); runExecute(exe); } diff --git a/src/main/org/apache/tools/ant/taskdefs/Java.java b/src/main/org/apache/tools/ant/taskdefs/Java.java index 36fe69ca9..8e7b32010 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Java.java +++ b/src/main/org/apache/tools/ant/taskdefs/Java.java @@ -135,7 +135,7 @@ public class Java extends Task { } if (fork) { - log("Forking " + cmdl.toString(), Project.MSG_VERBOSE); + log(cmdl.describeCommand(), Project.MSG_VERBOSE); } else { if (cmdl.getVmCommand().size() > 1) { log("JVM args ignored when same JVM is used.", @@ -151,7 +151,7 @@ public class Java extends Task { + "JVM is used.", Project.MSG_WARN); } - log("Running in same VM " + cmdl.getJavaCommand().toString(), + log("Running in same VM " + cmdl.describeJavaCommand(), Project.MSG_VERBOSE); } diff --git a/src/main/org/apache/tools/ant/taskdefs/Javadoc.java b/src/main/org/apache/tools/ant/taskdefs/Javadoc.java index 61b7b14d8..80315d877 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Javadoc.java +++ b/src/main/org/apache/tools/ant/taskdefs/Javadoc.java @@ -1687,7 +1687,7 @@ public class Javadoc extends Task { if (packageList != null) { toExecute.createArgument().setValue("@" + packageList); } - log("Javadoc args: " + toExecute, Project.MSG_VERBOSE); + log(toExecute.describeCommand(), Project.MSG_VERBOSE); log("Javadoc execution", Project.MSG_INFO); diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java b/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java index 318863f88..cd8426228 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java @@ -374,8 +374,8 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter { * &qout;niceSourceList" */ protected void logAndAddFilesToCompile(Commandline cmd) { - attributes.log("Compilation args: " + cmd.toString(), - Project.MSG_VERBOSE); + attributes.log("Compilation " + cmd.describeArguments(), + Project.MSG_VERBOSE); StringBuffer niceSourceList = new StringBuffer("File"); if (compileList.length != 1) { diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ANTLR.java b/src/main/org/apache/tools/ant/taskdefs/optional/ANTLR.java index afa6f34c0..8f4577877 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ANTLR.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ANTLR.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2001 The Apache Software Foundation. All rights + * Copyright (c) 2000-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -188,7 +188,7 @@ public class ANTLR extends Task { commandline.createArgument().setValue(outputDirectory.toString()); commandline.createArgument().setValue(target.toString()); - log("Forking " + commandline.toString(), Project.MSG_VERBOSE); + log(commandline.describeCommand(), Project.MSG_VERBOSE); int err = run(commandline.getCommandline()); if (err == 1) { throw new BuildException("ANTLR returned: " + err, location); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/Javah.java b/src/main/org/apache/tools/ant/taskdefs/optional/Javah.java index 977402c3c..b7daeb43d 100755 --- a/src/main/org/apache/tools/ant/taskdefs/optional/Javah.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/Javah.java @@ -390,7 +390,7 @@ public class Javah extends Task { */ protected void logAndAddFilesToCompile(Commandline cmd) { int n = 0; - log("Compilation args: " + cmd.toString(), + log("Compilation " + cmd.describeArguments(), Project.MSG_VERBOSE); StringBuffer niceClassList = new StringBuffer(); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java b/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java index 433f228b1..a6a971e5c 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java @@ -171,7 +171,7 @@ public class Rpm extends Task { exe.setAntRun(project); if (topDir == null) { - topDir = project.getBaseDir(); + topDir = project.getBaseDir(); } exe.setWorkingDirectory(topDir); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ccm/CCMCreateTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/ccm/CCMCreateTask.java index f06112214..92613d08f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ccm/CCMCreateTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ccm/CCMCreateTask.java @@ -119,7 +119,7 @@ public class CCMCreateTask extends Continuus implements ExecuteStreamHandler { commandLine2.createArgument().setValue(COMMAND_DEFAULT_TASK); commandLine2.createArgument().setValue(getTask()); - log(commandLine.toString(), Project.MSG_DEBUG); + log(commandLine.describeCommand(), Project.MSG_DEBUG); result = run(commandLine2); if (result != 0) { diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/clearcase/CCUpdate.java b/src/main/org/apache/tools/ant/taskdefs/optional/clearcase/CCUpdate.java index bb98e5877..ced0de18a 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/clearcase/CCUpdate.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/clearcase/CCUpdate.java @@ -323,31 +323,31 @@ public class CCUpdate extends ClearCase { } } - /** + /** * -graphical flag -- display graphical dialog during update operation */ public static final String FLAG_GRAPHICAL = "-graphical"; - /** + /** * -log flag -- file to log status to */ public static final String FLAG_LOG = "-log"; - /** + /** * -overwrite flag -- overwrite hijacked files */ public static final String FLAG_OVERWRITE = "-overwrite"; - /** + /** * -noverwrite flag -- do not overwrite hijacked files */ public static final String FLAG_NOVERWRITE = "-noverwrite"; - /** + /** * -rename flag -- rename hijacked files with .keep extension */ public static final String FLAG_RENAME = "-rename"; - /** + /** * -ctime flag -- modified time is written as the current time */ public static final String FLAG_CURRENTTIME = "-ctime"; - /** + /** * -ptime flag -- modified time is written as the VOB time */ public static final String FLAG_PRESERVETIME = "-ptime"; diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/NetCommand.java b/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/NetCommand.java index d2cad5028..90ba7dbe3 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/NetCommand.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/NetCommand.java @@ -242,10 +242,10 @@ public class NetCommand { // assume the worst try { if (traceCommandLine) { - owner.log(commandLine.toString()); + owner.log(commandLine.describeCommand()); } else { //in verbose mode we always log stuff - logVerbose(commandLine.toString()); + logVerbose(commandLine.describeCommand()); } executable.setCommandline(commandLine.getCommandline()); err = executable.execute(); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandDeploymentTool.java index e7e6c9f77..b94d94db1 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandDeploymentTool.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandDeploymentTool.java @@ -351,7 +351,7 @@ public class BorlandDeploymentTool extends GenericDeploymentTool implements Exe try { log("Calling java2iiop", Project.MSG_VERBOSE); - log(commandline.toString(), Project.MSG_DEBUG); + log(commandline.describeCommand(), Project.MSG_DEBUG); execTask.setCommandline(commandline.getCommandline()); int result = execTask.execute(); if (result != 0) { diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java b/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java index d2c5206d5..def2ea427 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java @@ -212,7 +212,7 @@ public class JJTree extends Task { Project.MSG_INFO, Project.MSG_INFO), null); - log(cmdl.toString(), Project.MSG_VERBOSE); + log(cmdl.describeCommand(), Project.MSG_VERBOSE); process.setCommandline(cmdl.getCommandline()); try { diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java index 1bd8ff282..92377b72a 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java @@ -410,7 +410,7 @@ public class JDependTask extends Task { if (getOutputFile() != null) { log("Output to be stored in " + getOutputFile().getPath()); } - log("Executing: " + commandline.toString(), Project.MSG_VERBOSE); + log(commandline.describeCommand(), Project.MSG_VERBOSE); try { return execute.execute(); } catch (IOException e) { diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/DefaultJspCompilerAdapter.java b/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/DefaultJspCompilerAdapter.java index 514305257..2b11f7543 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/DefaultJspCompilerAdapter.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/jsp/compilers/DefaultJspCompilerAdapter.java @@ -84,7 +84,8 @@ public abstract class DefaultJspCompilerAdapter protected void logAndAddFilesToCompile(JspC jspc, Vector compileList, Commandline cmd) { - jspc.log("Compilation args: " + cmd.toString(), Project.MSG_VERBOSE); + jspc.log("Compilation " + cmd.describeArguments(), + Project.MSG_VERBOSE); StringBuffer niceSourceList = new StringBuffer("File"); if (compileList.size() != 1) { diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java index d6eda053f..59e292849 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java @@ -667,7 +667,7 @@ public class JUnitTask extends Task { execute.setNewenvironment(newEnvironment); execute.setEnvironment(environment); - log("Executing: " + cmd.toString(), Project.MSG_VERBOSE); + log(cmd.describeCommand(), Project.MSG_VERBOSE); int retVal; try { retVal = execute.execute(); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/metamata/AbstractMetamataTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/metamata/AbstractMetamataTask.java index 5ec37f718..386bc83b8 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/metamata/AbstractMetamataTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/metamata/AbstractMetamataTask.java @@ -212,7 +212,7 @@ public abstract class AbstractMetamataTask extends Task { /** execute the process with a specific handler */ protected void execute0(ExecuteStreamHandler handler) throws BuildException { final Execute process = new Execute(handler); - log(cmdl.toString(), Project.MSG_VERBOSE); + log(cmdl.describeCommand(), Project.MSG_VERBOSE); process.setCommandline(cmdl.getCommandline()); try { if (process.execute() != 0) { diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/metamata/MParse.java b/src/main/org/apache/tools/ant/taskdefs/optional/metamata/MParse.java index a218b6a9c..b0cc90ac6 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/metamata/MParse.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/metamata/MParse.java @@ -212,7 +212,7 @@ public class MParse extends Task { } final Execute process = new Execute(handler); - log(cmdl.toString(), Project.MSG_VERBOSE); + log(cmdl.describeCommand(), Project.MSG_VERBOSE); process.setCommandline(cmdl.getCommandline()); try { if (process.execute() != 0) { diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Base.java b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Base.java index 218dd9515..3450f08ea 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Base.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Base.java @@ -188,7 +188,7 @@ public abstract class P4Base extends org.apache.tools.ant.Task { cmdl += cmdline[i] + " "; } - log("Execing " + cmdl, Project.MSG_VERBOSE); + log(cmdl.describeCommand(), Project.MSG_VERBOSE); if (handler == null) { handler = new SimpleP4OutputHandler(this); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java b/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java index 1006cee5f..5b004e182 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java @@ -208,7 +208,7 @@ public class Pvcs extends org.apache.tools.ant.Task { Random rand = new Random(System.currentTimeMillis()); tmp = new File("pvcs_ant_" + rand.nextLong() + ".log"); tmp2 = new File("pvcs_ant_" + rand.nextLong() + ".log"); - log("Executing " + commandLine.toString(), Project.MSG_VERBOSE); + log(commandLine.describeCommand(), Project.MSG_VERBOSE); result = runCmd(commandLine, new PumpStreamHandler(new FileOutputStream(tmp), new LogOutputStream(this, Project.MSG_WARN))); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/CovMerge.java b/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/CovMerge.java index b15c084ae..8d1e76818 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/CovMerge.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/CovMerge.java @@ -135,7 +135,7 @@ public class CovMerge extends Task { LogStreamHandler handler = new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN); Execute exec = new Execute(handler); - log(cmdl.toString(), Project.MSG_VERBOSE); + log(cmdl.describeCommand(), Project.MSG_VERBOSE); exec.setCommandline(cmdl.getCommandline()); // JProbe process always return 0 so we will not be diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/CovReport.java b/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/CovReport.java index 5b83c93d0..6a799bdc3 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/CovReport.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/CovReport.java @@ -285,7 +285,7 @@ public class CovReport extends Task { // use the custom handler for stdin issues LogStreamHandler handler = new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN); Execute exec = new Execute(handler); - log(cmdl.toString(), Project.MSG_VERBOSE); + log(cmdl.describeCommand(), Project.MSG_VERBOSE); exec.setCommandline(cmdl.getCommandline()); int exitValue = exec.execute(); if (exitValue != 0) { diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/Coverage.java b/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/Coverage.java index 06e9b8190..77c28ffb9 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/Coverage.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/sitraka/Coverage.java @@ -277,7 +277,7 @@ public class Coverage extends Task { // use the custom handler for stdin issues LogStreamHandler handler = new CoverageStreamHandler(this); Execute exec = new Execute(handler); - log(cmdl.toString(), Project.MSG_VERBOSE); + log(cmdl.describeCommand(), Project.MSG_VERBOSE); exec.setCommandline(cmdl.getCommandline()); int exitValue = exec.execute(); if (exitValue != 0) { diff --git a/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java b/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java index 2f34167d7..0b5f71f94 100644 --- a/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java +++ b/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java @@ -260,7 +260,7 @@ public abstract class DefaultRmicAdapter implements RmicAdapter { protected void logAndAddFilesToCompile(Commandline cmd) { Vector compileList = attributes.getCompileList(); - attributes.log("Compilation args: " + cmd.toString(), + attributes.log("Compilation " + cmd.describeArguments(), Project.MSG_VERBOSE); StringBuffer niceSourceList = new StringBuffer("File"); diff --git a/src/main/org/apache/tools/ant/types/Commandline.java b/src/main/org/apache/tools/ant/types/Commandline.java index 68baa08fe..e19b9e985 100644 --- a/src/main/org/apache/tools/ant/types/Commandline.java +++ b/src/main/org/apache/tools/ant/types/Commandline.java @@ -55,6 +55,7 @@ package org.apache.tools.ant.types; import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.util.StringUtils; import java.io.File; import java.util.Vector; import java.util.StringTokenizer; @@ -87,6 +88,13 @@ public class Commandline implements Cloneable { private Vector arguments = new Vector(); private String executable = null; + protected static final String DISCLAIMER = + StringUtils.LINE_SEP + + "The \' characters around the executable and arguments are" + + StringUtils.LINE_SEP + + "not part of the command." + + StringUtils.LINE_SEP; + public Commandline(String to_process) { super(); String[] tmp = translateCommandline(to_process); @@ -230,7 +238,7 @@ public class Commandline implements Cloneable { */ public void setExecutable(String executable) { if (executable == null || executable.length() == 0) { - return; + return; } this.executable = executable.replace('/', File.separatorChar) .replace('\\', File.separatorChar); @@ -254,7 +262,7 @@ public class Commandline implements Cloneable { public String[] getCommandline() { final String[] args = getArguments(); if (executable == null) { - return args; + return args; } final String[] result = new String[args.length + 1]; result[0] = executable; @@ -313,10 +321,14 @@ public class Commandline implements Cloneable { } } + /** + * Quotes the parts of the given array in way that makes them + * usable as command line arguments. + */ public static String toString(String [] line) { // empty path return empty string if (line == null || line.length == 0) { - return ""; + return ""; } // path containing one or more elements @@ -411,7 +423,8 @@ public class Commandline implements Cloneable { } /** - * Clear out the arguments but leave the executable in place for another operation. + * Clear out the arguments but leave the executable in place for + * another operation. */ public void clearArgs() { arguments.removeAllElements(); @@ -428,4 +441,112 @@ public class Commandline implements Cloneable { return new Marker(arguments.size()); } + /** + * Returns a String that describes the command and arguments + * suitable for verbose output before a call to + * Runtime.exec(String[]) + * + * @since Ant 1.5 + */ + public String describeCommand() { + return describeCommand(this); + } + + /** + * Returns a String that describes the arguments suitable for + * verbose output before a call to + * Runtime.exec(String[]) + * + * @since Ant 1.5 + */ + public String describeArguments() { + return describeArguments(this); + } + + /** + * Returns a String that describes the command and arguments + * suitable for verbose output before a call to + * Runtime.exec(String[]) + * + * @since Ant 1.5 + */ + public static String describeCommand(Commandline line) { + return describeCommand(line.getCommandline()); + } + + /** + * Returns a String that describes the arguments suitable for + * verbose output before a call to + * Runtime.exec(String[]) + * + * @since Ant 1.5 + */ + public static String describeArguments(Commandline line) { + return describeArguments(line.getArguments()); + } + + /** + * Returns a String that describes the command and arguments + * suitable for verbose output before a call to + * Runtime.exec(String[]) + * + *

This method assumes that the first entry in the array is the + * executable to run.

+ * + * @since Ant 1.5 + */ + public static String describeCommand(String[] args) { + if (args == null || args.length == 0) { + return ""; + } + + StringBuffer buf = new StringBuffer("Executing \'"); + buf.append(args[0]); + buf.append("\'"); + if (args.length > 0) { + buf.append(" with "); + buf.append(describeArguments(args, 1)); + } else { + buf.append(DISCLAIMER); + } + return buf.toString(); + } + + /** + * Returns a String that describes the arguments suitable for + * verbose output before a call to + * Runtime.exec(String[]) + * + * @since Ant 1.5 + */ + public static String describeArguments(String[] args) { + return describeArguments(args, 0); + } + + /** + * Returns a String that describes the arguments suitable for + * verbose output before a call to + * Runtime.exec(String[]) + * + * @param offset ignore entries before this index + * + * @since Ant 1.5 + */ + protected static String describeArguments(String[] args, int offset) { + if (args == null || args.length <= offset) { + return ""; + } + + StringBuffer buf = new StringBuffer("argument"); + if (args.length > offset) { + buf.append("s"); + } + buf.append(":").append(StringUtils.LINE_SEP); + for (int i = offset; i < args.length; i++) { + buf.append("\'").append(args[i]).append("\'") + .append(StringUtils.LINE_SEP); + } + buf.append(DISCLAIMER); + return buf.toString(); + } } diff --git a/src/main/org/apache/tools/ant/types/CommandlineJava.java b/src/main/org/apache/tools/ant/types/CommandlineJava.java index 64d172343..12e5bc337 100644 --- a/src/main/org/apache/tools/ant/types/CommandlineJava.java +++ b/src/main/org/apache/tools/ant/types/CommandlineJava.java @@ -283,6 +283,29 @@ public class CommandlineJava implements Cloneable { return Commandline.toString(getCommandline()); } + /** + * Returns a String that describes the command and arguments + * suitable for verbose output before a call to + * Runtime.exec(String[]) + * + * @since Ant 1.5 + */ + public String describeCommand() { + return Commandline.describeCommand(getCommandline()); + } + + /** + * Returns a String that describes the java command and arguments + * for in VM executions. + * + *

The class name is the executable in this context.

+ * + * @since Ant 1.5 + */ + public String describeJavaCommand() { + return Commandline.describeCommand(getJavaCommand()); + } + private Commandline getActualVMCommand() { Commandline actualVMCommand = (Commandline) vmCommand.clone(); if (maxMemory != null) {