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

  1. !!Script
  2. // Copyright ⌐ 1997-1998 - Modelworks Software
  3. // @Modified build 230 cm19981101 - created function DefineJDKDirectory() out of SetNewDirectory()
  4. // @Modified build 263 cm19990204 - added instructions for new users
  5. // @Modified build 317 cm19990805 - see below
  6. // @Modified build 422 cm20000923 - see below
  7.  
  8. /**
  9. @Tool: JDK~displays a open folder dialog to let you select 
  10. your JDK (Java Development Kit) directory. 
  11. @Image: Open Folder Dialog showing a JDK directory@select_JDK_Directory.gif
  12. @Tip: Because some JDK tools do not process classpaths correctly if the classpath contains a 
  13. space, you should avoid using spaces in folder names that contain Java source or class file 
  14. names. 
  15. @EndTip:
  16. @EndTool: 
  17. @Summary: JDK~sets the path to your JDK directory
  18. */
  19.  
  20. var gOutput = getOutput();
  21. var gHelpers = getMapFile("ApplicationHelpers");
  22. var gOptions = getMapFile("JDKToolsStandardOptions");
  23.  
  24. function DoCommand()
  25. {
  26.     var jdk_bin_directory = gHelpers.lookup("jdk-bin_directory");
  27.     if (jdk_bin_directory == null || !jdk_bin_directory.exists)
  28.     {
  29.         InitilizeJDKDirectory(); //cm20000923
  30.     }
  31.     
  32.     jdk_bin_directory = gHelpers.lookup("jdk-bin_directory");
  33.     if (jdk_bin_directory && jdk_bin_directory.exists)
  34.     {    
  35.         var compilePath = newFile(jdk_bin_directory.path + "\\javac.exe");
  36.         if (compilePath.exists)
  37.         {
  38.             var to = jdk_bin_directory.path.length - 4;
  39.             var jdk_directory_path = jdk_bin_directory.path.substring(0, to);
  40.             if (confirm("Your current JDK directory is: " + jdk_directory_path + 
  41.             ". Do you want to change to a new directory?"))
  42.             {
  43.                 SetNewDirectory(jdk_directory_path);
  44.             }
  45.             return; // cm19990805
  46.         }
  47.     }
  48.  
  49.     if (confirm("If you have not downloaded JDK from Sun Microsystems, "
  50.          +    "\nyou will need to do so before you continue. \n"
  51.          + "Select no to get instructions, select yes to continue."))
  52.     {
  53.         SetNewDirectory("C:\\");
  54.     }
  55.     else
  56.     {    
  57.         var outputEditor = gOutput.getEditor();
  58.         var startLine = outputEditor.getLineCount();
  59.         
  60.         gOutput.writeLine("\nTo download the current JDK and documentation go to: ");
  61.         gOutput.writeLine("http://www.javasoft.com/products/jdk/index.html");
  62.  
  63.         gOutput.writeLine("");
  64.         gOutput.writeLine("We recommend that you install JDK in a top level folder, such as C:\\JDK.1.2,");
  65.         gOutput.writeLine("without any spaces in the folder name, so that the visual debugger will work");
  66.         gOutput.writeLine("(Sun's JDK debugger will not work if there is a space in a classpath).");
  67.         
  68.         gOutput.writeLine("");
  69.         gOutput.writeLine("After downloading and installing JDK you can then restart " + Application.name + ".");
  70.         gOutput.writeLine("If you installed a recent version of JDK (at least version 1.1.7) then ");
  71.         gOutput.writeLine(Application.name + " will automatically locate your JDK during startup if you ");
  72.         gOutput.writeLine("have not already selected a JDK directory.");
  73.  
  74.         gOutput.writeLine("");
  75.         gOutput.writeLine("You may also want to see \"Documents/Ide/Useful Links\" for other useful");
  76.         gOutput.writeLine("internet shortcuts.");
  77.         
  78.         outputEditor.scrollTo(startLine);
  79.     }
  80. }
  81.  
  82. function SetNewDirectory(oldPath)
  83. {
  84.     gOutput.clear();
  85.     
  86.     var directory = chooseDirectory("Locate your Java JDK directory", oldPath, "");
  87.     if (directory)
  88.     { 
  89.         var test = newFile(directory + "\\java.exe");
  90.         if (test.exists) // Remove "\\bin"
  91.         {
  92.             var to = directory.length - 4;
  93.             directory = directory.substring(0, to);
  94.         }
  95.         
  96.         if (DefineJDKDirectory(directory))
  97.         {
  98.             gOutput.writeLine("Reminder: be sure to change your standard and custom classpaths if required.");
  99.         }
  100.     }
  101. }
  102.  
  103. function DefineJDKDirectory(directory)
  104. {    
  105.     var jdk_directoryFile = newFile(directory);
  106.     
  107.     var jdk_bin_directory = newFile(directory + "\\bin");
  108.     var compilePath = newFile(directory + "\\bin\\javac.exe");
  109.     if (jdk_bin_directory.exists && compilePath.exists)
  110.     {
  111.         gHelpers.add("jdk-directory", jdk_directoryFile);
  112.         gHelpers.add("jdk-bin_directory", jdk_bin_directory);
  113.         
  114.         var tool = newTool();
  115.         var pathEnvironment = getGlobal("EnvironmentPath");
  116.         tool.setEnvironmentVariable("Path", jdk_bin_directory.path + ";" + pathEnvironment);
  117.         
  118.         // Java compiler
  119.         var compilePath_g = newFile(directory + "\\bin\\javac_g.exe");
  120.         gHelpers.add("jdk-compiler_release", compilePath);
  121.         if (compilePath_g.exists)
  122.         {
  123.             gHelpers.add("jdk-compiler_debug", compilePath_g);
  124.             gHelpers.add("jdk-compiler", compilePath_g);
  125.         }
  126.         else
  127.         {
  128.             gHelpers.add("jdk-compiler_debug", compilePath);
  129.             gHelpers.add("jdk-compiler", compilePath);
  130.         }
  131.         
  132.         // Appletviewer
  133.         var appletviewerPath = newFile(directory + "\\bin\\appletviewer.exe");
  134.         var appletviewerPath_g = newFile(directory + "\\bin\\appletviewer_g.exe");
  135.         
  136.         gHelpers.add("jdk-appletviewer_release", appletviewerPath);
  137.         if (appletviewerPath_g.exists)
  138.         {
  139.             gHelpers.add("jdk-appletviewer_debug", appletviewerPath_g);
  140.             gHelpers.add("jdk-appletviewer", appletviewerPath_g);
  141.         }
  142.         else
  143.         {
  144.             gHelpers.add("jdk-appletviewer_debug", appletviewerPath);
  145.             gHelpers.add("jdk-appletviewer", appletviewerPath);
  146.         }
  147.         
  148.         // Application runtime
  149.         var runApplicationPath = newFile(directory + "\\bin\\java.exe");
  150.         var runApplicationPath_g = newFile(directory + "\\bin\\java_g.exe");
  151.         
  152.         gHelpers.add("jdk-runapplication_release", runApplicationPath);
  153.         if (runApplicationPath_g.exists)
  154.         {
  155.             gHelpers.add("jdk-runapplication_debug", runApplicationPath_g);
  156.             gHelpers.add("jdk-runapplication", runApplicationPath_g);
  157.         }
  158.         else
  159.         {
  160.             gHelpers.add("jdk-runapplication_debug", runApplicationPath);
  161.             gHelpers.add("jdk-runapplication", runApplicationPath);
  162.         }
  163.         
  164.         var runApplicationPathWindow = newFile(directory + "\\bin\\javaw.exe");
  165.         var runApplicationPathWindow_g = newFile(directory + "\\bin\\javaw_g.exe");
  166.         
  167.         gHelpers.add("jdk-runapplicationwindow_release", runApplicationPathWindow);
  168.         if (runApplicationPathWindow_g.exists)
  169.         {
  170.             gHelpers.add("jdk-runapplicationwindow_debug", runApplicationPathWindow_g);
  171.             gHelpers.add("jdk-runapplicationwindow", runApplicationPathWindow_g);
  172.         }
  173.         else
  174.         {
  175.             gHelpers.add("jdk-runapplicationwindow_debug", runApplicationPathWindow);
  176.             gHelpers.add("jdk-runapplicationwindow", runApplicationPathWindow);
  177.         }
  178.         
  179.         // Debugger
  180.         var debuggerPath = newFile(directory + "\\bin\\jdb.exe");
  181.         gHelpers.add("jdk-debugger", debuggerPath);
  182.         
  183.         // Add Classes.zip if it exists
  184.         var classesPath = newFile(directory + "\\lib\\classes.zip");
  185.         if (classesPath && classesPath.exists)
  186.         {
  187.             gHelpers.add("jdk-classes.zip", classesPath);
  188.         }
  189.         else
  190.         {
  191.             gHelpers.remove("jdk-classes.zip");
  192.         }
  193.         
  194.         // Generate C bindings
  195.         var javahPath = newFile(directory + "\\bin\\javah.exe");
  196.         gHelpers.add("jdk-javah", javahPath);
  197.         
  198.         // Update the options
  199.         
  200.         var buildmode = gOptions.lookup("jdk-buildmode", "");
  201.         if (buildmode == "")  // Define the initial options
  202.         {
  203.             gOptions.setValue("jdk-buildmode", "release");
  204.             gOptions.setValue("jdk-build", "JDK Release Build"); 
  205.             gOptions.lookup("runInWindow", true); 
  206.             //alert("JDK Release Build Configuration Set");
  207.         }
  208.         
  209.         var jdkOptions = getScriptObject("\\Library\\jdkOptions");
  210.         jdkOptions.UpdateOptions();
  211.         
  212.         gOutput.writeLine("JDK directory set to: \"" + directory + "\"");
  213.         if (directory.indexOf(" ") != -1)
  214.         {
  215.             gOutput.writeLine("Warning: some JDK tools may not work correctly with a space in your JDK path.");
  216.         }
  217.         
  218.         return true;
  219.     }
  220.     else
  221.     {
  222.         gOutput.writeLine("WARNING: The directory, \"" + directory + 
  223.         "\" does not appear to be a valid JDK directory");
  224.         gOutput.writeLine("A valid JDK directory contains a bin folder containing Sun's Java tools (e.g., javac.exe)");
  225.     }
  226.         
  227.     return false;
  228. }
  229.  
  230. function InitilizeJDKDirectory() //cm19981101
  231. {
  232.     var key = "SOFTWARE\\JavaSoft\\Java Development Kit";
  233.     var currentVersion = Application.getRegistryValue("HKEY_LOCAL_MACHINE", 
  234.         key ,"CurrentVersion");
  235.     if (currentVersion && currentVersion != "")
  236.     {
  237.         key += "\\" + currentVersion;
  238.         var javaHome = Application.getRegistryValue("HKEY_LOCAL_MACHINE",        
  239.             key, "JavaHome");
  240.         
  241.         if (javaHome && javaHome != "")
  242.         {
  243.             DefineJDKDirectory(javaHome);
  244.         }
  245.     }
  246. }
  247.  
  248.  
  249. !!/Script
  250.