home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 67 / IOPROG_67A.ISO / soft / Tools / mwsppv4.exe / COMPILE.SCRIPT < prev    next >
Encoding:
Text File  |  2000-05-17  |  4.3 KB  |  149 lines

  1. !!Include "Library\msjUtilities.script"
  2. !!Script
  3. // Copyright ⌐ 1997-1998 - Modelworks Software
  4. // @Modified build 225 cm19981008 - restore accelerator when changing menu name
  5. // @Modified build 228 cm19981021 - added path parameter to GetMSJCompileCommandLine
  6. // @Modified build 353 cm20000517 - added support for ouput tabs
  7.  
  8. /**   
  9. @Tool: compile~translates a java file into Java bytecodes 
  10. using Microsoft's Java compiler (jvc.exe). This script will compile the 
  11. active editor if it is a java file, otherwise this script will ask you 
  12. to select a Java file to compile. The class file generated by this script 
  13. will be put into the same directory as the source file unless the source 
  14. file is included in an open project. In that case the destination directory 
  15. will be determined using the package destination directory. 
  16. @Note: This is the script that is used by the MSJ/Compile menu.
  17. @EndNote:
  18. @EndTool: 
  19. @Summary: compile~translates a java file into Java bytecodes
  20. */
  21.  
  22. var gOutput = getOutput("Build");
  23. var helpers = getMapFile("ApplicationHelpers");
  24. var gOptions = getMapFile("MSJToolsStandardOptions");
  25.  
  26. function DoUpdate(cmdUI) 
  27. {
  28.     var textSet = false;
  29.     // If the current document is a Java file then use that file
  30.     var editor = getActiveEditor();
  31.     if (editor)
  32.     {
  33.         var file = editor.getFile();
  34.         if (file)  // Carefull: an untitled document does not have a file
  35.         {
  36.             var fileType = file.fileType.toLowerCase();
  37.             if (fileType == "java")
  38.             {
  39.                 var label = cmdUI.getText(); //cm19981008
  40.                 var tabIndex = label.indexOf('\t');
  41.                 var shortcut = "";
  42.                 if (tabIndex > -1) //cm19981008
  43.                 {
  44.                     shortcut = label.substring(tabIndex, label.length);
  45.                 }
  46.                 cmdUI.setText("Compile " + file.name + shortcut);
  47.                 textSet = true;
  48.             }
  49.         }
  50.     }
  51.     
  52.     if (!textSet)
  53.     {
  54.         var label = cmdUI.getText(); //cm19981008
  55.         var tabIndex = label.indexOf('\t');
  56.         var shortcut = "";
  57.         if (tabIndex > -1)
  58.         {
  59.             shortcut = label.substring(tabIndex, label.length);
  60.         }
  61.         cmdUI.setText("Compile..." + shortcut);
  62.     }
  63.     
  64.     cmdUI.enable(true);
  65.     return true;
  66. }
  67.  
  68. function DoCommand() 
  69. {
  70.     if (!MSJSupported()) 
  71.     {
  72.         return; 
  73.     }
  74.     
  75.     gOutput.clear();
  76.     
  77.     // Save all open files
  78.     saveAll();
  79.     
  80.     var path = "";
  81.     
  82.     // If the current document is a Java file then use that file
  83.     var editor = getActiveEditor();
  84.     if (editor)
  85.     {
  86.         var fileType = editor.getFile().fileType.toLowerCase();
  87.         if (fileType == "java")
  88.         {
  89.             path = editor.path;
  90.         }
  91.     }
  92.     
  93.     // Else ask the user to locate a Java file
  94.     if (path == "")
  95.     {
  96.         var file = chooseFile("Choose a Java file to compile", "Java files", "*.java");
  97.         if (file && file.exists)
  98.         {
  99.             path = file.path;
  100.         }
  101.     }
  102.     
  103.     if (path.length > 0)
  104.     {
  105.         var command = GetMSJCompileCommandLine(path); //cm19981021
  106.         if (command && command.length > 0)
  107.         {   
  108.             var build = gOptions.lookup("msj-build", "");
  109.             gOutput.writeLine("---------------- " + build + " ------------------");
  110.             gOutput.writeLine("Compiling " + path);
  111.             DoCompile(command, path);
  112.             gOutput.writeLine("Finished");     
  113.         }
  114.     }
  115. }
  116.  
  117. function DoCompile(command, path)
  118. {
  119.     // Add the destination directory if required
  120.     var destinationPath = GetDestinationPath(path);
  121.     if (destinationPath.length > 0)
  122.     {
  123.         command += " /d \"" + destinationPath + "\"";
  124.     } 
  125.     
  126.     // Add the path of the file to be compiled
  127.     command += " \"" + path + "\"";
  128.     
  129.     if (gOptions.lookup("showCommandLine",false)==true)
  130.     {
  131.         gOutput.writeLine("Command Line: " + command);
  132.     }
  133.     
  134.     File.setDirectory(path);
  135.     if (gOptions.lookup("showCommandLine",false)==true)
  136.     {
  137.         gOutput.writeLine("The current directory is: " + File.getDirectory().path);
  138.     }
  139.     
  140.     // Create a process to run the compiler
  141.     var compileTool = newTool(gOutput);
  142.     
  143.     clearCLASSPATH(compileTool);   
  144.     
  145.     compileTool.run(command);   
  146. }
  147.  
  148. !!/Script
  149.