public class Builder extends Object
Modifier and Type | Field and Description |
---|---|
(package private) ClassScanner |
classScanner
|
(package private) boolean |
compile
If true, compiles the generated source file to a shared library and deletes source.
|
(package private) Collection<String> |
compilerOptions
Contains additional command line options from the user for the native compiler.
|
(package private) boolean |
copyLibs
If true, also copies to the output directory dependent shared libraries (link and preload).
|
(package private) boolean |
deleteJniFiles
If true, preserves the generated C++ JNI files after compilation
|
(package private) Map<String,String> |
environmentVariables
User specified environment variables to pass to the native compiler.
|
(package private) boolean |
header
If true, also generates C++ header files containing declarations of callback functions.
|
(package private) String |
jarPrefix
The name of the JAR file to create, if not
null . |
(package private) Logger |
logger
Logger where to send debug, info, warning, and error messages.
|
(package private) File |
outputDirectory
The directory where the generated files and compiled shared libraries get written to.
|
(package private) String |
outputName
The name of the output generated source file or shared library.
|
(package private) Properties |
properties
Accumulates the various properties loaded from resources, files, command line options, etc.
|
Constructor and Description |
---|
Builder()
Default constructor that simply initializes everything.
|
Builder(Logger logger)
Constructor that simply initializes everything.
|
Modifier and Type | Method and Description |
---|---|
File[] |
build()
Starts the build process and returns an array of
File produced. |
Builder |
classesOrPackages(String... classesOrPackages)
Requests the
classScanner to add a class or all classes from a package. |
Builder |
classPaths(String... classPaths)
Appends argument to the paths of the
classScanner . |
Builder |
classPaths(String classPaths)
Splits argument with
File.pathSeparator and appends result to paths of the classScanner . |
Builder |
compile(boolean compile)
Sets the
compile field to the argument. |
(package private) int |
compile(String sourceFilename,
String outputFilename,
ClassProperties properties,
File workingDirectory)
Launches and waits for the native compiler to produce a native shared library.
|
Builder |
compilerOptions(String... options)
Appends arguments to the
compilerOptions field. |
Builder |
copyLibs(boolean copyLibs)
Sets the
copyLibs field to the argument. |
(package private) void |
createJar(File jarFile,
String[] classPath,
File... files)
Stores all the files in the given JAR file.
|
Builder |
deleteJniFiles(boolean deleteJniFiles)
Sets the
deleteJniFiles field to the argument. |
Builder |
environmentVariables(Map<String,String> environmentVariables)
Sets the
environmentVariables field to the argument. |
(package private) File |
generateAndCompile(Class[] classes,
String outputName)
Generates a C++ source file for classes, and compiles everything in
one shared library when
compile == true . |
Builder |
header(boolean header)
Sets the
header field to the argument. |
(package private) void |
includeJavaPaths(ClassProperties properties,
boolean header)
Tries to find automatically include paths for
jni.h and jni_md.h ,
as well as the link and library paths for the jvm library. |
Builder |
jarPrefix(String jarPrefix)
Sets the
jarPrefix field to the argument. |
static void |
main(String[] args)
The terminal shell interface to the Builder.
|
Builder |
outputDirectory(File outputDirectory)
Sets the
outputDirectory field to the argument. |
Builder |
outputDirectory(String outputDirectory)
Sets the
outputDirectory field to the argument. |
Builder |
outputName(String outputName)
Sets the
outputName field to the argument. |
(package private) File |
parse(String[] classPath,
Class cls)
Calls
Parser.parse(File, String[], Class) after creating an instance of the Class. |
static void |
printHelp()
Simply prints out to the display the command line usage.
|
Builder |
properties(Properties properties)
Adds all the properties of the argument to the
properties field. |
Builder |
properties(String platform)
Sets the
properties field to the ones loaded from resources for the specified platform. |
Builder |
property(String keyValue)
Sets a property of the
properties field, in either "key=value" or "key:value" format. |
Builder |
property(String key,
String value)
Sets a key/value pair property of the
properties field. |
Builder |
propertyFile(File propertyFile)
Sets the
properties field to the ones loaded from the specified file. |
Builder |
propertyFile(String filename)
Sets the
properties field to the ones loaded from the specified file. |
final Logger logger
File outputDirectory
.class
file.String outputName
String jarPrefix
null
.boolean compile
boolean deleteJniFiles
boolean header
boolean copyLibs
Properties properties
ClassScanner classScanner
Map<String,String> environmentVariables
Collection<String> compilerOptions
public Builder()
public Builder(Logger logger)
logger
- where to send messagesFile parse(String[] classPath, Class cls) throws IOException, ParserException
Parser.parse(File, String[], Class)
after creating an instance of the Class.classPath
- an array of paths to try to load header files fromcls
- The class annotated with Properties
and implementing InfoMapper
IOException
- on Java target file writing errorParserException
- on C/C++ header file parsing errorvoid includeJavaPaths(ClassProperties properties, boolean header)
jni.h
and jni_md.h
,
as well as the link and library paths for the jvm
library.properties
- the Properties containing the paths to updateheader
- to request support for exporting callbacks via generated header fileint compile(String sourceFilename, String outputFilename, ClassProperties properties, File workingDirectory) throws IOException, InterruptedException
sourceFilename
- the C++ source filenameoutputFilename
- the output filename of the shared libraryproperties
- the Properties detailing the compiler options to useProcess.waitFor()
IOException
InterruptedException
File generateAndCompile(Class[] classes, String outputName) throws IOException, InterruptedException
compile == true
.classes
- the Class objects as input to GeneratoroutputName
- the output name of the shared libraryIOException
InterruptedException
void createJar(File jarFile, String[] classPath, File... files) throws IOException
jarFile
- the JAR file to createclassPath
- an array of paths to try to use as root for classesfiles
- a list of files to store in the JAR fileIOException
public Builder classPaths(String classPaths)
File.pathSeparator
and appends result to paths of the classScanner
.public Builder classPaths(String... classPaths)
classScanner
.public Builder outputDirectory(String outputDirectory)
outputDirectory
field to the argument.public Builder outputDirectory(File outputDirectory)
outputDirectory
field to the argument.public Builder deleteJniFiles(boolean deleteJniFiles)
deleteJniFiles
field to the argument.public Builder outputName(String outputName)
outputName
field to the argument.public Builder properties(String platform)
properties
field to the ones loaded from resources for the specified platform.public Builder properties(Properties properties)
properties
field.public Builder propertyFile(String filename) throws IOException
properties
field to the ones loaded from the specified file.IOException
public Builder propertyFile(File propertyFile) throws IOException
properties
field to the ones loaded from the specified file.IOException
public Builder property(String keyValue)
properties
field, in either "key=value" or "key:value" format.public Builder property(String key, String value)
properties
field.public Builder classesOrPackages(String... classesOrPackages) throws IOException, ClassNotFoundException, NoClassDefFoundError
classScanner
to add a class or all classes from a package.
A null
argument indicates the unnamed package.public Builder environmentVariables(Map<String,String> environmentVariables)
environmentVariables
field to the argument.public Builder compilerOptions(String... options)
compilerOptions
field.public File[] build() throws IOException, InterruptedException, ParserException
File
produced.IOException
InterruptedException
ParserException
public static void printHelp()
public static void main(String[] args) throws Exception
args
- an array of arguments as described by printHelp()
Exception
Copyright © 2016. All rights reserved.