source: release-kits/lirk3/resources/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/CVSPass.java@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 5.7 KB
Line 
1/*
2 * Copyright 2001-2005 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18package org.apache.tools.ant.taskdefs;
19
20import java.io.BufferedReader;
21import java.io.File;
22import java.io.FileReader;
23import java.io.FileWriter;
24import java.io.IOException;
25import java.io.PrintWriter;
26import org.apache.tools.ant.BuildException;
27import org.apache.tools.ant.Project;
28import org.apache.tools.ant.Task;
29import org.apache.tools.ant.util.StringUtils;
30
31/**
32 * Adds an new entry to a CVS password file.
33 *
34 *
35 * @since Ant 1.4
36 *
37 * @ant.task category="scm"
38 */
39public class CVSPass extends Task {
40 /** CVS Root */
41 private String cvsRoot = null;
42 /** Password file to add password to */
43 private File passFile = null;
44 /** Password to add to file */
45 private String password = null;
46
47 /** Array contain char conversion data */
48 private final char[] shifts = {
49 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
50 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
51 114, 120, 53, 79, 96, 109, 72, 108, 70, 64, 76, 67, 116, 74, 68, 87,
52 111, 52, 75, 119, 49, 34, 82, 81, 95, 65, 112, 86, 118, 110, 122, 105,
53 41, 57, 83, 43, 46, 102, 40, 89, 38, 103, 45, 50, 42, 123, 91, 35,
54 125, 55, 54, 66, 124, 126, 59, 47, 92, 71, 115, 78, 88, 107, 106, 56,
55 36, 121, 117, 104, 101, 100, 69, 73, 99, 63, 94, 93, 39, 37, 61, 48,
56 58, 113, 32, 90, 44, 98, 60, 51, 33, 97, 62, 77, 84, 80, 85, 223,
57 225, 216, 187, 166, 229, 189, 222, 188, 141, 249, 148, 200, 184, 136, 248, 190,
58 199, 170, 181, 204, 138, 232, 218, 183, 255, 234, 220, 247, 213, 203, 226, 193,
59 174, 172, 228, 252, 217, 201, 131, 230, 197, 211, 145, 238, 161, 179, 160, 212,
60 207, 221, 254, 173, 202, 146, 224, 151, 140, 196, 205, 130, 135, 133, 143, 246,
61 192, 159, 244, 239, 185, 168, 215, 144, 139, 165, 180, 157, 147, 186, 214, 176,
62 227, 231, 219, 169, 175, 156, 206, 198, 129, 164, 150, 210, 154, 177, 134, 127,
63 182, 128, 158, 208, 162, 132, 167, 209, 149, 241, 153, 251, 237, 236, 171, 195,
64 243, 233, 253, 240, 194, 250, 191, 155, 142, 137, 245, 235, 163, 242, 178, 152
65 };
66
67 /**
68 * Create a CVS task using the default cvspass file location.
69 */
70 public CVSPass() {
71 passFile = new File(
72 System.getProperty("cygwin.user.home",
73 System.getProperty("user.home"))
74 + File.separatorChar + ".cvspass");
75 }
76
77 /**
78 * Does the work.
79 *
80 * @exception BuildException if something goes wrong with the build
81 */
82 public final void execute() throws BuildException {
83 if (cvsRoot == null) {
84 throw new BuildException("cvsroot is required");
85 }
86 if (password == null) {
87 throw new BuildException("password is required");
88 }
89
90 log("cvsRoot: " + cvsRoot, Project.MSG_DEBUG);
91 log("password: " + password, Project.MSG_DEBUG);
92 log("passFile: " + passFile, Project.MSG_DEBUG);
93
94 BufferedReader reader = null;
95 PrintWriter writer = null;
96 try {
97 StringBuffer buf = new StringBuffer();
98
99 if (passFile.exists()) {
100 reader = new BufferedReader(new FileReader(passFile));
101
102 String line = null;
103
104 while ((line = reader.readLine()) != null) {
105 if (!line.startsWith(cvsRoot)) {
106 buf.append(line).append(StringUtils.LINE_SEP);
107 }
108 }
109 }
110
111 String pwdfile = buf.toString() + cvsRoot + " A"
112 + mangle(password);
113
114 log("Writing -> " + pwdfile , Project.MSG_DEBUG);
115
116 writer = new PrintWriter(new FileWriter(passFile));
117
118 writer.println(pwdfile);
119 } catch (IOException e) {
120 throw new BuildException(e);
121 } finally {
122 if (reader != null) {
123 try {
124 reader.close();
125 } catch (IOException e) {
126 // ignore
127 }
128 }
129 if (writer != null) {
130 writer.close();
131 }
132 }
133 }
134
135 private final String mangle(String password) {
136 StringBuffer buf = new StringBuffer();
137 for (int i = 0; i < password.length(); i++) {
138 buf.append(shifts[password.charAt(i)]);
139 }
140 return buf.toString();
141 }
142
143 /**
144 * The CVS repository to add an entry for.
145 *
146 * @param cvsRoot the CVS repository
147 */
148 public void setCvsroot(String cvsRoot) {
149 this.cvsRoot = cvsRoot;
150 }
151
152 /**
153 * Password file to add the entry to.
154 *
155 * @param passFile the password file.
156 */
157 public void setPassfile(File passFile) {
158 this.passFile = passFile;
159 }
160
161 /**
162 * Password to be added to the password file.
163 *
164 * @param password the password.
165 */
166 public void setPassword(String password) {
167 this.password = password;
168 }
169
170}
Note: See TracBrowser for help on using the repository browser.