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 @ 40557
History | View | Annotate | Download (4.63 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
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
/*
|
25 |
* AUTHORS (In addition to CIT):
|
26 |
* 2010 {Prodevelop} {Task}
|
27 |
*/
|
28 |
|
29 |
package org.gvsig.installer.app.extension.execution; |
30 |
|
31 |
import java.io.BufferedReader; |
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.app.ApplicationLocator; |
42 |
import org.gvsig.app.ApplicationManager; |
43 |
import org.gvsig.app.extension.InitializeApplicationExtension; |
44 |
import org.gvsig.app.extension.Version; |
45 |
import org.gvsig.installer.lib.api.InstallerLocator; |
46 |
import org.gvsig.installer.lib.api.InstallerManager; |
47 |
import org.gvsig.installer.lib.api.PackageInfo; |
48 |
import org.gvsig.installer.swing.api.SwingInstallerLocator; |
49 |
import org.gvsig.installer.swing.api.SwingInstallerManager; |
50 |
|
51 |
import org.slf4j.Logger; |
52 |
import org.slf4j.LoggerFactory; |
53 |
|
54 |
/**
|
55 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
56 |
*/
|
57 |
public class InstallPackageExtension extends Extension { |
58 |
|
59 |
private static final Logger LOG = LoggerFactory |
60 |
.getLogger(InstallPackageExtension.class); |
61 |
|
62 |
public void execute(String actionCommand) { |
63 |
if ("tools-addonsmanager".equalsIgnoreCase(actionCommand)) { |
64 |
PluginsManager manager = PluginsLocator.getManager(); |
65 |
try {
|
66 |
PluginServices.getMDIManager().addCentredWindow( |
67 |
new InstallPackageWindow(
|
68 |
manager.getApplicationFolder(), manager |
69 |
.getInstallFolder())); |
70 |
} catch (Error e) { |
71 |
LOG.error("Error creating the wizard to install a package ", e);
|
72 |
} catch (Exception e) { |
73 |
LOG.error("Error creating the wizard to install a package ", e);
|
74 |
} |
75 |
} |
76 |
} |
77 |
|
78 |
public void initialize() { |
79 |
ApplicationManager application = ApplicationLocator.getManager(); |
80 |
Version version = application.getVersion(); |
81 |
|
82 |
InstallerLocator.getInstallerManager().setVersion(version.asInstallerVersion()); |
83 |
try {
|
84 |
IconThemeHelper.registerIcon("action", "tools-addonsmanager", this); |
85 |
|
86 |
SwingInstallerManager manager = SwingInstallerLocator |
87 |
.getSwingInstallerManager(); |
88 |
|
89 |
try {
|
90 |
PluginsManager pm = PluginsLocator.getManager(); |
91 |
PackageInfo packageInfo = pm.getPackageInfo(InitializeApplicationExtension.class); |
92 |
|
93 |
if( packageInfo!=null && (packageInfo.getState().startsWith(InstallerManager.STATE.BETA) || |
94 |
packageInfo.getState().startsWith(InstallerManager.STATE.RC) || |
95 |
packageInfo.getState().equalsIgnoreCase(InstallerManager.STATE.FINAL)) ) { |
96 |
|
97 |
String installURL = manager.getInstallerManager().getDownloadBaseURL().toString()
|
98 |
+ "dists/<%Version%>/builds/<%Build%>/packages.gvspki";
|
99 |
manager.addDefaultDownloadURL(installURL); |
100 |
} |
101 |
} catch (Throwable th) { |
102 |
LOG.info("Error. Can't select default gvspki", th);
|
103 |
} |
104 |
|
105 |
InputStream is = this.getClass().getResourceAsStream( |
106 |
"/defaultDownloadsURLs");
|
107 |
BufferedReader in = new BufferedReader(new InputStreamReader(is)); |
108 |
String line = null; |
109 |
for (line = in.readLine(); line != null; line = in.readLine()) { |
110 |
try {
|
111 |
manager.addDefaultDownloadURL(line); |
112 |
} catch (MalformedURLException e) { |
113 |
LOG.error( |
114 |
"Error creating the default packages download URL pointing to "
|
115 |
+ line, e); |
116 |
} |
117 |
} |
118 |
manager.getInstallerManager().setVersion(version.getFormat()); |
119 |
} catch (Throwable e) { |
120 |
LOG.error("Error reading the default packages download URL file "
|
121 |
+ "/defaultDownloadsURLs", e);
|
122 |
} |
123 |
} |
124 |
|
125 |
public boolean isEnabled() { |
126 |
return true; |
127 |
} |
128 |
|
129 |
public boolean isVisible() { |
130 |
return true; |
131 |
} |
132 |
|
133 |
} |