KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > bull > eclipse > jonas > actions > StartActionDelegate


1 package com.bull.eclipse.jonas.actions;
2
3 /*
4  * (c) Copyright Bull SA 2003.
5  * All Rights Reserved.
6  */

7 import java.io.BufferedWriter JavaDoc;
8 import java.io.File JavaDoc;
9 import java.io.FileWriter JavaDoc;
10 import java.io.IOException JavaDoc;
11
12 import org.eclipse.debug.core.DebugPlugin;
13 import org.eclipse.debug.core.ILaunch;
14 import org.eclipse.debug.core.ILaunchConfiguration;
15 import org.eclipse.debug.core.ILaunchConfigurationType;
16 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
17 import org.eclipse.debug.core.ILaunchManager;
18 import org.eclipse.debug.ui.DebugUITools;
19 import org.eclipse.jface.action.IAction;
20 import org.eclipse.jface.viewers.ISelection;
21 import org.eclipse.ui.IWorkbenchWindow;
22 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
23 import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
24
25 import com.bull.eclipse.jonas.JonasLauncherPlugin;
26 import com.bull.eclipse.jonas.JonasPluginResources;
27 import com.bull.eclipse.jonas.utils.StringUtil;
28 import com.bull.eclipse.jonas.utils.TemplateDirUtil;
29 import com.bull.eclipse.jonas.utils.VMLauncherUtility;
30
31 public class StartActionDelegate implements IWorkbenchWindowActionDelegate {
32
33             
34     private IWorkbenchWindow window;
35     private IAction action;
36     private static final String JavaDoc JONAS_LAUNCH_BAT = "/jonas_launch_DOS.bat";
37
38     /*
39      * @see IWorkbenchWindowActionDelegate#dispose()
40      */

41     public void dispose() {
42     }
43
44     /*
45      * @see IWorkbenchWindowActionDelegate#init(IWorkbenchWindow)
46      */

47     public void init(IWorkbenchWindow window) {
48         this.window = window;
49     }
50
51     /*
52      * @see IActionDelegate#run(IAction)
53      */

54     public void run(IAction action) {
55         JonasLauncherPlugin.log(JonasLauncherPlugin.getResourceString("msg.start"));
56         JonasLauncherPlugin.log("msg.start");
57         try {
58             if (JonasLauncherPlugin.getDefault().isDebugMode()) {
59                 JonasLauncherPlugin.getDefault().getJonasBootstrap().start();
60             } else {
61                 String JavaDoc pathJonas = JonasLauncherPlugin.getDefault().getJonasDir();;
62                 String JavaDoc batchfilePath = TemplateDirUtil.getTemplateDir() + JONAS_LAUNCH_BAT;
63                 String JavaDoc param = JonasLauncherPlugin.getDefault().getJonasBootstrap().getStartCommand();
64                 this.action = action;
65 // ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
66
// ILaunchConfigurationType configType = manager.getLaunchConfigurationType(IExternalToolConstants.ID_PROGRAM_BUILDER_LAUNCH_CONFIGURATION_TYPE);
67
// ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, JonasLauncherPlugin.getDefault().getJonasBootstrap().getLabel());
68
String JavaDoc commandLine = MAJLaunchingBatch(batchfilePath,param);
69                 try {
70                     Process JavaDoc proc = Runtime.getRuntime().exec(commandLine);
71                     proc.waitFor();
72                 } catch (IOException JavaDoc e1) {
73                     // TODO Auto-generated catch block
74
e1.printStackTrace();
75                 }
76
77 // wc.setAttribute(IExternalToolConstants.ATTR_LOCATION, batchfilePath);
78
// wc.setAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS,param);
79
// ILaunchConfiguration config=wc.doSave();
80
// config.launch(ILaunchManager.RUN_MODE, null);
81
}
82         } catch (Exception JavaDoc ex) {
83             ex.printStackTrace();
84             String JavaDoc msg = JonasLauncherPlugin.getResourceString("msg.start.failed");
85             JonasLauncherPlugin.log(msg + "/n");
86             JonasLauncherPlugin.log(ex);
87         }
88     }
89
90     private String JavaDoc MAJLaunchingBatch(String JavaDoc batchFilePath, String JavaDoc startClass) {
91         String JavaDoc param = "cmd.exe /C start " + VMLauncherUtility.getVMInstall().getInstallLocation().toString() + File.separator + "bin" + File.separator + "java ";
92         String JavaDoc vmArgs [] = JonasLauncherPlugin.getDefault().getJonasBootstrap().getVmArgs();
93         String JavaDoc prefParams[] = StringUtil.cutString(JonasLauncherPlugin.getDefault().getJvmParamaters(), JonasPluginResources.PREF_PAGE_LIST_SEPARATOR);
94         vmArgs = StringUtil.concat(vmArgs, prefParams);
95         int i =0;
96         String JavaDoc vmArg = "";
97         while(i != vmArgs.length ){
98             vmArg += vmArgs[i]+" ";
99             i++;
100         }
101         String JavaDoc classpaths [] =JonasLauncherPlugin.getDefault().getJonasBootstrap().getClasspath();
102         int j =0;
103         String JavaDoc classpath="\"";
104         while(j != classpaths.length ){
105             if(j==(classpaths.length-1))
106                 classpath += classpaths[j]+"\" ";
107             else
108                 classpath += classpaths[j]+";";
109             j++;
110         }
111         param += vmArg+"-classpath "+classpath+JonasLauncherPlugin.getDefault().getJonasBootstrap().getMainClass()+ " " + startClass;
112         return param;
113 // try {
114
// Runtime.getRuntime().exec(param);
115
// } catch (IOException e1) {
116
// // TODO Auto-generated catch block
117
// e1.printStackTrace();
118
// }
119
// try {
120
// BufferedWriter output = new BufferedWriter(new FileWriter(batchFilePath));
121
// output.write(param);
122
// output.flush();
123
// output.close();
124
// }catch(Exception e){
125
// System.out.println("File Not Found = "+e.getMessage());
126
// }
127

128     }
129     
130
131
132
133     /*
134      * @see IActionDelegate#selectionChanged(IAction, ISelection)
135      */

136     public void selectionChanged(IAction action, ISelection selection) {
137
138     }
139
140     /**
141      * @return
142      */

143     public IAction getAction() {
144         return action;
145     }
146
147     /**
148      * @param action
149      */

150     public void setAction(IAction action) {
151         this.action = action;
152     }
153
154
155
156 }
157
158
Popular Tags