Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 202   Methods: 6
NCLOC: 97   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CVSPass.java 81.2% 97.1% 100% 93%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
 5   
  * reserved.
 6   
  *
 7   
  * Redistribution and use in source and binary forms, with or without
 8   
  * modification, are permitted provided that the following conditions
 9   
  * are met:
 10   
  *
 11   
  * 1. Redistributions of source code must retain the above copyright
 12   
  *    notice, this list of conditions and the following disclaimer.
 13   
  *
 14   
  * 2. Redistributions in binary form must reproduce the above copyright
 15   
  *    notice, this list of conditions and the following disclaimer in
 16   
  *    the documentation and/or other materials provided with the
 17   
  *    distribution.
 18   
  *
 19   
  * 3. The end-user documentation included with the redistribution, if
 20   
  *    any, must include the following acknowlegement:
 21   
  *       "This product includes software developed by the
 22   
  *        Apache Software Foundation (http://www.apache.org/)."
 23   
  *    Alternately, this acknowlegement may appear in the software itself,
 24   
  *    if and wherever such third-party acknowlegements normally appear.
 25   
  *
 26   
  * 4. The names "Ant" and "Apache Software
 27   
  *    Foundation" must not be used to endorse or promote products derived
 28   
  *    from this software without prior written permission. For written
 29   
  *    permission, please contact apache@apache.org.
 30   
  *
 31   
  * 5. Products derived from this software may not be called "Apache"
 32   
  *    nor may "Apache" appear in their names without prior written
 33   
  *    permission of the Apache Group.
 34   
  *
 35   
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 36   
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 37   
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 38   
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 39   
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 40   
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 41   
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 42   
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 43   
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 44   
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 45   
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 46   
  * SUCH DAMAGE.
 47   
  * ====================================================================
 48   
  *
 49   
  * This software consists of voluntary contributions made by many
 50   
  * individuals on behalf of the Apache Software Foundation.  For more
 51   
  * information on the Apache Software Foundation, please see
 52   
  * <http://www.apache.org/>.
 53   
  */
 54   
 
 55   
 package org.apache.tools.ant.taskdefs;
 56   
 
 57   
 import java.io.BufferedReader;
 58   
 import java.io.File;
 59   
 import java.io.FileReader;
 60   
 import java.io.FileWriter;
 61   
 import java.io.IOException;
 62   
 import java.io.PrintWriter;
 63   
 import org.apache.tools.ant.BuildException;
 64   
 import org.apache.tools.ant.Project;
 65   
 import org.apache.tools.ant.Task;
 66   
 import org.apache.tools.ant.util.StringUtils;
 67   
 
 68   
 /**
 69   
  * Adds an new entry to a CVS password file.
 70   
  *
 71   
  * @author <a href="jeff@custommonkey.org">Jeff Martin</a>
 72   
  * @version $Revision: 1.18 $
 73   
  *
 74   
  * @since Ant 1.4
 75   
  *
 76   
  * @ant.task category="scm"
 77   
  */
 78   
 public class CVSPass extends Task {
 79   
     /** CVS Root */
 80   
     private String cvsRoot = null;
 81   
     /** Password file to add password to */
 82   
     private File passFile = null;
 83   
     /** Password to add to file */
 84   
     private String password = null;
 85   
 
 86   
     /** Array contain char conversion data */
 87   
     private final char[] shifts = {
 88   
           0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12,  13,  14,  15,
 89   
          16,  17,  18,  19,  20,  21,  22,  23,  24,  25,  26,  27,  28,  29,  30,  31,
 90   
         114, 120,  53,  79,  96, 109,  72, 108,  70,  64,  76,  67, 116,  74,  68,  87,
 91   
         111,  52,  75, 119,  49,  34,  82,  81,  95,  65, 112,  86, 118, 110, 122, 105,
 92   
          41,  57,  83,  43,  46, 102,  40,  89,  38, 103,  45,  50,  42, 123,  91,  35,
 93   
         125,  55,  54,  66, 124, 126,  59,  47,  92,  71, 115,  78,  88, 107, 106,  56,
 94   
          36, 121, 117, 104, 101, 100,  69,  73,  99,  63,  94,  93,  39,  37,  61,  48,
 95   
          58, 113,  32,  90,  44,  98,  60,  51,  33,  97,  62,  77,  84,  80,  85, 223,
 96   
         225, 216, 187, 166, 229, 189, 222, 188, 141, 249, 148, 200, 184, 136, 248, 190,
 97   
         199, 170, 181, 204, 138, 232, 218, 183, 255, 234, 220, 247, 213, 203, 226, 193,
 98   
         174, 172, 228, 252, 217, 201, 131, 230, 197, 211, 145, 238, 161, 179, 160, 212,
 99   
         207, 221, 254, 173, 202, 146, 224, 151, 140, 196, 205, 130, 135, 133, 143, 246,
 100   
         192, 159, 244, 239, 185, 168, 215, 144, 139, 165, 180, 157, 147, 186, 214, 176,
 101   
         227, 231, 219, 169, 175, 156, 206, 198, 129, 164, 150, 210, 154, 177, 134, 127,
 102   
         182, 128, 158, 208, 162, 132, 167, 209, 149, 241, 153, 251, 237, 236, 171, 195,
 103   
         243, 233, 253, 240, 194, 250, 191, 155, 142, 137, 245, 235, 163, 242, 178, 152
 104   
     };
 105   
 
 106   
     /**
 107   
      * Create a CVS task using the default cvspass file location.
 108   
      */
 109  9
     public CVSPass(){
 110  9
         passFile = new File(
 111   
             System.getProperty("cygwin.user.home",
 112   
                 System.getProperty("user.home"))
 113   
             + File.separatorChar + ".cvspass");
 114   
     }
 115   
 
 116   
     /**
 117   
      * Does the work.
 118   
      *
 119   
      * @exception BuildException if someting goes wrong with the build
 120   
      */
 121  9
     public final void execute() throws BuildException {
 122  9
         if (cvsRoot == null) {
 123  1
             throw new BuildException("cvsroot is required");
 124   
         }
 125  8
         if (password == null) {
 126  1
             throw new BuildException("password is required");
 127   
         }
 128   
 
 129  7
         log("cvsRoot: " + cvsRoot, Project.MSG_DEBUG);
 130  7
         log("password: " + password, Project.MSG_DEBUG);
 131  7
         log("passFile: " + passFile, Project.MSG_DEBUG);
 132   
 
 133  7
         BufferedReader reader = null;
 134  7
         PrintWriter writer = null;
 135  7
         try {
 136  7
             StringBuffer buf = new StringBuffer();
 137   
 
 138  7
             if (passFile.exists()) {
 139  4
                 reader = new BufferedReader(new FileReader(passFile));
 140   
 
 141  4
                 String line = null;
 142   
 
 143  ?
                 while ((line = reader.readLine()) != null) {
 144  5
                     if (!line.startsWith(cvsRoot)) {
 145  4
                         buf.append(line).append(StringUtils.LINE_SEP);
 146   
                     }
 147   
                 }
 148   
             }
 149   
 
 150  7
             String pwdfile = buf.toString() + cvsRoot + " A"
 151   
                 + mangle(password);
 152   
 
 153  7
             log("Writing -> " + pwdfile , Project.MSG_DEBUG);
 154   
 
 155  7
             writer = new PrintWriter(new FileWriter(passFile));
 156   
 
 157  7
             writer.println(pwdfile);
 158   
         } catch (IOException e) {
 159  0
             throw new BuildException(e);
 160   
         } finally {
 161  7
             if (reader != null) {
 162  4
                 try {
 163  4
                     reader.close();
 164   
                 } catch (IOException e) {}
 165   
             }
 166  7
             if (writer != null) {
 167  7
                 writer.close();
 168   
             }
 169   
         }
 170   
     }
 171   
 
 172  7
     private final String mangle(String password){
 173  7
         StringBuffer buf = new StringBuffer();
 174  7
         for (int i = 0; i < password.length(); i++) {
 175  45
             buf.append(shifts[password.charAt(i)]);
 176   
         }
 177  7
         return buf.toString();
 178   
     }
 179   
 
 180   
     /**
 181   
      * The CVS repository to add an entry for.
 182   
      */
 183  8
     public void setCvsroot(String cvsRoot) {
 184  8
         this.cvsRoot = cvsRoot;
 185   
     }
 186   
 
 187   
     /**
 188   
      * Password file to add the entry to.
 189   
      */
 190  8
     public void setPassfile(File passFile) {
 191  8
         this.passFile = passFile;
 192   
     }
 193   
 
 194   
     /**
 195   
      * Password to be added to the password file.
 196   
      */
 197  7
     public void setPassword(String password) {
 198  7
         this.password = password;
 199   
     }
 200   
 
 201   
 }
 202