Package com.sun.javatest.lib
Class JavaCompileCommand
- java.lang.Object
-
- com.sun.javatest.Command
-
- com.sun.javatest.lib.JavaCompileCommand
-
public class JavaCompileCommand extends Command
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); }
orpublic class COMPILER { public COMPILER(); public int compile(String[] args); }
orpublic 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 Modifier and Type Field Description static boolean
defaultVerbose
-
Constructor Summary
Constructors Constructor Description JavaCompileCommand()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
main(java.lang.String... args)
A stand-alone entry point for this command.Status
run(java.lang.String[] args, java.io.PrintWriter log, java.io.PrintWriter ref)
Invoke a specified compiler, or the default, javac.-
Methods inherited from class com.sun.javatest.Command
getClassLoader, setClassLoader
-
-
-
-
Method Detail
-
main
public static void main(java.lang.String... args)
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(java.lang.String[], java.io.PrintWriter, java.io.PrintWriter)
-
run
public Status run(java.lang.String[] args, java.io.PrintWriter log, java.io.PrintWriter ref)
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.
-
-