1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.mavenizer.core;
18
19 import java.io.File;
20 import java.util.ArrayList;
21 import java.util.HashMap;
22 import java.util.HashSet;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.Set;
26
27 import net.sf.mavenizer.core.loader.DefaultJarIdBuilder;
28 import net.sf.mavenizer.core.loader.JarIdBuilder;
29
30
31 /***
32 * @author <a href="mailto:cedric-vidal@users.sourceforge.net">Cédric Vidal</a>
33 *
34 */
35 public class Jar {
36 private File jarFile = null;
37
38 private File uncompressedDir = null;
39
40 private List classEntries = new ArrayList();
41
42 private List classDependencies = new ArrayList();
43
44 private List unresolvedClassDependencies = new ArrayList();
45
46 private Set jarDependencies = new HashSet();
47
48 private Set packages = new HashSet();
49
50 private String version = null;
51
52 private String artifactId = null;
53
54 private String artifactFileName = null;
55
56 private Map candidateVersions = new HashMap();
57
58 private boolean dependencyLookupDone = false;
59
60 private String groupId;
61
62 private String artifactFilePath;
63
64 private String pomFileName;
65
66 private String fullRepoPath;
67
68 private JarIdBuilder jarIdBuilder;
69
70 public List getClassEntries() {
71 return classEntries;
72 }
73
74 public void setClassEntries(List entries) {
75 this.classEntries = entries;
76 }
77
78 public File getJarFile() {
79 return jarFile;
80 }
81
82 public void setJarFile(File jarFile) {
83 this.jarFile = jarFile;
84 }
85
86 public File getUncompressedDir() {
87 return uncompressedDir;
88 }
89
90 public void setUncompressedDir(File uncompressedDir) {
91 this.uncompressedDir = uncompressedDir;
92 }
93
94 public List getClassDependencies() {
95 return classDependencies;
96 }
97
98 public void setClassDependencies(List classDependencies) {
99 this.classDependencies = classDependencies;
100 }
101
102 public Set getPackages() {
103 return packages;
104 }
105
106 public void setPackages(Set packages) {
107 this.packages = packages;
108 }
109
110 public String getVersion() {
111 if (version == null) {
112 version = "1.0";
113 }
114 return version;
115 }
116
117 public void setVersion(String version) {
118 this.version = version;
119 }
120
121 public Map getCandidateVersions() {
122 return candidateVersions;
123 }
124
125 public void setCandidateVersions(Map candidateVersions) {
126 this.candidateVersions = candidateVersions;
127 }
128
129 public Set getJarDependencies() {
130 return jarDependencies;
131 }
132
133 public void setJarDependencies(Set jarDependencies) {
134 this.jarDependencies = jarDependencies;
135 }
136
137 public List getUnresolvedClassDependencies() {
138 return unresolvedClassDependencies;
139 }
140
141 public void setUnresolvedClassDependencies(List unresolvedClassDependencies) {
142 this.unresolvedClassDependencies = unresolvedClassDependencies;
143 }
144
145 public String toString() {
146 String string = null;
147 if (getJarFile() != null) {
148 string = getJarFile().toString();
149 }
150 if (string == null) {
151 string = super.toString();
152 }
153 return string;
154 }
155
156 public String getArtifactId() {
157 return artifactId;
158 }
159
160 public void setArtifactId(String artifactId) {
161 this.artifactId = artifactId;
162 }
163
164 public boolean isDependencyLookupDone() {
165 return dependencyLookupDone;
166 }
167
168 public void setDependencyLookupDone(boolean dependencyLookupDone) {
169 this.dependencyLookupDone = dependencyLookupDone;
170 }
171
172 public String getArtifactFileName() {
173 if (artifactFileName == null) {
174 String fileName = null;
175 if (artifactId != null) {
176 fileName = artifactId;
177 if (version != null) {
178 fileName += "-" + version;
179 }
180 fileName += ".jar";
181 }
182 this.artifactFileName = fileName;
183 }
184 return artifactFileName;
185 }
186
187 public void setArtifactFileName(String artifactFileName) {
188 this.artifactFileName = artifactFileName;
189 }
190
191 public String getGroupId() {
192 if (groupId == null) {
193 if (!getPackages().isEmpty()) {
194 groupId = (String) getPackages().iterator().next();
195 }
196 }
197 return groupId;
198 }
199
200 public void setGroupId(String groupId) {
201 this.groupId = groupId;
202 }
203
204 public String getArtifactFilePath() {
205 if (artifactFilePath == null) {
206 if (getGroupId() != null && getArtifactId() != null
207 && getVersion() != null) {
208 artifactFilePath = File.separatorChar
209 + getGroupId().replace('.', File.separatorChar)
210 + File.separatorChar + getArtifactId()
211 + File.separatorChar + getVersion();
212 }
213 }
214 return artifactFilePath;
215 }
216
217 public void setArtifactFilePath(String artifactFilePath) {
218 this.artifactFilePath = artifactFilePath;
219 }
220
221 public String getFullRepoPath() {
222 if (fullRepoPath == null) {
223 fullRepoPath = getArtifactFilePath() + getArtifactFileName();
224 }
225 return fullRepoPath;
226 }
227
228 public void setFullRepoPath(String fullRepoPath) {
229 this.fullRepoPath = fullRepoPath;
230 }
231
232 public String getPomFileName() {
233 if (pomFileName == null) {
234 String fileName = null;
235 if (artifactId != null) {
236 fileName = artifactId;
237 if (version != null) {
238 fileName += "-" + version;
239 }
240 fileName += ".pom";
241 }
242 this.pomFileName = fileName;
243 }
244 return pomFileName;
245 }
246
247 public void setPomFileName(String pomFileName) {
248 this.pomFileName = pomFileName;
249 }
250
251 public String getId() {
252 File file = getJarFile();
253 if (file == null) {
254 return null;
255 } else {
256 return getJarIdBuilder().buildId(file);
257 }
258 }
259
260 /***
261 * @return Returns the jarIdBuilder.
262 */
263 public JarIdBuilder getJarIdBuilder() {
264 if (jarIdBuilder == null) {
265 jarIdBuilder = new DefaultJarIdBuilder();
266 }
267 return jarIdBuilder;
268 }
269
270 /***
271 * @param jarIdBuilder
272 * The jarIdBuilder to set.
273 */
274 public void setJarIdBuilder(JarIdBuilder jarIdBuilder) {
275 this.jarIdBuilder = jarIdBuilder;
276 }
277 }