home *** CD-ROM | disk | FTP | other *** search
/ PC User 2001 August / APC_Aug2001_CD2.iso / features / web_dev / files / mwjpp516.exe / %MAINDIR% / Tools / Library / msjUtilities.script < prev    next >
Encoding:
Text File  |  2001-06-19  |  8.0 KB  |  353 lines

  1. !!Script
  2. // Copyright ⌐ 1997-1998 - Modelworks Software
  3. // @Modified build 216 cm19980914 - see below
  4. // @Modified build 228 cm19981021 - added path parameter to GetJViewCommandLine and GetMSJCompileCommandLine
  5. // @Modified build 329 cm19991128 - added option to share classpaths with JDK
  6. // @Modified build 356 cm20000602 - fixed AddFilePathsToBatchFile - output not defined
  7.  
  8. // MSJUtiltity functions
  9.  
  10. var gJDKOptions = getMapFile("JDKToolsStandardOptions");
  11. var gMSJOptions = getMapFile("MSJToolsStandardOptions");
  12.  
  13. // removed function DoCommand() - cm19980914
  14.  
  15. function MSJSupported()
  16. {
  17.     var supported = getGlobal("MSJ");
  18.     if (!supported)
  19.     {
  20.         alert("Microsoft's Java Tools are not supported on NT 3.51");
  21.     }
  22.     return supported;
  23. }
  24.  
  25. function GetJViewCommandLine(className, path) //cm19981021
  26. {
  27.     var commandLine = "";
  28.     
  29.     var jviewPath;
  30.     var standardOptions;
  31.     
  32.     var useEnvironmentClasspath = gMSJOptions.lookup("useEnvironmentClasspath", false);
  33.     var runInWindow = gMSJOptions.lookup("runInWindow", true);
  34.     
  35.     if (runInWindow)
  36.     {
  37.         jviewPath = helpers.lookup("msj-wjview");
  38.         standardOptions = gMSJOptions.lookup("msj-wjview", "");
  39.     }
  40.     else
  41.     {
  42.         jviewPath = helpers.lookup("msj-jview");
  43.         standardOptions = gMSJOptions.lookup("msj-jview", "");
  44.     }
  45.     
  46.     if (jviewPath)
  47.     {
  48.         commandLine = "\"" + jviewPath.path + "\" ";
  49.         
  50.         // Add options
  51.         if (standardOptions.length > 0)
  52.         {
  53.             commandLine += standardOptions + " ";
  54.         }
  55.         
  56.         if (useEnvironmentClasspath)
  57.         {
  58.             var tool = newTool();
  59.             tool.setEnvironmentVariable("Classpath", getGlobal("EnvironmentClasspath"));
  60.         }
  61.         else
  62.         {
  63.             commandLine += GetClassPathArgument(false, path); //cm19981021
  64.         }
  65.         
  66.         commandLine += " " + className;
  67.     }
  68.     else
  69.     {
  70.         var result = confirm("You need to run the MSJ setup script\n"
  71.         + "before you can use this command.\n" +
  72.         "Do you want to run the setup script now?");
  73.         if (result)
  74.         {
  75.             run("Configuration\\MSJ");
  76.         }        
  77.     }
  78.     
  79.     return commandLine;
  80. }
  81.  
  82. function GetMSJCompileCommandLine(javafile) // cm19981021
  83. {
  84.     // Get the compiler file object
  85.     var compiler = helpers.lookup("msj-jvc");
  86.     
  87.     var useEnvironmentClasspath = gMSJOptions.lookup("useEnvironmentClasspath", false);
  88.     var standardOptions = gMSJOptions.lookup("msj-jvc", "");
  89.     
  90.     if (compiler && compiler.exists)
  91.     {       
  92.         // Quote all paths in case a path contains spaces
  93.         
  94.         // Add the path of the compiler -- this must be first
  95.         var commandLine = "\"" + compiler.path + "\" ";
  96.         
  97.         // Add other options for the compiler
  98.         if (standardOptions.length > 0)
  99.         {
  100.             commandLine += standardOptions + " ";
  101.         }
  102.         
  103.         if (useEnvironmentClasspath)
  104.         {
  105.             var tool = newTool();
  106.             tool.setEnvironmentVariable("Classpath", getGlobal("EnvironmentClasspath"));
  107.         }
  108.         else
  109.         {
  110.             commandLine += GetClassPathArgument(true, javafile); // cm19981021
  111.         }
  112.         
  113.         return commandLine;
  114.     }
  115.     else
  116.     {
  117.         var result = confirm("You need to run the MSJ setup script\n"
  118.         + "before you can use this command.\n" +
  119.         "Do you want to run the setup script now?");
  120.         if (result)
  121.         {
  122.             run("Configuration\\MSJ");
  123.         }
  124.     }
  125. }
  126.  
  127. // This function set the global environment CLASSPATH
  128. // Use it as an alternative to the command line argument
  129. function setCLASSPATH(tool)
  130. {    
  131.     var value = ".";    // Add the current directory
  132.     value += GetPackageClassPaths();    
  133.     value += GetCustomClassPaths();
  134.     
  135.     var currentClasspath = 
  136.     tool.setEnvironmentVariable("CLASSPATH", value);
  137.     
  138.     // Return the current CLASSPATH
  139.     return currentClasspath;
  140. }
  141.  
  142. function clearCLASSPATH(tool)
  143.     var useEnvironmentClasspath = gMSJOptions.lookup("useEnvironmentClasspath", false);
  144.     if (useEnvironmentClasspath)
  145.     {
  146.         tool.setEnvironmentVariable("Classpath", getGlobal("EnvironmentClasspath"));
  147.     }
  148.     else
  149.     {
  150.         tool.setEnvironmentVariable("CLASSPATH", "");
  151.     }
  152. }
  153.  
  154. function GetClassPathArgument(build, classpath)
  155. {
  156.     // Add the classpaths quoting the classpaths argument
  157.     var argument = "";
  158.     
  159.     var classPaths;
  160.     if (build)
  161.     {
  162.         classPaths = GetBuildPackageClassPaths();
  163.     }
  164.     else
  165.     {
  166.         classPaths = GetPackageClassPaths();
  167.     }
  168.     
  169.     var customClassPaths = GetCustomClassPaths();
  170.     if (classPaths != "" || customClassPaths != "")
  171.     {
  172.         argument += "/cp:p \"";  // Prepend these packages paths to the standard classpath
  173.         if (classpath != "")
  174.         {
  175.             argument += Java.getClassPath(classpath) + ';';
  176.         }
  177.         if (customClassPaths != "")
  178.         {
  179.             argument += customClassPaths;
  180.             if (classPaths != "")
  181.             {
  182.                 argument += ";";
  183.             }
  184.         }    
  185.         argument += classPaths + "\"";
  186.     }   
  187.     return argument;
  188. }
  189.  
  190. function GetCustomClassPaths()
  191. {
  192.     var shareCustomClasspathsWithJDK = getMapFileValue("Preferences", "Share JDK classpaths when using MSJ tools", true);; //cm19991128
  193.     
  194.     if (shareCustomClasspathsWithJDK)
  195.     {
  196.         var classpaths = "";
  197.         classpaths = GetJDKCustomClassPaths(classpaths);
  198.         return classpaths;
  199.     }
  200.     
  201.     var classpaths = "";
  202.     var entry = gMSJOptions.lookup("customClasspaths", "");
  203.     if (entry != "")
  204.     {
  205.         classpaths = entry;
  206.     }
  207.     return classpaths;
  208. }
  209.  
  210. function GetJDKCustomClassPaths(classpaths) //cm19991128
  211. {    
  212.     var entry = gJDKOptions.lookup("standardClasspaths", "");
  213.     if (entry != "")
  214.     {
  215.         if (classpaths.length > 0)
  216.         {
  217.             classpaths += ";" + entry;
  218.         }
  219.         else
  220.         {
  221.             classpaths += entry;
  222.         }
  223.     }
  224.     
  225.     var entry = gJDKOptions.lookup("customClasspaths", "");
  226.     if (entry != "")
  227.     {
  228.         if (classpaths.length > 0)
  229.         {
  230.             classpaths += ";" + entry;
  231.         }
  232.         else
  233.         {
  234.             classpaths += entry;
  235.         }
  236.     }    
  237.     return classpaths;
  238. }
  239.  
  240. function GetPackageClassPaths()
  241. {
  242.     var classpaths = "";
  243.     var project = getCurrentProject();
  244.     if (project)
  245.     {
  246.         var packageList = project.getPackageList();
  247.         if (packageList)
  248.         {
  249.             var position = packageList.getHeadPosition();
  250.             while (position && position.valid)
  251.             {
  252.                 var packageClassPath = 
  253.                 packageList.getNext(position).getJavaClassPath();
  254.                 if (packageClassPath && classpaths.indexOf(packageClassPath) == -1)
  255.                 {
  256.                     classpaths += packageClassPath;
  257.                 }
  258.                 if (position.valid)
  259.                 {
  260.                     classpaths += ";";
  261.                 }
  262.             }
  263.         }
  264.     }
  265.     return classpaths;
  266. }
  267.  
  268. function GetBuildPackageClassPaths()
  269. {
  270.     var classpaths = "";
  271.     var project = getCurrentProject();
  272.     if (project)
  273.     {
  274.         var packageList = project.getPackageList();
  275.         if (packageList)
  276.         {
  277.             var position = packageList.getHeadPosition();
  278.             while (position && position.valid)
  279.             {
  280.                 var packageClassPath = 
  281.                 packageList.getNext(position).getJavaClassPath();
  282.                 if (packageClassPath && classpaths.indexOf(packageClassPath) == -1)
  283.                 {
  284.                     classpaths += packageClassPath;
  285.                 }
  286.                 if (position.valid)
  287.                 {
  288.                     classpaths += ";";
  289.                 }
  290.             }
  291.             // Add SourcePath directories if needed
  292.             position = packageList.getHeadPosition();
  293.             while (position.valid)
  294.             {
  295.                 var pack = packageList.getNext(position);
  296.                 if (pack.destinationNotSource)
  297.                 {
  298.                     var packageClassPath = 
  299.                     pack.getJavaSourceClassPath();
  300.                     if (packageClassPath && classpaths.indexOf(packageClassPath) == -1)
  301.                     {
  302.                         classpaths += ";" + packageClassPath;
  303.                     }
  304.                 }
  305.             }
  306.         }
  307.     }
  308.     return classpaths;
  309. }
  310.  
  311. function GetDestinationPath(sourcePath)
  312. {
  313.     var destinationPath = "";
  314.     var project = getCurrentProject();
  315.     if (project)
  316.     {
  317.         var sourcePackage = project.getPackage(sourcePath);
  318.         if (sourcePackage)
  319.         {
  320.             return sourcePackage.getDestinationPath(sourcePath);
  321.         }
  322.     }
  323.     return destinationPath;
  324. }
  325.  
  326. function AddFilePathsToBatchFile(buildList)
  327. {
  328.     var file = null;
  329.     var path = File.getDataPath() + "\\MSJCommandFile.txt";
  330.     var editor = newEditor(path, false);
  331.     if (editor)
  332.     {
  333.         editor.removeAll();
  334.         var position = buildList.getHeadPosition();
  335.         while (position.valid)
  336.         {
  337.             var file = buildList.getNext(position);
  338.             if (file.fileType == "java")
  339.             {
  340.                 editor.append(file.path + "\n");
  341.                 gOutput.writeLine("Including: " + file.path);
  342.             }
  343.         }
  344.         
  345.         file = editor.getFile();
  346.         editor.close();
  347.     }
  348.     return file;
  349. }
  350.  
  351. !!/Script
  352.