home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 67 / IOPROG_67A.ISO / soft / Tools / mwsppv4.exe / DEBUGCLASS.SCRIPT < prev    next >
Encoding:
Text File  |  2002-10-15  |  6.6 KB  |  225 lines

  1. !!include "Library\jdkUtilities.script"
  2. !!Script
  3. // Copyright ⌐ 1997-2002 - Modelworks Software
  4. // @Modified build 223 cm19980923 - removed runInWindow test
  5. // @Modified build 228 cm19981020 - replaced inline classpath computation with a function call
  6. // @Modified build 265 cm19990213 - added support for the changed chooseApplication dialog
  7. // @Modified build 346 cm20000507 - add support for debug tab 
  8. // @Modified build 595 cm20020129 - added support custom options
  9. // @Modified build 611 cm20020409 - added support for ReplaceEnvironmentVariables 
  10.  
  11. /**
  12. @Tool: debugClass~displays a dialog to let enter a class to 
  13. debug using the IDE's visual debugger wrapped around Sun's command line debugger. 
  14. @Image: Debug Class Dialog@debugClassJDKDialog.gif 
  15. @Note: This is the script that is used by the JDK/Debug Class menu. 
  16. @EndNote:
  17. @Tip: Make sure you do not name your JDK directory with a space (e.g., "JDK 1.1.4" or 
  18. use spaces in naming any of your own directories that may need to be included in a classpath. 
  19. This can cause a problem for some of Sun's tools. In particular, Sun's debugger (as of JDK 1.1.4) 
  20. does not work if you have a classpath with a space. 
  21. @EndTip:
  22. @Tip: Sun's command line debugger communicates with the debugee using TCP/IP. Because of this, 
  23. jdb may prompt you to connect to the internet during initilization if you use a dial-up connection 
  24. to the internet. However, jdb does need the connection to the internet, so you should be able 
  25. to proceed by just canceling the connect dialog. 
  26. @EndTip:
  27. @EndTool: 
  28. @Summary: debugClass~runs the visual java debugger
  29. */
  30.  
  31. var gOutput = getOutput("Debug");
  32. var helpers = getMapFile("ApplicationHelpers");   
  33. var gOptions = getMapFile("JDKToolsStandardOptions");
  34.  
  35. function DoCommand()  
  36. {
  37.     gOutput.clear();
  38.     
  39.     // Save all open files
  40.     saveAll();
  41.     Application.showOutputPanel(true);
  42.     
  43.     var javaUtilities = getScriptObject("\\Library\\javaUtilities");
  44.     var lastClassRun = javaUtilities.GetLastClassRun();
  45.     var applicationParameters = javaUtilities.GetApplicationParameters();
  46.     
  47.     var runApplicationFile = helpers.lookup("jdk-debugger");
  48.     if (runApplicationFile == null)
  49.     {
  50.         var result = confirm("You need to run the JDK setup script\n"
  51.             + "before you can use this command.\n" +
  52.             "Do you want to run the setup script now?");
  53.         if (result)
  54.         {
  55.             run("Configuration\\JDK");
  56.         }
  57.         return;
  58.     }
  59.     
  60.     // cm19990213 - start changes
  61.     
  62.     var fileInfo = lastClassRun;
  63.     
  64.     var editor = getActiveEditor();
  65.     if (editor)
  66.     {
  67.         var file = editor.getFile();
  68.         if (file.fileType == "java")
  69.         {
  70.             fileInfo = file.path;
  71.             var mainFindData = editor.findFirst("void main", 0, 0);
  72.             if (mainFindData)
  73.             {
  74.                 lastClassRun = file.title;
  75.             }
  76.         }
  77.     }
  78.     
  79.     var history = gOptions.lookup("runClass History");
  80.     if (history == null)
  81.     {
  82.         history = newList();
  83.         gOptions.add("runClass History", history);
  84.     }
  85.     
  86.     var jdkOptions = getScriptObject("\\Library\\jdkOptions");
  87.     var message = "Enter the full class name of the class to debug. ";
  88.     message += "Warning: your class will not run unless the class file exists in the current classpath ";
  89.     var result = chooseApplication(message, 
  90.         "", 
  91.         lastClassRun, "", 
  92.         "Using application parameters (Be sure to quote strings with spaces)", 
  93.         applicationParameters,
  94.         "Debug Java application class using " + runApplicationFile.name,
  95.         "Options...",
  96.         jdkOptions.ChooseRunOptions,
  97.         fileInfo, 
  98.         history); 
  99.     
  100.     if (result)
  101.     {
  102.         CleanupHistory(history);
  103.         gOptions.forceUpdate();// cm19990213  - end changes
  104.         
  105.         var className = result.key;
  106.         applicationParameters = result.value;
  107.         JDKDebugClass(className, applicationParameters);
  108.         
  109.         // Update Data
  110.         javaUtilities.SetLastClassRun(className);
  111.         javaUtilities.SetApplicationParameters(applicationParameters);
  112.     }
  113.  
  114. function CleanupHistory(history)
  115. {
  116.     while (history.count > 10)
  117.     {
  118.         history.removeTail();
  119.     }
  120. }
  121.  
  122. function JDKDebugClass(className, applicationParameters)
  123. {
  124.     var jdb = helpers.lookup("jdk-debugger"); 
  125.     
  126.     var useEnvironmentClasspath = gOptions.lookup("useEnvironmentClasspath", false);
  127.     var standardOptions = gOptions.lookup("jdk-debugger", ""); // cm19980923
  128.     var customOptions = gOptions.lookup("customOptions", ""); // cm20020129
  129.     
  130.     if (jdb && jdb.exists)
  131.     {
  132.         gOutput.writeLine("Starting debugger for " + className);
  133.         
  134.         // Quote all paths in case a path contains spaces
  135.         
  136.         // Add the path to the tool -- this must be first
  137.         var command = "\"" + jdb.path + "\" ";
  138.         
  139.         // Add options
  140.         if (standardOptions.length > 0)
  141.         {
  142.             command += standardOptions + " ";
  143.         }
  144.         if (customOptions.length > 0)
  145.         {
  146.             command += customOptions + " ";
  147.         }
  148.         
  149.         if (useEnvironmentClasspath)
  150.         {
  151.             var tool = newTool();
  152.             tool.setEnvironmentVariable("Classpath", getGlobal("EnvironmentClasspath"));
  153.         }
  154.         else
  155.         {
  156.             // Add the classpaths quoting the classpaths argument
  157.             command += GetClasspathArgument(""); // cm19981020
  158.         }
  159.         
  160.         // Add the class name of the file to be run
  161.         command += className;
  162.         
  163.         // Add application parameters to command line        
  164.         if (applicationParameters.length > 0)
  165.         {
  166.             command += " " + applicationParameters;
  167.         }
  168.         
  169.         command = ReplaceEnvironmentVariables(command); //cm20020409    
  170.         if (gOptions.lookup("showCommandLine",false)==true)
  171.         {
  172.             gOutput.writeLine("Command line: " + command);
  173.         }
  174.         
  175.         // Invoke visual debugger for JDK
  176.         var utilities = getScriptObject("\\Java\\Jdk\\Debugger\\utilities.script");
  177.         if (utilities)
  178.         {
  179.             var verbose = gOptions.lookup("ShowAllDebugOutput", 1);
  180.             var jdkDebugger = utilities.CreateJDKDebugger(jdb.path, command, verbose, gOutput);
  181.             if (jdkDebugger)
  182.             {
  183.                 // Add standard Debug menu
  184.                 utilities.AddDebugMenu();
  185.                 
  186.                 if (!jdkDebugger.verbose)
  187.                 {
  188.                     gOutput.writeLine("Initializing debugger...");
  189.                 }
  190.                 
  191.                 // Set all current breakpoints
  192.                 if (utilities.SetBreakpoints(jdkDebugger) == 0)
  193.                 {
  194.                     var jdb_g = newFile(jdb.directory + "\\jdb_g.exe");
  195.                     gOutput.writeLine("No breakpoints set - stopping in main");
  196.                     if (jdb_g.exists) // JDK 1.1 and earlier
  197.                     {
  198.                         jdkDebugger.sendCommand("stop in " + className + ".main\n");
  199.                     }
  200.                     else
  201.                     {
  202.                         jdkDebugger.sendCommand("stop in " + className + ".main(java/lang/String[])\n");
  203.                     }
  204.                 }
  205.                 
  206.                 // Go!
  207.                 jdkDebugger.sendCommand("run\n");
  208.             }
  209.         }
  210.     }
  211.     else
  212.     {
  213.         var result = confirm("You need to run the JDK setup script\n"
  214.             + "before you can use this command.\n" +
  215.             "Do you want to run the setup script now?");
  216.         if (result)
  217.         {
  218.             run("Configuration\\JDK");
  219.         }
  220.     }
  221. }
  222.  
  223. !!/Script
  224.