1 11 package org.eclipse.pde.internal.ui.launcher; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 import java.util.Properties ; 16 import java.util.StringTokenizer ; 17 18 import org.eclipse.core.runtime.Preferences; 19 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 20 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; 21 import org.eclipse.pde.internal.core.ICoreConstants; 22 import org.eclipse.pde.internal.core.PDECore; 23 import org.eclipse.pde.internal.core.TargetPlatformHelper; 24 import org.eclipse.pde.internal.ui.IPDEUIConstants; 25 import org.eclipse.pde.ui.launcher.IPDELauncherConstants; 26 import org.eclipse.pde.ui.launcher.OSGiLaunchConfigurationInitializer; 27 28 public class EquinoxInitializer extends OSGiLaunchConfigurationInitializer { 29 30 private Map fStartLevels; 31 32 public void initialize(ILaunchConfigurationWorkingCopy configuration) { 33 super.initialize(configuration); 34 initializeProgramArguments(configuration); 35 initializeVMArguments(configuration); 36 initializeTracing(configuration); 37 } 38 39 private void initializeProgramArguments(ILaunchConfigurationWorkingCopy configuration) { 40 StringBuffer buffer = new StringBuffer (LaunchArgumentsHelper.getInitialProgramArguments()); 41 if (buffer.length() > 0) { 42 if (buffer.indexOf("-console") == -1) { buffer.append(" -console"); } 45 } else { 46 buffer.append("-console"); } 48 configuration.setAttribute(IPDEUIConstants.APPEND_ARGS_EXPLICITLY, true); 49 configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, buffer.toString()); } 51 52 private void initializeVMArguments(ILaunchConfigurationWorkingCopy configuration) { 53 configuration.setAttribute(IPDEUIConstants.LAUNCHER_PDE_VERSION, "3.3"); Preferences preferences = PDECore.getDefault().getPluginPreferences(); 55 StringBuffer vmArgs = new StringBuffer (preferences.getString(ICoreConstants.VM_ARGS)); 56 if (vmArgs.indexOf("-Declipse.ignoreApp") == -1) { if (vmArgs.length() > 0) 58 vmArgs.append(" "); vmArgs.append("-Declipse.ignoreApp=true"); } 61 if (vmArgs.indexOf("-Dosgi.noShutdown") == -1) { vmArgs.append(" -Dosgi.noShutdown=true"); } 64 configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, vmArgs.toString()); 65 } 66 67 private void initializeTracing(ILaunchConfigurationWorkingCopy configuration) { 68 configuration.setAttribute(IPDELauncherConstants.TRACING_CHECKED, 69 IPDELauncherConstants.TRACING_NONE); 70 } 71 72 protected void initializeBundleState(ILaunchConfigurationWorkingCopy configuration) { 73 initializeBundleState(); 74 super.initializeBundleState(configuration); 75 } 76 77 protected String getAutoStart(String bundleID) { 78 if (fStartLevels.containsKey(bundleID)) { 79 String value = fStartLevels.get(bundleID).toString(); 80 return value.substring(value.indexOf(":") + 1); } 82 return super.getAutoStart(bundleID); 83 } 84 85 protected String getStartLevel(String bundleID) { 86 if (fStartLevels.containsKey(bundleID)) { 87 String value = fStartLevels.get(bundleID).toString(); 88 return value.substring(0, value.indexOf(":")); } 90 return super.getStartLevel(bundleID); 91 } 92 93 94 private void initializeBundleState() { 95 if (fStartLevels == null) 96 fStartLevels = new HashMap (); 97 Properties props = TargetPlatformHelper.getConfigIniProperties(); 98 if (props != null) { 99 String value = (String )props.get("osgi.bundles"); if (value != null) { 101 StringTokenizer tokenizer = new StringTokenizer (value, ","); while (tokenizer.hasMoreTokens()) { 103 String tokenValue = tokenizer.nextToken(); 104 int index = tokenValue.indexOf("@"); if (index > 0) { 106 String bundle = tokenValue.substring(0,index).trim(); 107 fStartLevels.put(bundle, getStartValue(tokenValue.substring(index))); 108 } 109 } 110 } 111 } 112 } 113 114 private String getStartValue(String value) { 115 StringBuffer buffer = new StringBuffer (value); 116 StringBuffer result = new StringBuffer (":"); 118 int index = value.indexOf("start"); result.append(Boolean.toString(index != -1)); 120 121 if (index != -1) 122 buffer.delete(index, index + 5); 123 124 int colon = value.indexOf(':'); 125 if (colon != -1) 126 buffer.deleteCharAt(colon); 127 128 buffer.deleteCharAt(0); 130 131 try { 132 result.insert(0, Integer.parseInt(buffer.toString().trim())); 133 } catch (NumberFormatException e) { 134 result.insert(0, DEFAULT); 135 } 136 return result.toString(); 137 } 138 139 } 140 | Popular Tags |