home *** CD-ROM | disk | FTP | other *** search
/ PC User 2001 August / APC_Aug2001_CD2.iso / features / web_dev / files / mwjpp516.exe / %MAINDIR% / Tools / Command / run.script < prev   
Encoding:
Text File  |  2001-06-19  |  8.2 KB  |  344 lines

  1. !!Script
  2. // Copyright ⌐ 2001 - Modelworks Software
  3. // @Created build 503 cm20010319
  4.  
  5. /**
  6. @Tool: run~execute a command line in the specified
  7. directory. This script is designed to be run by the
  8. Command Line toolbar. 
  9. @EndTool: 
  10. @Summary: run~execute a command line
  11. */
  12.  
  13. var gCommandLineMapfile = getMapFile("CommandLine.map");
  14.  
  15. var gOutput = getOutput("Command Line");
  16.  
  17. function ProcessEditorPath(commandLine)
  18. {
  19.     var macro = "$editor.path";
  20.     var index = commandLine.indexOf(macro);
  21.     if (index > -1)
  22.     {
  23.         var replace = "";
  24.         var editor = getActiveEditor();
  25.         if (editor)
  26.         {
  27.             replace = editor.getFile().path;
  28.         }
  29.         else
  30.         {
  31.             gOutput.writeLine("Warning: no editor is open. Replacing $editor.path with the empty string");
  32.         }
  33.         while (index > -1)
  34.         {
  35.             commandLine = replaceInString(commandLine, index, macro.length, replace);
  36.             index = commandLine.indexOf(macro);
  37.         }
  38.     }
  39.     return commandLine;
  40. }
  41.  
  42. function ProcessEditorDirectory(commandLine)
  43. {
  44.     var macro = "$editor.directory";
  45.     var index = commandLine.indexOf(macro);
  46.     if (index > -1)
  47.     {
  48.         var replace = "";
  49.         var editor = getActiveEditor();
  50.         if (editor)
  51.         {
  52.             replace = editor.getFile().directory;
  53.         }
  54.         else
  55.         {
  56.             gOutput.writeLine("Warning: no editor is open. Replacing $editor.directory with the empty string");
  57.         }
  58.         while (index > -1)
  59.         {
  60.             commandLine = replaceInString(commandLine, index, macro.length, replace);
  61.             index = commandLine.indexOf(macro);
  62.         }
  63.     }
  64.     return commandLine;
  65. }
  66.  
  67.  
  68. function ProcessEditorName(commandLine)
  69. {
  70.     var macro = "$editor.name";
  71.     var index = commandLine.indexOf(macro);
  72.     if (index > -1)
  73.     {
  74.         var replace = "";
  75.         var editor = getActiveEditor();
  76.         if (editor)
  77.         {
  78.             replace = editor.getFile().title;
  79.         }
  80.         else
  81.         {
  82.             gOutput.writeLine("Warning: no editor is open. Replacing $editor.name with the empty string");
  83.         }
  84.         while (index > -1)
  85.         {
  86.             commandLine = replaceInString(commandLine, index, macro.length, replace);
  87.             index = commandLine.indexOf(macro);
  88.         }
  89.     }
  90.     return commandLine;
  91. }
  92.  
  93. function ProcessEditorFileType(commandLine)
  94. {
  95.     var macro = "$editor.fileType";
  96.     var index = commandLine.indexOf(macro);
  97.     if (index > -1)
  98.     {
  99.         var replace = "";
  100.         var editor = getActiveEditor();
  101.         if (editor)
  102.         {
  103.             replace = editor.getFile().fileType;
  104.         }
  105.         else
  106.         {
  107.             gOutput.writeLine("Warning: no editor is open. Replacing $editor.fileType with the empty string");
  108.         }
  109.         while (index > -1)
  110.         {
  111.             commandLine = replaceInString(commandLine, index, macro.length, replace);
  112.             index = commandLine.indexOf(macro);
  113.         }
  114.     }
  115.     return commandLine;
  116. }
  117.  
  118. function ProcessEditorSourcepath(commandLine)
  119. {
  120.     var macro = "$editor.sourcepath";
  121.     var index = commandLine.indexOf(macro);
  122.     if (index > -1)
  123.     {
  124.         var replace = "";
  125.         var editor = getActiveEditor();
  126.         if (editor)
  127.         {
  128.             if (editor.getFile().fileType == 'java')
  129.             {
  130.                 replace = Java.getClassPath(editor.path);
  131.             }
  132.             else
  133.             {
  134.                 gOutput.writeLine("Warning: sourcepath not defined for non-java file. Replacing $editor.sourcepath with the empty string");
  135.             }
  136.         }
  137.         else
  138.         {
  139.             gOutput.writeLine("Warning: no editor is open. Replacing $editor.sourcepath with the empty string");
  140.         }
  141.         
  142.         while (index > -1)
  143.         {
  144.             commandLine = replaceInString(commandLine, index, macro.length, replace);
  145.             index = commandLine.indexOf(macro);
  146.         }
  147.     }
  148.     return commandLine;
  149. }
  150.  
  151. function ProcessProjectClasspaths(commandLine)
  152. {
  153.     var macro = "$project.java.classpaths";
  154.     var index = commandLine.indexOf(macro);
  155.     if (index > -1)
  156.     {
  157.         var classpaths = "";
  158.         var project = getCurrentProject();
  159.         if (project)
  160.         {
  161.             var packageList = project.getPackageList();
  162.             var position = packageList.getHeadPosition();
  163.             while (position && position.valid)
  164.             {
  165.                 var pkg = packageList.getNext(position);
  166.                 var classpath = pkg.getJavaClasspath();
  167.                 if (classpath && classpath.length > 0)
  168.                 {
  169.                     if (classpaths.length > 0)
  170.                     {
  171.                         classpaths += ";";
  172.                     }
  173.                     classpaths += classpath;
  174.                 }
  175.             }
  176.         }
  177.         else
  178.         {
  179.             gOutput.writeLine("Warning: no project is open. Replacing $project.java.classpaths with the empty string");
  180.         }
  181.  
  182.         while (index > -1)
  183.         {
  184.             commandLine = replaceInString(commandLine, index, macro.length, classpaths);
  185.             index = commandLine.indexOf(macro);
  186.         }
  187.     }
  188.     return commandLine;
  189. }
  190.  
  191. function ProcessJavaStandardClasspaths(commandLine)
  192. {
  193.     var macro = "$java.jdk.standardclasspaths";
  194.     var index = commandLine.indexOf(macro);
  195.     if (index > -1)
  196.     {
  197.         var options = getMapFile("JDKToolsStandardOptions");
  198.         var classpath = options.lookup("standardClasspaths", "");
  199.         while (index > -1)
  200.         {
  201.             commandLine = replaceInString(commandLine, index, macro.length, classpath);
  202.             index = commandLine.indexOf(macro);
  203.         }
  204.     }
  205.     return commandLine;
  206. }
  207.  
  208. function ProcessJavaCustomClasspaths(commandLine)
  209. {
  210.     var macro = "$java.jdk.customclasspaths";
  211.     var index = commandLine.indexOf(macro);
  212.     if (index > -1)
  213.     {
  214.         var options = getMapFile("JDKToolsStandardOptions");
  215.         var classpath = options.lookup("customClasspaths", "");
  216.         while (index > -1)
  217.         {
  218.             commandLine = replaceInString(commandLine, index, macro.length, classpath);
  219.             index = commandLine.indexOf(macro);
  220.         }
  221.     }
  222.     return commandLine;
  223. }
  224.  
  225. function ProcessMacros(commandLine)
  226. {
  227.     commandLine = ProcessEditorPath(commandLine);
  228.     commandLine = ProcessEditorDirectory(commandLine);
  229.     commandLine = ProcessEditorName(commandLine);
  230.     commandLine = ProcessEditorFileType(commandLine);
  231.     commandLine = ProcessEditorSourcepath(commandLine);
  232.     commandLine = ProcessProjectClasspaths(commandLine);
  233.     commandLine = ProcessJavaStandardClasspaths(commandLine);
  234.     commandLine = ProcessJavaCustomClasspaths(commandLine);
  235.     
  236.     return commandLine;
  237. }
  238.  
  239. function DoCommand()
  240. {
  241.     gOutput.clear();
  242.     
  243.     var gCommandLineComboBox = getGlobal("CommandLine.CommandLineComboBox");
  244.     var gDirectoryComboBox = getGlobal("CommandLine.DirectoryComboBox");
  245.  
  246.     var commandLine = ProcessMacros(gCommandLineComboBox.text);
  247.     var directory = ProcessMacros(gDirectoryComboBox.text);
  248.     
  249.     if (commandLine.length > 0)
  250.     {
  251.         /*
  252.         var tool = newTool();
  253.         tool.async = true;
  254.         tool.output = gOutput;
  255.  
  256.         gOutput.writeLine("Command line: " + commandLine);
  257.         if (directory.length > 0)
  258.         {
  259.             File.setDirectory(directory);
  260.             gOutput.writeLine("Current directory: " + directory);
  261.         }
  262.         
  263.         tool.run(commandLine);
  264.         */
  265.         
  266.         gOutput.writeLine("Command line: " + commandLine);
  267.         if (directory.length > 0)
  268.         {
  269.             File.setDirectory(directory);
  270.             gOutput.writeLine("Current directory: " + directory);
  271.         }
  272.         
  273.         var cleanupHandler = File.getToolsPath() + "\\Command\\onCleanupProcess.script";
  274.         var process = newProcess();
  275.         setGlobal("interactiveProcess", process);
  276.         
  277.         process.output = gOutput;
  278.         var items = commandLine.split(' ');
  279.         process.run(items[0], commandLine, getScriptPath());
  280.         
  281.         // Now update command line data
  282.         
  283.         commandLine = gCommandLineComboBox.text;
  284.         directory = gDirectoryComboBox.text;
  285.         if (directory.length > 0)
  286.         {
  287.             var directoryList = gCommandLineMapfile.lookup("DirectoryList", null);
  288.             if (directoryList == null)
  289.             {
  290.                 directoryList = newList();
  291.                 gCommandLineMapfile.add("DirectoryList", directoryList);
  292.             }
  293.             
  294.             var index = directoryList.find(directory, false);
  295.             if (index > -1)
  296.             {
  297.                 var position = directoryList.getPosition(index)
  298.                 directoryList.removeAt(position);
  299.             }
  300.             
  301.             directoryList.addHead(directory);
  302.             gCommandLineMapfile.add("CurrentDirectory", directory);
  303.             
  304.             while(directoryList.count > 20)
  305.             {
  306.                 directoryList.removeTail();
  307.             }
  308.         }
  309.         
  310.         var commandList = gCommandLineMapfile.lookup("CommandList", null);
  311.         if (commandList == null)
  312.         {
  313.             commandList = newList();
  314.             gCommandLineMapfile.add("CommandList", commandList);
  315.         }
  316.         
  317.         var index = commandList.find(commandLine, false);
  318.         if (index > -1)
  319.         {
  320.             var position = commandList.getPosition(index)
  321.             commandList.removeAt(position);
  322.         }
  323.         
  324.         commandList.addHead(commandLine);
  325.         gCommandLineMapfile.add("CurrentCommand", commandLine);
  326.         
  327.         while(commandList.count > 20)
  328.         {
  329.             commandList.removeTail();
  330.         }
  331.         
  332.         gCommandLineMapfile.forceUpdate();
  333.     }
  334. }
  335.  
  336. function OnNotify()
  337. {
  338.     removeGlobal("interactiveProcess");
  339. }
  340.  
  341.  
  342. !!/Script
  343.  
  344.