svn-gvsig-desktop / tags / v2_0_0_Build_2052 / extensions / org.gvsig.installer.app / org.gvsig.installer.app.extension / src / main / java / org / gvsig / installer / app / extension / execution / InstallPackageExtension.java @ 38855
History | View | Annotate | Download (4.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.app.extension.execution; |
29 |
|
30 |
import java.io.BufferedReader; |
31 |
import java.io.InputStream; |
32 |
import java.io.InputStreamReader; |
33 |
import java.net.MalformedURLException; |
34 |
|
35 |
import org.gvsig.andami.IconThemeHelper; |
36 |
import org.gvsig.andami.PluginServices; |
37 |
import org.gvsig.andami.PluginsLocator; |
38 |
import org.gvsig.andami.PluginsManager; |
39 |
import org.gvsig.andami.plugins.Extension; |
40 |
import org.gvsig.app.ApplicationLocator; |
41 |
import org.gvsig.app.ApplicationManager; |
42 |
import org.gvsig.app.extension.InitializeApplicationExtension; |
43 |
import org.gvsig.app.extension.Version; |
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.swing.api.SwingInstallerLocator; |
48 |
import org.gvsig.installer.swing.api.SwingInstallerManager; |
49 |
|
50 |
import org.slf4j.Logger; |
51 |
import org.slf4j.LoggerFactory; |
52 |
|
53 |
/**
|
54 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
55 |
*/
|
56 |
public class InstallPackageExtension extends Extension { |
57 |
|
58 |
private static final Logger LOG = LoggerFactory |
59 |
.getLogger(InstallPackageExtension.class); |
60 |
|
61 |
public void execute(String actionCommand) { |
62 |
if ("tools-addonsmanager".equalsIgnoreCase(actionCommand)) { |
63 |
PluginsManager manager = PluginsLocator.getManager(); |
64 |
try {
|
65 |
PluginServices.getMDIManager().addCentredWindow( |
66 |
new InstallPackageWindow(
|
67 |
manager.getApplicationFolder(), manager |
68 |
.getInstallFolder())); |
69 |
} catch (Error e) { |
70 |
LOG.error("Error creating the wizard to install a package ", e);
|
71 |
} catch (Exception e) { |
72 |
LOG.error("Error creating the wizard to install a package ", e);
|
73 |
} |
74 |
} |
75 |
} |
76 |
|
77 |
public void initialize() { |
78 |
ApplicationManager application = ApplicationLocator.getManager(); |
79 |
Version version = application.getVersion(); |
80 |
|
81 |
InstallerLocator.getInstallerManager().setVersion(version.asInstallerVersion()); |
82 |
try {
|
83 |
IconThemeHelper.registerIcon("action", "tools-addonsmanager", this); |
84 |
|
85 |
SwingInstallerManager manager = SwingInstallerLocator |
86 |
.getSwingInstallerManager(); |
87 |
|
88 |
try {
|
89 |
PluginsManager pm = PluginsLocator.getManager(); |
90 |
PackageInfo packageInfo = pm.getPackageInfo(InitializeApplicationExtension.class); |
91 |
|
92 |
if( packageInfo!=null && (packageInfo.getState().startsWith(InstallerManager.STATE.BETA) || |
93 |
packageInfo.getState().startsWith(InstallerManager.STATE.RC) || |
94 |
packageInfo.getState().equalsIgnoreCase(InstallerManager.STATE.FINAL)) ) { |
95 |
|
96 |
String installURL = manager.getInstallerManager().getDownloadBaseURL().toString()
|
97 |
+ "dists/<%Version%>/builds/<%Build%>/packages.gvspki";
|
98 |
manager.addDefaultDownloadURL(installURL); |
99 |
} |
100 |
} catch (Throwable th) { |
101 |
LOG.info("Error. Can't select default gvspki", th);
|
102 |
} |
103 |
|
104 |
InputStream is = this.getClass().getResourceAsStream( |
105 |
"/defaultDownloadsURLs");
|
106 |
BufferedReader in = new BufferedReader(new InputStreamReader(is)); |
107 |
String line = null; |
108 |
for (line = in.readLine(); line != null; line = in.readLine()) { |
109 |
try {
|
110 |
manager.addDefaultDownloadURL(line); |
111 |
} catch (MalformedURLException e) { |
112 |
LOG.error( |
113 |
"Error creating the default packages download URL pointing to "
|
114 |
+ line, e); |
115 |
} |
116 |
} |
117 |
manager.getInstallerManager().setVersion(version.getFormat()); |
118 |
} catch (Throwable e) { |
119 |
LOG.error("Error reading the default packages download URL file "
|
120 |
+ "/defaultDownloadsURLs", e);
|
121 |
} |
122 |
} |
123 |
|
124 |
public boolean isEnabled() { |
125 |
return true; |
126 |
} |
127 |
|
128 |
public boolean isVisible() { |
129 |
return true; |
130 |
} |
131 |
|
132 |
} |