Author: jkf Date: Sat Sep 8 08:16:57 2007 New Revision: 573853 URL: http://svn.apache.org/viewvc?rev=573853&view=rev Log: Pr 43330, suppress printing of cvs password in case it is given on the command line.
Modified: ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java Modified: ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java URL: http://svn.apache.org/viewvc/ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java?rev=573853&r1=573852&r2=573853&view=diff ============================================================================== --- ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java (original) +++ ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java Sat Sep 8 08:16:57 2007 @@ -334,10 +334,13 @@ 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 +409,9 @@ 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(); @@ -429,9 +432,38 @@ } /** + * 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:[EMAIL PROTECTED]: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) { --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]