home *** CD-ROM | disk | FTP | other *** search
- !!Include "Library\msjUtilities.script"
- !!Script
- // Copyright ⌐ 1997-1998 - Modelworks Software
- // @Modified build 225 cm19981008 - restore accelerator when changing menu name
- // @Modified build 228 cm19981021 - added path parameter to GetMSJCompileCommandLine
- // @Modified build 353 cm20000517 - added support for ouput tabs
-
- /**
- @Tool: compile~translates a java file into Java bytecodes
- using Microsoft's Java compiler (jvc.exe). This script will compile the
- active editor if it is a java file, otherwise this script will ask you
- to select a Java file to compile. The class file generated by this script
- will be put into the same directory as the source file unless the source
- file is included in an open project. In that case the destination directory
- will be determined using the package destination directory.
- @Note: This is the script that is used by the MSJ/Compile menu.
- @EndNote:
- @EndTool:
- @Summary: compile~translates a java file into Java bytecodes
- */
-
- var gOutput = getOutput("Build");
- var helpers = getMapFile("ApplicationHelpers");
- var gOptions = getMapFile("MSJToolsStandardOptions");
-
- function DoUpdate(cmdUI)
- {
- var textSet = false;
- // If the current document is a Java file then use that file
- var editor = getActiveEditor();
- if (editor)
- {
- var file = editor.getFile();
- if (file) // Carefull: an untitled document does not have a file
- {
- var fileType = file.fileType.toLowerCase();
- if (fileType == "java")
- {
- var label = cmdUI.getText(); //cm19981008
- var tabIndex = label.indexOf('\t');
- var shortcut = "";
- if (tabIndex > -1) //cm19981008
- {
- shortcut = label.substring(tabIndex, label.length);
- }
- cmdUI.setText("Compile " + file.name + shortcut);
- textSet = true;
- }
- }
- }
-
- if (!textSet)
- {
- var label = cmdUI.getText(); //cm19981008
- var tabIndex = label.indexOf('\t');
- var shortcut = "";
- if (tabIndex > -1)
- {
- shortcut = label.substring(tabIndex, label.length);
- }
- cmdUI.setText("Compile..." + shortcut);
- }
-
- cmdUI.enable(true);
- return true;
- }
-
- function DoCommand()
- {
- if (!MSJSupported())
- {
- return;
- }
-
- gOutput.clear();
-
- // Save all open files
- saveAll();
-
- var path = "";
-
- // If the current document is a Java file then use that file
- var editor = getActiveEditor();
- if (editor)
- {
- var fileType = editor.getFile().fileType.toLowerCase();
- if (fileType == "java")
- {
- path = editor.path;
- }
- }
-
- // Else ask the user to locate a Java file
- if (path == "")
- {
- var file = chooseFile("Choose a Java file to compile", "Java files", "*.java");
- if (file && file.exists)
- {
- path = file.path;
- }
- }
-
- if (path.length > 0)
- {
- var command = GetMSJCompileCommandLine(path); //cm19981021
- if (command && command.length > 0)
- {
- var build = gOptions.lookup("msj-build", "");
- gOutput.writeLine("---------------- " + build + " ------------------");
- gOutput.writeLine("Compiling " + path);
- DoCompile(command, path);
- gOutput.writeLine("Finished");
- }
- }
- }
-
- function DoCompile(command, path)
- {
- // Add the destination directory if required
- var destinationPath = GetDestinationPath(path);
- if (destinationPath.length > 0)
- {
- command += " /d \"" + destinationPath + "\"";
- }
-
- // Add the path of the file to be compiled
- command += " \"" + path + "\"";
-
- if (gOptions.lookup("showCommandLine",false)==true)
- {
- gOutput.writeLine("Command Line: " + command);
- }
-
- File.setDirectory(path);
- if (gOptions.lookup("showCommandLine",false)==true)
- {
- gOutput.writeLine("The current directory is: " + File.getDirectory().path);
- }
-
- // Create a process to run the compiler
- var compileTool = newTool(gOutput);
-
- clearCLASSPATH(compileTool);
-
- compileTool.run(command);
- }
-
- !!/Script
-