You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by jk...@apache.org on 2007/09/08 17:24:41 UTC

svn commit: r573855 - /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java

Author: jkf
Date: Sat Sep  8 08:24:40 2007
New Revision: 573855

URL: http://svn.apache.org/viewvc?rev=573855&view=rev
Log:
Pr 43330, suppress printing of cvs password in case it is given on the command line.

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java?rev=573855&r1=573854&r2=573855&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java Sat Sep  8 08:24:40 2007
@@ -334,10 +334,11 @@
 
         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 @@
 
     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 +430,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: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) {
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org