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 @ 43126
History | View | Annotate | Download (7.47 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 | public class InstallPackageExtension extends Extension { |
||
51 | |||
52 | 41916 | jjdelcerro | private static final Logger logger = LoggerFactory |
53 | 41620 | jjdelcerro | .getLogger(InstallPackageExtension.class); |
54 | 40435 | jjdelcerro | |
55 | 43126 | jjdelcerro | @Override
|
56 | 41620 | jjdelcerro | public void execute(String actionCommand) { |
57 | this.execute(actionCommand, null); |
||
58 | } |
||
59 | 41916 | jjdelcerro | |
60 | 43126 | jjdelcerro | @Override
|
61 | 41620 | jjdelcerro | public void execute(String actionCommand, Object[] args) { |
62 | 41916 | jjdelcerro | |
63 | if ("tools-addonsmanager".equalsIgnoreCase(actionCommand)) { |
||
64 | // InstallerManager installManager = InstallerLocator.getInstallerManager();
|
||
65 | // if (installManager.needAdminRights()) {
|
||
66 | // showExternalAddonsManager();
|
||
67 | // } else {
|
||
68 | showInternalAddonsManager(args); |
||
69 | // }
|
||
70 | } |
||
71 | } |
||
72 | |||
73 | private void showExternalAddonsManager() { |
||
74 | InstallerManager installManager = InstallerLocator.getInstallerManager(); |
||
75 | |||
76 | PluginsManager pluginManager = PluginsLocator.getManager(); |
||
77 | |||
78 | 43126 | jjdelcerro | String cmd;
|
79 | 41916 | jjdelcerro | boolean useInternalAddonsManager = false; |
80 | |||
81 | if( InstallerManager.OS.WINDOWS.equalsIgnoreCase(installManager.getOperatingSystem()) ) {
|
||
82 | cmd = "runas /noprofile /user:Administrator " + pluginManager.getApplicationFolder() + File.separator + "gvsig-package-installer.exe --install"; |
||
83 | try {
|
||
84 | Process p = Runtime.getRuntime().exec(cmd); |
||
85 | if( p.exitValue() != 0 ) { |
||
86 | useInternalAddonsManager = true;
|
||
87 | 41620 | jjdelcerro | } |
88 | 41916 | jjdelcerro | } catch (IOException ex) { |
89 | logger.warn("Can't execute command '"+cmd+"'.",ex); |
||
90 | useInternalAddonsManager = true;
|
||
91 | 41620 | jjdelcerro | } |
92 | 41916 | jjdelcerro | } else {
|
93 | cmd = "pkexec " + pluginManager.getApplicationFolder() + File.separator + "/gvSIG.sh --install"; |
||
94 | 41620 | jjdelcerro | try {
|
95 | 41916 | jjdelcerro | Process p = Runtime.getRuntime().exec(cmd); |
96 | if( p.exitValue() != 0 ) { |
||
97 | useInternalAddonsManager = true;
|
||
98 | } |
||
99 | } catch (IOException ex) { |
||
100 | logger.warn("Can't execute command '"+cmd+"'.",ex); |
||
101 | useInternalAddonsManager = true;
|
||
102 | 41620 | jjdelcerro | } |
103 | 40893 | jjdelcerro | } |
104 | 41916 | jjdelcerro | if( useInternalAddonsManager ) {
|
105 | logger.warn("Use internal addons manager.");
|
||
106 | showInternalAddonsManager(null);
|
||
107 | } |
||
108 | 41620 | jjdelcerro | } |
109 | 41916 | jjdelcerro | |
110 | |||
111 | private void showInternalAddonsManager(Object[] args) { |
||
112 | boolean skipBundleSelection = false; |
||
113 | if (args != null && args.length > 0) { |
||
114 | String subcmd = (String) args[0]; |
||
115 | if ("skipBundleSelection".equalsIgnoreCase(subcmd)) { |
||
116 | skipBundleSelection = true;
|
||
117 | } |
||
118 | } |
||
119 | PluginsManager manager = PluginsLocator.getManager(); |
||
120 | try {
|
||
121 | PluginServices.getMDIManager().addCentredWindow( |
||
122 | new InstallPackageWindow(
|
||
123 | manager.getApplicationFolder(), |
||
124 | manager.getInstallFolder(), |
||
125 | skipBundleSelection |
||
126 | ) |
||
127 | ); |
||
128 | } catch (Error e) { |
||
129 | 43126 | jjdelcerro | logger.warn("Error creating the wizard to install a package ", e);
|
130 | } catch (Throwable e) { |
||
131 | logger.warn("Error creating the wizard to install a package ", e);
|
||
132 | 41916 | jjdelcerro | } |
133 | 40435 | jjdelcerro | |
134 | 41916 | jjdelcerro | } |
135 | |||
136 | 43126 | jjdelcerro | @Override
|
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 | 43126 | jjdelcerro | if( packageInfo.getState().startsWith(InstallerManager.STATE.BETA) ||
|
157 | packageInfo.getState().startsWith(InstallerManager.STATE.RC) || |
||
158 | packageInfo.getState().equalsIgnoreCase(InstallerManager.STATE.FINAL) |
||
159 | ) { |
||
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 | 43126 | jjdelcerro | InputStream is = this.getClass().getResourceAsStream("/defaultDownloadsURLs"); |
169 | 41620 | jjdelcerro | BufferedReader in = new BufferedReader(new InputStreamReader(is)); |
170 | 43126 | jjdelcerro | for (String line = in.readLine(); line != null; line = in.readLine()) { |
171 | 41620 | jjdelcerro | try {
|
172 | manager.addDefaultDownloadURL(line); |
||
173 | } catch (MalformedURLException e) { |
||
174 | 43126 | jjdelcerro | logger.warn( |
175 | "Error creating the default packages download URL pointing to " + line,
|
||
176 | e |
||
177 | ); |
||
178 | 41620 | jjdelcerro | } |
179 | } |
||
180 | manager.getInstallerManager().setVersion(version); |
||
181 | } catch (Throwable e) { |
||
182 | 43126 | jjdelcerro | logger.warn( |
183 | "Error reading the default packages download URL file /defaultDownloadsURLs",
|
||
184 | e |
||
185 | ); |
||
186 | 41620 | jjdelcerro | } |
187 | } |
||
188 | |||
189 | 43126 | jjdelcerro | @Override
|
190 | 41620 | jjdelcerro | public boolean isEnabled() { |
191 | return true; |
||
192 | } |
||
193 | |||
194 | 43126 | jjdelcerro | @Override
|
195 | 41620 | jjdelcerro | public boolean isVisible() { |
196 | return true; |
||
197 | } |
||
198 | |||
199 | 40435 | jjdelcerro | } |