home *** CD-ROM | disk | FTP | other *** search
- !!include "Library\jdkUtilities.script"
- !!Script
- // Copyright ⌐ 1997-2002 - Modelworks Software
- // @Modified build 223 cm19980923 - removed runInWindow test
- // @Modified build 228 cm19981020 - replaced inline classpath computation with a function call
- // @Modified build 265 cm19990213 - added support for the changed chooseApplication dialog
- // @Modified build 346 cm20000507 - add support for debug tab
- // @Modified build 595 cm20020129 - added support custom options
- // @Modified build 611 cm20020409 - added support for ReplaceEnvironmentVariables
-
- /**
- @Tool: debugClass~displays a dialog to let enter a class to
- debug using the IDE's visual debugger wrapped around Sun's command line debugger.
- @Image: Debug Class Dialog@debugClassJDKDialog.gif
- @Note: This is the script that is used by the JDK/Debug Class menu.
- @EndNote:
- @Tip: Make sure you do not name your JDK directory with a space (e.g., "JDK 1.1.4" or
- use spaces in naming any of your own directories that may need to be included in a classpath.
- This can cause a problem for some of Sun's tools. In particular, Sun's debugger (as of JDK 1.1.4)
- does not work if you have a classpath with a space.
- @EndTip:
- @Tip: Sun's command line debugger communicates with the debugee using TCP/IP. Because of this,
- jdb may prompt you to connect to the internet during initilization if you use a dial-up connection
- to the internet. However, jdb does need the connection to the internet, so you should be able
- to proceed by just canceling the connect dialog.
- @EndTip:
- @EndTool:
- @Summary: debugClass~runs the visual java debugger
- */
-
- var gOutput = getOutput("Debug");
- var helpers = getMapFile("ApplicationHelpers");
- var gOptions = getMapFile("JDKToolsStandardOptions");
-
- function DoCommand()
- {
- gOutput.clear();
-
- // Save all open files
- saveAll();
- Application.showOutputPanel(true);
-
- var javaUtilities = getScriptObject("\\Library\\javaUtilities");
- var lastClassRun = javaUtilities.GetLastClassRun();
- var applicationParameters = javaUtilities.GetApplicationParameters();
-
- var runApplicationFile = helpers.lookup("jdk-debugger");
- if (runApplicationFile == null)
- {
- var result = confirm("You need to run the JDK setup script\n"
- + "before you can use this command.\n" +
- "Do you want to run the setup script now?");
- if (result)
- {
- run("Configuration\\JDK");
- }
- return;
- }
-
- // cm19990213 - start changes
-
- var fileInfo = lastClassRun;
-
- var editor = getActiveEditor();
- if (editor)
- {
- var file = editor.getFile();
- if (file.fileType == "java")
- {
- fileInfo = file.path;
- var mainFindData = editor.findFirst("void main", 0, 0);
- if (mainFindData)
- {
- lastClassRun = file.title;
- }
- }
- }
-
- var history = gOptions.lookup("runClass History");
- if (history == null)
- {
- history = newList();
- gOptions.add("runClass History", history);
- }
-
- var jdkOptions = getScriptObject("\\Library\\jdkOptions");
- var message = "Enter the full class name of the class to debug. ";
- message += "Warning: your class will not run unless the class file exists in the current classpath ";
- var result = chooseApplication(message,
- "",
- lastClassRun, "",
- "Using application parameters (Be sure to quote strings with spaces)",
- applicationParameters,
- "Debug Java application class using " + runApplicationFile.name,
- "Options...",
- jdkOptions.ChooseRunOptions,
- fileInfo,
- history);
-
- if (result)
- {
- CleanupHistory(history);
- gOptions.forceUpdate();// cm19990213 - end changes
-
- var className = result.key;
- applicationParameters = result.value;
- JDKDebugClass(className, applicationParameters);
-
- // Update Data
- javaUtilities.SetLastClassRun(className);
- javaUtilities.SetApplicationParameters(applicationParameters);
- }
- }
-
- function CleanupHistory(history)
- {
- while (history.count > 10)
- {
- history.removeTail();
- }
- }
-
- function JDKDebugClass(className, applicationParameters)
- {
- var jdb = helpers.lookup("jdk-debugger");
-
- var useEnvironmentClasspath = gOptions.lookup("useEnvironmentClasspath", false);
- var standardOptions = gOptions.lookup("jdk-debugger", ""); // cm19980923
- var customOptions = gOptions.lookup("customOptions", ""); // cm20020129
-
- if (jdb && jdb.exists)
- {
- gOutput.writeLine("Starting debugger for " + className);
-
- // Quote all paths in case a path contains spaces
-
- // Add the path to the tool -- this must be first
- var command = "\"" + jdb.path + "\" ";
-
- // Add options
- if (standardOptions.length > 0)
- {
- command += standardOptions + " ";
- }
- if (customOptions.length > 0)
- {
- command += customOptions + " ";
- }
-
- if (useEnvironmentClasspath)
- {
- var tool = newTool();
- tool.setEnvironmentVariable("Classpath", getGlobal("EnvironmentClasspath"));
- }
- else
- {
- // Add the classpaths quoting the classpaths argument
- command += GetClasspathArgument(""); // cm19981020
- }
-
- // Add the class name of the file to be run
- command += className;
-
- // Add application parameters to command line
- if (applicationParameters.length > 0)
- {
- command += " " + applicationParameters;
- }
-
- command = ReplaceEnvironmentVariables(command); //cm20020409
- if (gOptions.lookup("showCommandLine",false)==true)
- {
- gOutput.writeLine("Command line: " + command);
- }
-
- // Invoke visual debugger for JDK
- var utilities = getScriptObject("\\Java\\Jdk\\Debugger\\utilities.script");
- if (utilities)
- {
- var verbose = gOptions.lookup("ShowAllDebugOutput", 1);
- var jdkDebugger = utilities.CreateJDKDebugger(jdb.path, command, verbose, gOutput);
- if (jdkDebugger)
- {
- // Add standard Debug menu
- utilities.AddDebugMenu();
-
- if (!jdkDebugger.verbose)
- {
- gOutput.writeLine("Initializing debugger...");
- }
-
- // Set all current breakpoints
- if (utilities.SetBreakpoints(jdkDebugger) == 0)
- {
- var jdb_g = newFile(jdb.directory + "\\jdb_g.exe");
- gOutput.writeLine("No breakpoints set - stopping in main");
- if (jdb_g.exists) // JDK 1.1 and earlier
- {
- jdkDebugger.sendCommand("stop in " + className + ".main\n");
- }
- else
- {
- jdkDebugger.sendCommand("stop in " + className + ".main(java/lang/String[])\n");
- }
- }
-
- // Go!
- jdkDebugger.sendCommand("run\n");
- }
- }
- }
- else
- {
- var result = confirm("You need to run the JDK setup script\n"
- + "before you can use this command.\n" +
- "Do you want to run the setup script now?");
- if (result)
- {
- run("Configuration\\JDK");
- }
- }
- }
-
- !!/Script
-