home *** CD-ROM | disk | FTP | other *** search
- !!Script
- // Copyright ⌐ 1997-1998 - Modelworks Software
- // @Modified build 216 cm19980914 - see below
- // @Modified build 228 cm19981020 - added GetClasspathArgument function
- // @Modified build 247 cm19981230 - leave '\' in classpaths
- // @Modified build 262 cm19990202 - added support for boot classpaths
- // @Modified build 290 cm19990427 - check for duplicate classpaths
- // @Modified build 309 cm19990630 - removed empty classpath from the command line
- // @Modified build 314 cm19990723 - fixed problem with no ';' in classpath
- // @Modified build 316 cm19990725 - fixed bougs "space in classpath" message
- // @Modified build 334 cm19991220 - added archive files in project to classpath
-
- // Utility functions for JDK tool scripts
-
- // removed function DoCommand warning - cm19980914
-
- function GetJDKCompileCommandLine(sourcefile) // cm19981020
- {
- // Get the compiler and systemClasses file objects
- var compiler = helpers.lookup("jdk-compiler");
- var systemClasses = helpers.lookup("jdk-classes.zip");
- var appendSystemClasses = getMapFileValue("Preferences", "Append JDK classes.zip file to classpaths", true);
-
- var standardOptions = gOptions.lookup("jdk-compiler", "");
- var useEnvironmentClasspath = gOptions.lookup("useEnvironmentClasspath", false);
-
- if (compiler && compiler.exists)
- {
- // Quote all paths in case a path contains spaces
-
- // Add the path of the compiler -- this must be first
- var command = "\"" + compiler.path + "\" ";
-
- // Add other options for the compiler
- if (standardOptions.length > 0)
- {
- command += standardOptions + " ";
- }
-
- var jikes = compiler.path.indexOf("jikes") > -1;
- if (jikes)
- {
- command += "+E ";
- }
-
- if (!systemClasses) // Java 2 platform
- {
- var bootPaths = GetBootClassPaths();
- if (bootPaths.length > 0)
- {
- command += "-bootclasspath \"" + bootPaths + "\" ";
- }
- }
-
- if (useEnvironmentClasspath)
- {
- var tool = newTool();
- tool.setEnvironmentVariable("Classpath", getGlobal("EnvironmentClasspath"));
- }
- else
- {
- // Add the classpaths quoting the classpaths argument
- command += "-classpath \""; // Add the current directory
- var classpath = "";
- if (sourcefile != "")
- {
- classpath += Java.getClassPath(sourcefile);
- }
- classpath = GetBuildPackageClassPaths(classpath);
- classpath = GetCustomClassPaths(classpath);
- if (appendSystemClasses && systemClasses && systemClasses.exists)
- {
- if (classpath.length > 0)
- {
- classpath += ";" + systemClasses.path;
- }
- else
- {
- classpath += systemClasses.path;
- }
- }
-
- if (jikes && !systemClasses)
- {
- var jdkDirectory = helpers.lookup("jdk-directory", null);
- if (jdkDirectory)
- {
- var rtjar = jdkDirectory.path + "\\jre\\lib\\rt.jar";
- if (classpath.length > 0)
- {
- classpath += ";" + rtjar;
- }
- else
- {
- classpath += rtjar;
- }
- }
- }
-
- command += classpath + "\" ";
- }
-
- return command;
- }
- else
- {
- var result = confirm("You need to run the JDK setup script\n"
- + "before you can use this command.\n" +
- "Do you want to run the setup script now?");
- if (result)
- {
- run("Configuration\\JDK");
- }
- }
- }
-
- // This function set the global environment CLASSPATH
- // Use it as an alternative to the standard "-classpath "
- // command line argument
- function setCLASSPATH(tool)
- {
- var systemClasses = helpers.lookup("jdk-classes.zip");
- var appendSystemClasses = getMapFileValue("Preferences", "Append JDK classes.zip file to classpaths", true);
-
- var value = "."; // Add the current directory
- value = GetPackageClassPaths(value);
- value = GetCustomClassPaths(value);
-
- if (appendSystemClasses && systemClasses && systemClasses.exists)
- {
- if (value.length > 0)
- {
- value += ";" + systemClasses.path;
- }
- else
- {
- value += systemClasses.path;
- }
- }
-
- CheckForSpaceInClasspath(value);
-
- var currentClasspath =
- tool.setEnvironmentVariable("CLASSPATH", value);
-
- // Return the current CLASSPATH
- return currentClasspath;
- }
-
- function GetCustomClassPaths(classpaths)
- {
- var entry = gOptions.lookup("standardClasspaths", "");
- if (entry != "")
- {
- if (classpaths.length > 0)
- {
- classpaths += ";" + entry;
- }
- else
- {
- classpaths += entry;
- }
- }
-
- var entry = gOptions.lookup("customClasspaths", "");
- if (entry != "")
- {
- if (classpaths.length > 0)
- {
- classpaths += ";" + entry;
- }
- else
- {
- classpaths += entry;
- }
- }
-
- CheckForSpaceInClasspath(classpaths);
-
- return classpaths;
- }
-
- function GetBootClassPaths()
- {
- var classpaths = "";
- var entry = gOptions.lookup("bootClasspaths", "");
- if (entry != "")
- {
- classpaths = entry;
- }
-
- CheckForSpaceInClasspath(classpaths);
- return classpaths;
- }
-
- function GetArchiveClassPaths(packagePath) //cm19991220
- {
- var classpath = "";
-
- return classpath; // Comment this out if you need to add archive files
- // to your classpath
-
- var list = getDirectoryFiles(packagePath, "*.jar;*.zip", true, false);
- if (list)
- {
- var semicolon = "";
- var position = list.getHeadPosition();
- while(position && position.valid)
- {
- classpath += semicolon + list.getNext(position).path;
- semicolon = ";";
- }
- }
- //gOutput.writeLine("found: " + classpath);
- return classpath;
- }
-
- function GetPackageClassPaths(classpaths)
- {
- var project = getCurrentProject();
- if (project)
- {
- var packageList = project.getPackageList();
- if (packageList)
- {
- var position = packageList.getHeadPosition();
- while (position.valid)
- {
- var packageClassPath =
- packageList.getNext(position).getJavaClassPath();
- if (packageClassPath && classpaths.indexOf(packageClassPath) == -1)
- {
- if (classpaths.length > 0)
- {
- classpaths += ";" + packageClassPath;
- }
- else
- {
- classpaths += packageClassPath;
- }
- }
- var archivePaths = GetArchiveClassPaths(packageClassPath); //cm19991220
- if (archivePaths.length > 0)
- {
- classpaths += ";" + archivePaths;
- }
- }
- }
- }
- CheckForSpaceInClasspath(classpaths);
-
- return classpaths;
- }
-
- function GetBuildPackageClassPaths(classpaths)
- {
- var project = getCurrentProject();
- if (project)
- {
- var packageList = project.getPackageList();
- if (packageList)
- {
- var position = packageList.getHeadPosition();
- while (position.valid)
- {
- var packageClassPath = packageList.getNext(position).getJavaClassPath();
- if (packageClassPath && classpaths.indexOf(packageClassPath) == -1)
- {
- if (classpaths.length == 0)
- {
- classpaths += packageClassPath;
- }
- else
- {
- classpaths += ";" + packageClassPath;
- }
- }
- var archivePaths = GetArchiveClassPaths(packageClassPath); //cm19991220
- if (archivePaths.length > 0)
- {
- classpaths += ";" + archivePaths;
- }
- }
-
- // Add SourcePath directories if needed
- position = packageList.getHeadPosition();
- while (position.valid)
- {
- var pkg = packageList.getNext(position);
- if (pkg.destinationNotSource)
- {
- var packageClassPath =
- pkg.getJavaSourceClassPath();
- if (packageClassPath && classpaths.indexOf(packageClassPath) == -1)
- {
- if (classpaths.length == 0)
- {
- classpaths += packageClassPath;
- }
- else
- {
- classpaths += ";" + packageClassPath;
- }
- }
- }
- }
- }
- }
- CheckForSpaceInClasspath(classpaths);
-
- return classpaths;
- }
-
- function CheckForSpaceInClasspath(classpaths)
- {
- var spaceIndex = classpaths.indexOf(" ");
- if (spaceIndex > -1)
- {
- gOutput.writeLine("Warning: Space found in classpath: " + classpaths);
- gOutput.writeLine("Sun's JDK debugger will not work correctly with a space in the classpath.");
- }
- }
-
- function GetDestinationPath(sourcePath)
- {
- var destinationPath = "";
- var project = getCurrentProject();
- if (project)
- {
- var sourcePackage = project.getPackage(sourcePath);
- if (sourcePackage)
- {
- return sourcePackage.getDestinationPath(sourcePath);
- }
- }
- return destinationPath;
- }
-
- function AppendSeparator(classpath)
- {
- if (classpath.length > 0)
- {
- var lastChar = classpath.charAt(classpath.length-1);
- if (lastChar != '"' && lastChar != ';')
- {
- classpath += ';';
- }
- }
- return classpath;
- }
-
- function GetClasspathArgument(classfilepath, special) // cm19981020
- {
- var appendSystemClasses = getMapFileValue("Preferences", "Append JDK classes.zip file to classpaths", true);
- var systemClasses = helpers.lookup("jdk-classes.zip");
-
- var bootclasspath = "";
-
- if (!systemClasses) // Java 2 platform
- {
- var bootPaths = GetBootClassPaths();
- if (bootPaths.length > 0)
- {
- bootclasspath += "-Xbootclasspath:" + bootPaths + " ";
- }
- }
-
- var classpath = "";
-
- if (classfilepath != "")
- {
- classpath += Java.getClassPath(classfilepath); // Add a local classpath for classfilepath if needed
- }
-
- classpath = GetPackageClassPaths(classpath);
- classpath = GetCustomClassPaths(classpath);
- if (appendSystemClasses && systemClasses && systemClasses.exists)
- {
- classpath = AppendSeparator(classpath);
- classpath += systemClasses.path;
- }
-
- if (special)
- {
- classpath = AppendSeparator(classpath);
- classpath += special;
- }
-
- if (classpath == "")
- {
- return bootclasspath;
- }
- else
- {
- return bootclasspath + "-classpath \"" + classpath + "\" ";
- }
- }
-
- function AddFilesToCompile(commandLine, filePathList) //cm20000530
- {
- var result = "";
- if (gOptions.lookup("useCommandFileWhenCompiling",false))
- {
- result = AddFilePathsToBatchFile(filePathList);
- }
- else
- {
- var position = filePathList.getHeadPosition();
- while(position && position.valid)
- {
- var path = filePathList.getNext(position);
- result += " \"" + path + "\"";
- }
- }
- return result;
- }
-
- function AddFilePathsToBatchFile(buildList) //cm19991223
- {
- var path = File.getDataPath() + "\\JDKCommandFile.txt";
- var commandFile = "@" + "\"" + path + "\""; //Bruno Konik20001215
- var editor = newEditor(path, false);
- if (editor)
- {
- editor.removeAll();
- var position = buildList.getHeadPosition();
- while (position && position.valid)
- {
- var path = buildList.getNext(position);
- editor.append(path + "\n");
- }
-
- file = editor.getFile();
- editor.close();
- return commandFile;
- }
- return "";
- }
-
- !!/Script
-