Revision 41916 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

View differences:

InstallPackageExtension.java
3 3
 *
4 4
 * Copyright (C) 2007-2013 gvSIG Association.
5 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.
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 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.
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 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.
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.
20 19
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
23 22
 */
24 23
/*
25 24
 * AUTHORS (In addition to CIT):
......
28 27
package org.gvsig.installer.app.extension.execution;
29 28

  
30 29
import java.io.BufferedReader;
30
import java.io.File;
31
import java.io.IOException;
31 32
import java.io.InputStream;
32 33
import java.io.InputStreamReader;
33 34
import java.net.MalformedURLException;
35
import java.util.logging.Level;
34 36

  
35 37
import org.gvsig.andami.IconThemeHelper;
36 38
import org.gvsig.andami.Launcher;
......
52 54
 */
53 55
public class InstallPackageExtension extends Extension {
54 56

  
55
    private static final Logger LOG = LoggerFactory
57
    private static final Logger logger = LoggerFactory
56 58
            .getLogger(InstallPackageExtension.class);
57 59

  
58 60
    public void execute(String actionCommand) {
59 61
        this.execute(actionCommand, null);
60 62
    }
61
    
63

  
62 64
    public void execute(String actionCommand, Object[] args) {
63
    
64
        if ( "tools-addonsmanager".equalsIgnoreCase(actionCommand) ) {
65
            boolean skipBundleSelection = false;
66
            if( args!=null && args.length>0 ) {
67
                String subcmd = (String) args[0];
68
                if( "skipBundleSelection".equalsIgnoreCase(subcmd) ) {
69
                    skipBundleSelection=true;
65

  
66
        if ("tools-addonsmanager".equalsIgnoreCase(actionCommand)) {
67
//            InstallerManager installManager = InstallerLocator.getInstallerManager();
68
//            if (installManager.needAdminRights()) {
69
//                showExternalAddonsManager();
70
//            } else {
71
                showInternalAddonsManager(args);
72
//            }
73
        }
74
    }
75

  
76
    private void showExternalAddonsManager() {
77
        InstallerManager installManager = InstallerLocator.getInstallerManager();
78

  
79
        PluginsManager pluginManager = PluginsLocator.getManager();
80
        
81
        String cmd = null;
82
        boolean useInternalAddonsManager = false;
83

  
84
        if( InstallerManager.OS.WINDOWS.equalsIgnoreCase(installManager.getOperatingSystem()) ) {
85
            cmd = "runas /noprofile /user:Administrator " + pluginManager.getApplicationFolder() + File.separator + "gvsig-package-installer.exe --install";
86
            try {
87
                Process p = Runtime.getRuntime().exec(cmd);
88
                if( p.exitValue() != 0 ) {
89
                    useInternalAddonsManager = true;
70 90
                }
91
            } catch (IOException ex) {
92
                logger.warn("Can't execute command '"+cmd+"'.",ex);
93
                useInternalAddonsManager = true;
71 94
            }
72
            PluginsManager manager = PluginsLocator.getManager();
95
        } else {
96
            cmd = "pkexec " + pluginManager.getApplicationFolder() + File.separator + "/gvSIG.sh --install";
73 97
            try {
74
                PluginServices.getMDIManager().addCentredWindow(
75
                        new InstallPackageWindow(
76
                                manager.getApplicationFolder(), 
77
                                manager.getInstallFolder(),
78
                                skipBundleSelection
79
                        )
80
                );
81
            } catch (Error e) {
82
                LOG.error("Error creating the wizard to install a package ", e);
83
            } catch (Exception e) {
84
                LOG.error("Error creating the wizard to install a package ", e);
98
                Process p = Runtime.getRuntime().exec(cmd);
99
                if( p.exitValue() != 0 ) {
100
                    useInternalAddonsManager = true;
101
                }
102
            } catch (IOException ex) {
103
                logger.warn("Can't execute command '"+cmd+"'.",ex);
104
                useInternalAddonsManager = true;
85 105
            }
86 106
        }
107
        if( useInternalAddonsManager ) {
108
            logger.warn("Use internal addons manager.");
109
            showInternalAddonsManager(null);
110
        }
87 111
    }
112
    
113
    
114
    private void showInternalAddonsManager(Object[] args) {
115
        boolean skipBundleSelection = false;
116
        if (args != null && args.length > 0) {
117
            String subcmd = (String) args[0];
118
            if ("skipBundleSelection".equalsIgnoreCase(subcmd)) {
119
                skipBundleSelection = true;
120
            }
121
        }
122
        PluginsManager manager = PluginsLocator.getManager();
123
        try {
124
            PluginServices.getMDIManager().addCentredWindow(
125
                    new InstallPackageWindow(
126
                            manager.getApplicationFolder(),
127
                            manager.getInstallFolder(),
128
                            skipBundleSelection
129
                    )
130
            );
131
        } catch (Error e) {
132
            logger.error("Error creating the wizard to install a package ", e);
133
        } catch (Exception e) {
134
            logger.error("Error creating the wizard to install a package ", e);
135
        }
88 136

  
137
    }
138

  
89 139
    public void initialize() {
90 140
        PluginsManager pm = PluginsLocator.getManager();
91 141
        PackageInfo packageInfo = pm.getPackageInfo();
......
99 149
                    .getSwingInstallerManager();
100 150

  
101 151
            try {
102
                if ( packageInfo != null && (packageInfo.getState().startsWith(InstallerManager.STATE.BETA)
152
                if (packageInfo != null && (packageInfo.getState().startsWith(InstallerManager.STATE.BETA)
103 153
                        || packageInfo.getState().startsWith(InstallerManager.STATE.RC)
104
                        || packageInfo.getState().equalsIgnoreCase(InstallerManager.STATE.FINAL)) ) {
154
                        || packageInfo.getState().equalsIgnoreCase(InstallerManager.STATE.FINAL))) {
105 155

  
106 156
                    String installURL = manager.getInstallerManager().getDownloadBaseURL().toString()
107 157
                            + "dists/<%Version%>/builds/<%Build%>/packages.gvspki ## Official gvSIG repository (frozen in this version)";
108 158
                    manager.addDefaultDownloadURL(installURL);
109 159
                }
110 160
            } catch (Throwable th) {
111
                LOG.info("Error. Can't select default gvspki", th);
161
                logger.info("Error. Can't select default gvspki", th);
112 162
            }
113 163

  
114 164
            InputStream is = this.getClass().getResourceAsStream(
115 165
                    "/defaultDownloadsURLs");
116 166
            BufferedReader in = new BufferedReader(new InputStreamReader(is));
117 167
            String line = null;
118
            for ( line = in.readLine(); line != null; line = in.readLine() ) {
168
            for (line = in.readLine(); line != null; line = in.readLine()) {
119 169
                try {
120 170
                    manager.addDefaultDownloadURL(line);
121 171
                } catch (MalformedURLException e) {
122
                    LOG.error(
172
                    logger.error(
123 173
                            "Error creating the default packages download URL pointing to "
124 174
                            + line, e);
125 175
                }
126 176
            }
127 177
            manager.getInstallerManager().setVersion(version);
128 178
        } catch (Throwable e) {
129
            LOG.error("Error reading the default packages download URL file "
179
            logger.error("Error reading the default packages download URL file "
130 180
                    + "/defaultDownloadsURLs", e);
131 181
        }
132 182
    }

Also available in: Unified diff