KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > syncclient > spap > launcher > Win32Launcher


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.syncclient.spap.launcher;
20
21 import java.io.File JavaDoc;
22 import java.io.IOException JavaDoc;
23
24 import sync4j.syncclient.common.logging.Logger;
25 import sync4j.syncclient.spap.AssetInstallationException;
26 import sync4j.syncclient.spap.installer.InstallationContext;
27
28 /**
29  * This class represents a <code>Laucher</code> for the execution of
30  * the win program.
31  *
32  * @version $Id: Win32Launcher.java,v 1.4 2005/01/19 11:18:36 fabius Exp $
33  * @author Stefano Nichele
34  */

35
36 public class Win32Launcher implements Launcher {
37
38
39     // -----------------------------------------------------------Private data
40

41     private Logger logger = new Logger();
42
43     // -----------------------------------------------------------Public methods
44

45     /**
46      * Executes the win program with given name.
47      *
48      * @param programName the program to execute.
49      * @param install <code>true</code> if the program is the installation program,
50      * <code>false</code> if the program is the uninstallation program
51      * @param ctx installation context information
52      *
53      * @throws AssetInstallationException if an error occurs during the execution
54      */

55     public int execute(String JavaDoc programName, boolean install, InstallationContext ctx)
56             throws AssetInstallationException {
57
58         String JavaDoc completeProgramPath = ctx.getWorkingDirectory() + File.separator + programName;
59         if (logger.isLoggable(Logger.DEBUG)) {
60             logger.debug("Win32Launcher - Execute " +
61                          completeProgramPath );
62         }
63
64         int exitState = -1;
65         try {
66             Process JavaDoc proc = Runtime.getRuntime().exec(
67                     completeProgramPath, null, new File JavaDoc(ctx.getWorkingDirectory())
68                     );
69
70             proc.waitFor();
71
72             exitState = proc.exitValue();
73
74             if (logger.isLoggable(Logger.DEBUG)) {
75                 logger.debug("Process executed. Return state: " + exitState);
76             }
77
78         } catch (Exception JavaDoc e) {
79             throw new AssetInstallationException("Error launching '" + completeProgramPath + "'", e);
80         }
81
82         return exitState;
83     }
84
85
86 }
Popular Tags