svn-gvsig-desktop / tags / v2_0_0_Build_2051 / extensions / org.gvsig.installer / org.gvsig.installer.swing / org.gvsig.installer.swing.impl / src / main / java / org / gvsig / installer / swing / impl / DefaultSwingInstallerManager.java @ 38753
History | View | Annotate | Download (8.54 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.swing.impl; |
29 |
|
30 |
import java.io.BufferedReader; |
31 |
import java.io.File; |
32 |
import java.io.FileInputStream; |
33 |
import java.io.FileNotFoundException; |
34 |
import java.io.IOException; |
35 |
import java.io.InputStream; |
36 |
import java.io.InputStreamReader; |
37 |
import java.net.MalformedURLException; |
38 |
import java.net.URL; |
39 |
import java.util.ArrayList; |
40 |
import java.util.List; |
41 |
|
42 |
import org.gvsig.i18n.Messages; |
43 |
import org.gvsig.installer.lib.api.Dependencies; |
44 |
import org.gvsig.installer.lib.api.InstallerLocator; |
45 |
import org.gvsig.installer.lib.api.InstallerManager; |
46 |
import org.gvsig.installer.lib.api.PackageInfo; |
47 |
import org.gvsig.installer.lib.api.Version; |
48 |
import org.gvsig.installer.swing.api.JProgressPanel; |
49 |
import org.gvsig.installer.swing.api.SwingInstallerManager; |
50 |
import org.gvsig.installer.swing.api.creation.JOutputPanel; |
51 |
import org.gvsig.installer.swing.api.creation.JPackageInfoPanel; |
52 |
import org.gvsig.installer.swing.api.creation.MakePluginPackageWizard; |
53 |
import org.gvsig.installer.swing.api.creation.MakePluginPackageWizardException; |
54 |
import org.gvsig.installer.swing.api.execution.AbstractInstallPackageWizard; |
55 |
import org.gvsig.installer.swing.api.execution.InstallPackageWizardException; |
56 |
import org.gvsig.installer.swing.api.execution.JShowPackageStatusAndAskContinuePanel; |
57 |
import org.gvsig.installer.swing.api.execution.JShowRequiredPackagesAndAskContinuePanel; |
58 |
import org.gvsig.installer.swing.api.execution.JShowUnresolvedDependenciesAndAskContinuePanel; |
59 |
import org.gvsig.installer.swing.impl.creation.panel.DefaultOutputPanel; |
60 |
import org.gvsig.installer.swing.impl.creation.panel.DefaultPackageInfoPanel; |
61 |
import org.gvsig.installer.swing.impl.panel.DefaultProgressPanel; |
62 |
import org.gvsig.tools.ToolsLocator; |
63 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
64 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
65 |
import org.slf4j.Logger; |
66 |
import org.slf4j.LoggerFactory; |
67 |
|
68 |
/**
|
69 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
70 |
*/
|
71 |
public class DefaultSwingInstallerManager implements SwingInstallerManager { |
72 |
|
73 |
private static Logger logger = LoggerFactory |
74 |
.getLogger(DefaultSwingInstallerManager.class); |
75 |
|
76 |
private static final String SWING_INSTALLER_MANAGER_EXTENSION_POINT = "SwingInstallerManagerExtensionPoint"; |
77 |
private static final String CREATE_INSTALLER_WIZARD_NAME = "CreateInstallerWizard"; |
78 |
private static final String EXECUTE_INSTALLER_WIZARD_NAME = "ExecuteInstallerWizard"; |
79 |
private ExtensionPointManager extensionPoints = ToolsLocator
|
80 |
.getExtensionPointManager(); |
81 |
|
82 |
private String applicationVersion = "1.0.0"; |
83 |
private List<URL> defaultDownloadURLs = new ArrayList<URL>(); |
84 |
|
85 |
public String getText(String key) { |
86 |
return Messages.getText(key);
|
87 |
} |
88 |
|
89 |
public void registerMakePluginPackageWizardInstallerCreationWizard( |
90 |
Class<? extends MakePluginPackageWizard> clazz) { |
91 |
ExtensionPoint extensionPoint = extensionPoints.add( |
92 |
SWING_INSTALLER_MANAGER_EXTENSION_POINT, "");
|
93 |
extensionPoint.append(CREATE_INSTALLER_WIZARD_NAME, "", clazz);
|
94 |
} |
95 |
|
96 |
public void registerInstallPackageWizard( |
97 |
Class<? extends AbstractInstallPackageWizard> clazz) { |
98 |
ExtensionPoint extensionPoint = extensionPoints.add( |
99 |
SWING_INSTALLER_MANAGER_EXTENSION_POINT, "");
|
100 |
extensionPoint.append(EXECUTE_INSTALLER_WIZARD_NAME, "", clazz);
|
101 |
} |
102 |
|
103 |
public String getApplicationVersion() { |
104 |
return applicationVersion;
|
105 |
} |
106 |
|
107 |
public void setApplicationVersion(String gvSIGVersion) { |
108 |
this.applicationVersion = gvSIGVersion;
|
109 |
} |
110 |
|
111 |
public URL getDefaultDownloadURL() { |
112 |
if (defaultDownloadURLs.size() < 1) { |
113 |
return null; |
114 |
} |
115 |
return defaultDownloadURLs.get(0); |
116 |
} |
117 |
|
118 |
public void setDefaultDownloadURL(String defaultDownloadURLs) { |
119 |
String[] urls = defaultDownloadURLs.split(";"); |
120 |
for (int i = 0; i < urls.length; i++) { |
121 |
try {
|
122 |
this.defaultDownloadURLs.add(new URL(urls[i])); |
123 |
} catch (MalformedURLException e) { |
124 |
logger.info("Malformed URL", e);
|
125 |
} |
126 |
} |
127 |
} |
128 |
|
129 |
public void setDefaultDownloadURL(URL defaultDownloadURL) { |
130 |
this.defaultDownloadURLs.clear();
|
131 |
this.defaultDownloadURLs.add(defaultDownloadURL);
|
132 |
} |
133 |
|
134 |
public void setDefaultDownloadURL(File defaultDownloadURLs) { |
135 |
InputStream is;
|
136 |
try {
|
137 |
is = new FileInputStream(defaultDownloadURLs); |
138 |
} catch (FileNotFoundException e1) { |
139 |
logger.error( |
140 |
"Can't open the file " + defaultDownloadURLs.getName(), e1);
|
141 |
return;
|
142 |
} |
143 |
BufferedReader in = new BufferedReader(new InputStreamReader(is)); |
144 |
String line = null; |
145 |
try {
|
146 |
for (line = in.readLine(); line != null; line = in.readLine()) { |
147 |
try {
|
148 |
this.addDefaultDownloadURL(line);
|
149 |
} catch (MalformedURLException e) { |
150 |
logger.error( |
151 |
"Error creating the default packages download URL pointing to "
|
152 |
+ line, e); |
153 |
} |
154 |
} |
155 |
} catch (IOException e) { |
156 |
logger.error("Error reading the file "
|
157 |
+ defaultDownloadURLs.getName(), e); |
158 |
} |
159 |
} |
160 |
|
161 |
public void addDefaultDownloadURL(URL url) { |
162 |
this.defaultDownloadURLs.add(url);
|
163 |
} |
164 |
|
165 |
public void addDefaultDownloadURL(String url) throws MalformedURLException { |
166 |
Version version = getInstallerManager().createVersion(); |
167 |
String versionFormat = version.getMayor() + "." + version.getMinor() |
168 |
+ "." + version.getRevision();
|
169 |
url = url.replace("$version", versionFormat);
|
170 |
url = url.replace("<%Version%>", versionFormat);
|
171 |
url = url.replace("$build", Integer.toString(version.getBuild())); |
172 |
url = url.replace("<%Build%>", Integer.toString(version.getBuild())); |
173 |
addDefaultDownloadURL(new URL(url)); |
174 |
} |
175 |
|
176 |
public List<URL> getDefaultDownloadURLs() { |
177 |
return this.defaultDownloadURLs; |
178 |
} |
179 |
|
180 |
public InstallerManager getInstallerManager() {
|
181 |
return InstallerLocator.getInstallerManager();
|
182 |
} |
183 |
|
184 |
public JShowPackageStatusAndAskContinuePanel createJShowPackageStatusAndAskContinuePanel(
|
185 |
List<PackageInfo> packages, String message) { |
186 |
return new DefaultJShowPackageStatusAndAskContinuePanel(this, packages, |
187 |
message); |
188 |
} |
189 |
|
190 |
public JShowRequiredPackagesAndAskContinuePanel createJShowRequiredPackagesAndAskContinuePanel(
|
191 |
List<PackageInfo> packages, String message) { |
192 |
return new DefaultJShowRequiredPackagesAndAskContinuePanel(this, |
193 |
packages, message); |
194 |
} |
195 |
|
196 |
public JShowUnresolvedDependenciesAndAskContinuePanel createJShowUnresolvedDependenciesAndAskContinuePanel(
|
197 |
Dependencies dependencies, String message) {
|
198 |
return new DefaultJShowUnresolvedDependenciesAndAskContinuePanel(this, |
199 |
dependencies, message); |
200 |
} |
201 |
|
202 |
public JPackageInfoPanel createPackageInfoPanel() {
|
203 |
return new DefaultPackageInfoPanel(); |
204 |
} |
205 |
|
206 |
public JOutputPanel createOutputPanel() {
|
207 |
return new DefaultOutputPanel(); |
208 |
} |
209 |
|
210 |
public JProgressPanel createProgressPanel() {
|
211 |
return new DefaultProgressPanel(); |
212 |
} |
213 |
|
214 |
public AbstractInstallPackageWizard createInstallPackageWizard(
|
215 |
File applicationDirectory, File installFolder) |
216 |
throws InstallPackageWizardException {
|
217 |
ExtensionPoint ep = extensionPoints |
218 |
.add(SWING_INSTALLER_MANAGER_EXTENSION_POINT); |
219 |
try {
|
220 |
Object[] args = new Object[2]; |
221 |
args[0] = applicationDirectory;
|
222 |
args[1] = installFolder;
|
223 |
return (AbstractInstallPackageWizard) ep.create(
|
224 |
EXECUTE_INSTALLER_WIZARD_NAME, args); |
225 |
|
226 |
} catch (Exception e) { |
227 |
throw new InstallPackageWizardException( |
228 |
"Error creating the wizard", e);
|
229 |
} |
230 |
} |
231 |
|
232 |
public MakePluginPackageWizard createMakePluginPackageWizard(
|
233 |
File applicationDirectory, File installFolder) |
234 |
throws MakePluginPackageWizardException {
|
235 |
ExtensionPoint ep = extensionPoints |
236 |
.add(SWING_INSTALLER_MANAGER_EXTENSION_POINT); |
237 |
try {
|
238 |
Object[] args = new Object[2]; |
239 |
args[0] = applicationDirectory;
|
240 |
args[1] = installFolder;
|
241 |
return (MakePluginPackageWizard) ep.create(
|
242 |
CREATE_INSTALLER_WIZARD_NAME, args); |
243 |
} catch (Exception e) { |
244 |
throw new MakePluginPackageWizardException( |
245 |
"Error creating the wizard", e);
|
246 |
} |
247 |
} |
248 |
|
249 |
} |