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 @ 40581
History | View | Annotate | Download (14.6 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 | 40581 | jjdelcerro | import java.util.Collection; |
42 | import java.util.Iterator; |
||
43 | 40435 | jjdelcerro | import java.util.List; |
44 | 40581 | jjdelcerro | import java.util.ListIterator; |
45 | 40435 | jjdelcerro | |
46 | import org.gvsig.i18n.Messages; |
||
47 | import org.gvsig.installer.lib.api.Dependencies; |
||
48 | import org.gvsig.installer.lib.api.InstallerLocator; |
||
49 | import org.gvsig.installer.lib.api.InstallerManager; |
||
50 | import org.gvsig.installer.lib.api.PackageInfo; |
||
51 | import org.gvsig.installer.lib.api.Version; |
||
52 | import org.gvsig.installer.swing.api.JProgressPanel; |
||
53 | import org.gvsig.installer.swing.api.SwingInstallerManager; |
||
54 | import org.gvsig.installer.swing.api.creation.JOutputPanel; |
||
55 | import org.gvsig.installer.swing.api.creation.JPackageInfoPanel; |
||
56 | import org.gvsig.installer.swing.api.creation.MakePluginPackageWizard; |
||
57 | import org.gvsig.installer.swing.api.creation.MakePluginPackageWizardException; |
||
58 | import org.gvsig.installer.swing.api.execution.AbstractInstallPackageWizard; |
||
59 | import org.gvsig.installer.swing.api.execution.InstallPackageWizardException; |
||
60 | import org.gvsig.installer.swing.api.execution.JShowPackageStatusAndAskContinuePanel; |
||
61 | import org.gvsig.installer.swing.api.execution.JShowRequiredPackagesAndAskContinuePanel; |
||
62 | import org.gvsig.installer.swing.api.execution.JShowUnresolvedDependenciesAndAskContinuePanel; |
||
63 | import org.gvsig.installer.swing.impl.creation.panel.DefaultOutputPanel; |
||
64 | import org.gvsig.installer.swing.impl.creation.panel.DefaultPackageInfoPanel; |
||
65 | import org.gvsig.installer.swing.impl.panel.DefaultProgressPanel; |
||
66 | import org.gvsig.tools.ToolsLocator; |
||
67 | import org.gvsig.tools.extensionpoint.ExtensionPoint; |
||
68 | import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
||
69 | import org.slf4j.Logger; |
||
70 | import org.slf4j.LoggerFactory; |
||
71 | |||
72 | /**
|
||
73 | * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
||
74 | */
|
||
75 | public class DefaultSwingInstallerManager implements SwingInstallerManager { |
||
76 | |||
77 | 40581 | jjdelcerro | public class DefaultUrlAndLabel implements UrlAndLabel { |
78 | |||
79 | private URL url; |
||
80 | private String label; |
||
81 | |||
82 | public DefaultUrlAndLabel(URL url, String label) { |
||
83 | this.url = url;
|
||
84 | this.label = label;
|
||
85 | } |
||
86 | public URL getURL() { |
||
87 | return this.url; |
||
88 | } |
||
89 | |||
90 | public String getLabel() { |
||
91 | return this.label; |
||
92 | } |
||
93 | |||
94 | public void setLabel(String label) { |
||
95 | this.label = label;
|
||
96 | } |
||
97 | @Override
|
||
98 | public String toString() { |
||
99 | if( label == null ) { |
||
100 | return this.url.toString(); |
||
101 | } |
||
102 | return this.label + " - " + this.url.toString(); |
||
103 | } |
||
104 | } |
||
105 | |||
106 | /**
|
||
107 | *
|
||
108 | * This class is for compatibility with deprecated method
|
||
109 | * List<URL> getDefaultDownloadURLs()
|
||
110 | *
|
||
111 | * @author jjdelcerro
|
||
112 | *
|
||
113 | */
|
||
114 | public class DefaultDownloadURLsIterator<URL> implements ListIterator<URL> { |
||
115 | private List<UrlAndLabel> urlAndLabels; |
||
116 | private ListIterator<UrlAndLabel> it; |
||
117 | |||
118 | DefaultDownloadURLsIterator(List<UrlAndLabel> urlAndLabels, int index) { |
||
119 | this.urlAndLabels = urlAndLabels;
|
||
120 | this.it = this.urlAndLabels.listIterator(index); |
||
121 | } |
||
122 | |||
123 | DefaultDownloadURLsIterator(List<UrlAndLabel> urlAndLabels) {
|
||
124 | this.urlAndLabels = urlAndLabels;
|
||
125 | this.it = this.urlAndLabels.listIterator(); |
||
126 | } |
||
127 | |||
128 | public boolean hasNext() { |
||
129 | return this.it.hasNext(); |
||
130 | } |
||
131 | |||
132 | public URL next() { |
||
133 | UrlAndLabel value = this.it.next();
|
||
134 | if( value == null ) { |
||
135 | return null; |
||
136 | } |
||
137 | return (URL) value.getURL(); |
||
138 | } |
||
139 | |||
140 | public boolean hasPrevious() { |
||
141 | return it.hasPrevious();
|
||
142 | } |
||
143 | |||
144 | public int nextIndex() { |
||
145 | return it.nextIndex();
|
||
146 | } |
||
147 | |||
148 | public URL previous() { |
||
149 | UrlAndLabel value = this.it.previous();
|
||
150 | if( value == null ) { |
||
151 | return null; |
||
152 | } |
||
153 | return (URL) value.getURL(); |
||
154 | } |
||
155 | |||
156 | public int previousIndex() { |
||
157 | return it.previousIndex();
|
||
158 | } |
||
159 | |||
160 | public void remove() { |
||
161 | throw new UnsupportedOperationException("This is read-only"); |
||
162 | } |
||
163 | |||
164 | public void add(Object arg0) { |
||
165 | throw new UnsupportedOperationException("This is read-only"); |
||
166 | } |
||
167 | |||
168 | public void set(Object arg0) { |
||
169 | throw new UnsupportedOperationException("This is read-only"); |
||
170 | } |
||
171 | } |
||
172 | |||
173 | /**
|
||
174 | *
|
||
175 | * This class is for compatibility with deprecated method
|
||
176 | * List<URL> getDefaultDownloadURLs()
|
||
177 | *
|
||
178 | * @author jjdelcerro
|
||
179 | *
|
||
180 | */
|
||
181 | public class DefaultDownloadURLs<URL> implements List<URL> { |
||
182 | |||
183 | private List<UrlAndLabel> urlAndLabels; |
||
184 | |||
185 | DefaultDownloadURLs(List<UrlAndLabel> urlAndLabels) {
|
||
186 | this.urlAndLabels = urlAndLabels;
|
||
187 | } |
||
188 | |||
189 | public boolean add(Object url) { |
||
190 | throw new UnsupportedOperationException("This is a read-only list"); |
||
191 | } |
||
192 | |||
193 | public void add(int arg0, Object url) { |
||
194 | throw new UnsupportedOperationException("This is a read-only list"); |
||
195 | } |
||
196 | |||
197 | public boolean addAll(Collection arg0) { |
||
198 | throw new UnsupportedOperationException("This is a read-only list"); |
||
199 | } |
||
200 | |||
201 | public boolean addAll(int arg0, Collection arg1) { |
||
202 | throw new UnsupportedOperationException("This is a read-only list"); |
||
203 | } |
||
204 | |||
205 | public void clear() { |
||
206 | throw new UnsupportedOperationException("This is a read-only list"); |
||
207 | } |
||
208 | |||
209 | public boolean contains(Object arg0) { |
||
210 | Iterator<UrlAndLabel> it = this.urlAndLabels.iterator(); |
||
211 | while( it.hasNext() ) {
|
||
212 | UrlAndLabel x = it.next(); |
||
213 | if( x.getURL().equals(arg0) ) {
|
||
214 | return true; |
||
215 | } |
||
216 | } |
||
217 | return false; |
||
218 | } |
||
219 | |||
220 | public boolean containsAll(Collection arg0) { |
||
221 | throw new UnsupportedOperationException("This method is not supported"); |
||
222 | } |
||
223 | |||
224 | public URL get(int arg0) { |
||
225 | return (URL) this.urlAndLabels.get(arg0).getURL(); |
||
226 | } |
||
227 | |||
228 | public int indexOf(Object arg0) { |
||
229 | for( int i=0; i<this.urlAndLabels.size(); i++) { |
||
230 | if( this.urlAndLabels.get(i).getURL().equals(arg0) ) { |
||
231 | return i;
|
||
232 | } |
||
233 | } |
||
234 | return -1; |
||
235 | } |
||
236 | |||
237 | public boolean isEmpty() { |
||
238 | return this.urlAndLabels.isEmpty(); |
||
239 | } |
||
240 | |||
241 | public Iterator iterator() { |
||
242 | return new DefaultDownloadURLsIterator(this.urlAndLabels); |
||
243 | } |
||
244 | |||
245 | public int lastIndexOf(Object arg0) { |
||
246 | for( int i=this.urlAndLabels.size()-1; i>=0; i--) { |
||
247 | if( this.urlAndLabels.get(i).getURL().equals(arg0) ) { |
||
248 | return i;
|
||
249 | } |
||
250 | } |
||
251 | return -1; |
||
252 | } |
||
253 | |||
254 | public ListIterator listIterator() { |
||
255 | return new DefaultDownloadURLsIterator(this.urlAndLabels); |
||
256 | } |
||
257 | |||
258 | public ListIterator listIterator(int arg0) { |
||
259 | return new DefaultDownloadURLsIterator(this.urlAndLabels, arg0); |
||
260 | } |
||
261 | |||
262 | public boolean remove(Object arg0) { |
||
263 | throw new UnsupportedOperationException("This is a read-only list"); |
||
264 | } |
||
265 | |||
266 | public URL remove(int arg0) { |
||
267 | throw new UnsupportedOperationException("This is a read-only list"); |
||
268 | } |
||
269 | |||
270 | public boolean removeAll(Collection arg0) { |
||
271 | throw new UnsupportedOperationException("This is a read-only list"); |
||
272 | } |
||
273 | |||
274 | public boolean retainAll(Collection arg0) { |
||
275 | throw new UnsupportedOperationException("This is a read-only list"); |
||
276 | } |
||
277 | |||
278 | public Object set(int arg0, Object arg1) { |
||
279 | throw new UnsupportedOperationException("This is a read-only list"); |
||
280 | } |
||
281 | |||
282 | public int size() { |
||
283 | return this.urlAndLabels.size(); |
||
284 | } |
||
285 | |||
286 | public List subList(int arg0, int arg1) { |
||
287 | throw new UnsupportedOperationException("This method is not supported"); |
||
288 | } |
||
289 | |||
290 | public Object[] toArray() { |
||
291 | throw new UnsupportedOperationException("This method is not supported"); |
||
292 | } |
||
293 | |||
294 | public Object[] toArray(Object[] arg0) { |
||
295 | throw new UnsupportedOperationException("This method is not supported"); |
||
296 | } |
||
297 | |||
298 | } |
||
299 | |||
300 | 40435 | jjdelcerro | private static Logger logger = LoggerFactory |
301 | .getLogger(DefaultSwingInstallerManager.class); |
||
302 | |||
303 | private static final String SWING_INSTALLER_MANAGER_EXTENSION_POINT = "SwingInstallerManagerExtensionPoint"; |
||
304 | private static final String CREATE_INSTALLER_WIZARD_NAME = "CreateInstallerWizard"; |
||
305 | private static final String EXECUTE_INSTALLER_WIZARD_NAME = "ExecuteInstallerWizard"; |
||
306 | private ExtensionPointManager extensionPoints = ToolsLocator
|
||
307 | .getExtensionPointManager(); |
||
308 | |||
309 | private String applicationVersion = "1.0.0"; |
||
310 | 40581 | jjdelcerro | private List<UrlAndLabel> defaultDownloadURLs = new ArrayList<UrlAndLabel>(); |
311 | 40435 | jjdelcerro | |
312 | public String getText(String key) { |
||
313 | return Messages.getText(key);
|
||
314 | } |
||
315 | |||
316 | public void registerMakePluginPackageWizardInstallerCreationWizard( |
||
317 | Class<? extends MakePluginPackageWizard> clazz) { |
||
318 | ExtensionPoint extensionPoint = extensionPoints.add( |
||
319 | SWING_INSTALLER_MANAGER_EXTENSION_POINT, "");
|
||
320 | extensionPoint.append(CREATE_INSTALLER_WIZARD_NAME, "", clazz);
|
||
321 | } |
||
322 | |||
323 | public void registerInstallPackageWizard( |
||
324 | Class<? extends AbstractInstallPackageWizard> clazz) { |
||
325 | ExtensionPoint extensionPoint = extensionPoints.add( |
||
326 | SWING_INSTALLER_MANAGER_EXTENSION_POINT, "");
|
||
327 | extensionPoint.append(EXECUTE_INSTALLER_WIZARD_NAME, "", clazz);
|
||
328 | } |
||
329 | |||
330 | public String getApplicationVersion() { |
||
331 | return applicationVersion;
|
||
332 | } |
||
333 | |||
334 | public void setApplicationVersion(String gvSIGVersion) { |
||
335 | this.applicationVersion = gvSIGVersion;
|
||
336 | } |
||
337 | |||
338 | public URL getDefaultDownloadURL() { |
||
339 | if (defaultDownloadURLs.size() < 1) { |
||
340 | return null; |
||
341 | } |
||
342 | 40581 | jjdelcerro | return defaultDownloadURLs.get(0).getURL(); |
343 | 40435 | jjdelcerro | } |
344 | |||
345 | 40581 | jjdelcerro | public List<URL> getDefaultDownloadURLs() { |
346 | return new DefaultDownloadURLs(this.defaultDownloadURLs); |
||
347 | } |
||
348 | |||
349 | public List<UrlAndLabel> getDefaultDownloadUrlAndLabels() { |
||
350 | return this.defaultDownloadURLs; |
||
351 | } |
||
352 | |||
353 | 40435 | jjdelcerro | public void setDefaultDownloadURL(String defaultDownloadURLs) { |
354 | String[] urls = defaultDownloadURLs.split(";"); |
||
355 | for (int i = 0; i < urls.length; i++) { |
||
356 | try {
|
||
357 | this.addDefaultDownloadURL(urls[i]);
|
||
358 | } catch (MalformedURLException e) { |
||
359 | logger.info("Malformed URL ("+urls[i]+").", e); |
||
360 | } |
||
361 | } |
||
362 | } |
||
363 | |||
364 | public void setDefaultDownloadURL(URL defaultDownloadURL) { |
||
365 | this.defaultDownloadURLs.clear();
|
||
366 | this.addDefaultDownloadURL(defaultDownloadURL);
|
||
367 | } |
||
368 | |||
369 | public void setDefaultDownloadURL(File defaultDownloadURLs) { |
||
370 | InputStream is;
|
||
371 | try {
|
||
372 | is = new FileInputStream(defaultDownloadURLs); |
||
373 | } catch (FileNotFoundException e1) { |
||
374 | logger.error( |
||
375 | "Can't open the file " + defaultDownloadURLs.getName(), e1);
|
||
376 | return;
|
||
377 | } |
||
378 | BufferedReader in = new BufferedReader(new InputStreamReader(is)); |
||
379 | String line = null; |
||
380 | try {
|
||
381 | for (line = in.readLine(); line != null; line = in.readLine()) { |
||
382 | try {
|
||
383 | this.addDefaultDownloadURL(line);
|
||
384 | } catch (MalformedURLException e) { |
||
385 | logger.error( |
||
386 | "Error creating the default packages download URL pointing to "
|
||
387 | + line, e); |
||
388 | } |
||
389 | } |
||
390 | } catch (IOException e) { |
||
391 | logger.error("Error reading the file "
|
||
392 | + defaultDownloadURLs.getName(), e); |
||
393 | } |
||
394 | } |
||
395 | |||
396 | public void addDefaultDownloadURL(URL url) { |
||
397 | 40581 | jjdelcerro | addDefaultDownloadURL(url,null);
|
398 | } |
||
399 | |||
400 | public void addDefaultDownloadURL(URL url, String label) { |
||
401 | Iterator<UrlAndLabel> it = this.defaultDownloadURLs.iterator(); |
||
402 | while( it.hasNext() ) {
|
||
403 | DefaultUrlAndLabel value = (DefaultUrlAndLabel) it.next(); |
||
404 | if( value.getURL().equals(url) ) {
|
||
405 | if( value.getLabel() == null ) { |
||
406 | value.setLabel(label); |
||
407 | } |
||
408 | // Already exists the url, don't duplicate.
|
||
409 | return;
|
||
410 | } |
||
411 | 40435 | jjdelcerro | } |
412 | 40581 | jjdelcerro | this.defaultDownloadURLs.add( new DefaultUrlAndLabel(url, label)); |
413 | 40435 | jjdelcerro | } |
414 | |||
415 | public void addDefaultDownloadURL(String url) throws MalformedURLException { |
||
416 | 40581 | jjdelcerro | String label = null; |
417 | |||
418 | if( url.startsWith("#") ) { |
||
419 | return;
|
||
420 | } |
||
421 | 40435 | jjdelcerro | Version version = getInstallerManager().createVersion(); |
422 | String versionFormat = version.getMajor() + "." + version.getMinor() |
||
423 | + "." + version.getRevision();
|
||
424 | 40581 | jjdelcerro | int n = url.indexOf("##"); |
425 | if( n>0 ) { |
||
426 | label = url.substring(n+2);
|
||
427 | url = url.substring(0, n-1); |
||
428 | } |
||
429 | 40435 | jjdelcerro | url = url.replace("$version", versionFormat);
|
430 | url = url.replace("<%Version%>", versionFormat);
|
||
431 | url = url.replace("$build", Integer.toString(version.getBuild())); |
||
432 | url = url.replace("<%Build%>", Integer.toString(version.getBuild())); |
||
433 | 40581 | jjdelcerro | addDefaultDownloadURL(new URL(url), label); |
434 | 40435 | jjdelcerro | } |
435 | |||
436 | public InstallerManager getInstallerManager() {
|
||
437 | return InstallerLocator.getInstallerManager();
|
||
438 | } |
||
439 | |||
440 | public JShowPackageStatusAndAskContinuePanel createJShowPackageStatusAndAskContinuePanel(
|
||
441 | List<PackageInfo> packages, String message) { |
||
442 | return new DefaultJShowPackageStatusAndAskContinuePanel(this, packages, |
||
443 | message); |
||
444 | } |
||
445 | |||
446 | public JShowRequiredPackagesAndAskContinuePanel createJShowRequiredPackagesAndAskContinuePanel(
|
||
447 | List<PackageInfo> packages, String message) { |
||
448 | return new DefaultJShowRequiredPackagesAndAskContinuePanel(this, |
||
449 | packages, message); |
||
450 | } |
||
451 | |||
452 | public JShowUnresolvedDependenciesAndAskContinuePanel createJShowUnresolvedDependenciesAndAskContinuePanel(
|
||
453 | Dependencies dependencies, String message) {
|
||
454 | return new DefaultJShowUnresolvedDependenciesAndAskContinuePanel(this, |
||
455 | dependencies, message); |
||
456 | } |
||
457 | |||
458 | public JPackageInfoPanel createPackageInfoPanel() {
|
||
459 | return new DefaultPackageInfoPanel(); |
||
460 | } |
||
461 | |||
462 | public JOutputPanel createOutputPanel() {
|
||
463 | return new DefaultOutputPanel(); |
||
464 | } |
||
465 | |||
466 | public JProgressPanel createProgressPanel() {
|
||
467 | return new DefaultProgressPanel(); |
||
468 | } |
||
469 | |||
470 | public AbstractInstallPackageWizard createInstallPackageWizard(
|
||
471 | File applicationDirectory, File installFolder) |
||
472 | throws InstallPackageWizardException {
|
||
473 | ExtensionPoint ep = extensionPoints |
||
474 | .add(SWING_INSTALLER_MANAGER_EXTENSION_POINT); |
||
475 | try {
|
||
476 | Object[] args = new Object[2]; |
||
477 | args[0] = applicationDirectory;
|
||
478 | args[1] = installFolder;
|
||
479 | return (AbstractInstallPackageWizard) ep.create(
|
||
480 | EXECUTE_INSTALLER_WIZARD_NAME, args); |
||
481 | |||
482 | } catch (Exception e) { |
||
483 | throw new InstallPackageWizardException( |
||
484 | "Error creating the wizard", e);
|
||
485 | } |
||
486 | } |
||
487 | |||
488 | public MakePluginPackageWizard createMakePluginPackageWizard(
|
||
489 | File applicationDirectory, File installFolder) |
||
490 | throws MakePluginPackageWizardException {
|
||
491 | ExtensionPoint ep = extensionPoints |
||
492 | .add(SWING_INSTALLER_MANAGER_EXTENSION_POINT); |
||
493 | try {
|
||
494 | Object[] args = new Object[2]; |
||
495 | args[0] = applicationDirectory;
|
||
496 | args[1] = installFolder;
|
||
497 | return (MakePluginPackageWizard) ep.create(
|
||
498 | CREATE_INSTALLER_WIZARD_NAME, args); |
||
499 | } catch (Exception e) { |
||
500 | throw new MakePluginPackageWizardException( |
||
501 | "Error creating the wizard", e);
|
||
502 | } |
||
503 | } |
||
504 | |||
505 | } |