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 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* 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 |
*
|
11 |
* 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 |
*
|
16 |
* 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 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
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 |
import java.io.File; |
31 |
import java.io.IOException; |
32 |
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 |
import org.gvsig.installer.lib.api.Version; |
45 |
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 |
private static final Logger logger = LoggerFactory |
53 |
.getLogger(InstallPackageExtension.class); |
54 |
|
55 |
@Override
|
56 |
public void execute(String actionCommand) { |
57 |
this.execute(actionCommand, null); |
58 |
} |
59 |
|
60 |
@Override
|
61 |
public void execute(String actionCommand, Object[] args) { |
62 |
|
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 |
String cmd;
|
79 |
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 |
} |
88 |
} catch (IOException ex) { |
89 |
logger.warn("Can't execute command '"+cmd+"'.",ex); |
90 |
useInternalAddonsManager = true;
|
91 |
} |
92 |
} else {
|
93 |
cmd = "pkexec " + pluginManager.getApplicationFolder() + File.separator + "/gvSIG.sh --install"; |
94 |
try {
|
95 |
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 |
} |
103 |
} |
104 |
if( useInternalAddonsManager ) {
|
105 |
logger.warn("Use internal addons manager.");
|
106 |
showInternalAddonsManager(null);
|
107 |
} |
108 |
} |
109 |
|
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 |
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 |
} |
133 |
|
134 |
} |
135 |
|
136 |
@Override
|
137 |
public void initialize() { |
138 |
PluginsManager pm = PluginsLocator.getManager(); |
139 |
PackageInfo packageInfo = pm.getPackageInfo(); |
140 |
Version version = packageInfo.getVersion(); |
141 |
|
142 |
InstallerLocator.getInstallerManager().setVersion(version); |
143 |
try {
|
144 |
IconThemeHelper.registerIcon("action", "tools-addonsmanager", this); |
145 |
|
146 |
SwingInstallerManager manager = SwingInstallerLocator |
147 |
.getSwingInstallerManager(); |
148 |
|
149 |
try {
|
150 |
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 |
if( packageInfo.getState().startsWith(InstallerManager.STATE.BETA) ||
|
157 |
packageInfo.getState().startsWith(InstallerManager.STATE.RC) || |
158 |
packageInfo.getState().equalsIgnoreCase(InstallerManager.STATE.FINAL) |
159 |
) { |
160 |
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 |
logger.info("Error. Can't select default gvspki", th);
|
166 |
} |
167 |
|
168 |
InputStream is = this.getClass().getResourceAsStream("/defaultDownloadsURLs"); |
169 |
BufferedReader in = new BufferedReader(new InputStreamReader(is)); |
170 |
for (String line = in.readLine(); line != null; line = in.readLine()) { |
171 |
try {
|
172 |
manager.addDefaultDownloadURL(line); |
173 |
} catch (MalformedURLException e) { |
174 |
logger.warn( |
175 |
"Error creating the default packages download URL pointing to " + line,
|
176 |
e |
177 |
); |
178 |
} |
179 |
} |
180 |
manager.getInstallerManager().setVersion(version); |
181 |
} catch (Throwable e) { |
182 |
logger.warn( |
183 |
"Error reading the default packages download URL file /defaultDownloadsURLs",
|
184 |
e |
185 |
); |
186 |
} |
187 |
} |
188 |
|
189 |
@Override
|
190 |
public boolean isEnabled() { |
191 |
return true; |
192 |
} |
193 |
|
194 |
@Override
|
195 |
public boolean isVisible() { |
196 |
return true; |
197 |
} |
198 |
|
199 |
} |