KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > savant > ant > types > CVSProcess


1 /*
2  * Copyright (c) 2002-2004, Inversoft, All Rights Reserved
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.savant.ant.types;
8
9
10 import java.io.File JavaDoc;
11
12 import org.apache.tools.ant.BuildException;
13 import org.apache.tools.ant.taskdefs.Cvs;
14 import org.apache.tools.ant.types.DataType;
15
16 import com.inversoft.savant.Artifact;
17 import com.inversoft.savant.LocalCacheStore;
18 import com.inversoft.savant.Process;
19 import com.inversoft.savant.SavantException;
20
21
22 /**
23  * <p>
24  * This class is a CVS process that attempts to locate
25  * artifacts in a CVS module. This is done using the
26  * CVS tasks.
27  * </p>
28  *
29  * @author Brian Pontarelli
30  */

31 public class CVSProcess extends DataType implements Process JavaDoc {
32
33     private String JavaDoc cvsroot;
34     private boolean compression;
35     private int compressionlevel;
36     private String JavaDoc cvsrsh;
37     private File JavaDoc dest;
38     private String JavaDoc pack;
39     private String JavaDoc tag;
40     private String JavaDoc date;
41     private int port;
42     private File JavaDoc passfile;
43
44
45     /**
46      * Constructs a new <code>CVSProcess</code> with no repository or checkout
47      * directory specified.
48      */

49     public CVSProcess() {
50     }
51
52
53     public void setCvsroot(String JavaDoc cvsroot) {
54         this.cvsroot = cvsroot;
55     }
56
57     public void setCompression(boolean compression) {
58         this.compression = compression;
59     }
60
61     public void setCompressionlevel(int compressionlevel) {
62         this.compressionlevel = compressionlevel;
63     }
64
65     public void setCvsrsh(String JavaDoc cvsrsh) {
66         this.cvsrsh = cvsrsh;
67     }
68
69     public void setDest(File JavaDoc dest) {
70         this.dest = dest;
71     }
72
73     public void setPackage(String JavaDoc pack) {
74         this.pack = pack;
75     }
76
77     public void setTag(String JavaDoc tag) {
78         this.tag = tag;
79     }
80
81     public void setDate(String JavaDoc date) {
82         this.date = date;
83     }
84
85     public void setPort(int port) {
86         this.port = port;
87     }
88
89     public void setPassfile(File JavaDoc passfile) {
90         this.passfile = passfile;
91     }
92
93     /**
94      * <p>
95      * This method attempts to locate the dependencies of the given Artifact
96      * using the an XML dependency file fetched from the CVS repository.
97      * If the dependency file exists, the given artifact is updated.
98      * </p>
99      *
100      * @param artifact The artifact to update with the resolved dependencies.
101      * @return True if the artifact was updated, false otherwise.
102      * @throws SavantException If the resolution failed or the XML was corrupt.
103      */

104     public boolean resolveArtifactDependencies(Artifact artifact,
105             LocalCacheStore localCache)
106     throws SavantException {
107         File JavaDoc depsFile = executeCheckout(artifact.getArtifactDepsFile());
108         if (depsFile.exists()) {
109             localCache.storeDeps(artifact, depsFile);
110             return true;
111         }
112
113         return false;
114     }
115
116     /**
117      * Attempts to fetch the artifact given from a CVS repository. The name of
118      * the repository is either specified in the XML as an attribute or can be
119      * passed in during construction or set after construction. The location
120      * to checkout the repository is also specified in the same manner.
121      *
122      * @param artifact The artifact to look for
123      * @param localCache The local cache store to copy the artifact to after
124      * it is found
125      * @return The artifact or null if not found
126      */

127     public File JavaDoc fetch(Artifact artifact, LocalCacheStore localCache)
128     throws SavantException {
129         File JavaDoc artifactFile = executeCheckout(artifact.getArtifactFile());
130         if (artifactFile.exists()) {
131             artifactFile = localCache.store(artifact, artifactFile);
132         } else {
133             artifactFile = null;
134         }
135
136         return artifactFile;
137     }
138
139     protected File JavaDoc executeCheckout(String JavaDoc filePath) {
140         // Set the default destination
141
if (dest == null) {
142             dest = new File JavaDoc(System.getProperty("user.home") + File.separator +
143                 ".savant_cvs_repository");
144         }
145
146         Cvs cvs = (Cvs) getProject().createTask("cvs");
147         cvs.setPackage(pack);
148         cvs.setCvsRoot(cvsroot);
149         cvs.setCvsRsh(cvsrsh);
150         cvs.setCompression(compression);
151         cvs.setCompressionLevel(compressionlevel);
152         cvs.setDest(dest);
153         cvs.setTag(tag);
154         cvs.setDate(date);
155         cvs.setPort(port);
156         cvs.setPassfile(passfile);
157         cvs.setReallyquiet(true);
158
159         // Check out the module from CVS
160
String JavaDoc module = pack + File.separator + filePath;
161         cvs.setPackage(module);
162         cvs.perform();
163
164         String JavaDoc file = pack + File.separator + filePath;
165         return new File JavaDoc(dest, file);
166     }
167
168     /**
169      * Validates that the caller supplied a package.
170      *
171      * @throws BuildException If package is null
172      */

173     public void validate() throws BuildException {
174         if (pack == null) {
175             throw new BuildException("A package must be specified");
176         }
177     }
178 }
179
Popular Tags