%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
nl.toolforge.karma.core.scm.ModuleDependency |
|
|
1 | /* |
|
2 | Karma core - Core of the Karma application |
|
3 | Copyright (C) 2004 Toolforge <www.toolforge.nl> |
|
4 | ||
5 | This library is free software; you can redistribute it and/or |
|
6 | modify it under the terms of the GNU Lesser General Public |
|
7 | License as published by the Free Software Foundation; either |
|
8 | version 2.1 of the License, or (at your option) any later version. |
|
9 | ||
10 | This library is distributed in the hope that it will be useful, |
|
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 | Lesser General Public License for more details. |
|
14 | ||
15 | You should have received a copy of the GNU Lesser General Public |
|
16 | License along with this library; if not, write to the Free Software |
|
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | */ |
|
19 | package nl.toolforge.karma.core.scm; |
|
20 | ||
21 | import java.io.File; |
|
22 | ||
23 | /** |
|
24 | * <p>Describes a dependency for a <code>Module</code>. This class is used by a Digester reading in a file called |
|
25 | * <code>dependencies.xml</code> which is located in the root for each module that need dependencies. Dependencies can |
|
26 | * be defined in three ways: |
|
27 | * |
|
28 | * <ul> |
|
29 | * <li/><code><dependency module="<module-name>"/></code> defines a dependency to another module that is |
|
30 | * part of the same manifest. Those modules should be of the correct type (<code>Java - Source Module</code>). |
|
31 | * <li/><code><dependency groupId="" artifactId="" version=""/></code> defines a dependency Maven-style. This |
|
32 | * means that the actual <code>jar</code>-file is found on a local disk in a Maven repository. Karma imposes a |
|
33 | * stronger definition of Maven dependencies than Maven does itself. Karma does not allow the following |
|
34 | * structure : <code>id="" jar=""</code>. |
|
35 | * <li/><code><dependency libmodule="" artifactId="" version=""/></code> defines that the |
|
36 | * <code><artifactId>-<version>.jar</code> package is 'loaded' from the given lib module. |
|
37 | * </ul> |
|
38 | * <p> |
|
39 | * As an optional attribute <code>package</code> can be defined, with possible values <code>true</code> or <code>false</code>. |
|
40 | * <code>false</code> is the default. This defines whether or not the dependency should be packaged in the current module's package. |
|
41 | * </p> |
|
42 | * |
|
43 | * @see nl.toolforge.karma.core.cmd.util.DependencyException |
|
44 | * |
|
45 | * @author D.A. Smedes |
|
46 | * @version $Id: ModuleDependency.java,v 1.14 2004/10/19 19:57:00 hippe Exp $ |
|
47 | */ |
|
48 | 156 | public final class ModuleDependency { |
49 | ||
50 | 156 | private String id = null; |
51 | 156 | private String jar = null; |
52 | ||
53 | 156 | private String groupId = null; |
54 | 156 | private String libModule = null; |
55 | 156 | private String artifactId = null; |
56 | 156 | private String version = null; |
57 | ||
58 | 156 | private String module = null; |
59 | ||
60 | 156 | private boolean doPackage = false; |
61 | ||
62 | ||
63 | public String getId() { |
|
64 | 0 | return id; |
65 | } |
|
66 | ||
67 | public void setId(String id) { |
|
68 | 0 | this.id = id; |
69 | 0 | } |
70 | ||
71 | public String getGroupId() { |
|
72 | 0 | return groupId; |
73 | } |
|
74 | ||
75 | public void setGroupId(String groupId) { |
|
76 | 104 | this.groupId = groupId; |
77 | 104 | } |
78 | ||
79 | public String getArtifactId() { |
|
80 | 0 | return artifactId; |
81 | } |
|
82 | ||
83 | public void setArtifactId(String artifactId) { |
|
84 | 104 | this.artifactId = artifactId; |
85 | 104 | } |
86 | ||
87 | public String getVersion() { |
|
88 | 0 | return version; |
89 | } |
|
90 | ||
91 | public void setVersion(String version) { |
|
92 | 104 | this.version = version; |
93 | 104 | } |
94 | ||
95 | public String getModule() { |
|
96 | 0 | return module; |
97 | } |
|
98 | ||
99 | public void setModule(String module) { |
|
100 | 52 | this.module = module; |
101 | 52 | } |
102 | ||
103 | public String getLibModule() { |
|
104 | 0 | return libModule; |
105 | } |
|
106 | ||
107 | public void setLibModule(String libModule) { |
|
108 | 0 | this.libModule = libModule; |
109 | 0 | } |
110 | ||
111 | public String getJar() { |
|
112 | 0 | return jar; |
113 | } |
|
114 | ||
115 | public void setJar(String jar) { |
|
116 | 0 | this.jar = jar; |
117 | 0 | } |
118 | ||
119 | public void setPackage(boolean b) { |
|
120 | 0 | this.doPackage = b; |
121 | 0 | } |
122 | ||
123 | public boolean doPackage() { |
|
124 | 0 | return this.doPackage; |
125 | } |
|
126 | ||
127 | public String getJarDependency() { |
|
128 | ||
129 | 0 | String dep = null; |
130 | ||
131 | 0 | if (groupId != null) { |
132 | // <dependency groupId="" artifactId="" version=""/> |
|
133 | // |
|
134 | 0 | dep = groupId + File.separator + "jars" + File.separator + artifactId + "-" + version; |
135 | 0 | dep += ".jar"; |
136 | 0 | } else if (libModule != null) { |
137 | // <dependency libModule="" artifactId="" version=""/> |
|
138 | // |
|
139 | 0 | dep = libModule + File.separator + "lib" + File.separator + artifactId + "-" + version; |
140 | 0 | dep += ".jar"; |
141 | 0 | } else if (id != null) { |
142 | // <dependency id="" jar=""/> |
|
143 | // |
|
144 | 0 | dep = id + File.separator + "jars" + File.separator + jar; |
145 | } |
|
146 | ||
147 | 0 | return dep; |
148 | } |
|
149 | ||
150 | /** |
|
151 | * <code>true</code> if the dependency identifies a module in the same |
|
152 | * manifest, otherwise false. |
|
153 | */ |
|
154 | public boolean isModuleDependency() { |
|
155 | ||
156 | // <dependency module=""/> |
|
157 | // |
|
158 | 182 | return module != null; |
159 | } |
|
160 | ||
161 | /** |
|
162 | * <code>true</code> if the dependency identifies a jar in a module in the |
|
163 | * same manifest, otherwise false. |
|
164 | */ |
|
165 | public boolean isLibModuleDependency() { |
|
166 | ||
167 | // <dependency module=""/> |
|
168 | // |
|
169 | 0 | return libModule != null; |
170 | } |
|
171 | ||
172 | /** |
|
173 | * Returns the hash code for this instance. The hash code is either <code>module.hashCode()</code> or |
|
174 | * <code>artifactId.hashCode()</code>; this follows the general structure |
|
175 | * |
|
176 | * @return |
|
177 | */ |
|
178 | public int hashCode() { |
|
179 | 104 | if (isModuleDependency()) { |
180 | 0 | return module.hashCode(); |
181 | } else { |
|
182 | 104 | if (groupId != null || libModule != class="keyword">null) { |
183 | 104 | return artifactId.hashCode(); |
184 | } else { |
|
185 | 0 | return id.hashCode(); |
186 | } |
|
187 | } |
|
188 | } |
|
189 | ||
190 | /** |
|
191 | * Checks two <code>ModuleDependency</code> instances for equality. If the dependency is a module dependency, their |
|
192 | * module names are checked for equality. Otherwise the <code>artifactId</code> attribute is used to determine |
|
193 | * equality. |
|
194 | * |
|
195 | * @param obj Another <code>ModuleDependency</code>. |
|
196 | */ |
|
197 | public boolean equals(Object obj) { |
|
198 | ||
199 | 78 | if (!(obj instanceof ModuleDependency)) { |
200 | 0 | return false; |
201 | } else { |
|
202 | ||
203 | 78 | if (isModuleDependency()) { |
204 | 26 | return module.equals(((ModuleDependency) obj).module); |
205 | 52 | } else if (groupId != null || libModule != class="keyword">null){ |
206 | 52 | return artifactId.equals(((ModuleDependency) obj).artifactId); |
207 | 0 | } else if (id != null) { |
208 | 0 | return id.equals(((ModuleDependency) obj).id) && |
209 | jar.equals(((ModuleDependency) obj).jar); |
|
210 | } else { |
|
211 | 0 | return false; |
212 | } |
|
213 | } |
|
214 | } |
|
215 | ||
216 | public String toString() { |
|
217 | 0 | String result = "<dependency "; |
218 | ||
219 | 0 | if (module != null) { |
220 | 0 | result += "module=\""+module+"\" "; |
221 | 0 | } else if (groupId != null) { |
222 | 0 | result += "groupId=\""+groupId+"\" artifactId=\""+artifactId+"\" version=\""+version+"\" "; |
223 | 0 | } else if (id != null) { |
224 | 0 | result += "id=\""+id+"\" jar=\""+jar+"\" "; |
225 | } else { |
|
226 | 0 | result += "libModule=\""+libModule+"\" artifactId=\""+artifactId+"\" version=\""+version+"\" "; |
227 | } |
|
228 | 0 | if (doPackage) { |
229 | 0 | result += "package=\"true\" "; |
230 | } else { |
|
231 | 0 | result += "package=\"false\" "; |
232 | } |
|
233 | 0 | result += "/>"; |
234 | 0 | return result; |
235 | } |
|
236 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |