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