svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.installer / org.gvsig.installer.lib / org.gvsig.installer.lib.impl / src / main / java / org / gvsig / installer / lib / impl / DefaultPackageInfo.java @ 37599
History | View | Annotate | Download (12.7 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2010 {Prodevelop} {Task}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.installer.lib.impl; |
29 |
|
30 |
import java.io.File; |
31 |
import java.io.IOException; |
32 |
import java.net.MalformedURLException; |
33 |
import java.net.URL; |
34 |
import java.util.ArrayList; |
35 |
import java.util.List; |
36 |
|
37 |
import org.gvsig.installer.lib.api.Dependencies; |
38 |
import org.gvsig.installer.lib.api.PackageInfo; |
39 |
import org.gvsig.installer.lib.api.Version; |
40 |
import org.gvsig.installer.lib.api.InstallerManager.ARCH; |
41 |
import org.gvsig.installer.lib.api.InstallerManager.JVM; |
42 |
import org.gvsig.installer.lib.api.InstallerManager.OS; |
43 |
import org.gvsig.installer.lib.api.InstallerManager.STATE; |
44 |
import org.gvsig.installer.lib.api.execution.InstallPackageServiceException; |
45 |
import org.gvsig.installer.lib.impl.info.InstallerInfoTags; |
46 |
import org.gvsig.installer.lib.impl.utils.DeleteFile; |
47 |
import org.gvsig.installer.lib.impl.utils.Download; |
48 |
import org.gvsig.tools.task.SimpleTaskStatus; |
49 |
|
50 |
/**
|
51 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
52 |
*/
|
53 |
public class DefaultPackageInfo implements PackageInfo { |
54 |
|
55 |
private String code = null; |
56 |
private String name = null; |
57 |
private String description = null; |
58 |
private Version version = null; |
59 |
// private int build = 0;
|
60 |
private boolean official; |
61 |
private List<File> auxFiles = null; |
62 |
private String antScript = null; |
63 |
private String type = "unknow"; |
64 |
|
65 |
private String state = STATE.DEVEL; |
66 |
private String operatingSystem = OS.ALL; |
67 |
private String architecture = ARCH.ALL; |
68 |
private String javaVM = JVM.J1_5; |
69 |
|
70 |
private String owner = ""; |
71 |
private URL sources = null; |
72 |
private String gvSIGVersion = ""; |
73 |
|
74 |
// private URL defaultDownloadURL = null;
|
75 |
private String defaultDownloadURL = null; |
76 |
|
77 |
private String modelVersion = "1.0.1"; |
78 |
private Dependencies dependencies = null; |
79 |
// private Set<String> categories = null;
|
80 |
private List<String> categories = null; |
81 |
|
82 |
private URL webURL = null; |
83 |
|
84 |
public DefaultPackageInfo() {
|
85 |
super();
|
86 |
auxFiles = new ArrayList<File>(); |
87 |
this.version = new DefaultVersion().parse("0.0.1"); |
88 |
this.dependencies = new DefaultDependencies(); |
89 |
this.categories = new ArrayList<String>(); |
90 |
} |
91 |
|
92 |
public String getCode() { |
93 |
return code;
|
94 |
} |
95 |
|
96 |
public String getID() { |
97 |
String id = this.getCode() + "#" + this.getVersion() + "#" |
98 |
+ this.getBuild() + "#" + this.getOperatingSystem() + "#" |
99 |
+ this.getArchitecture();
|
100 |
return id;
|
101 |
} |
102 |
|
103 |
public String getName() { |
104 |
return name;
|
105 |
} |
106 |
|
107 |
public String getDescription() { |
108 |
return description;
|
109 |
} |
110 |
|
111 |
public Version getVersion() {
|
112 |
return version;
|
113 |
} |
114 |
|
115 |
public int getBuild() { |
116 |
return this.version.getBuild(); |
117 |
} |
118 |
|
119 |
public String getState() { |
120 |
return state;
|
121 |
} |
122 |
|
123 |
public boolean isOfficial() { |
124 |
return official;
|
125 |
} |
126 |
|
127 |
public void setCode(String code) { |
128 |
this.code = code;
|
129 |
} |
130 |
|
131 |
public void setName(String name) { |
132 |
this.name = name;
|
133 |
} |
134 |
|
135 |
public void setDescription(String description) { |
136 |
this.description = description;
|
137 |
} |
138 |
|
139 |
public void setVersion(String version) { |
140 |
if (version == null) { |
141 |
return;
|
142 |
} |
143 |
int prev = this.version.getBuild(); |
144 |
this.version.parse(version);
|
145 |
int curr = this.version.getBuild(); |
146 |
if (prev != 0 && curr == 0) { |
147 |
this.version.setBuild(prev);
|
148 |
} |
149 |
} |
150 |
|
151 |
public void setVersion(Version version) { |
152 |
try {
|
153 |
int prev = this.version.getBuild(); |
154 |
this.version = (Version) version.clone();
|
155 |
int curr = this.version.getBuild(); |
156 |
if (prev != 0 && curr == 0) { |
157 |
this.version.setBuild(prev);
|
158 |
} |
159 |
} catch (CloneNotSupportedException e) { |
160 |
throw new RuntimeException(e); |
161 |
} |
162 |
} |
163 |
|
164 |
public void setBuild(int build) { |
165 |
this.version.setBuild(build);
|
166 |
} |
167 |
|
168 |
public void setState(String state) { |
169 |
this.state = state;
|
170 |
} |
171 |
|
172 |
public void setOfficial(boolean official) { |
173 |
this.official = official;
|
174 |
} |
175 |
|
176 |
public String getOperatingSystem() { |
177 |
return operatingSystem;
|
178 |
} |
179 |
|
180 |
public void setOperatingSystem(String operatingSystem) { |
181 |
this.operatingSystem = operatingSystem;
|
182 |
} |
183 |
|
184 |
public String getArchitecture() { |
185 |
return architecture;
|
186 |
} |
187 |
|
188 |
public void setArchitecture(String architecture) { |
189 |
this.architecture = architecture;
|
190 |
} |
191 |
|
192 |
public String getJavaVM() { |
193 |
return javaVM;
|
194 |
} |
195 |
|
196 |
public void setJavaVM(String javaVM) { |
197 |
this.javaVM = javaVM;
|
198 |
} |
199 |
|
200 |
public String getAntScript() { |
201 |
return antScript;
|
202 |
} |
203 |
|
204 |
public void setAntScript(String antScript) { |
205 |
this.antScript = antScript;
|
206 |
} |
207 |
|
208 |
public String getType() { |
209 |
return type;
|
210 |
} |
211 |
|
212 |
public void setType(String type) { |
213 |
this.type = type;
|
214 |
} |
215 |
|
216 |
public String getGvSIGVersion() { |
217 |
return gvSIGVersion;
|
218 |
} |
219 |
|
220 |
public void setGvSIGVersion(String gvSIGVersion) { |
221 |
this.gvSIGVersion = gvSIGVersion;
|
222 |
} |
223 |
|
224 |
public URL getDownloadURL() { |
225 |
URL url = null; |
226 |
try {
|
227 |
url = new URL(defaultDownloadURL); |
228 |
} catch (MalformedURLException e) { |
229 |
// TODO Auto-generated catch block
|
230 |
e.printStackTrace(); |
231 |
} |
232 |
return url;
|
233 |
} |
234 |
|
235 |
public String getDownloadURLAsString() { |
236 |
return this.defaultDownloadURL; |
237 |
} |
238 |
|
239 |
public URL getDownloadURL(URL baseURL) { |
240 |
String URLString = baseURL.toString();
|
241 |
|
242 |
if (!URLString.endsWith("/")) { |
243 |
URLString += "/";
|
244 |
} |
245 |
URLString += ("dists/" + getGvSIGVersion() + "/" + "packages.gvspki"); |
246 |
try {
|
247 |
return new URL(URLString); |
248 |
} catch (MalformedURLException e) { |
249 |
// TODO Auto-generated catch block
|
250 |
e.printStackTrace(); |
251 |
return null; |
252 |
} |
253 |
} |
254 |
|
255 |
public void setDownloadURL(URL defaultDownloadURL) { |
256 |
this.defaultDownloadURL = defaultDownloadURL.toString();
|
257 |
} |
258 |
|
259 |
public void setDownloadURL(String defaultDownloadURL) { |
260 |
this.defaultDownloadURL = defaultDownloadURL;
|
261 |
} |
262 |
|
263 |
public String getModelVersion() { |
264 |
return modelVersion;
|
265 |
} |
266 |
|
267 |
public void setModelVersion(String modelVersion) { |
268 |
this.modelVersion = modelVersion;
|
269 |
} |
270 |
|
271 |
public String getOwner() { |
272 |
return owner;
|
273 |
} |
274 |
|
275 |
public void setOwner(String owner) { |
276 |
this.owner = owner;
|
277 |
} |
278 |
|
279 |
public URL getSourcesURL() { |
280 |
return sources;
|
281 |
} |
282 |
|
283 |
public void setSourcesURL(URL sources) { |
284 |
this.sources = sources;
|
285 |
} |
286 |
|
287 |
@Override
|
288 |
public String toString() { |
289 |
StringBuffer buffer = new StringBuffer(super.toString()).append(" ("); |
290 |
|
291 |
append(buffer, InstallerInfoTags.CODE, getCode()); |
292 |
append(buffer, InstallerInfoTags.NAME, getName()); |
293 |
append(buffer, InstallerInfoTags.DESCRIPTION, getDescription()); |
294 |
append(buffer, InstallerInfoTags.GVSIG_VERSION, getGvSIGVersion()); |
295 |
append(buffer, InstallerInfoTags.VERSION, getVersion()); |
296 |
append(buffer, InstallerInfoTags.BUILD, getBuild()); |
297 |
append(buffer, InstallerInfoTags.OS, getOperatingSystem()); |
298 |
append(buffer, InstallerInfoTags.ARCHITECTURE, getArchitecture()); |
299 |
append(buffer, InstallerInfoTags.JVM, getJavaVM()); |
300 |
append(buffer, InstallerInfoTags.DOWNLOAD_URL, getDownloadURL()); |
301 |
append(buffer, InstallerInfoTags.STATE, getState()); |
302 |
append(buffer, InstallerInfoTags.OFFICIAL, isOfficial()); |
303 |
append(buffer, InstallerInfoTags.TYPE, getType()); |
304 |
append(buffer, InstallerInfoTags.MODEL_VERSION, getModelVersion()); |
305 |
append(buffer, InstallerInfoTags.OWNER, getOwner()); |
306 |
append(buffer, InstallerInfoTags.SOURCES_URL, getSourcesURL()); |
307 |
append(buffer, InstallerInfoTags.DEPENDENCIES, getDependencies()); |
308 |
append(buffer, InstallerInfoTags.WEB_URL, getWebURL()); |
309 |
append(buffer, InstallerInfoTags.CATEGORIES, getCategories()); |
310 |
|
311 |
return buffer.append(')').toString(); |
312 |
} |
313 |
|
314 |
public String toStringCompact() { |
315 |
// type code version state os arch jvm dep
|
316 |
return String |
317 |
.format( |
318 |
"%1$-8.8s %2$-40s %3$-20.20s %4$-5.5s %5$-5.5s %6$-6.6s %7$-5.5s %8$s",
|
319 |
this.type, this.code, this.version, this.state, |
320 |
this.operatingSystem, this.architecture, this.javaVM, |
321 |
this.dependencies);
|
322 |
} |
323 |
|
324 |
private DefaultPackageInfo append(StringBuffer buffer, String key, |
325 |
Object value) {
|
326 |
buffer.append("\n\t").append(key).append(": ").append( |
327 |
value == null ? "" : value); |
328 |
return this; |
329 |
} |
330 |
|
331 |
@Override
|
332 |
public Object clone() throws CloneNotSupportedException { |
333 |
DefaultPackageInfo clone = (DefaultPackageInfo) super.clone();
|
334 |
clone.auxFiles = new ArrayList<File>(auxFiles); |
335 |
return clone;
|
336 |
} |
337 |
|
338 |
public File downloadFile() throws InstallPackageServiceException { |
339 |
return this.downloadFile(null); |
340 |
} |
341 |
|
342 |
public class FileDownloadException extends InstallPackageServiceException { |
343 |
|
344 |
private static final long serialVersionUID = 8640183295766490512L; |
345 |
|
346 |
private static final String message = "File '%(url)s' download error"; |
347 |
|
348 |
private static final String KEY = "_File_XurlX_download_error"; |
349 |
|
350 |
public FileDownloadException(URL url, IOException e) { |
351 |
super(message, e, KEY, serialVersionUID);
|
352 |
setValue("url", url.toString());
|
353 |
} |
354 |
|
355 |
} |
356 |
|
357 |
public File downloadFile(SimpleTaskStatus taskStatus) |
358 |
throws InstallPackageServiceException {
|
359 |
Download download = new Download(taskStatus);
|
360 |
try {
|
361 |
return download.downloadFile(this.getDownloadURL(), null); |
362 |
} catch (IOException e) { |
363 |
throw new FileDownloadException(this.getDownloadURL(), e); |
364 |
} |
365 |
} |
366 |
|
367 |
public void addFileToCopy(File file) { |
368 |
auxFiles.add(file); |
369 |
} |
370 |
|
371 |
public File getFileToCopy(int i) { |
372 |
return auxFiles.get(i);
|
373 |
} |
374 |
|
375 |
public void removeFileToCopy(File file) { |
376 |
auxFiles.remove(file); |
377 |
} |
378 |
|
379 |
public void clearFilesToCopy() { |
380 |
auxFiles.clear(); |
381 |
} |
382 |
|
383 |
public List<File> getFilesToCopy() { |
384 |
return auxFiles;
|
385 |
} |
386 |
|
387 |
public boolean removeInstallFolder(File folder) { |
388 |
DeleteFile delete = new DeleteFile();
|
389 |
boolean success = delete.delete(folder);
|
390 |
setAntScript(null);
|
391 |
clearFilesToCopy(); |
392 |
return success;
|
393 |
} |
394 |
|
395 |
public boolean removeFilesFolder(File folder) { |
396 |
DeleteFile delete = new DeleteFile();
|
397 |
return delete.delete(folder);
|
398 |
} |
399 |
|
400 |
public boolean matchID(String string) { |
401 |
String id = this.getID(); |
402 |
String[] stringParts = string.split("#"); |
403 |
|
404 |
if (stringParts.length == 1) { |
405 |
|
406 |
if (stringParts[0].equals(this.getCode())) { |
407 |
return true; |
408 |
} else {
|
409 |
return false; |
410 |
} |
411 |
} else {
|
412 |
if (stringParts.length == 2) { |
413 |
if ((stringParts[0] + stringParts[1]) |
414 |
.equals((this.getCode() + this.getVersion()))) { |
415 |
return true; |
416 |
} else {
|
417 |
return true; |
418 |
} |
419 |
} else {
|
420 |
if (string.equals(id)) {
|
421 |
return true; |
422 |
} else {
|
423 |
return false; |
424 |
} |
425 |
} |
426 |
} |
427 |
|
428 |
} |
429 |
|
430 |
public Dependencies getDependencies() {
|
431 |
return this.dependencies; |
432 |
} |
433 |
|
434 |
public void setDependencies(Dependencies dependencies) { |
435 |
this.dependencies = dependencies;
|
436 |
} |
437 |
|
438 |
public void setDependencies(String dependencies) { |
439 |
if (dependencies == null) { |
440 |
this.dependencies = null; |
441 |
} else {
|
442 |
this.dependencies = new DefaultDependencies().parse(dependencies); |
443 |
} |
444 |
} |
445 |
|
446 |
@Override
|
447 |
public boolean equals(Object obj) { |
448 |
PackageInfo other; |
449 |
try {
|
450 |
other = (PackageInfo) obj; |
451 |
} catch (Exception e) { |
452 |
return false; |
453 |
} |
454 |
if (!code.equalsIgnoreCase(other.getCode())) {
|
455 |
return false; |
456 |
} |
457 |
if (!version.check("=", other.getVersion())) { |
458 |
return false; |
459 |
} |
460 |
if (!operatingSystem.equalsIgnoreCase(other.getOperatingSystem())) {
|
461 |
return false; |
462 |
} |
463 |
if (!gvSIGVersion.equalsIgnoreCase(other.getGvSIGVersion())) {
|
464 |
return false; |
465 |
} |
466 |
if (!state.equalsIgnoreCase(other.getState())) {
|
467 |
return false; |
468 |
} |
469 |
if (!architecture.equalsIgnoreCase(other.getArchitecture())) {
|
470 |
return false; |
471 |
} |
472 |
if (!javaVM.equalsIgnoreCase(other.getJavaVM())) {
|
473 |
return false; |
474 |
} |
475 |
if (!type.equalsIgnoreCase(other.getType())) {
|
476 |
return false; |
477 |
} |
478 |
if (official != other.isOfficial()) {
|
479 |
return false; |
480 |
} |
481 |
return true; |
482 |
} |
483 |
|
484 |
public URL getWebURL() { |
485 |
return webURL;
|
486 |
} |
487 |
|
488 |
public void setWebURL(URL webURL) { |
489 |
this.webURL = webURL;
|
490 |
} |
491 |
|
492 |
public List<String> getCategories() { |
493 |
return this.categories; |
494 |
} |
495 |
|
496 |
public void setCategories(List<String> categoriesList) { |
497 |
for (int i = 0; i < categoriesList.size(); i++) { |
498 |
if (!this.categories.contains(categoriesList.get(i))) { |
499 |
this.categories.add(categoriesList.get(i));
|
500 |
} |
501 |
} |
502 |
} |
503 |
|
504 |
public String getCategoriesAsString() { |
505 |
String categoriesString = ""; |
506 |
for (int i = 0; i < this.categories.size(); i++) { |
507 |
categoriesString += this.categories.get(i) + ", "; |
508 |
} |
509 |
return categoriesString;
|
510 |
} |
511 |
|
512 |
public void addCategoriesAsString(String categoriesString) { |
513 |
categoriesString.trim(); |
514 |
String[] cadena = categoriesString.split(","); |
515 |
|
516 |
for (int i = 0; i < cadena.length; i++) { |
517 |
String trimCadena = cadena[i].trim();
|
518 |
if ((!this.categories.contains(trimCadena)) && (trimCadena != "")) { |
519 |
this.categories.add(trimCadena);
|
520 |
} |
521 |
} |
522 |
|
523 |
} |
524 |
|
525 |
} |