svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.installer.app / org.gvsig.installer.app.mainplugin / src / main / java / org / gvsig / installer / app / extension / execution / InstallPackageExtension.java @ 42685
History | View | Annotate | Download (7.51 KB)
1 | 40557 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40557 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | *
|
||
6 | 41916 | jjdelcerro | * This program is free software; you can redistribute it and/or modify it under
|
7 | * the terms of the GNU General Public License as published by the Free Software
|
||
8 | * Foundation; either version 3 of the License, or (at your option) any later
|
||
9 | * version.
|
||
10 | 40557 | jjdelcerro | *
|
11 | 41916 | jjdelcerro | * This program is distributed in the hope that it will be useful, but WITHOUT
|
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||
13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||
14 | * details.
|
||
15 | 40557 | jjdelcerro | *
|
16 | 41916 | jjdelcerro | * You should have received a copy of the GNU General Public License along with
|
17 | * this program; if not, write to the Free Software Foundation, Inc., 51
|
||
18 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
19 | 40557 | jjdelcerro | *
|
20 | 41916 | jjdelcerro | * For any additional information, do not hesitate to contact us at info AT
|
21 | * gvsig.com, or visit our website www.gvsig.com.
|
||
22 | 40435 | jjdelcerro | */
|
23 | /*
|
||
24 | * AUTHORS (In addition to CIT):
|
||
25 | * 2010 {Prodevelop} {Task}
|
||
26 | */
|
||
27 | package org.gvsig.installer.app.extension.execution; |
||
28 | |||
29 | import java.io.BufferedReader; |
||
30 | 41916 | jjdelcerro | import java.io.File; |
31 | import java.io.IOException; |
||
32 | 40435 | jjdelcerro | import java.io.InputStream; |
33 | import java.io.InputStreamReader; |
||
34 | import java.net.MalformedURLException; |
||
35 | |||
36 | import org.gvsig.andami.IconThemeHelper; |
||
37 | import org.gvsig.andami.PluginServices; |
||
38 | import org.gvsig.andami.PluginsLocator; |
||
39 | import org.gvsig.andami.PluginsManager; |
||
40 | import org.gvsig.andami.plugins.Extension; |
||
41 | import org.gvsig.installer.lib.api.InstallerLocator; |
||
42 | import org.gvsig.installer.lib.api.InstallerManager; |
||
43 | import org.gvsig.installer.lib.api.PackageInfo; |
||
44 | 40893 | jjdelcerro | import org.gvsig.installer.lib.api.Version; |
45 | 40435 | jjdelcerro | import org.gvsig.installer.swing.api.SwingInstallerLocator; |
46 | import org.gvsig.installer.swing.api.SwingInstallerManager; |
||
47 | import org.slf4j.Logger; |
||
48 | import org.slf4j.LoggerFactory; |
||
49 | |||
50 | /**
|
||
51 | * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
||
52 | */
|
||
53 | public class InstallPackageExtension extends Extension { |
||
54 | |||
55 | 41916 | jjdelcerro | private static final Logger logger = LoggerFactory |
56 | 41620 | jjdelcerro | .getLogger(InstallPackageExtension.class); |
57 | 40435 | jjdelcerro | |
58 | 41620 | jjdelcerro | public void execute(String actionCommand) { |
59 | this.execute(actionCommand, null); |
||
60 | } |
||
61 | 41916 | jjdelcerro | |
62 | 41620 | jjdelcerro | public void execute(String actionCommand, Object[] args) { |
63 | 41916 | jjdelcerro | |
64 | if ("tools-addonsmanager".equalsIgnoreCase(actionCommand)) { |
||
65 | // InstallerManager installManager = InstallerLocator.getInstallerManager();
|
||
66 | // if (installManager.needAdminRights()) {
|
||
67 | // showExternalAddonsManager();
|
||
68 | // } else {
|
||
69 | showInternalAddonsManager(args); |
||
70 | // }
|
||
71 | } |
||
72 | } |
||
73 | |||
74 | private void showExternalAddonsManager() { |
||
75 | InstallerManager installManager = InstallerLocator.getInstallerManager(); |
||
76 | |||
77 | PluginsManager pluginManager = PluginsLocator.getManager(); |
||
78 | |||
79 | String cmd = null; |
||
80 | boolean useInternalAddonsManager = false; |
||
81 | |||
82 | if( InstallerManager.OS.WINDOWS.equalsIgnoreCase(installManager.getOperatingSystem()) ) {
|
||
83 | cmd = "runas /noprofile /user:Administrator " + pluginManager.getApplicationFolder() + File.separator + "gvsig-package-installer.exe --install"; |
||
84 | try {
|
||
85 | Process p = Runtime.getRuntime().exec(cmd); |
||
86 | if( p.exitValue() != 0 ) { |
||
87 | useInternalAddonsManager = true;
|
||
88 | 41620 | jjdelcerro | } |
89 | 41916 | jjdelcerro | } catch (IOException ex) { |
90 | logger.warn("Can't execute command '"+cmd+"'.",ex); |
||
91 | useInternalAddonsManager = true;
|
||
92 | 41620 | jjdelcerro | } |
93 | 41916 | jjdelcerro | } else {
|
94 | cmd = "pkexec " + pluginManager.getApplicationFolder() + File.separator + "/gvSIG.sh --install"; |
||
95 | 41620 | jjdelcerro | try {
|
96 | 41916 | jjdelcerro | Process p = Runtime.getRuntime().exec(cmd); |
97 | if( p.exitValue() != 0 ) { |
||
98 | useInternalAddonsManager = true;
|
||
99 | } |
||
100 | } catch (IOException ex) { |
||
101 | logger.warn("Can't execute command '"+cmd+"'.",ex); |
||
102 | useInternalAddonsManager = true;
|
||
103 | 41620 | jjdelcerro | } |
104 | 40893 | jjdelcerro | } |
105 | 41916 | jjdelcerro | if( useInternalAddonsManager ) {
|
106 | logger.warn("Use internal addons manager.");
|
||
107 | showInternalAddonsManager(null);
|
||
108 | } |
||
109 | 41620 | jjdelcerro | } |
110 | 41916 | jjdelcerro | |
111 | |||
112 | private void showInternalAddonsManager(Object[] args) { |
||
113 | boolean skipBundleSelection = false; |
||
114 | if (args != null && args.length > 0) { |
||
115 | String subcmd = (String) args[0]; |
||
116 | if ("skipBundleSelection".equalsIgnoreCase(subcmd)) { |
||
117 | skipBundleSelection = true;
|
||
118 | } |
||
119 | } |
||
120 | PluginsManager manager = PluginsLocator.getManager(); |
||
121 | try {
|
||
122 | PluginServices.getMDIManager().addCentredWindow( |
||
123 | new InstallPackageWindow(
|
||
124 | manager.getApplicationFolder(), |
||
125 | manager.getInstallFolder(), |
||
126 | skipBundleSelection |
||
127 | ) |
||
128 | ); |
||
129 | } catch (Error e) { |
||
130 | logger.error("Error creating the wizard to install a package ", e);
|
||
131 | } catch (Exception e) { |
||
132 | logger.error("Error creating the wizard to install a package ", e);
|
||
133 | } |
||
134 | 40435 | jjdelcerro | |
135 | 41916 | jjdelcerro | } |
136 | |||
137 | 41620 | jjdelcerro | public void initialize() { |
138 | PluginsManager pm = PluginsLocator.getManager(); |
||
139 | PackageInfo packageInfo = pm.getPackageInfo(); |
||
140 | Version version = packageInfo.getVersion(); |
||
141 | 40435 | jjdelcerro | |
142 | 41620 | jjdelcerro | InstallerLocator.getInstallerManager().setVersion(version); |
143 | try {
|
||
144 | IconThemeHelper.registerIcon("action", "tools-addonsmanager", this); |
||
145 | 40435 | jjdelcerro | |
146 | 41620 | jjdelcerro | SwingInstallerManager manager = SwingInstallerLocator |
147 | .getSwingInstallerManager(); |
||
148 | 40435 | jjdelcerro | |
149 | 41620 | jjdelcerro | try {
|
150 | 42685 | jjdelcerro | manager.setDefaultDownloadURL( |
151 | new File( pm.getApplicationFolder(),"gvsig-installer-urls.config") |
||
152 | ); |
||
153 | manager.setDefaultDownloadURL( |
||
154 | new File( pm.getPlugin(this).getPluginDirectory(),"defaultDownloadsURLs") |
||
155 | ); |
||
156 | 41916 | jjdelcerro | if (packageInfo != null && (packageInfo.getState().startsWith(InstallerManager.STATE.BETA) |
157 | 41620 | jjdelcerro | || packageInfo.getState().startsWith(InstallerManager.STATE.RC) |
158 | 41916 | jjdelcerro | || packageInfo.getState().equalsIgnoreCase(InstallerManager.STATE.FINAL))) { |
159 | 40435 | jjdelcerro | |
160 | 41620 | jjdelcerro | String installURL = manager.getInstallerManager().getDownloadBaseURL().toString()
|
161 | + "dists/<%Version%>/builds/<%Build%>/packages.gvspki ## Official gvSIG repository (frozen in this version)";
|
||
162 | manager.addDefaultDownloadURL(installURL); |
||
163 | } |
||
164 | } catch (Throwable th) { |
||
165 | 41916 | jjdelcerro | logger.info("Error. Can't select default gvspki", th);
|
166 | 41620 | jjdelcerro | } |
167 | |||
168 | InputStream is = this.getClass().getResourceAsStream( |
||
169 | "/defaultDownloadsURLs");
|
||
170 | BufferedReader in = new BufferedReader(new InputStreamReader(is)); |
||
171 | String line = null; |
||
172 | 41916 | jjdelcerro | for (line = in.readLine(); line != null; line = in.readLine()) { |
173 | 41620 | jjdelcerro | try {
|
174 | manager.addDefaultDownloadURL(line); |
||
175 | } catch (MalformedURLException e) { |
||
176 | 41916 | jjdelcerro | logger.error( |
177 | 41620 | jjdelcerro | "Error creating the default packages download URL pointing to "
|
178 | + line, e); |
||
179 | } |
||
180 | } |
||
181 | manager.getInstallerManager().setVersion(version); |
||
182 | } catch (Throwable e) { |
||
183 | 41916 | jjdelcerro | logger.error("Error reading the default packages download URL file "
|
184 | 41620 | jjdelcerro | + "/defaultDownloadsURLs", e);
|
185 | } |
||
186 | } |
||
187 | |||
188 | public boolean isEnabled() { |
||
189 | return true; |
||
190 | } |
||
191 | |||
192 | public boolean isVisible() { |
||
193 | return true; |
||
194 | } |
||
195 | |||
196 | 40435 | jjdelcerro | } |