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 / DefaultInstallerManager.java @ 41706
History | View | Annotate | Download (21.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 |
package org.gvsig.installer.lib.impl; |
29 |
|
30 |
import java.io.File; |
31 |
import java.io.FileInputStream; |
32 |
import java.io.IOException; |
33 |
import java.io.InputStream; |
34 |
import java.net.URL; |
35 |
import java.text.MessageFormat; |
36 |
import java.util.ArrayList; |
37 |
import java.util.Collection; |
38 |
import java.util.HashMap; |
39 |
import java.util.HashSet; |
40 |
import java.util.Iterator; |
41 |
import java.util.List; |
42 |
import java.util.Map; |
43 |
import java.util.Set; |
44 |
import org.apache.commons.lang3.StringUtils; |
45 |
|
46 |
import org.gvsig.installer.lib.api.DependenciesCalculator; |
47 |
import org.gvsig.installer.lib.api.Dependency; |
48 |
import org.gvsig.installer.lib.api.InstallerManager; |
49 |
import org.gvsig.installer.lib.api.PackageInfo; |
50 |
import org.gvsig.installer.lib.api.PackageInfoReader; |
51 |
import org.gvsig.installer.lib.api.PackageInfoWriter; |
52 |
import org.gvsig.installer.lib.api.Version; |
53 |
import org.gvsig.installer.lib.api.creation.MakePackageService; |
54 |
import org.gvsig.installer.lib.api.creation.MakePluginPackageService; |
55 |
import org.gvsig.installer.lib.api.creation.MakePluginPackageServiceException; |
56 |
import org.gvsig.installer.lib.api.execution.InstallPackageService; |
57 |
import org.gvsig.installer.lib.api.execution.InstallPackageServiceException; |
58 |
import org.gvsig.installer.lib.impl.creation.DefaultMakePackageService; |
59 |
import org.gvsig.installer.lib.impl.info.InstallerInfoFileReader; |
60 |
import org.gvsig.installer.lib.impl.info.InstallerInfoFileWriter; |
61 |
import org.gvsig.installer.lib.spi.InstallerProviderManager; |
62 |
import org.gvsig.tools.ToolsLocator; |
63 |
import org.gvsig.tools.dynobject.DynObject; |
64 |
import org.gvsig.tools.exception.BaseException; |
65 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
66 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
67 |
import org.gvsig.tools.service.AbstractManager; |
68 |
import org.gvsig.tools.service.Service; |
69 |
import org.gvsig.tools.service.ServiceException; |
70 |
|
71 |
/**
|
72 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
73 |
*/
|
74 |
public class DefaultInstallerManager extends AbstractManager implements |
75 |
InstallerManager { |
76 |
|
77 |
private static class LocalRepositoryLocation { |
78 |
|
79 |
private File location; |
80 |
private Set<String> types; |
81 |
|
82 |
public LocalRepositoryLocation(File localtion, String type) { |
83 |
this.location = localtion;
|
84 |
this.types = new HashSet<String>(); |
85 |
this.addType(type);
|
86 |
} |
87 |
|
88 |
public LocalRepositoryLocation(File localtion) { |
89 |
this(localtion, null); |
90 |
} |
91 |
|
92 |
public void addType(String type) { |
93 |
if ( !StringUtils.isBlank(type) ) {
|
94 |
this.types.add(type);
|
95 |
} |
96 |
} |
97 |
|
98 |
public void addType(LocalRepositoryLocation location) { |
99 |
this.types.addAll(location.getTypes());
|
100 |
} |
101 |
|
102 |
public Collection<String> getTypes() { |
103 |
return this.types; |
104 |
} |
105 |
|
106 |
public File getLocation() { |
107 |
return this.location; |
108 |
} |
109 |
|
110 |
public String getDefaultType() { |
111 |
if ( this.types.isEmpty() ) { |
112 |
return null; |
113 |
} |
114 |
return this.types.iterator().next(); |
115 |
} |
116 |
|
117 |
public boolean is(File location) { |
118 |
if ( location.equals(this.location) ) { |
119 |
return true; |
120 |
} |
121 |
return false; |
122 |
} |
123 |
|
124 |
public boolean contains(File file) { |
125 |
if ( file.getAbsolutePath().startsWith(this.location.getAbsolutePath()) ) { |
126 |
return true; |
127 |
} |
128 |
return false; |
129 |
} |
130 |
|
131 |
public boolean contains(PackageInfo packageInfo) { |
132 |
if( !this.support(packageInfo.getType()) ) { |
133 |
return false; |
134 |
} |
135 |
String packageInfoName = packageInfo.getCode() + File.separator + PACKAGE_INFO_FILE_NAME; |
136 |
File packageInfoFile = new File(this.location,packageInfoName); |
137 |
return packageInfoFile.exists();
|
138 |
} |
139 |
|
140 |
public boolean support(String type) { |
141 |
for( String atype : this.types ) { |
142 |
if( atype != null ) { |
143 |
if( atype.equalsIgnoreCase(type) ) {
|
144 |
return true; |
145 |
} |
146 |
} |
147 |
} |
148 |
return false; |
149 |
} |
150 |
} |
151 |
|
152 |
private static class LocalRepositoriesLocations extends ArrayList<LocalRepositoryLocation> { |
153 |
|
154 |
public LocalRepositoryLocation getLocation(File location) { |
155 |
Iterator<LocalRepositoryLocation> it = super.iterator(); |
156 |
while ( it.hasNext() ) {
|
157 |
LocalRepositoryLocation x = it.next(); |
158 |
if ( x.is(location) ) {
|
159 |
return x;
|
160 |
} |
161 |
} |
162 |
return null; |
163 |
} |
164 |
|
165 |
public boolean add(LocalRepositoryLocation location) { |
166 |
LocalRepositoryLocation old = this.getLocation(location.getLocation());
|
167 |
if ( old != null ) { |
168 |
old.addType(location); |
169 |
return true; |
170 |
} |
171 |
return super.add(location); |
172 |
} |
173 |
|
174 |
} |
175 |
|
176 |
private static final String INSTALLER_MANAGER_EXTENSION_POINT = "InstallerManagerExtensionPoint"; |
177 |
private static final String INSTALLER_CREATION_SERVICE_NAME = "InstallerCreationService"; |
178 |
private static final String INSTALLER_EXECUTION_SERVICE_NAME = "InstallerExecutionService"; |
179 |
private ExtensionPointManager extensionPoints = ToolsLocator
|
180 |
.getExtensionPointManager(); |
181 |
|
182 |
private String packageSetNameFormat = "gvSIG-desktop-{0}-{1}-{2}-{4}-{5}-{6}-{7}.gvspks"; |
183 |
private String packageNameFormat = "gvSIG-desktop-{0}-{1}-{2}-{4}-{5}-{6}-{7}.gvspkg"; |
184 |
private String packageIndexNameFormat = "gvSIG-desktop-{0}-{1}-{2}-{4}-{5}-{6}-{7}.gvspki"; |
185 |
|
186 |
private URL BaseDownloadURL = null; |
187 |
private Version version = null; |
188 |
private List<LocalRepositoryLocation> localRepositoriesLocation = null; |
189 |
private Map<String,File> defaultRepositoryLocation = null; |
190 |
|
191 |
public DefaultInstallerManager() {
|
192 |
super(new DefaultInstallerProviderManager()); |
193 |
this.defaultRepositoryLocation = new HashMap<String,File>(); |
194 |
localRepositoriesLocation = new LocalRepositoriesLocations();
|
195 |
} |
196 |
|
197 |
public String getPackageSetNameFormat() { |
198 |
return packageSetNameFormat;
|
199 |
} |
200 |
|
201 |
public void setPackageSetNameFormat(String packageSetNameFormat) { |
202 |
this.packageSetNameFormat = packageSetNameFormat;
|
203 |
} |
204 |
|
205 |
public String getPackageNameFormat() { |
206 |
return packageNameFormat;
|
207 |
} |
208 |
|
209 |
public void setPackageNameFormat(String packageNameFormat) { |
210 |
this.packageNameFormat = packageNameFormat;
|
211 |
} |
212 |
|
213 |
public String getPackageIndexNameFormat() { |
214 |
return packageIndexNameFormat;
|
215 |
} |
216 |
|
217 |
public void setPackageIndexNameFormat(String packageIndexNameFormat) { |
218 |
this.packageIndexNameFormat = packageIndexNameFormat;
|
219 |
} |
220 |
|
221 |
public MakePluginPackageService getMakePluginPackageService()
|
222 |
throws MakePluginPackageServiceException {
|
223 |
ExtensionPoint ep = extensionPoints |
224 |
.add(INSTALLER_MANAGER_EXTENSION_POINT); |
225 |
try {
|
226 |
Object[] args = new Object[]{this}; |
227 |
return (MakePluginPackageService) ep.create(
|
228 |
INSTALLER_CREATION_SERVICE_NAME, args); |
229 |
} catch (Exception e) { |
230 |
throw new MakePluginPackageServiceException( |
231 |
"Exception creating the installer service to create installers",
|
232 |
e); |
233 |
} |
234 |
} |
235 |
|
236 |
public class InstallerCreationException extends |
237 |
InstallPackageServiceException { |
238 |
|
239 |
private static final long serialVersionUID = 759329820705535873L; |
240 |
|
241 |
private static final String message = "Error creating the installer service to install plugins"; |
242 |
|
243 |
private static final String KEY = "_Error_creating_the_installer_service_to_install_plugins"; |
244 |
|
245 |
public InstallerCreationException(Exception e) { |
246 |
super(message, e, KEY, serialVersionUID);
|
247 |
} |
248 |
|
249 |
} |
250 |
|
251 |
public InstallPackageService getInstallPackageService()
|
252 |
throws InstallPackageServiceException {
|
253 |
ExtensionPoint ep = extensionPoints |
254 |
.add(INSTALLER_MANAGER_EXTENSION_POINT); |
255 |
try {
|
256 |
Object[] args = new Object[1]; |
257 |
args[0] = this; |
258 |
return (InstallPackageService) ep.create(
|
259 |
INSTALLER_EXECUTION_SERVICE_NAME, args); |
260 |
} catch (Exception e) { |
261 |
throw new InstallerCreationException(e); |
262 |
} |
263 |
} |
264 |
|
265 |
public void registerMakePluginPackageService( |
266 |
Class<? extends MakePluginPackageService> clazz) { |
267 |
ExtensionPoint extensionPoint = extensionPoints.add( |
268 |
INSTALLER_MANAGER_EXTENSION_POINT, "");
|
269 |
extensionPoint.append(INSTALLER_CREATION_SERVICE_NAME, "", clazz);
|
270 |
} |
271 |
|
272 |
public void registerInstallPackageService( |
273 |
Class<? extends InstallPackageService> clazz) { |
274 |
ExtensionPoint extensionPoint = extensionPoints.add( |
275 |
INSTALLER_MANAGER_EXTENSION_POINT, "");
|
276 |
extensionPoint.append(INSTALLER_EXECUTION_SERVICE_NAME, "", clazz);
|
277 |
} |
278 |
|
279 |
public Service getService(DynObject parameters) throws ServiceException { |
280 |
return null; |
281 |
} |
282 |
|
283 |
public String getPackageSetFileName(PackageInfo info) { |
284 |
Object[] parameters = getPackageNameFormatParameters(info); |
285 |
return MessageFormat.format(getPackageSetNameFormat(), parameters); |
286 |
} |
287 |
|
288 |
public String getPackageFileName(PackageInfo info) { |
289 |
Object[] parameters = getPackageNameFormatParameters(info); |
290 |
return MessageFormat.format(getPackageNameFormat(), parameters); |
291 |
} |
292 |
|
293 |
public String getPackageIndexFileName(PackageInfo info) { |
294 |
Object[] parameters = getPackageNameFormatParameters(info); |
295 |
return MessageFormat.format(getPackageIndexNameFormat(), parameters); |
296 |
} |
297 |
|
298 |
private Object[] getPackageNameFormatParameters(PackageInfo info) { |
299 |
Object[] parameters = new Object[8]; |
300 |
parameters[PACKAGE_FILE_NAME_FIELDS.GVSIG_VERSION] = info |
301 |
.getGvSIGVersion(); |
302 |
parameters[PACKAGE_FILE_NAME_FIELDS.NAME] = info.getCode(); |
303 |
parameters[PACKAGE_FILE_NAME_FIELDS.VERSION] = info.getVersion(); |
304 |
parameters[PACKAGE_FILE_NAME_FIELDS.BUILD] = info.getBuild(); |
305 |
parameters[PACKAGE_FILE_NAME_FIELDS.STATE] = info.getState(); |
306 |
parameters[PACKAGE_FILE_NAME_FIELDS.OS] = info.getOperatingSystem(); |
307 |
parameters[PACKAGE_FILE_NAME_FIELDS.ARCH] = info.getArchitecture(); |
308 |
parameters[PACKAGE_FILE_NAME_FIELDS.JVM] = info.getJavaVM(); |
309 |
return parameters;
|
310 |
} |
311 |
|
312 |
public PackageInfo[] getInstalledPackages(File pluginsDirectory) |
313 |
throws MakePluginPackageServiceException {
|
314 |
MakePluginPackageService service = getMakePluginPackageService(); |
315 |
return service.getInstalledPackages();
|
316 |
} |
317 |
|
318 |
public PackageInfo[] getInstalledPackages() |
319 |
throws MakePluginPackageServiceException {
|
320 |
MakePluginPackageService service = getMakePluginPackageService(); |
321 |
return service.getInstalledPackages();
|
322 |
} |
323 |
|
324 |
public String getDefaultPackageFileExtension() { |
325 |
return "gvspkg"; |
326 |
} |
327 |
|
328 |
public String getDefaultPackageSetFileExtension() { |
329 |
return "gvspks"; |
330 |
} |
331 |
|
332 |
public String getDefaultIndexSetFileExtension() { |
333 |
return "gvspki"; |
334 |
} |
335 |
|
336 |
public String getOperatingSystem() { |
337 |
String osname = System.getProperty("os.name"); |
338 |
if ( osname.toLowerCase().startsWith("linux") ) { |
339 |
return InstallerManager.OS.LINUX;
|
340 |
} |
341 |
if ( osname.toLowerCase().startsWith("window") ) { |
342 |
return InstallerManager.OS.WINDOWS;
|
343 |
} |
344 |
return osname;
|
345 |
} |
346 |
|
347 |
public String getArchitecture() { |
348 |
String osarch = System.getProperty("os.arch"); |
349 |
if ( osarch.toLowerCase().startsWith("i386") ) { |
350 |
return InstallerManager.ARCH.X86;
|
351 |
} |
352 |
if ( osarch.toLowerCase().startsWith("x86") ) { |
353 |
return InstallerManager.ARCH.X86;
|
354 |
} |
355 |
if ( osarch.toLowerCase().startsWith("amd64") ) { |
356 |
return InstallerManager.ARCH.X86_64;
|
357 |
} |
358 |
return osarch;
|
359 |
} |
360 |
|
361 |
public Dependency createDependency(PackageInfo packageInfo) {
|
362 |
return new DefaultDependency(packageInfo); |
363 |
} |
364 |
|
365 |
public Dependency createDependency() {
|
366 |
return new DefaultDependency(); |
367 |
} |
368 |
|
369 |
public DependenciesCalculator createDependenciesCalculator(
|
370 |
InstallPackageService installService) { |
371 |
return new DefaultDependenciesCalculator(installService); |
372 |
} |
373 |
|
374 |
public Version createVersion() {
|
375 |
if ( version == null ) { |
376 |
return new DefaultVersion(); |
377 |
} |
378 |
Version v = null;
|
379 |
try {
|
380 |
v = (Version) version.clone(); |
381 |
} catch (CloneNotSupportedException e) { |
382 |
// Version clone can't trow exception
|
383 |
} |
384 |
return v;
|
385 |
} |
386 |
|
387 |
public PackageInfoReader getDefaultPackageInfoReader() {
|
388 |
return new InstallerInfoFileReader(); |
389 |
} |
390 |
|
391 |
public PackageInfoWriter getDefaultPackageInfoWriter() {
|
392 |
return new InstallerInfoFileWriter(); |
393 |
} |
394 |
|
395 |
public MakePackageService createMakePackage(File packageFolder, |
396 |
PackageInfo packageInfo) { |
397 |
return new DefaultMakePackageService(this, packageFolder, packageInfo); |
398 |
} |
399 |
|
400 |
public PackageInfo createPackageInfo() {
|
401 |
return new DefaultPackageInfo(); |
402 |
} |
403 |
|
404 |
public PackageInfo createPackageInfo(InputStream stream) throws BaseException { |
405 |
PackageInfo pkg = new DefaultPackageInfo();
|
406 |
PackageInfoReader reader = this.getDefaultPackageInfoReader();
|
407 |
reader.read(pkg, stream); |
408 |
return pkg;
|
409 |
} |
410 |
|
411 |
public PackageInfo createPackageInfo(File file) throws BaseException { |
412 |
FileInputStream fis = null; |
413 |
PackageInfo pkg = null;
|
414 |
try {
|
415 |
fis = new FileInputStream(file); |
416 |
pkg = this.createPackageInfo(fis);
|
417 |
fis.close(); |
418 |
} catch (Exception ex) { |
419 |
|
420 |
} finally {
|
421 |
try {
|
422 |
fis.close(); |
423 |
} catch (IOException ex) { |
424 |
//
|
425 |
} |
426 |
} |
427 |
return pkg;
|
428 |
} |
429 |
|
430 |
public URL getDownloadBaseURL() { |
431 |
return this.BaseDownloadURL; |
432 |
} |
433 |
|
434 |
public String getVersion() { |
435 |
return this.version.toString(); |
436 |
} |
437 |
|
438 |
public void setVersion(Version version) { |
439 |
try {
|
440 |
this.version = (Version) version.clone();
|
441 |
} catch (CloneNotSupportedException e) { |
442 |
// This should not happen
|
443 |
} |
444 |
|
445 |
} |
446 |
|
447 |
public Version getVersionEx() {
|
448 |
try {
|
449 |
return (Version) this.version.clone(); |
450 |
} catch (CloneNotSupportedException e) { |
451 |
// This should not happen
|
452 |
return null; |
453 |
} |
454 |
} |
455 |
|
456 |
public void setDownloadBaseURL(URL url) { |
457 |
this.BaseDownloadURL = url;
|
458 |
} |
459 |
|
460 |
public void setVersion(String version) { |
461 |
if ( this.version == null ) { |
462 |
this.version = new DefaultVersion(); |
463 |
} |
464 |
this.version.parse(version);
|
465 |
} |
466 |
|
467 |
public File getDefaultLocalAddonRepository() { |
468 |
File f = this.defaultRepositoryLocation.get("plugin"); |
469 |
return f;
|
470 |
} |
471 |
|
472 |
public void setDefaultLocalAddonRepository(File defaultAddonsRepository) { |
473 |
this.defaultRepositoryLocation.put("plugin", defaultAddonsRepository); |
474 |
this.localRepositoriesLocation.add(new LocalRepositoryLocation(defaultAddonsRepository, "plugin")); |
475 |
} |
476 |
|
477 |
public void addLocalAddonRepository(File path) { |
478 |
this.addLocalAddonRepository(path, "plugin"); |
479 |
} |
480 |
|
481 |
public File getDefaultLocalAddonRepository(String packageType) { |
482 |
return this.getDefaultLocalAddonRepository(packageType,ACCESS_READ); |
483 |
} |
484 |
|
485 |
public File getDefaultLocalAddonRepository(String packageType, int access) { |
486 |
File f = this.defaultRepositoryLocation.get(packageType); |
487 |
switch(access) {
|
488 |
case ACCESS_WRITE:
|
489 |
if( f.canWrite() ) {
|
490 |
return f;
|
491 |
} |
492 |
break;
|
493 |
case ACCESS_READ:
|
494 |
default:
|
495 |
if( f.canRead()) {
|
496 |
return f;
|
497 |
} |
498 |
break;
|
499 |
} |
500 |
List<File> repositoriesLocaltions = this.getLocalAddonRepositories(packageType); |
501 |
for( File repositoryLocation : repositoriesLocaltions ) { |
502 |
switch(access) {
|
503 |
case ACCESS_WRITE:
|
504 |
if( repositoryLocation.canWrite() ) {
|
505 |
return repositoryLocation;
|
506 |
} |
507 |
break;
|
508 |
case ACCESS_READ:
|
509 |
default:
|
510 |
if( repositoryLocation.canRead()) {
|
511 |
return repositoryLocation;
|
512 |
} |
513 |
break;
|
514 |
} |
515 |
} |
516 |
return null; |
517 |
} |
518 |
|
519 |
public void setDefaultLocalAddonRepository(File defaultAddonsRepository, String packageType) { |
520 |
this.defaultRepositoryLocation.put(packageType, defaultAddonsRepository);
|
521 |
this.localRepositoriesLocation.add(new LocalRepositoryLocation(defaultAddonsRepository, packageType)); |
522 |
} |
523 |
|
524 |
public void addLocalAddonRepository(File path, String type) { |
525 |
localRepositoriesLocation.add(new LocalRepositoryLocation(path, type));
|
526 |
} |
527 |
|
528 |
public String getDefaultLocalRepositoryType(File file) { |
529 |
Iterator<LocalRepositoryLocation> it = localRepositoriesLocation.iterator();
|
530 |
while ( it.hasNext() ) {
|
531 |
LocalRepositoryLocation location = it.next(); |
532 |
if ( location.contains(file) ) {
|
533 |
return location.getDefaultType();
|
534 |
} |
535 |
} |
536 |
return null; |
537 |
} |
538 |
|
539 |
public List<File> getLocalAddonRepositories() { |
540 |
return this.getLocalAddonRepositories(null); |
541 |
} |
542 |
|
543 |
public List<File> getLocalAddonRepositories(String type) { |
544 |
List<File> l = new ArrayList<File>(); |
545 |
Iterator<LocalRepositoryLocation> it = localRepositoriesLocation.iterator();
|
546 |
while ( it.hasNext() ) {
|
547 |
LocalRepositoryLocation location = it.next(); |
548 |
if( type==null || location.support(type) ) { |
549 |
l.add(location.getLocation()); |
550 |
} |
551 |
} |
552 |
return l;
|
553 |
} |
554 |
|
555 |
public List<File> getAddonFolders() { |
556 |
return this.getAddonFolders(null); |
557 |
} |
558 |
|
559 |
public List<File> getAddonFolders(String type) { |
560 |
List<File> addonFolders = new ArrayList<File>(); |
561 |
|
562 |
// Para cada directorio en la lista de repositorios locales
|
563 |
List<File> localAddonRepositories = this.getLocalAddonRepositories(type); |
564 |
for ( int i = 0; i < localAddonRepositories.size(); i++ ) { |
565 |
File repoPath = localAddonRepositories.get(i);
|
566 |
if ( repoPath.isDirectory() && repoPath.exists() ) {
|
567 |
File[] folderRepoList = repoPath.listFiles(); |
568 |
|
569 |
// recorrer los directorios que haya dentro
|
570 |
for ( int j = 0; j < folderRepoList.length; j++ ) { |
571 |
File addonFolder = folderRepoList[j];
|
572 |
if ( addonFolder.isDirectory() ) {
|
573 |
File pkginfofile = new File(addonFolder, "package.info"); |
574 |
if ( pkginfofile.exists() ) {
|
575 |
addonFolders.add(addonFolder); |
576 |
} |
577 |
} |
578 |
|
579 |
} |
580 |
} |
581 |
} |
582 |
|
583 |
return addonFolders;
|
584 |
} |
585 |
|
586 |
public File getAddonFolder(String code) { |
587 |
List<File> packagePaths = this.getAddonFolders(); |
588 |
for ( int i = 0; i < packagePaths.size(); i++ ) { |
589 |
try {
|
590 |
File pkgfile = new File(packagePaths.get(i), "package.info"); |
591 |
PackageInfo pkg = this.createPackageInfo(pkgfile);
|
592 |
if ( pkg.getCode().equalsIgnoreCase(code) ) {
|
593 |
return packagePaths.get(i);
|
594 |
} |
595 |
} catch (Exception ex) { |
596 |
|
597 |
} |
598 |
} |
599 |
return null; |
600 |
} |
601 |
|
602 |
public List<byte[]> getPublicKeys() { |
603 |
byte[] rawkey; |
604 |
try {
|
605 |
InputStream is = this.getClass().getResourceAsStream("/org/gvsig/installer/lib/keys/key.public"); |
606 |
rawkey = new byte[is.available()]; |
607 |
is.read(rawkey); |
608 |
is.close(); |
609 |
} catch (IOException e) { |
610 |
return null; |
611 |
} |
612 |
List<byte[]> keys = new ArrayList<byte[]>(); |
613 |
keys.add(rawkey); |
614 |
return keys;
|
615 |
} |
616 |
|
617 |
public boolean hasProviderToThisPackage(PackageInfo packageInfo) { |
618 |
InstallerProviderManager provmgr = (InstallerProviderManager) this.getProviderManager();
|
619 |
try {
|
620 |
return provmgr.getProviderFactory(packageInfo.getType()) != null; |
621 |
} catch (Exception e) { |
622 |
return false; |
623 |
} |
624 |
} |
625 |
|
626 |
} |