1 11 package org.eclipse.debug.core; 12 13 14 import java.io.ByteArrayInputStream ; 15 import java.io.File ; 16 import java.io.IOException ; 17 import java.io.InputStream ; 18 import java.util.ArrayList ; 19 import java.util.HashMap ; 20 import java.util.List ; 21 import java.util.Map ; 22 23 import javax.xml.parsers.DocumentBuilder ; 24 import javax.xml.parsers.DocumentBuilderFactory ; 25 import javax.xml.parsers.FactoryConfigurationError ; 26 import javax.xml.parsers.ParserConfigurationException ; 27 import javax.xml.transform.TransformerException ; 28 29 import org.eclipse.core.resources.ISaveContext; 30 import org.eclipse.core.resources.ISaveParticipant; 31 import org.eclipse.core.resources.ResourcesPlugin; 32 import org.eclipse.core.runtime.CoreException; 33 import org.eclipse.core.runtime.IAdapterManager; 34 import org.eclipse.core.runtime.IConfigurationElement; 35 import org.eclipse.core.runtime.IExtensionPoint; 36 import org.eclipse.core.runtime.IProgressMonitor; 37 import org.eclipse.core.runtime.ISafeRunnable; 38 import org.eclipse.core.runtime.IStatus; 39 import org.eclipse.core.runtime.ListenerList; 40 import org.eclipse.core.runtime.Platform; 41 import org.eclipse.core.runtime.Plugin; 42 import org.eclipse.core.runtime.SafeRunner; 43 import org.eclipse.core.runtime.Status; 44 import org.eclipse.core.runtime.jobs.Job; 45 import org.eclipse.debug.core.model.IDebugElement; 46 import org.eclipse.debug.core.model.IDisconnect; 47 import org.eclipse.debug.core.model.IDropToFrame; 48 import org.eclipse.debug.core.model.IProcess; 49 import org.eclipse.debug.core.model.IStep; 50 import org.eclipse.debug.core.model.IStepFilters; 51 import org.eclipse.debug.core.model.ISuspendResume; 52 import org.eclipse.debug.core.model.ITerminate; 53 import org.eclipse.debug.core.model.IValue; 54 import org.eclipse.debug.core.model.RuntimeProcess; 55 import org.eclipse.debug.internal.core.BreakpointManager; 56 import org.eclipse.debug.internal.core.DebugCoreMessages; 57 import org.eclipse.debug.internal.core.DebugOptions; 58 import org.eclipse.debug.internal.core.ExpressionManager; 59 import org.eclipse.debug.internal.core.LaunchManager; 60 import org.eclipse.debug.internal.core.LogicalStructureManager; 61 import org.eclipse.debug.internal.core.MemoryBlockManager; 62 import org.eclipse.debug.internal.core.StepFilterManager; 63 import org.eclipse.debug.internal.core.commands.CommandAdapterFactory; 64 import org.eclipse.debug.internal.core.sourcelookup.SourceLookupMessages; 65 import org.eclipse.debug.internal.core.sourcelookup.SourceLookupUtils; 66 import org.eclipse.osgi.service.environment.Constants; 67 import org.osgi.framework.BundleContext; 68 import org.w3c.dom.Document ; 69 import org.w3c.dom.Element ; 70 import org.xml.sax.SAXException ; 71 import org.xml.sax.helpers.DefaultHandler ; 72 73 import com.ibm.icu.text.MessageFormat; 74 75 91 public class DebugPlugin extends Plugin { 92 93 97 private static final String PI_DEBUG_CORE = "org.eclipse.debug.core"; 99 105 public static final String EXTENSION_POINT_LAUNCH_CONFIGURATION_TYPES= "launchConfigurationTypes"; 107 113 public static final String EXTENSION_POINT_LAUNCH_CONFIGURATION_COMPARATORS= "launchConfigurationComparators"; 115 121 public static final String EXTENSION_POINT_BREAKPOINTS= "breakpoints"; 123 129 public static final String EXTENSION_POINT_STATUS_HANDLERS= "statusHandlers"; 131 137 public static final String EXTENSION_POINT_SOURCE_LOCATORS= "sourceLocators"; 139 145 public static final String EXTENSION_POINT_LAUNCH_MODES= "launchModes"; 147 153 public static final String EXTENSION_POINT_LAUNCH_DELEGATES= "launchDelegates"; 155 161 public static final String EXTENSION_POINT_PROCESS_FACTORIES = "processFactories"; 163 169 public static final String EXTENSION_POINT_LOGICAL_STRUCTURE_TYPES = "logicalStructureTypes"; 171 177 public static final String EXTENSION_POINT_LOGICAL_STRUCTURE_PROVIDERS = "logicalStructureProviders"; 179 185 public static final String EXTENSION_POINT_SOURCE_CONTAINER_TYPES = "sourceContainerTypes"; 187 193 public static final String EXTENSION_POINT_SOURCE_PATH_COMPUTERS = "sourcePathComputers"; 195 200 public static final String EXTENSION_POINT_LAUNCH_OPTIONS = "launchOptions"; 202 205 public static final int INTERNAL_ERROR = 120; 206 207 217 public static final int ERR_WORKING_DIRECTORY_NOT_SUPPORTED = 115; 218 219 225 public static final String ATTR_PROCESS_FACTORY_ID = "process_factory_id"; 227 235 public static final String ATTR_CAPTURE_OUTPUT = PI_DEBUG_CORE + ".capture_output"; 237 238 249 public static final String ATTR_CONSOLE_ENCODING = "org.eclipse.debug.ui.ATTR_CONSOLE_ENCODING"; 251 254 private static DebugPlugin fgDebugPlugin= null; 255 256 259 private BreakpointManager fBreakpointManager; 260 261 264 private ExpressionManager fExpressionManager; 265 266 269 private LaunchManager fLaunchManager; 270 271 275 private MemoryBlockManager fMemoryBlockManager; 276 277 280 private ListenerList fEventListeners = new ListenerList(); 281 282 285 private ListenerList fEventFilters = null; 286 287 291 private boolean fShuttingDown= false; 292 293 297 private HashMap fStatusHandlers = null; 298 299 304 private HashMap fProcessFactories = null; 305 306 309 private static final int NOTIFY_FILTERS = 0; 310 private static final int NOTIFY_EVENTS = 1; 311 312 313 319 private List fEventQueue = new ArrayList (); 320 321 325 private EventDispatchJob fEventDispatchJob = new EventDispatchJob(); 326 327 332 class EventDispatchJob extends Job { 333 334 EventNotifier fNotifier = new EventNotifier(); 335 AsynchRunner fRunner = new AsynchRunner(); 336 337 340 public EventDispatchJob() { 341 super(DebugCoreMessages.DebugPlugin_1); 342 setPriority(Job.INTERACTIVE); 343 setSystem(true); 344 } 345 348 protected IStatus run(IProgressMonitor monitor) { 349 350 while (!fEventQueue.isEmpty()) { 351 Object next = null; 352 synchronized (fEventQueue) { 353 if (!fEventQueue.isEmpty()) { 354 next = fEventQueue.remove(0); 355 } 356 } 357 if (next instanceof Runnable ) { 358 fRunner.async((Runnable ) next); 359 } else if (next != null) { 360 fNotifier.dispatch((DebugEvent[]) next); 361 } 362 } 363 return Status.OK_STATUS; 364 } 365 366 369 public boolean shouldRun() { 370 return shouldSchedule(); 371 } 372 375 public boolean shouldSchedule() { 376 return !(isShuttingDown() || fEventListeners.isEmpty()); 377 } 378 379 } 380 381 386 public static DebugPlugin getDefault() { 387 return fgDebugPlugin; 388 } 389 390 396 private static void setDefault(DebugPlugin plugin) { 397 fgDebugPlugin = plugin; 398 } 399 400 405 public static String getUniqueIdentifier() { 406 return PI_DEBUG_CORE; 407 } 408 409 417 public DebugPlugin() { 418 super(); 419 setDefault(this); 420 } 421 422 430 public void addDebugEventListener(IDebugEventSetListener listener) { 431 fEventListeners.add(listener); 432 } 433 434 444 public void fireDebugEventSet(DebugEvent[] events) { 445 if (isShuttingDown() || events == null || fEventListeners.isEmpty()) 446 return; 447 synchronized (fEventQueue) { 448 fEventQueue.add(events); 449 } 450 fEventDispatchJob.schedule(); 451 } 452 453 462 public void asyncExec(Runnable r) { 463 synchronized (fEventQueue) { 464 fEventQueue.add(r); 465 } 466 fEventDispatchJob.schedule(); 467 } 468 469 475 public IBreakpointManager getBreakpointManager() { 476 if (fBreakpointManager == null) { 477 fBreakpointManager = new BreakpointManager(); 478 } 479 return fBreakpointManager; 480 } 481 482 488 public ILaunchManager getLaunchManager() { 489 if (fLaunchManager == null) { 490 fLaunchManager = new LaunchManager(); 491 } 492 return fLaunchManager; 493 } 494 495 501 public IMemoryBlockManager getMemoryBlockManager(){ 502 if (fMemoryBlockManager == null) { 503 fMemoryBlockManager = new MemoryBlockManager(); 504 } 505 return fMemoryBlockManager; 506 } 507 508 517 public IStatusHandler getStatusHandler(IStatus status) { 518 StatusHandlerKey key = new StatusHandlerKey(status.getPlugin(), status.getCode()); 519 if (fStatusHandlers == null) { 520 initializeStatusHandlers(); 521 } 522 IConfigurationElement config = (IConfigurationElement)fStatusHandlers.get(key); 523 if (config != null) { 524 try { 525 Object handler = config.createExecutableExtension("class"); if (handler instanceof IStatusHandler) { 527 return (IStatusHandler)handler; 528 } 529 invalidStatusHandler(null, MessageFormat.format("Registered status handler {0} does not implement required interface IStatusHandler.", new String [] {config.getDeclaringExtension().getUniqueIdentifier()})); } catch (CoreException e) { 531 log(e); 532 } 533 } 534 return null; 535 } 536 537 544 public IExpressionManager getExpressionManager() { 545 if (fExpressionManager == null) { 546 fExpressionManager = new ExpressionManager(); 547 } 548 return fExpressionManager; 549 } 550 551 559 public void removeDebugEventListener(IDebugEventSetListener listener) { 560 fEventListeners.remove(listener); 561 } 562 563 566 public void stop(BundleContext context) throws Exception { 567 try { 568 setShuttingDown(true); 569 570 if (fLaunchManager != null) { 571 fLaunchManager.shutdown(); 572 } 573 if (fBreakpointManager != null) { 574 fBreakpointManager.shutdown(); 575 } 576 if (fMemoryBlockManager != null) { 577 fMemoryBlockManager.shutdown(); 578 } 579 580 fEventListeners.clear(); 581 582 if (fEventFilters != null) { 583 fEventFilters = null; 584 } 585 SourceLookupUtils.shutdown(); 586 setDefault(null); 587 ResourcesPlugin.getWorkspace().removeSaveParticipant(this); 588 savePluginPreferences(); 589 } finally { 590 super.stop(context); 591 } 592 } 593 594 597 public void start(BundleContext context) throws Exception { 598 super.start(context); 599 DebugOptions.initDebugOptions(); 600 ResourcesPlugin.getWorkspace().addSaveParticipant(this, 601 new ISaveParticipant() { 602 public void saving(ISaveContext saveContext) throws CoreException { 603 savePluginPreferences(); 604 } 605 public void rollback(ISaveContext saveContext) {} 606 public void prepareToSave(ISaveContext saveContext) throws CoreException {} 607 public void doneSaving(ISaveContext saveContext) {} 608 }); 609 IAdapterManager manager= Platform.getAdapterManager(); 611 CommandAdapterFactory actionFactory = new CommandAdapterFactory(); 612 manager.registerAdapters(actionFactory, IDisconnect.class); 613 manager.registerAdapters(actionFactory, IDropToFrame.class); 614 manager.registerAdapters(actionFactory, IStep.class); 615 manager.registerAdapters(actionFactory, IStepFilters.class); 616 manager.registerAdapters(actionFactory, ISuspendResume.class); 617 manager.registerAdapters(actionFactory, ITerminate.class); 618 manager.registerAdapters(actionFactory, ILaunch.class); 619 manager.registerAdapters(actionFactory, IProcess.class); 620 manager.registerAdapters(actionFactory, IDebugElement.class); 621 } 622 623 640 public static IProcess newProcess(ILaunch launch, Process process, String label) { 641 return newProcess(launch, process, label, null); 642 } 643 644 665 public static IProcess newProcess(ILaunch launch, Process process, String label, Map attributes) { 666 ILaunchConfiguration config= launch.getLaunchConfiguration(); 667 String processFactoryID= null; 668 if (config != null) { 669 try { 670 processFactoryID= config.getAttribute(ATTR_PROCESS_FACTORY_ID, (String )null); 671 } catch (CoreException e) { 672 } 673 } 674 if (processFactoryID != null) { 675 DebugPlugin plugin= DebugPlugin.getDefault(); 676 if (plugin.fProcessFactories == null) { 677 plugin.initializeProcessFactories(); 678 } 679 IConfigurationElement element= (IConfigurationElement) plugin.fProcessFactories.get(processFactoryID); 680 if (element == null) { 681 return null; 682 } 683 IProcessFactory processFactory= null; 684 try { 685 processFactory = (IProcessFactory)element.createExecutableExtension("class"); } catch (CoreException exception) { 687 log(exception); 688 return null; 689 } 690 return processFactory.newProcess(launch, process, label, attributes); 691 } 692 return new RuntimeProcess(launch, process, label, attributes); 693 } 694 695 705 public static ILogicalStructureType[] getLogicalStructureTypes(IValue value) { 706 return LogicalStructureManager.getDefault().getLogicalStructureTypes(value); 707 } 708 709 721 public static ILogicalStructureType getDefaultStructureType(ILogicalStructureType[] types) { 722 return LogicalStructureManager.getDefault().getSelectedStructureType(types); 723 } 724 725 737 public static void setDefaultStructureType(ILogicalStructureType[] types, ILogicalStructureType def) { 738 LogicalStructureManager.getDefault().setEnabledType(types, def); 739 } 740 741 758 public static Process exec(String [] cmdLine, File workingDirectory) throws CoreException { 759 return exec(cmdLine, workingDirectory, null); 760 } 761 762 780 public static Process exec(String [] cmdLine, File workingDirectory, String [] envp) throws CoreException { 781 Process p= null; 782 try { 783 if (workingDirectory == null) { 784 p= Runtime.getRuntime().exec(cmdLine, envp); 785 } else { 786 p= Runtime.getRuntime().exec(cmdLine, envp, workingDirectory); 787 } 788 } catch (IOException e) { 789 Status status = new Status(IStatus.ERROR, getUniqueIdentifier(), INTERNAL_ERROR, DebugCoreMessages.DebugPlugin_Exception_occurred_executing_command_line__1, e); 790 throw new CoreException(status); 791 } catch (NoSuchMethodError e) { 792 IStatus status = new Status(IStatus.ERROR, getUniqueIdentifier(), ERR_WORKING_DIRECTORY_NOT_SUPPORTED, DebugCoreMessages.DebugPlugin_Eclipse_runtime_does_not_support_working_directory_2, e); 794 IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler(status); 795 796 if (handler != null) { 797 Object result = handler.handleStatus(status, null); 798 if (result instanceof Boolean && ((Boolean )result).booleanValue()) { 799 p= exec(cmdLine, null); 800 } 801 } 802 } 803 return p; 804 } 805 806 813 private boolean isShuttingDown() { 814 return fShuttingDown; 815 } 816 817 824 private void setShuttingDown(boolean value) { 825 fShuttingDown = value; 826 } 827 828 835 private Object [] getEventListeners() { 836 return fEventListeners.getListeners(); 837 } 838 839 847 public void addDebugEventFilter(IDebugEventFilter filter) { 848 if (fEventFilters == null) { 849 fEventFilters = new ListenerList(); 850 } 851 fEventFilters.add(filter); 852 } 853 854 862 public void removeDebugEventFilter(IDebugEventFilter filter) { 863 if (fEventFilters != null) { 864 fEventFilters.remove(filter); 865 if (fEventFilters.size() == 0) { 866 fEventFilters = null; 867 } 868 } 869 } 870 871 877 public static void logDebugMessage(String message) { 878 if (getDefault().isDebugging()) { 879 log(new Status(IStatus.ERROR, getUniqueIdentifier(), INTERNAL_ERROR, "Internal message logged from Debug Core: " + message, null)); } 883 } 884 885 891 public static void logMessage(String message, Throwable throwable) { 892 log(new Status(IStatus.ERROR, getUniqueIdentifier(), INTERNAL_ERROR, message, throwable)); 893 } 894 895 901 public static void log(IStatus status) { 902 getDefault().getLog().log(status); 903 } 904 905 911 public static void log(Throwable t) { 912 IStatus status= new Status(IStatus.ERROR, getUniqueIdentifier(), INTERNAL_ERROR, "Error logged from Debug Core: ", t); log(status); 914 } 915 916 920 private void initializeStatusHandlers() { 921 IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(DebugPlugin.PI_DEBUG_CORE, EXTENSION_POINT_STATUS_HANDLERS); 922 IConfigurationElement[] infos= extensionPoint.getConfigurationElements(); 923 fStatusHandlers = new HashMap (infos.length); 924 for (int i= 0; i < infos.length; i++) { 925 IConfigurationElement configurationElement = infos[i]; 926 String id = configurationElement.getAttribute("plugin"); String code = configurationElement.getAttribute("code"); 929 if (id != null && code != null) { 930 try { 931 StatusHandlerKey key = new StatusHandlerKey(id, Integer.parseInt(code)); 932 fStatusHandlers.put(key, configurationElement); 933 } catch (NumberFormatException e) { 934 invalidStatusHandler(e, configurationElement.getAttribute("id")); } 937 } else { 938 invalidStatusHandler(null, configurationElement.getAttribute("id")); } 941 } 942 } 943 944 948 private void initializeProcessFactories() { 949 IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(DebugPlugin.PI_DEBUG_CORE, EXTENSION_POINT_PROCESS_FACTORIES); 950 IConfigurationElement[] infos= extensionPoint.getConfigurationElements(); 951 fProcessFactories = new HashMap (infos.length); 952 for (int i= 0; i < infos.length; i++) { 953 IConfigurationElement configurationElement = infos[i]; 954 String id = configurationElement.getAttribute("id"); String clss = configurationElement.getAttribute("class"); if (id != null && clss != null) { 957 fProcessFactories.put(id, configurationElement); 958 } else { 959 String badDefiner= infos[i].getContributor().getName(); 961 log(new Status(IStatus.ERROR, DebugPlugin.PI_DEBUG_CORE, INTERNAL_ERROR, MessageFormat.format("Invalid process factory extension contributed by {0}; id: {1}", new String [] {badDefiner, id}), null)); } 963 } 964 } 965 966 private void invalidStatusHandler(Exception e, String id) { 967 log(new Status(IStatus.ERROR, DebugPlugin.PI_DEBUG_CORE, INTERNAL_ERROR, MessageFormat.format("Invalid status handler extension: {0}", new String [] {id}), e)); } 969 970 973 class StatusHandlerKey { 974 975 String fPluginId; 976 int fCode; 977 978 StatusHandlerKey(String pluginId, int code) { 979 fPluginId = pluginId; 980 fCode = code; 981 } 982 983 public int hashCode() { 984 return fPluginId.hashCode() + fCode; 985 } 986 987 public boolean equals(Object obj) { 988 if (obj instanceof StatusHandlerKey) { 989 StatusHandlerKey s = (StatusHandlerKey)obj; 990 return fCode == s.fCode && fPluginId.equals(s.fPluginId); 991 } 992 return false; 993 } 994 } 995 996 1001 private boolean hasEventFilters() { 1002 return fEventFilters != null && fEventFilters.size() > 0; 1003 } 1004 1005 1010 class AsynchRunner implements ISafeRunnable { 1011 1012 private Runnable fRunnable = null; 1013 1014 void async(Runnable runnable) { 1015 fRunnable = runnable; 1016 SafeRunner.run(this); 1017 fRunnable = null; 1018 1019 } 1020 1021 1024 public void handleException(Throwable exception) { 1025 IStatus status = new Status(IStatus.ERROR, getUniqueIdentifier(), INTERNAL_ERROR, "An exception occurred in asynchronous runnable.", exception); log(status); 1027 } 1028 1029 1032 public void run() throws Exception { 1033 fRunnable.run(); 1034 } 1035 1036 } 1037 1038 1042 class EventNotifier implements ISafeRunnable { 1043 1044 private DebugEvent[] fEvents; 1045 private IDebugEventSetListener fListener; 1046 private IDebugEventFilter fFilter; 1047 private int fMode; 1048 1049 1052 public void handleException(Throwable exception) { 1053 switch (fMode) { 1054 case NOTIFY_FILTERS: 1055 IStatus status = new Status(IStatus.ERROR, getUniqueIdentifier(), INTERNAL_ERROR, "An exception occurred while filtering debug events.", exception); log(status); 1057 break; 1058 case NOTIFY_EVENTS: 1059 status = new Status(IStatus.ERROR, getUniqueIdentifier(), INTERNAL_ERROR, "An exception occurred while dispatching debug events.", exception); log(status); 1061 break; 1062 } 1063 } 1064 1065 1068 public void run() throws Exception { 1069 switch (fMode) { 1070 case NOTIFY_FILTERS: 1071 fEvents = fFilter.filterDebugEvents(fEvents); 1072 break; 1073 case NOTIFY_EVENTS: 1074 fListener.handleDebugEvents(fEvents); 1075 break; 1076 } 1077 } 1078 1079 1085 void dispatch(DebugEvent[] events) { 1086 fEvents = events; 1087 if (hasEventFilters()) { 1088 fMode = NOTIFY_FILTERS; 1089 Object [] filters = fEventFilters.getListeners(); 1090 for (int i = 0; i < filters.length; i++) { 1091 fFilter = (IDebugEventFilter)filters[i]; 1092 SafeRunner.run(this); 1093 if (fEvents == null || fEvents.length == 0) { 1094 return; 1095 } 1096 } 1097 } 1098 1099 fMode = NOTIFY_EVENTS; 1100 Object [] listeners= getEventListeners(); 1101 if (DebugOptions.DEBUG_EVENTS) { 1102 for (int i = 0; i < fEvents.length; i++) { 1103 System.out.println(fEvents[i]); 1104 } 1105 } 1106 for (int i= 0; i < listeners.length; i++) { 1107 fListener = (IDebugEventSetListener)listeners[i]; 1108 SafeRunner.run(this); 1109 } 1110 fEvents = null; 1111 fFilter = null; 1112 fListener = null; 1113 } 1114 1115 } 1116 1117 1124 public static Document newDocument()throws CoreException { 1125 try { 1126 return LaunchManager.getDocument(); 1127 } catch (ParserConfigurationException e) { 1128 abort(SourceLookupMessages.SourceLookupUtils_3, e); 1129 } 1130 return null; 1131 } 1132 1133 1141 public static String serializeDocument(Document document) throws CoreException { 1142 try { 1143 return LaunchManager.serializeDocument(document); 1144 } catch (TransformerException e) { 1145 abort(SourceLookupMessages.SourceLookupUtils_4, e); 1146 } catch (IOException e) { 1147 abort(SourceLookupMessages.SourceLookupUtils_5, e); 1148 } 1149 return null; 1150 } 1151 1152 1161 public static Element parseDocument(String document) throws CoreException { 1162 Element root = null; 1163 InputStream stream = null; 1164 try{ 1165 DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 1166 parser.setErrorHandler(new DefaultHandler ()); 1167 stream = new ByteArrayInputStream (document.getBytes()); 1168 root = parser.parse(stream).getDocumentElement(); 1169 } catch (ParserConfigurationException e) { 1170 abort(SourceLookupMessages.SourceLookupUtils_6, e); 1171 } catch (FactoryConfigurationError e) { 1172 abort(SourceLookupMessages.SourceLookupUtils_7, e); 1173 } catch (SAXException e) { 1174 abort(SourceLookupMessages.SourceLookupUtils_8, e); 1175 } catch (IOException e) { 1176 abort(SourceLookupMessages.SourceLookupUtils_9, e); 1177 } finally { 1178 try{ 1179 if (stream != null) { 1180 stream.close(); 1181 } 1182 } catch(IOException e) { 1183 abort(SourceLookupMessages.SourceLookupUtils_10, e); 1184 } 1185 } 1186 return root; 1187 } 1188 1189 1196 private static void abort(String message, Throwable exception) throws CoreException { 1197 IStatus status = new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), DebugPlugin.INTERNAL_ERROR, message, exception); 1198 throw new CoreException(status); 1199 } 1200 1201 1206 private static class ArgumentParser { 1207 private String fArgs; 1208 private int fIndex= 0; 1209 private int ch= -1; 1210 1211 public ArgumentParser(String args) { 1212 fArgs= args; 1213 } 1214 1215 public String [] parseArguments() { 1216 List v= new ArrayList (); 1217 1218 ch= getNext(); 1219 while (ch > 0) { 1220 if (Character.isWhitespace((char)ch)) { 1221 ch= getNext(); 1222 } else { 1223 if (ch == '"') { 1224 StringBuffer buf = new StringBuffer (); 1225 buf.append(parseString()); 1226 if (buf.length() == 0 && Platform.getOS().equals(Constants.OS_WIN32)) { 1227 buf.append("\"\""); } 1230 v.add(buf.toString()); 1231 } else { 1232 v.add(parseToken()); 1233 } 1234 } 1235 } 1236 1237 String [] result= new String [v.size()]; 1238 v.toArray(result); 1239 return result; 1240 } 1241 1242 private int getNext() { 1243 if (fIndex < fArgs.length()) 1244 return fArgs.charAt(fIndex++); 1245 return -1; 1246 } 1247 1248 private String parseString() { 1249 ch= getNext(); 1250 if (ch == '"') { 1251 ch= getNext(); 1252 return ""; } 1254 StringBuffer buf= new StringBuffer (); 1255 while (ch > 0 && ch != '"') { 1256 if (ch == '\\') { 1257 ch= getNext(); 1258 if (ch != '"') { buf.append('\\'); 1260 } else { 1261 if (Platform.getOS().equals(Constants.OS_WIN32)) { 1262 buf.append('\\'); 1264 } 1265 } 1266 } 1267 if (ch > 0) { 1268 buf.append((char)ch); 1269 ch= getNext(); 1270 } 1271 } 1272 ch= getNext(); 1273 return buf.toString(); 1274 } 1275 1276 private String parseToken() { 1277 StringBuffer buf= new StringBuffer (); 1278 1279 while (ch > 0 && !Character.isWhitespace((char)ch)) { 1280 if (ch == '\\') { 1281 ch= getNext(); 1282 if (Character.isWhitespace((char)ch)) { 1283 buf.append('\\'); 1285 return buf.toString(); 1286 } 1287 if (ch > 0) { 1288 if (ch != '"') { buf.append('\\'); 1290 } else { 1291 if (Platform.getOS().equals(Constants.OS_WIN32)) { 1292 buf.append('\\'); 1294 } 1295 } 1296 buf.append((char)ch); 1297 ch= getNext(); 1298 } else if (ch == -1) { buf.append('\\'); 1300 } 1301 } else if (ch == '"') { 1302 buf.append(parseString()); 1303 } else { 1304 buf.append((char)ch); 1305 ch= getNext(); 1306 } 1307 } 1308 return buf.toString(); 1309 } 1310 } 1311 1312 1321 public static String [] parseArguments(String args) { 1322 if (args == null) 1323 return new String [0]; 1324 ArgumentParser parser= new ArgumentParser(args); 1325 String [] res= parser.parseArguments(); 1326 1327 return res; 1328 } 1329 1330 1339 public static void setUseStepFilters(boolean useStepFilters) { 1340 getStepFilterManager().setUseStepFilters(useStepFilters); 1341 } 1342 1343 1351 public static boolean isUseStepFilters() { 1352 return getStepFilterManager().isUseStepFilters(); 1353 } 1354 1355 1360 private static StepFilterManager getStepFilterManager() { 1361 return ((LaunchManager)getDefault().getLaunchManager()).getStepFilterManager(); 1362 } 1363 1364} 1365 1366 1367 | Popular Tags |