svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.installer / org.gvsig.installer.lib / org.gvsig.installer.lib.impl / src / main / java / org / gvsig / installer / lib / impl / DefaultInstallerManager.java @ 34444
History | View | Annotate | Download (6.59 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2010 {Prodevelop} {Task}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.installer.lib.impl; |
29 |
|
30 |
import java.io.File; |
31 |
import java.text.MessageFormat; |
32 |
|
33 |
import org.gvsig.installer.lib.api.InstallerManager; |
34 |
import org.gvsig.installer.lib.api.PackageInfo; |
35 |
import org.gvsig.installer.lib.api.creation.MakePluginPackageService; |
36 |
import org.gvsig.installer.lib.api.creation.MakePluginPackageServiceException; |
37 |
import org.gvsig.installer.lib.api.execution.InstallPackageService; |
38 |
import org.gvsig.installer.lib.api.execution.InstallPackageServiceException; |
39 |
import org.gvsig.tools.ToolsLocator; |
40 |
import org.gvsig.tools.dynobject.DynObject; |
41 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
42 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
43 |
import org.gvsig.tools.service.AbstractManager; |
44 |
import org.gvsig.tools.service.Service; |
45 |
import org.gvsig.tools.service.ServiceException; |
46 |
|
47 |
/**
|
48 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
49 |
*/
|
50 |
public class DefaultInstallerManager extends AbstractManager implements |
51 |
InstallerManager { |
52 |
|
53 |
private static final String INSTALLER_MANAGER_EXTENSION_POINT = "InstallerManagerExtensionPoint"; |
54 |
private static final String INSTALLER_CREATION_SERVICE_NAME = "InstallerCreationService"; |
55 |
private static final String INSTALLER_EXECUTION_SERVICE_NAME = "InstallerExecutionService"; |
56 |
private ExtensionPointManager extensionPoints = ToolsLocator
|
57 |
.getExtensionPointManager(); |
58 |
|
59 |
private String packageSetNameFormat = |
60 |
"gvSIG-desktop-{0}-{1}-{2}-{3,number,#}-{4}-{5}-{6}-{7}.gvspks";
|
61 |
|
62 |
private String packageNameFormat = |
63 |
"gvSIG-desktop-{0}-{1}-{2}-{3,number,#}-{4}-{5}-{6}-{7}.gvspkg";
|
64 |
|
65 |
private String packageIndexNameFormat = |
66 |
"gvSIG-desktop-{0}-{1}-{2}-{3,number,#}-{4}-{5}-{6}-{7}.gvspki";
|
67 |
|
68 |
public DefaultInstallerManager() {
|
69 |
super(new DefaultInstallerProviderManager()); |
70 |
} |
71 |
|
72 |
public String getPackageSetNameFormat() { |
73 |
return packageSetNameFormat;
|
74 |
} |
75 |
|
76 |
public void setPackageSetNameFormat(String packageSetNameFormat) { |
77 |
this.packageSetNameFormat = packageSetNameFormat;
|
78 |
} |
79 |
|
80 |
public String getPackageNameFormat() { |
81 |
return packageNameFormat;
|
82 |
} |
83 |
|
84 |
public void setPackageNameFormat(String packageNameFormat) { |
85 |
this.packageNameFormat = packageNameFormat;
|
86 |
} |
87 |
|
88 |
public String getPackageIndexNameFormat() { |
89 |
return packageIndexNameFormat;
|
90 |
} |
91 |
|
92 |
public void setPackageIndexNameFormat(String packageIndexNameFormat) { |
93 |
this.packageIndexNameFormat = packageIndexNameFormat;
|
94 |
} |
95 |
|
96 |
public MakePluginPackageService getMakePluginPackageService(
|
97 |
File pluginsDirectory) throws MakePluginPackageServiceException { |
98 |
ExtensionPoint ep = extensionPoints |
99 |
.add(INSTALLER_MANAGER_EXTENSION_POINT); |
100 |
try {
|
101 |
Object[] args = new Object[] { this, pluginsDirectory }; |
102 |
return (MakePluginPackageService) ep.create(
|
103 |
INSTALLER_CREATION_SERVICE_NAME, args); |
104 |
} catch (Exception e) { |
105 |
throw new MakePluginPackageServiceException( |
106 |
"Exception creating the installer service to create installers",
|
107 |
e); |
108 |
} |
109 |
} |
110 |
|
111 |
public InstallPackageService getInstallPackageService()
|
112 |
throws InstallPackageServiceException {
|
113 |
ExtensionPoint ep = extensionPoints |
114 |
.add(INSTALLER_MANAGER_EXTENSION_POINT); |
115 |
try {
|
116 |
Object[] args = new Object[1]; |
117 |
args[0] = this; |
118 |
return (InstallPackageService) ep.create(
|
119 |
INSTALLER_EXECUTION_SERVICE_NAME, args); |
120 |
} catch (Exception e) { |
121 |
throw new InstallPackageServiceException( |
122 |
"Exception creating the installer service to install plugins",
|
123 |
e); |
124 |
} |
125 |
} |
126 |
|
127 |
public void registerMakePluginPackageService( |
128 |
Class<? extends MakePluginPackageService> clazz) { |
129 |
ExtensionPoint extensionPoint = extensionPoints.add( |
130 |
INSTALLER_MANAGER_EXTENSION_POINT, "");
|
131 |
extensionPoint.append(INSTALLER_CREATION_SERVICE_NAME, "", clazz);
|
132 |
} |
133 |
|
134 |
public void registerInstallPackageService( |
135 |
Class<? extends InstallPackageService> clazz) { |
136 |
ExtensionPoint extensionPoint = extensionPoints.add( |
137 |
INSTALLER_MANAGER_EXTENSION_POINT, "");
|
138 |
extensionPoint.append(INSTALLER_EXECUTION_SERVICE_NAME, "", clazz);
|
139 |
} |
140 |
|
141 |
public Service getService(DynObject parameters) throws ServiceException { |
142 |
return null; |
143 |
} |
144 |
|
145 |
public String getPackageSetFileName(PackageInfo info) { |
146 |
Object[] parameters = getPackageNameFormatParameters(info); |
147 |
return MessageFormat.format(getPackageSetNameFormat(), parameters); |
148 |
} |
149 |
|
150 |
public String getPackageFileName(PackageInfo info) { |
151 |
Object[] parameters = getPackageNameFormatParameters(info); |
152 |
return MessageFormat.format(getPackageNameFormat(), parameters); |
153 |
} |
154 |
|
155 |
public String getPackageIndexFileName(PackageInfo info) { |
156 |
Object[] parameters = getPackageNameFormatParameters(info); |
157 |
return MessageFormat.format(getPackageIndexNameFormat(), parameters); |
158 |
} |
159 |
|
160 |
private Object[] getPackageNameFormatParameters(PackageInfo info) { |
161 |
Object[] parameters = new Object[8]; |
162 |
parameters[PACKAGE_FILE_NAME_FIELDS.GVSIG_VERSION] = info |
163 |
.getGvSIGVersion(); |
164 |
parameters[PACKAGE_FILE_NAME_FIELDS.NAME] = info.getCode(); |
165 |
parameters[PACKAGE_FILE_NAME_FIELDS.VERSION] = info.getVersion(); |
166 |
parameters[PACKAGE_FILE_NAME_FIELDS.BUILD] = info.getBuild(); |
167 |
parameters[PACKAGE_FILE_NAME_FIELDS.STATE] = info.getState(); |
168 |
parameters[PACKAGE_FILE_NAME_FIELDS.OS] = info.getOperatingSystem(); |
169 |
parameters[PACKAGE_FILE_NAME_FIELDS.ARCH] = info.getArchitecture(); |
170 |
parameters[PACKAGE_FILE_NAME_FIELDS.JVM] = info.getJavaVM(); |
171 |
return parameters;
|
172 |
} |
173 |
|
174 |
public PackageInfo[] getInstalledPackages(File pluginsDirectory) |
175 |
throws MakePluginPackageServiceException {
|
176 |
MakePluginPackageService service = getMakePluginPackageService(pluginsDirectory); |
177 |
return service.getInstalledPackages();
|
178 |
} |
179 |
|
180 |
public String getDefaultPackageFileExtension() { |
181 |
return "gvspkg"; |
182 |
} |
183 |
|
184 |
public String getDefaultPackageSetFileExtension() { |
185 |
return "gvspks"; |
186 |
} |
187 |
} |