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