gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.lib / src / main / java / org / gvsig / tools / packageutils / impl / DefaultPackageInfo.java @ 1713
History | View | Annotate | Download (25.6 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
/*
|
25 |
* AUTHORS (In addition to CIT):
|
26 |
* 2010 {Prodevelop} {Task}
|
27 |
*/
|
28 |
|
29 |
package org.gvsig.tools.packageutils.impl; |
30 |
|
31 |
import java.io.File; |
32 |
import java.net.MalformedURLException; |
33 |
import java.net.URL; |
34 |
import java.security.InvalidParameterException; |
35 |
import java.text.MessageFormat; |
36 |
import java.util.ArrayList; |
37 |
import java.util.HashMap; |
38 |
import java.util.Iterator; |
39 |
import java.util.List; |
40 |
import java.util.Map; |
41 |
import org.apache.commons.lang3.StringUtils; |
42 |
|
43 |
import org.gvsig.installer.lib.api.Dependencies; |
44 |
import org.gvsig.installer.lib.api.Version; |
45 |
import org.gvsig.tools.ToolsLocator; |
46 |
import org.gvsig.tools.exception.BaseException; |
47 |
import org.gvsig.tools.packageutils.PackageInfo; |
48 |
import org.gvsig.tools.packageutils.PackageManager; |
49 |
import org.gvsig.tools.packageutils.PackageManager.ARCH; |
50 |
import org.gvsig.tools.packageutils.PackageManager.JVM; |
51 |
import org.gvsig.tools.packageutils.PackageManager.OS; |
52 |
import org.gvsig.tools.packageutils.PackageManager.STATE; |
53 |
import org.gvsig.tools.packageutils.StringWithAlias; |
54 |
import org.gvsig.tools.task.SimpleTaskStatus; |
55 |
import org.slf4j.Logger; |
56 |
import org.slf4j.LoggerFactory; |
57 |
|
58 |
/**
|
59 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
60 |
*/
|
61 |
public class DefaultPackageInfo implements PackageInfo { |
62 |
|
63 |
private static final Logger logger = LoggerFactory |
64 |
.getLogger(DefaultPackageInfo.class); |
65 |
|
66 |
private static PackageManager packageManager = null; |
67 |
|
68 |
public static interface PACKAGE_FILE_NAME_FIELDS { |
69 |
static final int GVSIG_VERSION = 0; |
70 |
static final int NAME = 1; |
71 |
static final int VERSION = 2; |
72 |
static final int BUILD = 3; |
73 |
static final int STATE = 4; |
74 |
static final int OS = 5; |
75 |
static final int ARCH = 6; |
76 |
static final int JVM = 7; |
77 |
} |
78 |
private static final String PACKAGE_NAME_FORMAT = "gvSIG-desktop-{0}-{1}-{2}-{4}-{5}-{6}-{7}.gvspkg"; |
79 |
|
80 |
private static final String DEFAULT_MODEL_VERSION = "1.0.1"; |
81 |
private static final String DEFAULT_TYPE = "unknow"; |
82 |
|
83 |
private StringWithAlias code = null; |
84 |
private String name = null; |
85 |
private String description = null; |
86 |
private Version version = null; |
87 |
private boolean official; |
88 |
private String type = DEFAULT_TYPE; |
89 |
private boolean broken = false; |
90 |
|
91 |
private String state = STATE.DEVEL; |
92 |
// private String operatingSystem = OS.ALL;
|
93 |
private String operatingSystemFamily = OS.ALL; |
94 |
private String operatingSystemName = null; |
95 |
private String operatingSystemVersion = null; |
96 |
private String architecture = ARCH.ALL; |
97 |
private String javaVM = JVM.J1_5; |
98 |
|
99 |
private String owner = ""; |
100 |
private URL ownerURL = null; |
101 |
private URL sources = null; |
102 |
private Version applicationVersion = null; |
103 |
|
104 |
private String defaultDownloadURL = null; |
105 |
|
106 |
private String modelVersion = DEFAULT_MODEL_VERSION; |
107 |
private Dependencies dependencies = null; |
108 |
private List categories = null; |
109 |
|
110 |
private URL webURL = null; |
111 |
|
112 |
private String postInstallScript = null; |
113 |
|
114 |
private Map aditionalProperties = null; |
115 |
|
116 |
public DefaultPackageInfo() {
|
117 |
super();
|
118 |
PackageManager manager = ToolsLocator.getPackageManager(); |
119 |
this.version = manager.createVersion().parse("0.0.1"); |
120 |
this.applicationVersion = manager.createVersion().parse("0.0.1"); |
121 |
this.dependencies = manager.createDependencies();
|
122 |
this.categories = new ArrayList(); |
123 |
this.aditionalProperties = new HashMap(); |
124 |
} |
125 |
|
126 |
private PackageManager getPackageManager() {
|
127 |
if( packageManager==null ) { |
128 |
packageManager = ToolsLocator.getPackageManager(); |
129 |
} |
130 |
return packageManager;
|
131 |
} |
132 |
|
133 |
public String getCode() { |
134 |
if( code == null ) { |
135 |
return null; |
136 |
} |
137 |
return code.toString();
|
138 |
} |
139 |
|
140 |
public StringWithAlias getAllCodes() {
|
141 |
return this.code; |
142 |
} |
143 |
|
144 |
private String getAliasAsString() { |
145 |
if( this.code == null ) { |
146 |
return ""; |
147 |
} |
148 |
StringBuffer s = new StringBuffer(); |
149 |
Iterator alias = this.code.getAlias().iterator(); |
150 |
while( alias.hasNext() ) {
|
151 |
String ss = (String) alias.next(); |
152 |
s.append(ss); |
153 |
if( alias.hasNext() ) {
|
154 |
s.append(", ");
|
155 |
} |
156 |
} |
157 |
return s.toString();
|
158 |
} |
159 |
public boolean hasThisCode(String code) { |
160 |
if( this.code == null ) { |
161 |
if( code == null ) { |
162 |
return true; |
163 |
} |
164 |
return false; |
165 |
} |
166 |
return this.code.equalsIgnoreCase(code); |
167 |
} |
168 |
|
169 |
public boolean hasThisCode(StringWithAlias code) { |
170 |
if( this.code == null ) { |
171 |
if( code == null ) { |
172 |
return true; |
173 |
} |
174 |
return false; |
175 |
} |
176 |
return this.code.equalsIgnoreCase(code); |
177 |
} |
178 |
|
179 |
public String getID() { |
180 |
String id =
|
181 |
this.getCode() + "#" + this.getVersion() |
182 |
+ "#" + this.getOperatingSystem() + "#" |
183 |
+ this.getArchitecture();
|
184 |
return id;
|
185 |
} |
186 |
|
187 |
public String getName() { |
188 |
return name;
|
189 |
} |
190 |
|
191 |
public String getDescription() { |
192 |
return description;
|
193 |
} |
194 |
|
195 |
public Version getVersion() {
|
196 |
return version;
|
197 |
} |
198 |
|
199 |
public String getState() { |
200 |
return state;
|
201 |
} |
202 |
|
203 |
public boolean isOfficial() { |
204 |
return official;
|
205 |
} |
206 |
|
207 |
public void setCode(String code) { |
208 |
if( code == null ) { |
209 |
this.code = null; |
210 |
} else {
|
211 |
this.code = new DefaultStringWithAlias(code); |
212 |
} |
213 |
} |
214 |
|
215 |
public void setName(String name) { |
216 |
this.name = name;
|
217 |
} |
218 |
|
219 |
public void setDescription(String description) { |
220 |
this.description = description;
|
221 |
} |
222 |
|
223 |
public void setVersion(Version version) { |
224 |
try {
|
225 |
this.version = (Version) version.clone();
|
226 |
} catch (CloneNotSupportedException e) { |
227 |
throw new RuntimeException(e); |
228 |
} |
229 |
} |
230 |
|
231 |
public void setState(String state) { |
232 |
if( isEmptyString(state) ) {
|
233 |
this.state = STATE.DEVEL;
|
234 |
} else {
|
235 |
this.state = state;
|
236 |
} |
237 |
} |
238 |
|
239 |
public void setOfficial(boolean official) { |
240 |
this.official = official;
|
241 |
} |
242 |
|
243 |
@Override
|
244 |
public String getOperatingSystem() { |
245 |
StringBuilder operatingSystem = new StringBuilder(); |
246 |
operatingSystem.append(this.operatingSystemFamily);
|
247 |
if( !StringUtils.isEmpty(this.operatingSystemName) ) { |
248 |
operatingSystem.append("_");
|
249 |
operatingSystem.append(this.operatingSystemName);
|
250 |
if( !StringUtils.isEmpty(this.operatingSystemVersion) ) { |
251 |
operatingSystem.append("_");
|
252 |
operatingSystem.append(this.operatingSystemVersion);
|
253 |
} |
254 |
} |
255 |
return operatingSystem.toString();
|
256 |
} |
257 |
|
258 |
@Override
|
259 |
public void setOperatingSystem(String operatingSystem) { |
260 |
if( isEmptyString(operatingSystem) ) {
|
261 |
this.operatingSystemFamily = OS.ALL;
|
262 |
this.operatingSystemName = null; |
263 |
this.operatingSystemVersion = null; |
264 |
} else {
|
265 |
if( operatingSystem.contains("_") ) { |
266 |
String s[] = operatingSystem.split("_"); |
267 |
switch(s.length) {
|
268 |
case 2: |
269 |
this.operatingSystemFamily = s[0]; |
270 |
this.operatingSystemName = s[1]; |
271 |
break;
|
272 |
case 3: |
273 |
this.operatingSystemFamily = s[0]; |
274 |
this.operatingSystemName = s[1]; |
275 |
this.operatingSystemVersion = s[2]; |
276 |
break;
|
277 |
default:
|
278 |
throw new IllegalArgumentException("Can't parse OS '"+operatingSystem+"'."); |
279 |
} |
280 |
} else {
|
281 |
this.operatingSystemFamily = operatingSystem;
|
282 |
} |
283 |
} |
284 |
} |
285 |
|
286 |
@Override
|
287 |
public String getOperatingSystemFamily() { |
288 |
return this.operatingSystemFamily; |
289 |
} |
290 |
|
291 |
@Override
|
292 |
public String getOperatingSystemName() { |
293 |
return this.operatingSystemName; |
294 |
} |
295 |
|
296 |
@Override
|
297 |
public String getOperatingSystemVersion() { |
298 |
return this.operatingSystemVersion; |
299 |
} |
300 |
|
301 |
public void setOperatingSystemFamily(String operatingSystemFamily) { |
302 |
this.operatingSystemFamily = operatingSystemFamily;
|
303 |
} |
304 |
|
305 |
public void setOperatingSystemName(String operatingSystemName) { |
306 |
this.operatingSystemName = operatingSystemName;
|
307 |
} |
308 |
|
309 |
public void setOperatingSystemVersion(String operatingSystemVersion) { |
310 |
this.operatingSystemVersion = operatingSystemVersion;
|
311 |
} |
312 |
|
313 |
public String getArchitecture() { |
314 |
return architecture;
|
315 |
} |
316 |
|
317 |
public void setArchitecture(String architecture) { |
318 |
if( isEmptyString(architecture) ) {
|
319 |
this.architecture = ARCH.ALL;
|
320 |
} else {
|
321 |
this.architecture = architecture;
|
322 |
} |
323 |
} |
324 |
|
325 |
public String getJavaVM() { |
326 |
return javaVM;
|
327 |
} |
328 |
|
329 |
public void setJavaVM(String javaVM) { |
330 |
if( isEmptyString(javaVM) ) {
|
331 |
this.javaVM = JVM.J1_5;
|
332 |
} else {
|
333 |
this.javaVM = javaVM;
|
334 |
} |
335 |
} |
336 |
|
337 |
public String getType() { |
338 |
return type;
|
339 |
} |
340 |
|
341 |
public void setType(String type) { |
342 |
if( isEmptyString(type) ) {
|
343 |
this.type = DEFAULT_TYPE;
|
344 |
} else {
|
345 |
this.type = type;
|
346 |
} |
347 |
} |
348 |
|
349 |
public Version getApplicationVersion() {
|
350 |
return applicationVersion;
|
351 |
} |
352 |
|
353 |
public void setApplicationVersion(Version applicationVersion) { |
354 |
this.applicationVersion = applicationVersion;
|
355 |
} |
356 |
|
357 |
public URL getDownloadURL() { |
358 |
if( this.defaultDownloadURL == null ) { |
359 |
return null; |
360 |
} |
361 |
try {
|
362 |
return new URL(this.defaultDownloadURL); |
363 |
} catch (MalformedURLException e) { |
364 |
return null; |
365 |
// throw new RuntimeException(
|
366 |
// "Error converting to URL the package download url "+ this.defaultDownloadURL,
|
367 |
// e);
|
368 |
} |
369 |
} |
370 |
|
371 |
public String getDownloadURLAsString() { |
372 |
return this.defaultDownloadURL; |
373 |
} |
374 |
|
375 |
public void setDownloadURL(URL defaultDownloadURL) { |
376 |
this.defaultDownloadURL = defaultDownloadURL.toString();
|
377 |
} |
378 |
|
379 |
public void setDownloadURL(String defaultDownloadURL) { |
380 |
this.defaultDownloadURL = defaultDownloadURL;
|
381 |
} |
382 |
|
383 |
public String getModelVersion() { |
384 |
return modelVersion;
|
385 |
} |
386 |
|
387 |
public void setModelVersion(String modelVersion) { |
388 |
if( isEmptyString(modelVersion) ) {
|
389 |
this.modelVersion = DEFAULT_MODEL_VERSION;
|
390 |
} else {
|
391 |
this.modelVersion = modelVersion;
|
392 |
} |
393 |
} |
394 |
|
395 |
public String getOwner() { |
396 |
return owner;
|
397 |
} |
398 |
|
399 |
public void setOwner(String owner) { |
400 |
this.owner = owner;
|
401 |
} |
402 |
|
403 |
public URL getOwnerURL() { |
404 |
return ownerURL;
|
405 |
} |
406 |
|
407 |
public void setOwnerURL(URL sources) { |
408 |
this.ownerURL = sources;
|
409 |
} |
410 |
|
411 |
public URL getSourcesURL() { |
412 |
return sources;
|
413 |
} |
414 |
|
415 |
public void setSourcesURL(URL sources) { |
416 |
this.sources = sources;
|
417 |
} |
418 |
|
419 |
public String toString() { |
420 |
StringBuffer buffer = new StringBuffer(super.toString()).append(" ("); |
421 |
|
422 |
append(buffer, PackageInfoTags.CODE, getCode()); |
423 |
append(buffer, PackageInfoTags.NAME, getName()); |
424 |
append(buffer, PackageInfoTags.DESCRIPTION, getDescription()); |
425 |
append(buffer, PackageInfoTags.APPLICATION_VERSION, getApplicationVersion()); |
426 |
append(buffer, PackageInfoTags.VERSION, getVersion()); |
427 |
append(buffer, PackageInfoTags.OS, getOperatingSystem()); |
428 |
append(buffer, PackageInfoTags.ARCHITECTURE, getArchitecture()); |
429 |
append(buffer, PackageInfoTags.JVM, getJavaVM()); |
430 |
append(buffer, PackageInfoTags.DOWNLOAD_URL, getDownloadURL()); |
431 |
append(buffer, PackageInfoTags.STATE, getState()); |
432 |
append(buffer, PackageInfoTags.OFFICIAL, Boolean.valueOf(isOfficial()));
|
433 |
append(buffer, PackageInfoTags.TYPE, getType()); |
434 |
append(buffer, PackageInfoTags.MODEL_VERSION, getModelVersion()); |
435 |
append(buffer, PackageInfoTags.OWNER, getOwner()); |
436 |
append(buffer, PackageInfoTags.OWNER_URL, getOwnerURL()); |
437 |
append(buffer, PackageInfoTags.SOURCES_URL, getSourcesURL()); |
438 |
append(buffer, PackageInfoTags.DEPENDENCIES, getDependencies()); |
439 |
append(buffer, PackageInfoTags.WEB_URL, getWebURL()); |
440 |
append(buffer, PackageInfoTags.CATEGORIES, getCategories()); |
441 |
append(buffer, PackageInfoTags.CODEALIAS, getAliasAsString()); |
442 |
|
443 |
return buffer.append(')').toString(); |
444 |
} |
445 |
|
446 |
// public String toStringCompact() {
|
447 |
// // type code version state os arch jvm dep
|
448 |
// return String.format(
|
449 |
// "%1$-8.4s %2$-40s %3$-20.20s %4$-5.5s %5$-5.5s %6$-6.6s %7$-5.5s %8$s",
|
450 |
// new Object[] {
|
451 |
// this.type,
|
452 |
// this.code,
|
453 |
// this.version,
|
454 |
// this.state,
|
455 |
// this.operatingSystem,
|
456 |
// this.architecture,
|
457 |
// this.javaVM,
|
458 |
// this.dependencies
|
459 |
// }
|
460 |
// );
|
461 |
// }
|
462 |
|
463 |
public String toStringCompact() { |
464 |
// type code version state os arch jvm dep alias
|
465 |
StringBuffer s = new StringBuffer(); |
466 |
s.append(strformat(this.type,-8,-4)); |
467 |
s.append(" ");
|
468 |
s.append(strformat(this.code,-40,0)); |
469 |
s.append(" ");
|
470 |
s.append(strformat(this.version,-20,-20)); |
471 |
s.append(" ");
|
472 |
s.append(strformat(this.state,-5,-5)); |
473 |
s.append(" ");
|
474 |
s.append(strformat(this.getOperatingSystem(),-5,-5)); |
475 |
s.append(" ");
|
476 |
s.append(strformat(this.architecture,-6,-6)); |
477 |
s.append(" ");
|
478 |
s.append(strformat(this.javaVM,-5,-5)); |
479 |
s.append(" ");
|
480 |
s.append(strformat(this.dependencies,-8,0)); |
481 |
s.append(" ");
|
482 |
s.append(strformat(this.getAliasAsString(),-8,0)); |
483 |
return s.toString();
|
484 |
} |
485 |
|
486 |
private static final String SPACES256 = " "; |
487 |
|
488 |
private String strformat(Object o, int min, int max) { |
489 |
String s;
|
490 |
boolean alignright = true; |
491 |
if( o == null ) { |
492 |
s = "null";
|
493 |
} else {
|
494 |
s = o.toString(); |
495 |
} |
496 |
if( min < 0 ) { |
497 |
min = - min; |
498 |
alignright = false;
|
499 |
} |
500 |
if( max == 0 ) { |
501 |
if( s.length() < min ) {
|
502 |
if( alignright ) {
|
503 |
s = SPACES256+s; |
504 |
s = s.substring(s.length()-min); |
505 |
} else {
|
506 |
s = (s + SPACES256).substring(0, min);
|
507 |
} |
508 |
} |
509 |
} else {
|
510 |
if( max > 225) { |
511 |
max = 256;
|
512 |
} else if( max < 0 ) { |
513 |
max = -max; |
514 |
alignright = false;
|
515 |
} |
516 |
if( alignright ) {
|
517 |
if( s.length() > max ) {
|
518 |
s = s.substring(0, max);
|
519 |
} |
520 |
if( s.length() < min ) {
|
521 |
s = SPACES256.substring(0,min-s.length())+s;
|
522 |
} |
523 |
} else {
|
524 |
if( s.length() > max ) {
|
525 |
s = s.substring(0, max);
|
526 |
} |
527 |
if( s.length() < min ) {
|
528 |
s = s + SPACES256.substring(0,min-s.length());
|
529 |
} |
530 |
} |
531 |
} |
532 |
return s;
|
533 |
} |
534 |
|
535 |
private DefaultPackageInfo append(StringBuffer buffer, String key, |
536 |
Object value) {
|
537 |
buffer.append("\n\t").append(key).append(": ") |
538 |
.append(value == null ? "" : value); |
539 |
return this; |
540 |
} |
541 |
|
542 |
public Object clone() throws CloneNotSupportedException { |
543 |
DefaultPackageInfo other = (DefaultPackageInfo) super.clone();
|
544 |
|
545 |
/*
|
546 |
* If setDependencies is called with "" then
|
547 |
* dependencies is set to null, so we must check this:
|
548 |
*/
|
549 |
if (this.dependencies == null) { |
550 |
other.dependencies = null;
|
551 |
} else {
|
552 |
other.dependencies = (Dependencies) this.dependencies.clone();
|
553 |
} |
554 |
|
555 |
other.version = (Version) this.version.clone();
|
556 |
other.applicationVersion = (Version) this.applicationVersion.clone();
|
557 |
other.categories = new ArrayList(); |
558 |
other.categories.addAll(this.categories);
|
559 |
other.aditionalProperties = new HashMap(this.aditionalProperties); |
560 |
return other;
|
561 |
} |
562 |
|
563 |
|
564 |
public boolean matchID(String string) { |
565 |
String id = this.getID(); |
566 |
String[] stringParts = string.split("#"); |
567 |
Version version; |
568 |
|
569 |
switch (stringParts.length) {
|
570 |
case 1: // id |
571 |
if (stringParts[0].equals(this.getCode())) { |
572 |
return true; |
573 |
} else {
|
574 |
return false; |
575 |
} |
576 |
case 2: // id, version |
577 |
if (!stringParts[0].equals(this.getCode())) { |
578 |
return false; |
579 |
} |
580 |
version = new DefaultVersion();
|
581 |
try {
|
582 |
version.parse(stringParts[1]);
|
583 |
} catch (InvalidParameterException ex) { |
584 |
return false; |
585 |
} |
586 |
|
587 |
if (version.equals(this.getVersion())) { |
588 |
return true; |
589 |
} |
590 |
return false; |
591 |
case 4: // id, version, os, arch |
592 |
if (!stringParts[0].equals(this.getCode())) { |
593 |
return false; |
594 |
} |
595 |
if( !"any".equalsIgnoreCase(stringParts[1]) ) { |
596 |
version = new DefaultVersion();
|
597 |
try {
|
598 |
version.parse(stringParts[1]);
|
599 |
} catch (InvalidParameterException ex) { |
600 |
return false; |
601 |
} |
602 |
|
603 |
if (!version.equals(this.getVersion())) { |
604 |
return false; |
605 |
} |
606 |
} |
607 |
if( !"any".equalsIgnoreCase(stringParts[2]) ) { |
608 |
if( "current".equalsIgnoreCase(stringParts[2]) ) { |
609 |
if( !this.getOperatingSystem().equalsIgnoreCase(this.getPackageManager().getOperatingSystem()) ) { |
610 |
return false; |
611 |
} |
612 |
} else if( !this.getOperatingSystem().equalsIgnoreCase(stringParts[2]) ) { |
613 |
return false; |
614 |
} |
615 |
} |
616 |
if( !"any".equalsIgnoreCase(stringParts[3]) ) { |
617 |
if( "current".equalsIgnoreCase(stringParts[3]) ) { |
618 |
if( !this.getArchitecture().equalsIgnoreCase(this.getPackageManager().getArchitecture()) ) { |
619 |
return false; |
620 |
} |
621 |
} else if( !this.getArchitecture().equalsIgnoreCase(stringParts[3]) ) { |
622 |
return false; |
623 |
} |
624 |
} |
625 |
return true; |
626 |
|
627 |
default:
|
628 |
return string.equals(id);
|
629 |
|
630 |
} |
631 |
|
632 |
} |
633 |
|
634 |
public Dependencies getDependencies() {
|
635 |
return this.dependencies; |
636 |
} |
637 |
|
638 |
public void setDependencies(Dependencies dependencies) { |
639 |
this.dependencies = dependencies;
|
640 |
} |
641 |
|
642 |
public void setDependencies(String dependencies) { |
643 |
if ( isEmptyString(dependencies)) {
|
644 |
this.dependencies = null; |
645 |
} else {
|
646 |
this.dependencies = new DefaultDependencies().parse(dependencies); |
647 |
} |
648 |
} |
649 |
|
650 |
@Override
|
651 |
public boolean equals(Object obj) { |
652 |
PackageInfo other; |
653 |
try {
|
654 |
other = (PackageInfo) obj; |
655 |
} catch (Exception e) { |
656 |
return false; |
657 |
} |
658 |
if (!code.equalsIgnoreCase(other.getCode())) {
|
659 |
return false; |
660 |
} |
661 |
if (!version.check("=", other.getVersion())) { |
662 |
return false; |
663 |
} |
664 |
if (!getOperatingSystem().equalsIgnoreCase(other.getOperatingSystem())) {
|
665 |
return false; |
666 |
} |
667 |
if (!applicationVersion.equals(other.getApplicationVersion())) {
|
668 |
return false; |
669 |
} |
670 |
if (!state.equalsIgnoreCase(other.getState())) {
|
671 |
return false; |
672 |
} |
673 |
if (!architecture.equalsIgnoreCase(other.getArchitecture())) {
|
674 |
return false; |
675 |
} |
676 |
if (!javaVM.equalsIgnoreCase(other.getJavaVM())) {
|
677 |
return false; |
678 |
} |
679 |
if (!type.equalsIgnoreCase(other.getType())) {
|
680 |
return false; |
681 |
} |
682 |
if (official != other.isOfficial()) {
|
683 |
return false; |
684 |
} |
685 |
return true; |
686 |
} |
687 |
|
688 |
public URL getWebURL() { |
689 |
return webURL;
|
690 |
} |
691 |
|
692 |
public void setWebURL(URL webURL) { |
693 |
this.webURL = webURL;
|
694 |
} |
695 |
|
696 |
public List getCategories() { |
697 |
return this.categories; |
698 |
} |
699 |
|
700 |
public void setCategories(List categoriesList) { |
701 |
for (int i = 0; i < categoriesList.size(); i++) { |
702 |
if (!this.categories.contains(categoriesList.get(i))) { |
703 |
String s = (String) categoriesList.get(i); |
704 |
if(! StringUtils.isEmpty(s) ) {
|
705 |
this.categories.add(s.trim());
|
706 |
} |
707 |
} |
708 |
} |
709 |
} |
710 |
|
711 |
public String getCategoriesAsString() { |
712 |
String categoriesString = ""; |
713 |
for (int i = 0; i < this.categories.size(); i++) { |
714 |
if (i + 1 < this.categories.size()) { |
715 |
categoriesString += this.categories.get(i) + ","; |
716 |
} else {
|
717 |
categoriesString += this.categories.get(i);
|
718 |
} |
719 |
} |
720 |
return categoriesString;
|
721 |
} |
722 |
|
723 |
public void addCategoriesAsString(String categoriesString) { |
724 |
if ( StringUtils.isEmpty(categoriesString) ) {
|
725 |
return;
|
726 |
} |
727 |
categoriesString.trim(); |
728 |
String[] cadena = categoriesString.split(","); |
729 |
|
730 |
for (int i = 0; i < cadena.length; i++) { |
731 |
String category = cadena[i];
|
732 |
if( ! StringUtils.isEmpty(category) ) {
|
733 |
category = category.trim(); |
734 |
if( !this.categories.contains(category) ) { |
735 |
this.categories.add(category);
|
736 |
} |
737 |
} |
738 |
} |
739 |
|
740 |
} |
741 |
|
742 |
public boolean isBroken() { |
743 |
if (this.broken) { |
744 |
return true; |
745 |
} |
746 |
// if( this.isOfficial() && !this.isSigned() ) {
|
747 |
// return true;
|
748 |
// }
|
749 |
return false; |
750 |
} |
751 |
|
752 |
private boolean isEmptyString(String s) { |
753 |
if( s == null ) { |
754 |
return true; |
755 |
} |
756 |
return s.length()==0; |
757 |
} |
758 |
|
759 |
public String getPostInstallScript() { |
760 |
return this.postInstallScript; |
761 |
} |
762 |
|
763 |
public void setPostInstallScript(String script) { |
764 |
this.postInstallScript = script;
|
765 |
} |
766 |
|
767 |
protected void setBroken(boolean broken) { |
768 |
this.broken = broken;
|
769 |
} |
770 |
|
771 |
public void setValue(String name, Object value) { |
772 |
this.aditionalProperties.put(name, value);
|
773 |
} |
774 |
|
775 |
public Object getValue(String name) { |
776 |
return this.aditionalProperties.get(name); |
777 |
} |
778 |
|
779 |
private Object[] getPackageNameFormatParameters() { |
780 |
Object[] parameters = new Object[8]; |
781 |
parameters[PACKAGE_FILE_NAME_FIELDS.GVSIG_VERSION] = this.getApplicationVersion().toString();
|
782 |
parameters[PACKAGE_FILE_NAME_FIELDS.NAME] = this.getCode();
|
783 |
parameters[PACKAGE_FILE_NAME_FIELDS.VERSION] = this.getVersion();
|
784 |
parameters[PACKAGE_FILE_NAME_FIELDS.BUILD] = new Integer(this.getVersion().getBuild()); |
785 |
parameters[PACKAGE_FILE_NAME_FIELDS.STATE] = this.getState();
|
786 |
parameters[PACKAGE_FILE_NAME_FIELDS.OS] = this.getOperatingSystem();
|
787 |
parameters[PACKAGE_FILE_NAME_FIELDS.ARCH] = this.getArchitecture();
|
788 |
parameters[PACKAGE_FILE_NAME_FIELDS.JVM] = this.getJavaVM();
|
789 |
return parameters;
|
790 |
} |
791 |
|
792 |
public String getPreferedPackageFileName() { |
793 |
Object[] parameters = getPackageNameFormatParameters(); |
794 |
return MessageFormat.format(PACKAGE_NAME_FORMAT, parameters); |
795 |
} |
796 |
|
797 |
|
798 |
//
|
799 |
// =========================================================
|
800 |
//
|
801 |
// Deprecated methods
|
802 |
//
|
803 |
|
804 |
|
805 |
public int getBuild() { |
806 |
return this.getVersion().getBuild(); |
807 |
} |
808 |
|
809 |
public void setBuild(int build) { |
810 |
this.getVersion().setBuild(build);
|
811 |
} |
812 |
|
813 |
public String getGvSIGVersion() { |
814 |
// return this.getApplicationVersion().toString();
|
815 |
Version v = this.getApplicationVersion();
|
816 |
return v.getMajor() + "." + v.getMinor() + "." + v.getRevision(); |
817 |
} |
818 |
|
819 |
public void setGvSIGVersion(String gvSIGVersion) { |
820 |
this.getApplicationVersion().parse(gvSIGVersion);
|
821 |
} |
822 |
|
823 |
public URL getDownloadURL(URL baseURL) { |
824 |
logger.info("Deprecated methos, ignore parameter baseURL.");
|
825 |
return this.getOwnerURL(); |
826 |
} |
827 |
|
828 |
public String getAntScript() { |
829 |
return this.getPostInstallScript(); |
830 |
} |
831 |
|
832 |
public void setAntScript(String antScript) { |
833 |
this.setPostInstallScript(antScript);
|
834 |
} |
835 |
|
836 |
public File downloadFile() throws BaseException { |
837 |
throw new UnsupportedOperationException(); |
838 |
} |
839 |
|
840 |
public File downloadFile(SimpleTaskStatus taskStatus) throws BaseException { |
841 |
throw new UnsupportedOperationException(); |
842 |
} |
843 |
|
844 |
public void addFileToCopy(File file) { |
845 |
throw new UnsupportedOperationException(); |
846 |
} |
847 |
|
848 |
public File getFileToCopy(int i) { |
849 |
throw new UnsupportedOperationException(); |
850 |
} |
851 |
|
852 |
public void removeFileToCopy(File file) { |
853 |
throw new UnsupportedOperationException(); |
854 |
} |
855 |
|
856 |
public void clearFilesToCopy() { |
857 |
throw new UnsupportedOperationException(); |
858 |
} |
859 |
|
860 |
public List getFilesToCopy() { |
861 |
throw new UnsupportedOperationException(); |
862 |
} |
863 |
|
864 |
public boolean removeInstallFolder(File folder) { |
865 |
throw new UnsupportedOperationException(); |
866 |
} |
867 |
|
868 |
public boolean removeFilesFolder(File folder) { |
869 |
throw new UnsupportedOperationException(); |
870 |
} |
871 |
|
872 |
public boolean isSigned() { |
873 |
return true; |
874 |
} |
875 |
|
876 |
public void checkSignature(byte[] pkgdata) { |
877 |
// Do nothing
|
878 |
} |
879 |
|
880 |
/* (non-Javadoc)
|
881 |
* @see org.gvsig.installer.lib.api.PackageInfo#setVersion(java.lang.String)
|
882 |
*/
|
883 |
public void setVersion(String version) { |
884 |
this.version.parse(version);
|
885 |
} |
886 |
} |