1 package com.bull.eclipse.jonas; 2 3 7 8 9 import java.io.File ; 10 import java.io.IOException ; 11 import java.util.ArrayList ; 12 import java.util.Iterator ; 13 import java.util.List ; 14 import java.util.Vector ; 15 16 import org.eclipse.core.resources.IProject; 17 import org.eclipse.core.resources.IWorkspaceRoot; 18 import org.eclipse.core.resources.ResourcesPlugin; 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.debug.core.model.ISourceLocator; 21 import org.eclipse.jdt.core.IJavaProject; 22 import org.eclipse.jdt.core.JavaCore; 23 import org.eclipse.jdt.launching.JavaRuntime; 24 import org.eclipse.jdt.launching.sourcelookup.JavaSourceLocator; 25 26 import com.bull.eclipse.jonas.editors.ProjectListElement; 27 import com.bull.eclipse.jonas.utils.FileUtil; 28 import com.bull.eclipse.jonas.utils.StringUtil; 29 import com.bull.eclipse.jonas.utils.TemplateDirUtil; 30 import com.bull.eclipse.jonas.utils.VMLauncherUtility; 31 32 33 37 38 public abstract class JonasBootstrap { 39 40 public abstract String [] getClasspath(); 41 public abstract String [] getVmArgs(); 42 public abstract String [] getPrgArgs(String command,String [] options); 43 public abstract String getStartCommand(); 44 public abstract String getStopCommand(); 45 public abstract String getAdminCommand(); 46 public abstract String getMainClass(); 47 public abstract Vector getJonasJarPath(); 48 public abstract Vector getJonasWebJarPath(); 49 50 abstract public String getLabel(); 51 52 53 56 public void start() throws CoreException { 57 this.runJonasBootsrap(getStartCommand(), true, null); 58 } 59 62 public void stop() throws CoreException { 63 this.runJonasBootsrap(getStopCommand(), false, null); 64 } 65 66 69 public void admin(String [] options) throws CoreException { 70 this.runJonasBootsrap(getAdminCommand(), false, options); 71 } 72 73 76 public void restart() throws CoreException { 77 JonasLauncherPlugin.getDefault().setEventRestart(true); 78 this.stop(); 79 } 81 82 86 87 private void runJonasBootsrap(String jonasBootOption, boolean showInDebugger, String [] options) throws CoreException{ 88 String [] prgArgs = this.getPrgArgs(jonasBootOption,options); 89 90 String [] classpath = new String [0]; 91 classpath = addPreferenceJvmToClasspath(classpath); 92 classpath = addPreferenceProjectListToClasspath(classpath); 93 classpath = StringUtil.concat(classpath, this.getClasspath() ); 94 95 String [] vmArgs = this.getVmArgs(); 96 vmArgs = addPreferenceParameters(vmArgs); 97 98 String [] bootClasspath = addPreferenceJvmToBootClasspath(new String [0]); 99 100 VMLauncherUtility.runVM(getLabel(), getMainClass(), classpath, bootClasspath, vmArgs, prgArgs, getSourceLocator(), isDebugMode(), showInDebugger); 101 } 102 103 private boolean isDebugMode() { 104 return JonasLauncherPlugin.getDefault().isDebugMode(); 105 } 106 107 113 114 private ISourceLocator getSourceLocator() throws CoreException { 115 IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); 116 IProject[] allProjects = root.getProjects(); 117 118 ArrayList tempList = new ArrayList (allProjects.length); 119 for (int i = 0; i < allProjects.length; i++) { 120 if((allProjects[i].isOpen()) && allProjects[i].hasNature(JavaCore.NATURE_ID)) { 121 tempList.add(allProjects[i].getNature(JavaCore.NATURE_ID)); 122 } 123 } 124 125 ISourceLocator sourceLocator = null; 126 if(!tempList.isEmpty()) { 127 IJavaProject[] javaProjects = (IJavaProject[])tempList.toArray(new IJavaProject[1]); 128 sourceLocator = new JavaSourceLocator(javaProjects, true); 129 } 130 131 return sourceLocator; 132 } 133 134 135 protected String getJonasDir() { 136 return JonasLauncherPlugin.getDefault().getJonasDir(); 137 } 138 139 140 protected String getBaseDir() { 141 return JonasLauncherPlugin.getDefault().getBaseDir(); 142 } 143 144 protected String getXtraClasspath() { 145 return JonasLauncherPlugin.getDefault().getXtraClasspath(); 146 } 147 148 protected String getOrb() { 149 String orb = JonasLauncherPlugin.getDefault().getOrb(); 150 File jndiTemplate = new File (TemplateDirUtil.getTemplateDir() + File.separator + "jndi.properties." + orb.toLowerCase()); 151 File jndiFile = new File (TemplateDirUtil.getTemplateDir() + File.separator + "jndi.properties"); 152 try { 153 FileUtil.copyFile(jndiTemplate,jndiFile); 154 } catch (IOException ie) { 155 156 } 158 return orb; 159 } 160 161 private String [] addPreferenceProjectListToClasspath(String [] previouscp) { 162 List projectsList = JonasLauncherPlugin.getDefault().getProjectsInCP(); 163 String [] result = previouscp; 164 Iterator it = projectsList.iterator(); 165 while(it.hasNext()) { 166 try { 167 ProjectListElement ple = (ProjectListElement)it.next(); 168 IJavaProject jproject = JavaCore.create(ple.getProject()); 169 result = this.addProjectToClasspath(result, jproject); 170 } catch (Exception e) { 171 } 173 } 174 175 return result; 176 177 } 178 179 private String [] addProjectToClasspath(String [] previouscp, IJavaProject project) throws CoreException { 180 if((project != null) && (project.exists() && project.isOpen())) { 183 String [] projectcp = JavaRuntime.computeDefaultRuntimeClassPath(project); 184 return StringUtil.concat(projectcp, previouscp); 185 } else { 186 return previouscp; 187 } 188 } 189 190 private String [] addPreferenceParameters(String [] previous) { 191 String [] prefParams = StringUtil.cutString(JonasLauncherPlugin.getDefault().getJvmParamaters(), JonasPluginResources.PREF_PAGE_LIST_SEPARATOR); 192 return StringUtil.concat(previous, prefParams); 193 } 194 195 private String [] addPreferenceJvmToClasspath(String [] previous) { 196 String [] prefClasspath = StringUtil.cutString(JonasLauncherPlugin.getDefault().getJvmClasspath(), JonasPluginResources.PREF_PAGE_LIST_SEPARATOR); 197 return StringUtil.concat(previous, prefClasspath); 198 } 199 200 private String [] addPreferenceJvmToBootClasspath(String [] previous) { 201 String [] prefBootClasspath = StringUtil.cutString(JonasLauncherPlugin.getDefault().getJvmBootClasspath(), JonasPluginResources.PREF_PAGE_LIST_SEPARATOR); 202 return StringUtil.concat(previous, prefBootClasspath); 203 } 204 205 206 } 207 208 | Popular Tags |