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