1 package com.bull.eclipse.jonas; 2 3 7 8 import java.io.PrintWriter ; 9 import java.io.StringWriter ; 10 import java.util.ArrayList ; 11 import java.util.Iterator ; 12 import java.util.List ; 13 import java.util.MissingResourceException ; 14 import java.util.PropertyResourceBundle ; 15 import java.util.ResourceBundle ; 16 import java.util.StringTokenizer ; 17 18 import org.eclipse.core.resources.IResourceChangeEvent; 19 import org.eclipse.core.resources.IWorkspace; 20 import org.eclipse.core.resources.ResourcesPlugin; 21 import org.eclipse.core.runtime.CoreException; 22 import org.eclipse.core.runtime.ILog; 23 import org.eclipse.core.runtime.IPath; 24 import org.eclipse.core.runtime.IPluginDescriptor; 25 import org.eclipse.core.runtime.IStatus; 26 import org.eclipse.core.runtime.Path; 27 import org.eclipse.core.runtime.Status; 28 import org.eclipse.debug.core.DebugEvent; 29 import org.eclipse.debug.core.DebugPlugin; 30 import org.eclipse.debug.core.IDebugEventSetListener; 31 import org.eclipse.debug.core.model.IProcess; 32 import org.eclipse.jdt.core.JavaCore; 33 import org.eclipse.jdt.core.JavaModelException; 34 import org.eclipse.jdt.launching.JavaRuntime; 35 import org.eclipse.jface.preference.IPreferenceStore; 36 import org.eclipse.ui.plugin.AbstractUIPlugin; 37 38 import com.bull.eclipse.jonas.actions.StartActionDelegate; 39 import com.bull.eclipse.jonas.editors.ProjectListElement; 40 41 42 45 public class JonasLauncherPlugin extends AbstractUIPlugin implements IDebugEventSetListener { 46 47 public static final String PLUGIN_ID = "com.bull.eclipse.jonas" ; 48 public static final String NATURE_ID = PLUGIN_ID + ".jonasnature" ; 49 50 public static final String JONAS_PREF_HOME_KEY = "jonasDir"; 51 public static final String JONAS_PREF_BASE_KEY = "jonasBase"; 52 public static final String JONAS_PREF_VERSION_KEY = "jonasVersion"; 53 public static final String JONAS_PREF_JRE_KEY = "jonasJRE"; 54 public static final String JONAS_PREF_JVM_PARAMETERS_KEY = "jvmParameters"; 55 public static final String JONAS_PREF_JVM_CLASSPATH_KEY = "jvmClasspath"; 56 public static final String JONAS_PREF_JVM_BOOTCLASSPATH_KEY = "jvmBootClasspath"; 57 public static final String JONAS_PREF_PROJECTSINCP_KEY = "projectsInCp"; 58 public static final String JONAS_PREF_XTRA_CLASSPATH_KEY = "xtraClasspath"; 59 public static final String JONAS_EXTRA_RESOURCES_KEY = "extraResources"; 60 public static final String JONAS_PREF_ORB_KEY = "orb"; 61 public static final String JONAS_PREF_DEBUGMODE_KEY = "jonasDebugMode"; 62 public static final String JONAS_PREF_CONSOLEIN_KEY = "jonasConsoleIn"; 63 public static final String JONAS_VERSION30 = "jonas30"; 64 public static final String JONAS_VERSION31 = "jonas31"; 65 public static final String JONAS_VERSION40 = "jonas40"; 66 public static final String JONAS_VERSION41 = "jonas41"; 67 public static final String JONAS_VERSION414 = "jonas414"; 68 public static final String JONAS_ORB_RMI = "RMI"; 69 public static final String JONAS_ORB_JEREMIE = "JEREMIE"; 70 public static final String JONAS_PREF_DATABASE_KEY = "database"; 71 public static final String JONAS_PREF_AUTOMATICDEPLOY_KEY = "automaticDeploy"; 72 73 private static final String JONAS_HOME_CLASSPATH_VARIABLE = "JONAS_ROOT"; 74 75 76 private static JonasLauncherPlugin plugin; 78 private ResourceBundle resourceBundle; 80 81 private boolean eventRestart = false; 83 84 87 public JonasLauncherPlugin(IPluginDescriptor descriptor) { 88 super(descriptor); 89 plugin = this; 90 91 try { 92 resourceBundle= PropertyResourceBundle.getBundle("resources"); 93 } catch (MissingResourceException x) { 94 JonasLauncherPlugin.log("Problème lors du chargement du plugin"); 95 x.printStackTrace(); 96 resourceBundle = null; 97 } 98 99 JonasLauncherPlugin.getWorkspace().addResourceChangeListener(new JonasProjectChangeListener(), IResourceChangeEvent.PRE_DELETE); 100 } 101 102 105 public static JonasLauncherPlugin getDefault() { 106 return plugin; 107 } 108 109 112 public static IWorkspace getWorkspace() { 113 return ResourcesPlugin.getWorkspace(); 114 } 115 116 120 public static String getResourceString(String key) { 121 ResourceBundle bundle= JonasLauncherPlugin.getDefault().getResourceBundle(); 122 System.out.println("bundle = " + bundle); 123 try { 124 return bundle.getString(key); 125 } catch (MissingResourceException e) { 126 return key; 127 } 128 } 129 130 133 public ResourceBundle getResourceBundle() { 134 try { 135 resourceBundle= PropertyResourceBundle.getBundle("resources"); 136 } catch (MissingResourceException x) { 137 resourceBundle = null; 138 } 139 return resourceBundle; 140 } 141 142 143 public String getJonasDir() { 144 IPreferenceStore pref = JonasLauncherPlugin.getDefault().getPreferenceStore(); 145 return pref.getString(JONAS_PREF_HOME_KEY); 146 } 147 148 public String getBaseDir() { 149 IPreferenceStore pref = JonasLauncherPlugin.getDefault().getPreferenceStore(); 150 return pref.getString(JONAS_PREF_BASE_KEY); 151 } 152 153 public String getJonasVersion() { 154 IPreferenceStore pref = JonasLauncherPlugin.getDefault().getPreferenceStore(); 155 String result = pref.getString(JONAS_PREF_VERSION_KEY); 156 if (result.equals("")) 157 result = JONAS_VERSION30; 158 159 return result; 160 } 161 162 public String getJonasJRE() { 163 IPreferenceStore pref = JonasLauncherPlugin.getDefault().getPreferenceStore(); 164 String result = pref.getString(JONAS_PREF_JRE_KEY); 165 if (result.equals("")) 166 result = JavaRuntime.getDefaultVMInstall().getId(); 167 168 return result; 169 } 170 171 public boolean isDebugMode() { 172 IPreferenceStore pref = JonasLauncherPlugin.getDefault().getPreferenceStore(); 173 return !pref.getBoolean(JONAS_PREF_DEBUGMODE_KEY); 174 } 175 176 public boolean isConsoleIn() { 177 IPreferenceStore pref = JonasLauncherPlugin.getDefault().getPreferenceStore(); 178 return pref.getBoolean(JONAS_PREF_CONSOLEIN_KEY); 179 } 180 181 public String getJvmParamaters() { 182 IPreferenceStore pref = JonasLauncherPlugin.getDefault().getPreferenceStore(); 183 return pref.getString(JONAS_PREF_JVM_PARAMETERS_KEY); 184 } 185 186 public String getJvmClasspath() { 187 IPreferenceStore pref = JonasLauncherPlugin.getDefault().getPreferenceStore(); 188 return pref.getString(JONAS_PREF_JVM_CLASSPATH_KEY); 189 } 190 191 public String getJvmBootClasspath() { 192 IPreferenceStore pref = JonasLauncherPlugin.getDefault().getPreferenceStore(); 193 return pref.getString(JONAS_PREF_JVM_BOOTCLASSPATH_KEY); 194 } 195 196 public String getDatabase() { 197 IPreferenceStore pref = JonasLauncherPlugin.getDefault().getPreferenceStore(); 198 return pref.getString(JONAS_PREF_DATABASE_KEY); 199 } 200 201 public String getXtraClasspath() { 202 IPreferenceStore pref = JonasLauncherPlugin.getDefault().getPreferenceStore(); 203 return pref.getString(JONAS_PREF_XTRA_CLASSPATH_KEY); 204 } 205 206 public static String getPluginId() 207 { 208 return getDefault().getDescriptor().getUniqueIdentifier(); 209 } 210 211 public String getOrb() { 212 IPreferenceStore pref = JonasLauncherPlugin.getDefault().getPreferenceStore(); 213 return pref.getString(JONAS_PREF_ORB_KEY); 214 } 215 216 public String getAutomaticDeploy() { 217 IPreferenceStore pref = JonasLauncherPlugin.getDefault().getPreferenceStore(); 218 return pref.getString(JONAS_PREF_AUTOMATICDEPLOY_KEY); 219 } 220 221 public void setProjectsInCP(List projectsInCP) { 222 IPreferenceStore pref = JonasLauncherPlugin.getDefault().getPreferenceStore(); 223 StringBuffer buf = new StringBuffer (); 224 Iterator it = projectsInCP.iterator(); 225 while(it.hasNext()) { 226 ProjectListElement each = (ProjectListElement)it.next(); 227 buf.append(each.getID()); 228 buf.append(';'); 229 } 230 pref.setValue(JONAS_PREF_PROJECTSINCP_KEY, buf.toString()); 231 } 232 233 public List getProjectsInCP() { 234 IPreferenceStore pref = JonasLauncherPlugin.getDefault().getPreferenceStore(); 235 String stringList = pref.getString(JONAS_PREF_PROJECTSINCP_KEY); 236 237 List projectsIdList = new ArrayList (); 238 StringTokenizer tokenizer = new StringTokenizer (stringList, ";"); 239 while (tokenizer.hasMoreElements()) { 240 projectsIdList.add(tokenizer.nextToken()); 241 } 242 243 return ProjectListElement.stringsToProjectsList(projectsIdList); 244 245 } 246 247 248 public JonasBootstrap getJonasBootstrap() { 249 JonasBootstrap jonasBootsrap = null; 250 251 if(getJonasVersion().equals(JONAS_VERSION30)) { 252 jonasBootsrap = new Jonas30Bootstrap(); 253 } 254 255 if(getJonasVersion().equals(JONAS_VERSION31)) { 256 jonasBootsrap = new Jonas31Bootstrap(); 257 } 258 259 if(getJonasVersion().equals(JONAS_VERSION40)) { 260 jonasBootsrap = new Jonas40Bootstrap(); 261 } 262 263 if(getJonasVersion().equals(JONAS_VERSION41)) { 264 jonasBootsrap = new Jonas41Bootstrap(); 265 } 266 267 if(getJonasVersion().equals(JONAS_VERSION414)) { 268 jonasBootsrap = new Jonas414Bootstrap(); 269 } 270 271 return jonasBootsrap; 272 } 273 274 275 276 static public void log(String msg) { 277 ILog log = JonasLauncherPlugin.getDefault().getLog(); 278 Status status = new Status(IStatus.ERROR, JonasLauncherPlugin.getDefault().getDescriptor().getUniqueIdentifier(), IStatus.ERROR, msg + "\n", null); 279 log.log(status); 280 } 281 282 static public void log(Exception ex) { 283 ILog log = JonasLauncherPlugin.getDefault().getLog(); 284 StringWriter stringWriter = new StringWriter (); 285 ex.printStackTrace(new PrintWriter (stringWriter)); 286 String msg = stringWriter.getBuffer().toString(); 287 288 Status status = new Status(IStatus.ERROR, JonasLauncherPlugin.getDefault().getDescriptor().getUniqueIdentifier(), IStatus.ERROR, msg, null); 289 log.log(status); 290 } 291 292 293 public IPath getJonasIPath() { 294 IPath jonasPath = getJonasClasspathVariable(); 295 if(jonasPath == null) { 296 return new Path(JonasLauncherPlugin.getDefault().getJonasDir()); 297 } else { 298 return new Path(JONAS_HOME_CLASSPATH_VARIABLE); 299 } 300 } 301 302 private IPath getJonasClasspathVariable() { 303 IPath jonasPath = JavaCore.getClasspathVariable(JONAS_HOME_CLASSPATH_VARIABLE); 304 if(jonasPath == null) { 305 this.initJonasClasspathVariable(); 306 jonasPath = JavaCore.getClasspathVariable(JONAS_HOME_CLASSPATH_VARIABLE); 307 } 308 return jonasPath; 309 } 310 311 public void initJonasClasspathVariable() { 312 try { 313 JavaCore.setClasspathVariable( 314 JONAS_HOME_CLASSPATH_VARIABLE, 315 new Path(JonasLauncherPlugin.getDefault().getJonasDir()), 316 null); 317 } catch (JavaModelException e) { 318 log(e); 319 } 320 } 321 322 323 324 326 329 public void startup() throws CoreException { 330 super.startup(); 331 DebugPlugin.getDefault().addDebugEventListener(this); 332 } 333 334 337 public void handleDebugEvents(DebugEvent[] events) 338 { 339 for (int i = 0; i < events.length; i++) { 340 if (events[i].getKind() == DebugEvent.CREATE) { 341 if (events[i].getSource() instanceof IProcess) { 342 IProcess process = (IProcess) events[i].getSource(); 343 } 344 } 345 else if (events[i].getKind() == DebugEvent.TERMINATE) { 346 if (events[i].getSource() instanceof IProcess) { 347 IProcess process = (IProcess) events[i].getSource(); 348 if(eventRestart == true) { 349 eventRestart = false; 350 StartActionDelegate start = new StartActionDelegate(); 351 start.run(start.getAction()); 352 } 353 } 354 } 355 } 356 } 357 358 359 public boolean isEventRestart() { 360 return eventRestart; 361 } 362 363 public void setEventRestart(boolean b) { 364 eventRestart = b; 365 } 366 367 368 } 369 370 | Popular Tags |