Package com.sun.javatest.lib
Class JavaCompileCommand
java.lang.Object
com.sun.javatest.Command
com.sun.javatest.lib.JavaCompileCommand
Invoke a Java compiler via reflection.
The compiler is assumed to have a constructor and compile method
matching the following signature:
public class COMPILER { public COMPILER(java.io.OutputStream out, String compilerName); public boolean compile(String[] args); }or
public class COMPILER { public COMPILER(); public int compile(String[] args); }or
public class COMPILER { public static int compile(String[] args, PrintWriter out); }This means the command is suitable for (but not limited to) the compiler javac supplied with JDK. (Note that this uses an internal API of javac which is not documented and is not guaranteed to exist in any specific release of JDK.)
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
A stand-alone entry point for this command.run
(String[] args, PrintWriter log, PrintWriter ref) Invoke a specified compiler, or the default, javac.Methods inherited from class com.sun.javatest.Command
getClassLoader, setClassLoader
-
Field Details
-
defaultVerbose
public static boolean defaultVerbose
-
-
Constructor Details
-
JavaCompileCommand
public JavaCompileCommand()
-
-
Method Details
-
main
A stand-alone entry point for this command. An instance of this command is created, and itsrun
method invoked, passing in the command line args andSystem.out
andSystem.err
as the two streams.- Parameters:
args
- command line arguments for this command.- See Also:
-
run
Invoke a specified compiler, or the default, javac. If the first word in theargs
array is "-compiler" the second is interpreted as the class name for the compiler to be invoked, optionally preceded by a name for the compiler, separated from the class name by a colon. If no -compiler is specified, the default is `javac:com.sun.tools.javac.Main'. If -compiler is specified but no compiler name is given before the class name, the default name will be `java ' followed by the classname. For example, `-compiler Main' will result in the class name being `Main' and the compiler name being `java Main'. After determining the class and compiler name, an instance of the compiler class will be created, passing it a stream using theref
parameter, and the name of the compiler. Then the `compile' method will be invoked, passing it the remaining values of the `args' parameter. If the compile method returns true, the result will be a status of `passed'; if it returns `false', the result will be `failed'. If any problems arise, the result will be a status of `error'.- Specified by:
run
in classCommand
- Parameters:
args
- An optional specification for the compiler to be invoked, followed by arguments for the compiler's compile method.log
- Not used.ref
- Passed to the compiler that is invoked.- Returns:
- `passed' if the compilation is successful; `failed' if the compiler is invoked and errors are found in the file(s) being compiler; or `error' if some more serious problem arose that prevented the compiler performing its task.
-