Class JCompilerCommandBuilder
java.lang.Object
org.matwoess.jsourceprofiler.common.JCompilerCommandBuilder
Builder class for a
javac command line with arguments.
Used as a common abstraction to avoid hard-coding an array of javac command
strings for ProcessBuilder usages.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddCompileArg(String arg, String val) Specify additional compile options that will be added to the final command.addSourceFile(Path sourceFile) Register a source file that should be compiled.String[]build()Returns aan array of strings that can be joined to a validjavaccommand line.setClassPath(Path classPath) Define the class path directory for the finaljavaccommand.setDirectory(Path directory) Define the output directory for thejavaccommand, specified by the-doption.
-
Constructor Details
-
JCompilerCommandBuilder
public JCompilerCommandBuilder()
-
-
Method Details
-
addSourceFile
Register a source file that should be compiled.- Parameters:
sourceFile- target source file to compile- Returns:
- the builder object itself for method chaining
-
setClassPath
Define the class path directory for the finaljavaccommand. Will be appended using the-cpoption.- Parameters:
classPath- a directory that should be passed to the compiler as the class path option- Returns:
- the builder object itself for method chaining
-
setDirectory
Define the output directory for thejavaccommand, specified by the-doption. Is used to place compiled.classfiles in a different directory than the instrumented files.- Parameters:
directory- the directory path wherejavacoutputs are placed in- Returns:
- the builder object itself for method chaining
-
addCompileArg
Specify additional compile options that will be added to the final command.The arg and value are always joined with
" "together. The method can be called multiple times. Arguments will be added in-order.- Parameters:
arg- the java compile argument name (example: -target)val- the value associated with the argument- Returns:
- the builder object itself for method chaining
-
build
Returns aan array of strings that can be joined to a validjavaccommand line.The primary intended usage is to pass it to a
ProcessBuilder. This is commonly done with theUtil.runCommand(java.lang.String...)abstraction method.- Returns:
- the string array to form a
javaccommand, built by the setter methods
-