ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs CVSPassTest.java
Date Fri, 27 Apr 2001 11:52:55 GMT
bodewig     01/04/27 04:52:55

  Modified:    docs/manual coretasklist.html
               docs/manual/CoreTasks cvs.html
               src/main/org/apache/tools/ant/taskdefs Cvs.java
                        defaults.properties
  Added:       docs/manual/CoreTasks cvspass.html
               src/etc/testcases/taskdefs cvspass.xml
               src/main/org/apache/tools/ant/taskdefs CVSPass.java
               src/testcases/org/apache/tools/ant/taskdefs CVSPassTest.java
  Log:
  Make port and password file configurable in <cvs>.
  
  Add new task to insert a password into the CVS password file (only
  recommended for anonymous access to repositories).
  
  Submitted by:	Jeff Martin <jeff@custommonkey.org>
  
  Revision  Changes    Path
  1.8       +1 -0      jakarta-ant/docs/manual/coretasklist.html
  
  Index: coretasklist.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/manual/coretasklist.html,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- coretasklist.html	2001/04/12 06:03:39	1.7
  +++ coretasklist.html	2001/04/27 11:52:51	1.8
  @@ -28,6 +28,7 @@
   <a href="CoreTasks/copydir.html"><i>Copydir</i></a><br>
   <a href="CoreTasks/copyfile.html"><i>Copyfile</i></a><br>
   <a href="CoreTasks/cvs.html">Cvs</a><br>
  +<a href="CoreTasks/cvspass.html">CVSPass</a><br>
   <a href="CoreTasks/delete.html">Delete</a><br>
   <a href="CoreTasks/deltree.html"><i>Deltree</i></a><br>
   <a href="CoreTasks/echo.html">Echo</a><br>
  
  
  
  1.3       +10 -0     jakarta-ant/docs/manual/CoreTasks/cvs.html
  
  Index: cvs.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTasks/cvs.html,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- cvs.html	2001/02/13 12:31:50	1.2
  +++ cvs.html	2001/04/27 11:52:52	1.3
  @@ -70,6 +70,16 @@
       <td valign="top">the file to direct standard error from the command.</td>
       <td align="center" valign="top">No, default error to ANT Log as MSG_WARN.</td>
     </tr>
  +  <tr>
  +    <td valign="top">port</td>
  +    <td valign="top">Port used by CVS to communicate with the server.</td>
  +    <td align="center" valign="top">No, default port 2401.</td>
  +  </tr>
  +  <tr>
  +    <td valign="top">passfile</td>
  +    <td valign="top">Password file to read passwords from.</td>
  +    <td align="center" valign="top">No, default file ~/.cvspass.</td>
  +  </tr>
   </table>
   <h3>Examples</h3>
   <pre>  &lt;cvs cvsRoot=&quot;:pserver:anoncvs@jakarta.apache.org:/home/cvspublic&quot;
  
  
  
  1.1                  jakarta-ant/docs/manual/CoreTasks/cvspass.html
  
  Index: cvspass.html
  ===================================================================
  <html>
  
  <head>
  <meta http-equiv="Content-Language" content="en-us">
  <title>Ant User Manual</title>
  </head>
  
  <body>
  
  <h2><a name="cvs">cvspass</a></h2>
  <h3>Description</h3>
  <p>Adds entries to a .cvspass file. Adding entries to this file has the same affect
as a cvs login command.
  <h3>Parameters</h3>
  <table border="1" cellpadding="2" cellspacing="0">
    <tr>
      <td valign="top"><b>Attribute</b></td>
      <td valign="top"><b>Description</b></td>
      <td align="center" valign="top"><b>Required</b></td>
    </tr>
    <tr>
      <td valign="top">cvsroot</td>
      <td valign="top">the CVS repository to add an entry for.</td>
      <td align="center" valign="top">Yes</td>
    </tr>
    <tr>
      <td valign="top">password</td>
      <td valign="top">Password to be added to the password file.</td>
      <td align="center" valign="top">Yes</td>
    </tr>
    <tr>
      <td valign="top">passfile</td>
      <td valign="top">Password file to add the entry to.</td>
      <td align="center" valign="top">No, default is ~/.cvspass.</td>
    </tr>
  </table>
  <h3>Examples</h3>
  <pre>  &lt;cvspass cvsroot=&quot;:pserver:anoncvs@jakarta.apache.org:/home/cvspublic&quot;
         password=&quot;anoncvs&quot;
    /&gt;</pre>
  <p>Adds an entry into the ~/.cvspass password file.</p>
  
  </body>
  </html>
  
  
  
  
  1.1                  jakarta-ant/src/etc/testcases/taskdefs/cvspass.xml
  
  Index: cvspass.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <project name="cvspass-test" basedir="." default="test1">
  
    <taskdef name="cvspass" classname="org.apache.tools.ant.taskdefs.CVSPass"/>
  
    <target name="test1">
      <cvspass />
    </target>
   
    <target name="test2">
      <cvspass
        cvsroot=":pserver:anoncvs@jakarta.apache.org:/home/cvspublic"
        passfile="testpassfile.tmp"
      />
    </target>
   
    <target name="test3">
      <cvspass
        cvsroot=":pserver:anoncvs@jakarta.apache.org:/home/cvspublic"
        password="anoncvs"
        passfile="testpassfile.tmp"
      />
    </target>
   
    <target name="test4">
      <cvspass
        cvsroot=":pserver:anoncvs@jakarta.apache.org:/home/cvspublic"
        password="anoncvs"
        passfile="testpassfile.tmp"
      />
      <cvspass
        cvsroot=":pserver:anoncvs@jakarta.apache.org:/home/cvspublic"
        password="anoncvs"
        passfile="testpassfile.tmp"
      />
      <cvspass
        cvsroot=":pserver:guest@cvs.tigris.org:/cvs"
        password="guest"
        passfile="testpassfile.tmp"
      />
    </target>
   
    <target name="test5">
      <cvspass
        cvsroot=":pserver:anoncvs@jakarta.apache.org:/home/cvspublic"
        password="anoncvs"
        passfile="testpassfile.tmp"
      />
      <cvspass
        cvsroot=":pserver:anoncvs@xml.apache.org:/home/cvspublic"
        password="anoncvs"
        passfile="testpassfile.tmp"
      />
      <cvspass
        cvsroot=":pserver:guest@cvs.tigris.org:/cvs"
        password="guest"
        passfile="testpassfile.tmp"
      />
    </target>
   
    <target name="cleanup"> 
      <delete file="testpassfile.tmp"/>
    </target>
  
  </project>
  
  
  
  1.14      +36 -0     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Cvs.java
  
  Index: Cvs.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Cvs.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Cvs.java	2001/01/03 14:18:29	1.13
  +++ Cvs.java	2001/04/27 11:52:54	1.14
  @@ -56,6 +56,7 @@
   
   import org.apache.tools.ant.*;
   import org.apache.tools.ant.types.Commandline;
  +import org.apache.tools.ant.types.Environment;
   import java.io.*;
   
   /**
  @@ -96,6 +97,16 @@
       private boolean noexec = false;
   
       /**
  +     * CVS port
  +     */
  +    private int port = 0;
  +
  +    /**
  +     * CVS password file
  +     */
  +    private File passFile = null;
  +
  +    /**
        * the directory where the checked out files should be placed.
        */
       private File dest;
  @@ -138,6 +149,22 @@
               toExecute.createArgument().setLine(pack);
           }
   
  +        Environment env = new Environment();
  +
  +        if(port>0){
  +            Environment.Variable var = new Environment.Variable();
  +            var.setKey("CVS_CLIENT_PORT");
  +            var.setValue(String.valueOf(port));
  +            env.addVariable(var);
  +        }
  +
  +        if(passFile!=null){
  +            Environment.Variable var = new Environment.Variable();
  +            var.setKey("CVS_PASSFILE");
  +            var.setValue(String.valueOf(passFile));
  +            env.addVariable(var);
  +        }
  +
           ExecuteStreamHandler streamhandler = null;
           OutputStream outputstream = null;
           OutputStream errorstream = null; 
  @@ -177,6 +204,7 @@
           exe.setWorkingDirectory(dest);
   
           exe.setCommandline(toExecute.getCommandline());
  +        exe.setEnvironment(env.getVariables());
           try {
               exe.execute();
           } catch (IOException e) {
  @@ -203,6 +231,14 @@
           } 
   
           this.cvsRoot = root;
  +    }
  +
  +    public void setPort(int port){
  +        this.port = port;
  +    }
  +
  +    public void setPassfile(File passFile){
  +        this.passFile = passFile;
       }
   
       public void setDest(File dest) {
  
  
  
  1.72      +1 -0      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties
  
  Index: defaults.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties,v
  retrieving revision 1.71
  retrieving revision 1.72
  diff -u -r1.71 -r1.72
  --- defaults.properties	2001/04/12 06:03:39	1.71
  +++ defaults.properties	2001/04/27 11:52:54	1.72
  @@ -44,6 +44,7 @@
   uptodate=org.apache.tools.ant.taskdefs.UpToDate
   apply=org.apache.tools.ant.taskdefs.Transform
   record=org.apache.tools.ant.taskdefs.Recorder
  +cvspass=org.apache.tools.ant.taskdefs.CVSPass
   
   # optional tasks
   script=org.apache.tools.ant.taskdefs.optional.Script
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/taskdefs/CVSPass.java
  
  Index: CVSPass.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.tools.ant.taskdefs;
  
  import org.apache.tools.ant.*;
  import java.io.*;
  
  /**
   * CVSLogin
   *
   * Adds an new entry to a CVS password file
   *
   * @author <a href="jeff@custommonkey.org">Jeff Martin</a>
   * @version $Revision: 1.1 $
   */
  public class CVSPass extends Task {
      /** CVS Root */
      private String cvsRoot = null; 
      /** Password file to add password to */
      private File passFile = null;
      /** Password to add to file */
      private String password = null;
      /** End of line character */
      private final String EOL = System.getProperty("line.separator");
  
      /** Array contain char conversion data */
      char[] c=new char[128];
  
      public CVSPass(){
          passFile = new File(System.getProperty("user.home")+"/.cvspass");
          // Create lookup for password mangling
          c[32]='r'; c[33]='x'; c[34]='5'; c[35]='O'; c[37]='m';
          c[38]='H'; c[39]='l'; c[40]='F'; c[42]='L'; c[43]='C';
          c[44]='t'; c[45]='J'; c[46]='D'; c[47]='W'; c[48]='o';
          c[49]='4'; c[50]='K'; c[51]='w'; c[52]='1'; c[53]='"';
          c[54]='R'; c[55]='Q'; c[56]='_'; c[57]='A'; c[58]='p';
          c[59]='V'; c[60]='v'; c[61]='n'; c[62]='z'; c[63]='i';
          c[64]=')'; c[65]='9'; c[66]='S'; c[67]='+'; c[68]='.';
          c[69]='f'; c[70]='('; c[71]='Y'; c[72]='&'; c[73]='g';
          c[74]='-'; c[75]='2'; c[76]='*'; c[81]='7'; c[82]='6';
          c[83]='B'; c[86]=';'; c[87]='/'; c[89]='G'; c[90]='s';
          c[91]='N'; c[92]='X'; c[93]='k'; c[94]='j'; c[95]='%';
          c[97]='y'; c[98]='u'; c[99]='h'; c[100]='e'; c[101]='d';
          c[102]='E'; c[103]='I'; c[104]='c'; c[105]='?'; c[108]='\'';
          c[109]='%'; c[110]='='; c[111]='0'; c[112]=':'; c[113]='q';
          c[115]='Z'; c[116]=','; c[117]='b'; c[118]='<'; c[119]='3';
          c[120]='!'; c[121]='a'; c[122]='>'; c[123]='M'; c[124]='T';
          c[125]='P'; c[126]='U';
      }
  
      /**
       * Does the work.
       *
       * @exception BuildException if someting goes wrong with the build
       */
      public final void execute() throws BuildException {
          if(cvsRoot==null)throw new BuildException("cvsroot is required");
          if(password==null)throw new BuildException("password is required");
  
          log("cvsRoot: " + cvsRoot, project.MSG_DEBUG);
          log("password: " + password, project.MSG_DEBUG);
          log("passFile: " + passFile, project.MSG_DEBUG);
  
          try{
              StringBuffer buf = new StringBuffer();
  
              if(passFile.exists()){
                  BufferedReader reader =
                      new BufferedReader(new FileReader(passFile));
  
                  String line = null;
  
                  while((line=reader.readLine())!=null){
                      if(!line.startsWith(cvsRoot)){
                          buf.append(line+EOL);
                      }
                  }
  
              reader.close();
              }
  
              PrintWriter writer = new PrintWriter(new FileWriter(passFile));
  
  
              writer.print(buf.toString());
              writer.print(cvsRoot);
              writer.print(" A");
              writer.println(mangle(password));
  
              log("Writing -> " + buf.toString() + cvsRoot + " A" + mangle(password), project.MSG_DEBUG);
  
              writer.close();
          }catch(IOException e){
              throw new BuildException(e);
          }
  
      }
  
      private final String mangle(String password){
          StringBuffer buf = new StringBuffer();
          for(int i=0;i<password.length();i++){
              buf.append(c[password.charAt(i)]);
          }
          return buf.toString();
      }
  
      /**
       * Sets cvs root to be added to the password file
       */
      public void setCvsroot(String cvsRoot) {
          this.cvsRoot = cvsRoot;
      }
  
      /**
       * Sets the password file attribute.
       */
      public void setPassfile(File passFile) {
          this.passFile = passFile;
      }
  
      /**
       * Sets the password attribute.
       */
      public void setPassword(String password) {
          this.password = password;
      }
  
  }
  
  
  
  1.1                  jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/CVSPassTest.java
  
  Index: CVSPassTest.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.tools.ant.taskdefs;
  
  import java.io.*;
  import org.apache.tools.ant.*;
  
  /**
   * Tests CVSLogin task.
   *
   * @author <a href="mailto:jeff@custommonkey.org">Jeff Martin</a>
   */
  public class CVSPassTest extends TaskdefsTest { 
      private final String EOL = System.getProperty("line.separator");
      private final String JAKARTA_URL =
          ":pserver:anoncvs@jakarta.apache.org:/home/cvspublic Ay=0=h<Z";
      private final String XML_URL =
          ":pserver:anoncvs@xml.apache.org:/home/cvspublic Ay=0=h<Z";
      private final String TIGRIS_URL =
          ":pserver:guest@cvs.tigris.org:/cvs AIbdZ,";
      
      
      public CVSPassTest(String name) { 
          super(name);
      }
  
      public void setUp() { 
          configureProject("src/etc/testcases/taskdefs/cvspass.xml");
      }
  
      public void testNoCVSRoot() { 
          try{
              executeTarget("test1");
              fail("BuildException not thrown");
          }catch(BuildException e){
              assertEquals("cvsroot is required", e.getMessage());
          }
      }
  
      public void testNoPassword() { 
          try{
              executeTarget("test2");
              fail("BuildException not thrown");
          }catch(BuildException e){
              assertEquals("password is required", e.getMessage());
          }
      }
  
      public void tearDown() {
          executeTarget("cleanup");
      }
  
      public void testPassFile() throws Exception { 
          executeTarget("test3");
          File f = new File(getProjectDir(), "testpassfile.tmp");
  
          assert( "Passfile "+f+" not created", f.exists());
  
          assertEquals(JAKARTA_URL+EOL, readFile(f));
  
      }
  
      public void testPassFileDuplicateEntry() throws Exception { 
          executeTarget("test4");
          File f = new File(getProjectDir(), "testpassfile.tmp");
  
          assert( "Passfile "+f+" not created", f.exists());
  
          assertEquals(
              JAKARTA_URL+ EOL+
              TIGRIS_URL+ EOL,
              readFile(f));
      }
  
      public void testPassFileMultipleEntry() throws Exception { 
          executeTarget("test5");
          File f = new File(getProjectDir(), "testpassfile.tmp");
  
          assert( "Passfile "+f+" not created", f.exists());
  
          assertEquals(
              JAKARTA_URL+ EOL+
              XML_URL+ EOL+
              TIGRIS_URL+ EOL,
              readFile(f));
      }
  
      private String readFile(File f) throws Exception {
          BufferedReader reader = new BufferedReader(new FileReader(f));
  
          StringBuffer buf = new StringBuffer();
          String line=null;
          while((line=reader.readLine())!=null){
              buf.append(line + EOL);
          }
          return buf.toString();
      }
  }
  
  
  

Mime
View raw message