KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > savant > LocalProject


1 /*
2  * Copyright (c) 2003-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;
8
9
10 import java.io.File JavaDoc;
11
12
13 /**
14  * <p>
15  * This class is an ant type that models a project dependency
16  * on another project that can be built locally.
17  * </p>
18  *
19  * @author Brian Pontarelli
20  */

21 public class LocalProject {
22
23     private String JavaDoc group;
24     private String JavaDoc name;
25     private String JavaDoc antfile = "build.xml";
26     private String JavaDoc target;
27     private File JavaDoc dir;
28     private LocalProjectBuilder builder = new DefaultLocalProjectBuilder();
29
30     /**
31      * Constructs a new <code>LocalProjectType</code>.
32      */

33     public LocalProject() {
34     }
35
36
37     /**
38      * Returns the group that this local project belongs to.
39      */

40     public String JavaDoc getGroup() {
41         return group;
42     }
43
44     /**
45      * Sets the group that this local project belongs to.
46      */

47     public void setGroup(String JavaDoc group) {
48         this.group = group;
49     }
50
51     /**
52      * Returns the name of this local project.
53      */

54     public String JavaDoc getName() {
55         return name;
56     }
57
58     /**
59      * Sets the name of this local project.
60      */

61     public void setName(String JavaDoc name) {
62         this.name = name;
63     }
64
65     /**
66      * Returns the optional build file name of this local project. Defaults to
67      * build.xml.
68      */

69     public String JavaDoc getAntfile() {
70         return antfile;
71     }
72
73     /**
74      * Sets the optional build file name of this local project.
75      */

76     public void setAntfile(String JavaDoc antfile) {
77         this.antfile = antfile;
78     }
79
80     /**
81      * Returns the optional target name which is called to build this local
82      * project. This defaults to empty, which means the default target is used.
83      */

84     public String JavaDoc getTarget() {
85         return target;
86     }
87
88     /**
89      * Sets the optional target name which is called to build this local project.
90      */

91     public void setTarget(String JavaDoc target) {
92         this.target = target;
93     }
94
95     /**
96      * Returns the directory where this local project is located.
97      */

98     public File JavaDoc getDir() {
99         return dir;
100     }
101
102     /**
103      * Sets the directory where this local project is located.
104      */

105     public void setDir(File JavaDoc dir) {
106         this.dir = dir;
107     }
108
109     /**
110      * The LocalProjectBuilder that is used to build this local project. If this
111      * is never set, it uses the DefaultLocalProjectBuilder.
112      */

113     public LocalProjectBuilder getBuilder() {
114         return builder;
115     }
116
117     /**
118      * Sets the LocalProjectBuilder to use to build this local project.
119      */

120     public void setBuilder(LocalProjectBuilder builder) {
121         this.builder = builder;
122     }
123
124     /**
125      * Returns a unique identifier for this project, which is a composite of the
126      * group and name.
127      *
128      * @return An id
129      */

130     public String JavaDoc getID() {
131         return makeProjectID(group, name);
132     }
133
134     /**
135      * Makes a unique project ID from the given group and name.
136      *
137      * @param group The project's group
138      * @param name The project name
139      * @return The group, a hash symbol and then the project name
140      */

141     public static String JavaDoc makeProjectID(String JavaDoc group, String JavaDoc name) {
142         return group + "#" + name;
143     }
144
145     /**
146      * Validate that the project is configured correctly.
147      *
148      * @throws SavantException If that validation fails.
149      */

150     public void validate() throws SavantException {
151         if (group == null) {
152             throw new SavantException("group attribute is required for a localproject");
153         }
154
155         if (name == null) {
156             throw new SavantException("name attribute is required for a localproject");
157         }
158
159         if (dir == null) {
160             throw new SavantException("dir attribute is required for a localproject");
161         }
162     }
163
164     /**
165      * Builds the local project that this types refers to using an ant task. If
166      * the project doesn't exists, it is not built and this method returns.
167      */

168     public void build() throws SavantException {
169         builder.build(this);
170     }
171
172     /**
173      * Tests that this project is equal to the given object.
174      *
175      * @param obj The Object to compare to this local project
176      * @return True if they are equal (both LocalProjects and the same local
177      * project), false otherwise
178      */

179     public boolean equals(Object JavaDoc obj) {
180         if (this == obj) return true;
181         if (!(obj instanceof LocalProject)) return false;
182
183         final LocalProject localProjectType = (LocalProject) obj;
184
185         if (!group.equals(localProjectType.group)) return false;
186         if (!name.equals(localProjectType.name)) return false;
187
188         return true;
189     }
190
191     /**
192      * Returns the hash code of the local project using the group and name of the
193      * local project as the hash values.
194      *
195      * @return A unique hash code
196      */

197     public int hashCode() {
198         int result;
199         result = group.hashCode();
200         result = 29 * result + name.hashCode();
201         return result;
202     }
203 }
Popular Tags