KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cvsgrab > CVSGrabTask


1 /*
2  * CVSGrab
3  * Author: Ludovic Claude (ludovicc@users.sourceforge.net)
4  * Distributable under BSD license.
5  */

6 package net.sourceforge.cvsgrab;
7
8 import org.apache.commons.logging.Log;
9 import org.apache.tools.ant.BuildException;
10 import org.apache.tools.ant.Project;
11 import org.apache.tools.ant.Task;
12
13 /**
14  * Ant task for CVSGrab.
15  *
16  * @author Ludovic Claude
17  * @created April 19, 2002
18  * @version 1.0
19  */

20
21 public class CVSGrabTask extends Task {
22
23     private CVSGrab _grabber = new CVSGrab();
24     private boolean _verbose = true;
25     private int _connections;
26     private WebOptions _webOptions;
27
28     /**
29      * Constructor for the CVSGrabTask object
30      */

31     public CVSGrabTask() {
32         super();
33         _webOptions = _grabber.getWebOptions();
34     }
35
36     /**
37      * Sets the url attribute
38      *
39      * @param value The new rootUrl value
40      */

41     public void setUrl(String JavaDoc value) {
42         _grabber.setUrl(value);
43     }
44
45     /**
46      * Sets the root url attribute
47      *
48      * @param value The new rootUrl value
49      */

50     public void setRootUrl(String JavaDoc value) {
51         _webOptions.setRootUrl(value);
52     }
53
54     /**
55      * Sets the package path attribute
56      *
57      * @param value The new package value
58      */

59     public void setPackagePath(String JavaDoc value) {
60         _webOptions.setPackagePath(value);
61     }
62     
63     public void setProjectRoot(String JavaDoc value) {
64         _webOptions.setProjectRoot(value);
65     }
66
67     /**
68      * Sets the dest dir attribute
69      *
70      * @param value The new destDir value
71      */

72     public void setDestDir(String JavaDoc value) {
73         _grabber.setDestDir(value);
74     }
75
76     /**
77      * Sets the package dir attribute
78      *
79      * @param value The new package value
80      */

81     public void setPackageDir(String JavaDoc value) {
82         _grabber.setPackageDir(value);
83     }
84
85     /**
86      * Sets the cvs root attribute
87      *
88      * @param value The new cvsRoot value
89      */

90     public void setCvsRoot(String JavaDoc value) {
91         _grabber.setCvsRoot(value);
92     }
93
94     /**
95      * Sets the tag attribute
96      *
97      * @param value The new tag value
98      */

99     public void setTag(String JavaDoc value) {
100         _webOptions.setVersionTag(value);
101     }
102
103     public void setWebInterface(String JavaDoc value) {
104         _webOptions.setWebInterfaceId(value);
105     }
106
107     /**
108      * Sets the verbose attribute
109      *
110      * @param value The new verbose value
111      */

112     public void setVerbose(boolean value) {
113         _verbose = value;
114     }
115
116     /**
117      * Sets the prune empty dirs
118      *
119      * @param value The new pruneEmptyDirs value
120      */

121     public void setPruneEmptyDirs(boolean value) {
122         _grabber.setPruneEmptyDirs(value);
123     }
124
125     /**
126      * Sets the clean update
127      *
128      * @param value The new cleanUpdate value
129      */

130     public void setCleanUpdate(boolean value) {
131         _grabber.setCleanUpdate(value);
132     }
133     
134     /**
135      * Sets the number of simultaneous connections to open
136      * @param connections The connections to set.
137      */

138     public void setConnections(int connections) {
139         _connections = connections;
140     }
141
142     /**
143      * Create the nested element for configuring the proxy
144      *
145      * @return the nested element for the proxy
146      */

147     public WebOptions.HttpProxy createProxy() {
148         WebOptions.HttpProxy proxy = _webOptions.new HttpProxy();
149         _webOptions.setHttpProxy(proxy);
150         return proxy;
151     }
152
153     /**
154      * Create the nested element for configuring the web authentification
155      *
156      * @return the nested element for the web
157      */

158     public WebOptions.WebAuthentification createWeb() {
159         WebOptions.WebAuthentification auth = _webOptions.new WebAuthentification();
160         _webOptions.setWebAuthentification(auth);
161         return auth;
162     }
163
164     /**
165      * Execute the task
166      *
167      * @exception BuildException when an error occured in the build
168      */

169     public void execute() throws BuildException {
170         if (_grabber.getRootUrl() == null) {
171             throw new BuildException("rootUrl argument is not specified");
172         }
173         if (_grabber.getDestDir() == null) {
174             throw new BuildException("destDir argument is not specified");
175         }
176         if (_grabber.getPackagePath() == null) {
177             throw new BuildException("packagePath argument is not specified");
178         }
179
180         AntLogger log = new AntLogger(getProject());
181         log.setVerbose(_verbose);
182         CVSGrab.setLog(log);
183         _webOptions.setupConnectionSettings();
184
185         if (_connections > 1) {
186             ThreadPool.init(_connections);
187             WebBrowser.getInstance().useMultithreading();
188         }
189         _grabber.grabCVSRepository();
190     }
191
192     /**
193      * Adapter for the Ant logger
194      *
195      * @author lclaude
196      * @created April 29, 2002
197      */

198     class AntLogger implements Log {
199         private boolean verbose;
200         private Project antProject;
201
202         /**
203          * Constructor for the AntLogger object
204          *
205          * @param project Description of the Parameter
206          */

207         public AntLogger(Project project) {
208             antProject = project;
209         }
210
211         /**
212          * Sets the verbose attribute
213          *
214          * @param value The new verbose value
215          */

216         public void setVerbose(boolean value) {
217             this.verbose = value;
218         }
219
220         /**
221          * Sets the debug attribute
222          *
223          * @param value The new debug value
224          */

225         public void setDebug(boolean value) {
226             // do nothing, use Ant settings
227
}
228
229         /**
230          * {@inheritDoc}
231          *
232          * @param msg The message
233          */

234         public void debug(Object JavaDoc msg) {
235             // use VERBOSE and not DEBUG, because Ant debug messages are really too much...
236
antProject.log(msg.toString(), Project.MSG_VERBOSE);
237         }
238
239         /**
240          * {@inheritDoc}
241          *
242          * @param msg The message
243          */

244         public void verbose(Object JavaDoc msg) {
245             if (verbose) {
246                 antProject.log(msg.toString(), Project.MSG_INFO);
247             } else {
248                 antProject.log(msg.toString(), Project.MSG_VERBOSE);
249             }
250         }
251
252         /**
253          * {@inheritDoc}
254          *
255          * @param msg The message
256          */

257         public void info(Object JavaDoc msg) {
258             antProject.log(msg.toString(), Project.MSG_INFO);
259         }
260
261         /**
262          * {@inheritDoc}
263          *
264          * @param msg The message
265          */

266         public void warn(Object JavaDoc msg) {
267             antProject.log(msg.toString(), Project.MSG_WARN);
268         }
269
270         /**
271          * {@inheritDoc}
272          *
273          * @param msg The message
274          */

275         public void error(Object JavaDoc msg) {
276             antProject.log(msg.toString(), Project.MSG_ERR);
277         }
278
279         /**
280          * {@inheritDoc}
281          * @return
282          */

283         public boolean isDebugEnabled() {
284             return true;
285         }
286
287         /**
288          * {@inheritDoc}
289          * @return
290          */

291         public boolean isErrorEnabled() {
292             return true;
293         }
294
295         /**
296          * {@inheritDoc}
297          * @return
298          */

299         public boolean isFatalEnabled() {
300             return true;
301         }
302
303         /**
304          * {@inheritDoc}
305          * @return
306          */

307         public boolean isInfoEnabled() {
308             return true;
309         }
310
311         /**
312          * {@inheritDoc}
313          * @return
314          */

315         public boolean isTraceEnabled() {
316             return false;
317         }
318
319         /**
320          * {@inheritDoc}
321          * @return
322          */

323         public boolean isWarnEnabled() {
324             return true;
325         }
326
327         /**
328          * {@inheritDoc}
329          * @param arg0
330          */

331         public void trace(Object JavaDoc arg0) {
332             // do nothing
333
}
334
335         /**
336          * {@inheritDoc}
337          * @param arg0
338          * @param arg1
339          */

340         public void trace(Object JavaDoc arg0, Throwable JavaDoc arg1) {
341             // do nothing
342
}
343
344         /**
345          * {@inheritDoc}
346          * @param arg0
347          * @param arg1
348          */

349         public void debug(Object JavaDoc arg0, Throwable JavaDoc arg1) {
350             // do nothing
351
}
352
353         /**
354          * {@inheritDoc}
355          * @param arg0
356          * @param arg1
357          */

358         public void info(Object JavaDoc arg0, Throwable JavaDoc arg1) {
359             // do nothing
360
}
361
362         /**
363          * {@inheritDoc}
364          * @param arg0
365          * @param arg1
366          */

367         public void warn(Object JavaDoc arg0, Throwable JavaDoc arg1) {
368             // do nothing
369
}
370
371         /**
372          * {@inheritDoc}
373          * @param arg0
374          * @param arg1
375          */

376         public void error(Object JavaDoc arg0, Throwable JavaDoc arg1) {
377             // do nothing
378
}
379
380         /**
381          * {@inheritDoc}
382          * @param arg0
383          */

384         public void fatal(Object JavaDoc arg0) {
385             // do nothing
386
}
387
388         /**
389          * {@inheritDoc}
390          * @param arg0
391          * @param arg1
392          */

393         public void fatal(Object JavaDoc arg0, Throwable JavaDoc arg1) {
394             // do nothing
395
}
396     }
397 }
398
Popular Tags