From 228efb0efccfee88fc60e0c026da804e3321f7ae Mon Sep 17 00:00:00 2001 From: Jacobus Martinus Kruithof Date: Sat, 8 Sep 2007 15:24:40 +0000 Subject: [PATCH] Pr 43330, suppress printing of cvs password in case it is given on the command line. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@573855 13f79535-47bb-0310-9956-ffa450edef68 --- .../tools/ant/taskdefs/AbstractCvsTask.java | 42 ++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java b/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java index bbb6fedfa..8dad3dd45 100644 --- a/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java @@ -334,10 +334,11 @@ public abstract class AbstractCvsTask extends Task { try { String actualCommandLine = executeToString(exe); + log(actualCommandLine, Project.MSG_VERBOSE); int retCode = exe.execute(); log("retCode=" + retCode, Project.MSG_DEBUG); - /*Throw an exception if cvs exited with error. (Iulian)*/ + if (failOnError && Execute.isFailure(retCode)) { throw new BuildException("cvs exited with error code " + retCode @@ -406,9 +407,9 @@ public abstract class AbstractCvsTask extends Task { private String executeToString(Execute execute) { - StringBuffer stringBuffer = - new StringBuffer(Commandline.describeCommand(execute - .getCommandline())); + String cmdLine = Commandline.describeCommand(execute + .getCommandline()); + StringBuffer stringBuffer = removeCvsPassword(cmdLine); String newLine = StringUtils.LINE_SEP; String[] variableArray = execute.getEnvironment(); @@ -428,10 +429,39 @@ public abstract class AbstractCvsTask extends Task { return stringBuffer.toString(); } + /** + * Removes the cvs password from the command line, if given on the command + * line. This password can be given on the command line in the cvsRoot + * -d:pserver:user:password@server:path + * It has to be noted that the password may be omitted altogether. + * @param cmdLine the CVS command line + * @return a StringBuffer where the password has been removed (if available) + */ + private StringBuffer removeCvsPassword(String cmdLine) { + StringBuffer stringBuffer = new StringBuffer(cmdLine); + + int start = cmdLine.indexOf("-d:"); + + if (start >= 0) { + int stop = cmdLine.indexOf("@", start); + int startproto = cmdLine.indexOf(":", start); + int startuser = cmdLine.indexOf(":", startproto + 1); + int startpass = cmdLine.indexOf(":", startuser + 1); + stop = cmdLine.indexOf("@", start); + if (stop >= 0 && startpass > startproto && startpass < stop) { + for (int i = startpass + 1; i < stop; i++) { + stringBuffer.replace(i, i+1, "*"); + } + } + } + return stringBuffer; + } + /** * The CVSROOT variable. - * - * @param root the CVSROOT variable + * + * @param root + * the CVSROOT variable */ public void setCvsRoot(String root) {