1 package com.bull.eclipse.jonas.actions; 2 3 7 import java.io.BufferedWriter ; 8 import java.io.File ; 9 import java.io.FileWriter ; 10 import java.io.IOException ; 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 JONAS_LAUNCH_BAT = "/jonas_launch_DOS.bat"; 37 38 41 public void dispose() { 42 } 43 44 47 public void init(IWorkbenchWindow window) { 48 this.window = window; 49 } 50 51 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 pathJonas = JonasLauncherPlugin.getDefault().getJonasDir();; 62 String batchfilePath = TemplateDirUtil.getTemplateDir() + JONAS_LAUNCH_BAT; 63 String param = JonasLauncherPlugin.getDefault().getJonasBootstrap().getStartCommand(); 64 this.action = action; 65 String commandLine = MAJLaunchingBatch(batchfilePath,param); 69 try { 70 Process proc = Runtime.getRuntime().exec(commandLine); 71 proc.waitFor(); 72 } catch (IOException e1) { 73 e1.printStackTrace(); 75 } 76 77 } 82 } catch (Exception ex) { 83 ex.printStackTrace(); 84 String msg = JonasLauncherPlugin.getResourceString("msg.start.failed"); 85 JonasLauncherPlugin.log(msg + "/n"); 86 JonasLauncherPlugin.log(ex); 87 } 88 } 89 90 private String MAJLaunchingBatch(String batchFilePath, String startClass) { 91 String param = "cmd.exe /C start " + VMLauncherUtility.getVMInstall().getInstallLocation().toString() + File.separator + "bin" + File.separator + "java "; 92 String vmArgs [] = JonasLauncherPlugin.getDefault().getJonasBootstrap().getVmArgs(); 93 String prefParams[] = StringUtil.cutString(JonasLauncherPlugin.getDefault().getJvmParamaters(), JonasPluginResources.PREF_PAGE_LIST_SEPARATOR); 94 vmArgs = StringUtil.concat(vmArgs, prefParams); 95 int i =0; 96 String vmArg = ""; 97 while(i != vmArgs.length ){ 98 vmArg += vmArgs[i]+" "; 99 i++; 100 } 101 String classpaths [] =JonasLauncherPlugin.getDefault().getJonasBootstrap().getClasspath(); 102 int j =0; 103 String 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 128 } 129 130 131 132 133 136 public void selectionChanged(IAction action, ISelection selection) { 137 138 } 139 140 143 public IAction getAction() { 144 return action; 145 } 146 147 150 public void setAction(IAction action) { 151 this.action = action; 152 } 153 154 155 156 } 157 158 | Popular Tags |