home *** CD-ROM | disk | FTP | other *** search
- !!Script
- // Copyright ⌐ 2001 - Modelworks Software
- // @Created build 503 cm20010319
-
- /**
- @Tool: run~execute a command line in the specified
- directory. This script is designed to be run by the
- Command Line toolbar.
- @EndTool:
- @Summary: run~execute a command line
- */
-
- var gCommandLineMapfile = getMapFile("CommandLine.map");
-
- var gOutput = getOutput("Command Line");
-
- function ProcessEditorPath(commandLine)
- {
- var macro = "$editor.path";
- var index = commandLine.indexOf(macro);
- if (index > -1)
- {
- var replace = "";
- var editor = getActiveEditor();
- if (editor)
- {
- replace = editor.getFile().path;
- }
- else
- {
- gOutput.writeLine("Warning: no editor is open. Replacing $editor.path with the empty string");
- }
- while (index > -1)
- {
- commandLine = replaceInString(commandLine, index, macro.length, replace);
- index = commandLine.indexOf(macro);
- }
- }
- return commandLine;
- }
-
- function ProcessEditorDirectory(commandLine)
- {
- var macro = "$editor.directory";
- var index = commandLine.indexOf(macro);
- if (index > -1)
- {
- var replace = "";
- var editor = getActiveEditor();
- if (editor)
- {
- replace = editor.getFile().directory;
- }
- else
- {
- gOutput.writeLine("Warning: no editor is open. Replacing $editor.directory with the empty string");
- }
- while (index > -1)
- {
- commandLine = replaceInString(commandLine, index, macro.length, replace);
- index = commandLine.indexOf(macro);
- }
- }
- return commandLine;
- }
-
-
- function ProcessEditorName(commandLine)
- {
- var macro = "$editor.name";
- var index = commandLine.indexOf(macro);
- if (index > -1)
- {
- var replace = "";
- var editor = getActiveEditor();
- if (editor)
- {
- replace = editor.getFile().title;
- }
- else
- {
- gOutput.writeLine("Warning: no editor is open. Replacing $editor.name with the empty string");
- }
- while (index > -1)
- {
- commandLine = replaceInString(commandLine, index, macro.length, replace);
- index = commandLine.indexOf(macro);
- }
- }
- return commandLine;
- }
-
- function ProcessEditorFileType(commandLine)
- {
- var macro = "$editor.fileType";
- var index = commandLine.indexOf(macro);
- if (index > -1)
- {
- var replace = "";
- var editor = getActiveEditor();
- if (editor)
- {
- replace = editor.getFile().fileType;
- }
- else
- {
- gOutput.writeLine("Warning: no editor is open. Replacing $editor.fileType with the empty string");
- }
- while (index > -1)
- {
- commandLine = replaceInString(commandLine, index, macro.length, replace);
- index = commandLine.indexOf(macro);
- }
- }
- return commandLine;
- }
-
- function ProcessEditorSourcepath(commandLine)
- {
- var macro = "$editor.sourcepath";
- var index = commandLine.indexOf(macro);
- if (index > -1)
- {
- var replace = "";
- var editor = getActiveEditor();
- if (editor)
- {
- if (editor.getFile().fileType == 'java')
- {
- replace = Java.getClassPath(editor.path);
- }
- else
- {
- gOutput.writeLine("Warning: sourcepath not defined for non-java file. Replacing $editor.sourcepath with the empty string");
- }
- }
- else
- {
- gOutput.writeLine("Warning: no editor is open. Replacing $editor.sourcepath with the empty string");
- }
-
- while (index > -1)
- {
- commandLine = replaceInString(commandLine, index, macro.length, replace);
- index = commandLine.indexOf(macro);
- }
- }
- return commandLine;
- }
-
- function ProcessProjectClasspaths(commandLine)
- {
- var macro = "$project.java.classpaths";
- var index = commandLine.indexOf(macro);
- if (index > -1)
- {
- var classpaths = "";
- var project = getCurrentProject();
- if (project)
- {
- var packageList = project.getPackageList();
- var position = packageList.getHeadPosition();
- while (position && position.valid)
- {
- var pkg = packageList.getNext(position);
- var classpath = pkg.getJavaClasspath();
- if (classpath && classpath.length > 0)
- {
- if (classpaths.length > 0)
- {
- classpaths += ";";
- }
- classpaths += classpath;
- }
- }
- }
- else
- {
- gOutput.writeLine("Warning: no project is open. Replacing $project.java.classpaths with the empty string");
- }
-
- while (index > -1)
- {
- commandLine = replaceInString(commandLine, index, macro.length, classpaths);
- index = commandLine.indexOf(macro);
- }
- }
- return commandLine;
- }
-
- function ProcessJavaStandardClasspaths(commandLine)
- {
- var macro = "$java.jdk.standardclasspaths";
- var index = commandLine.indexOf(macro);
- if (index > -1)
- {
- var options = getMapFile("JDKToolsStandardOptions");
- var classpath = options.lookup("standardClasspaths", "");
- while (index > -1)
- {
- commandLine = replaceInString(commandLine, index, macro.length, classpath);
- index = commandLine.indexOf(macro);
- }
- }
- return commandLine;
- }
-
- function ProcessJavaCustomClasspaths(commandLine)
- {
- var macro = "$java.jdk.customclasspaths";
- var index = commandLine.indexOf(macro);
- if (index > -1)
- {
- var options = getMapFile("JDKToolsStandardOptions");
- var classpath = options.lookup("customClasspaths", "");
- while (index > -1)
- {
- commandLine = replaceInString(commandLine, index, macro.length, classpath);
- index = commandLine.indexOf(macro);
- }
- }
- return commandLine;
- }
-
- function ProcessMacros(commandLine)
- {
- commandLine = ProcessEditorPath(commandLine);
- commandLine = ProcessEditorDirectory(commandLine);
- commandLine = ProcessEditorName(commandLine);
- commandLine = ProcessEditorFileType(commandLine);
- commandLine = ProcessEditorSourcepath(commandLine);
- commandLine = ProcessProjectClasspaths(commandLine);
- commandLine = ProcessJavaStandardClasspaths(commandLine);
- commandLine = ProcessJavaCustomClasspaths(commandLine);
-
- return commandLine;
- }
-
- function DoCommand()
- {
- gOutput.clear();
-
- var gCommandLineComboBox = getGlobal("CommandLine.CommandLineComboBox");
- var gDirectoryComboBox = getGlobal("CommandLine.DirectoryComboBox");
-
- var commandLine = ProcessMacros(gCommandLineComboBox.text);
- var directory = ProcessMacros(gDirectoryComboBox.text);
-
- if (commandLine.length > 0)
- {
- /*
- var tool = newTool();
- tool.async = true;
- tool.output = gOutput;
-
- gOutput.writeLine("Command line: " + commandLine);
- if (directory.length > 0)
- {
- File.setDirectory(directory);
- gOutput.writeLine("Current directory: " + directory);
- }
-
- tool.run(commandLine);
- */
-
- gOutput.writeLine("Command line: " + commandLine);
- if (directory.length > 0)
- {
- File.setDirectory(directory);
- gOutput.writeLine("Current directory: " + directory);
- }
-
- var cleanupHandler = File.getToolsPath() + "\\Command\\onCleanupProcess.script";
- var process = newProcess();
- setGlobal("interactiveProcess", process);
-
- process.output = gOutput;
- var items = commandLine.split(' ');
- process.run(items[0], commandLine, getScriptPath());
-
- // Now update command line data
-
- commandLine = gCommandLineComboBox.text;
- directory = gDirectoryComboBox.text;
- if (directory.length > 0)
- {
- var directoryList = gCommandLineMapfile.lookup("DirectoryList", null);
- if (directoryList == null)
- {
- directoryList = newList();
- gCommandLineMapfile.add("DirectoryList", directoryList);
- }
-
- var index = directoryList.find(directory, false);
- if (index > -1)
- {
- var position = directoryList.getPosition(index)
- directoryList.removeAt(position);
- }
-
- directoryList.addHead(directory);
- gCommandLineMapfile.add("CurrentDirectory", directory);
-
- while(directoryList.count > 20)
- {
- directoryList.removeTail();
- }
- }
-
- var commandList = gCommandLineMapfile.lookup("CommandList", null);
- if (commandList == null)
- {
- commandList = newList();
- gCommandLineMapfile.add("CommandList", commandList);
- }
-
- var index = commandList.find(commandLine, false);
- if (index > -1)
- {
- var position = commandList.getPosition(index)
- commandList.removeAt(position);
- }
-
- commandList.addHead(commandLine);
- gCommandLineMapfile.add("CurrentCommand", commandLine);
-
- while(commandList.count > 20)
- {
- commandList.removeTail();
- }
-
- gCommandLineMapfile.forceUpdate();
- }
- }
-
- function OnNotify()
- {
- removeGlobal("interactiveProcess");
- }
-
-
- !!/Script
-
-