From f7fdd6f367071bd1c9ea39ccbdc71554f40cc8f2 Mon Sep 17 00:00:00 2001
From: Stefan Bodewig
Date: Fri, 27 Apr 2001 11:52:55 +0000
Subject: [PATCH] Make port and password file configurable in .
Add new task to insert a password into the CVS password file (only
recommended for anonymous access to repositories).
Submitted by: Jeff Martin
git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268979 13f79535-47bb-0310-9956-ffa450edef68
---
docs/manual/CoreTasks/cvs.html | 10 +
docs/manual/CoreTasks/cvspass.html | 44 +++++
docs/manual/coretasklist.html | 1 +
src/etc/testcases/taskdefs/cvspass.xml | 66 +++++++
.../apache/tools/ant/taskdefs/CVSPass.java | 180 ++++++++++++++++++
.../org/apache/tools/ant/taskdefs/Cvs.java | 36 ++++
.../tools/ant/taskdefs/defaults.properties | 1 +
.../tools/ant/taskdefs/CVSPassTest.java | 150 +++++++++++++++
8 files changed, 488 insertions(+)
create mode 100644 docs/manual/CoreTasks/cvspass.html
create mode 100644 src/etc/testcases/taskdefs/cvspass.xml
create mode 100644 src/main/org/apache/tools/ant/taskdefs/CVSPass.java
create mode 100644 src/testcases/org/apache/tools/ant/taskdefs/CVSPassTest.java
diff --git a/docs/manual/CoreTasks/cvs.html b/docs/manual/CoreTasks/cvs.html
index 8b26e86cf..cc82da3ad 100644
--- a/docs/manual/CoreTasks/cvs.html
+++ b/docs/manual/CoreTasks/cvs.html
@@ -70,6 +70,16 @@ preferred over the checkout command, because of speed.
the file to direct standard error from the command. |
No, default error to ANT Log as MSG_WARN. |
+
+ port |
+ Port used by CVS to communicate with the server. |
+ No, default port 2401. |
+
+
+ passfile |
+ Password file to read passwords from. |
+ No, default file ~/.cvspass. |
+
Examples
<cvs cvsRoot=":pserver:anoncvs@jakarta.apache.org:/home/cvspublic"
diff --git a/docs/manual/CoreTasks/cvspass.html b/docs/manual/CoreTasks/cvspass.html
new file mode 100644
index 000000000..c6b370425
--- /dev/null
+++ b/docs/manual/CoreTasks/cvspass.html
@@ -0,0 +1,44 @@
+
+
+
+
+Ant User Manual
+
+
+
+
+
+Description
+Adds entries to a .cvspass file. Adding entries to this file has the same affect as a cvs login command.
+
Parameters
+
+
+ Attribute |
+ Description |
+ Required |
+
+
+ cvsroot |
+ the CVS repository to add an entry for. |
+ Yes |
+
+
+ password |
+ Password to be added to the password file. |
+ Yes |
+
+
+ passfile |
+ Password file to add the entry to. |
+ No, default is ~/.cvspass. |
+
+
+Examples
+ <cvspass cvsroot=":pserver:anoncvs@jakarta.apache.org:/home/cvspublic"
+ password="anoncvs"
+ />
+Adds an entry into the ~/.cvspass password file.
+
+
+
+
diff --git a/docs/manual/coretasklist.html b/docs/manual/coretasklist.html
index 72776941c..9bb98b0d2 100644
--- a/docs/manual/coretasklist.html
+++ b/docs/manual/coretasklist.html
@@ -28,6 +28,7 @@
Copydir
Copyfile
Cvs
+CVSPass
Delete
Deltree
Echo
diff --git a/src/etc/testcases/taskdefs/cvspass.xml b/src/etc/testcases/taskdefs/cvspass.xml
new file mode 100644
index 000000000..91b7178a7
--- /dev/null
+++ b/src/etc/testcases/taskdefs/cvspass.xml
@@ -0,0 +1,66 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/org/apache/tools/ant/taskdefs/CVSPass.java b/src/main/org/apache/tools/ant/taskdefs/CVSPass.java
new file mode 100644
index 000000000..bc7f92f8c
--- /dev/null
+++ b/src/main/org/apache/tools/ant/taskdefs/CVSPass.java
@@ -0,0 +1,180 @@
+/*
+ * 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
+ * .
+ */
+
+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 Jeff Martin
+ * @version $Revision$
+ */
+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;i0){
+ 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 @@ public class Cvs extends Task {
exe.setWorkingDirectory(dest);
exe.setCommandline(toExecute.getCommandline());
+ exe.setEnvironment(env.getVariables());
try {
exe.execute();
} catch (IOException e) {
@@ -205,6 +233,14 @@ public class Cvs extends Task {
this.cvsRoot = root;
}
+ public void setPort(int port){
+ this.port = port;
+ }
+
+ public void setPassfile(File passFile){
+ this.passFile = passFile;
+ }
+
public void setDest(File dest) {
this.dest = dest;
}
diff --git a/src/main/org/apache/tools/ant/taskdefs/defaults.properties b/src/main/org/apache/tools/ant/taskdefs/defaults.properties
index 3b6970467..ea8831e16 100644
--- a/src/main/org/apache/tools/ant/taskdefs/defaults.properties
+++ b/src/main/org/apache/tools/ant/taskdefs/defaults.properties
@@ -44,6 +44,7 @@ war=org.apache.tools.ant.taskdefs.War
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
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/CVSPassTest.java b/src/testcases/org/apache/tools/ant/taskdefs/CVSPassTest.java
new file mode 100644
index 000000000..ee07c8f5b
--- /dev/null
+++ b/src/testcases/org/apache/tools/ant/taskdefs/CVSPassTest.java
@@ -0,0 +1,150 @@
+/*
+ * 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
+ * .
+ */
+
+package org.apache.tools.ant.taskdefs;
+
+import java.io.*;
+import org.apache.tools.ant.*;
+
+/**
+ * Tests CVSLogin task.
+ *
+ * @author Jeff Martin
+ */
+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