FileDocCategorySizeDatePackage
CVSPass.javaAPI DocApache Ant 1.705883Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.taskdefs

CVSPass

public class CVSPass extends org.apache.tools.ant.Task
Adds an new entry to a CVS password file.
since
Ant 1.4
ant.task
category="scm"

Fields Summary
private String
cvsRoot
CVS Root
private File
passFile
Password file to add password to
private String
password
Password to add to file
private final char[]
shifts
Array contain char conversion data
Constructors Summary
public CVSPass()
Create a CVS task using the default cvspass file location.


                   
      
        passFile = new File(
            System.getProperty("cygwin.user.home",
                System.getProperty("user.home"))
            + File.separatorChar + ".cvspass");
    
Methods Summary
public final voidexecute()
Does the work.

exception
BuildException if something goes wrong with the build

        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);

        BufferedReader reader = null;
        PrintWriter writer = null;
        try {
            StringBuffer buf = new StringBuffer();

            if (passFile.exists()) {
                reader = new BufferedReader(new FileReader(passFile));

                String line = null;

                while ((line = reader.readLine()) != null) {
                    if (!line.startsWith(cvsRoot)) {
                        buf.append(line).append(StringUtils.LINE_SEP);
                    }
                }
            }

            String pwdfile = buf.toString() + cvsRoot + " A"
                + mangle(password);

            log("Writing -> " + pwdfile , Project.MSG_DEBUG);

            writer = new PrintWriter(new FileWriter(passFile));

            writer.println(pwdfile);
        } catch (IOException e) {
            throw new BuildException(e);
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    // ignore
                }
            }
            if (writer != null) {
                writer.close();
            }
        }
    
private final java.lang.Stringmangle(java.lang.String password)

        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < password.length(); i++) {
            buf.append(shifts[password.charAt(i)]);
        }
        return buf.toString();
    
public voidsetCvsroot(java.lang.String cvsRoot)
The CVS repository to add an entry for.

param
cvsRoot the CVS repository

        this.cvsRoot = cvsRoot;
    
public voidsetPassfile(java.io.File passFile)
Password file to add the entry to.

param
passFile the password file.

        this.passFile = passFile;
    
public voidsetPassword(java.lang.String password)
Password to be added to the password file.

param
password the password.

        this.password = password;