public class Builder extends Object
Modifier and Type | Field and Description |
---|---|
(package private) String[] |
buildCommand
A system command for
ProcessBuilder to execute for the build, instead of JavaCPP itself. |
(package private) ClassScanner |
classScanner
|
(package private) boolean |
clean
If true, deletes all files from
outputDirectory before writing anything in it. |
(package private) CommandExecutor |
commandExecutor
An alternative CommandExecutor to use to execute commands.
|
(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) File |
configDirectory
The name of the directory where to output config files for GraalVM native-image, if not
null . |
(package private) boolean |
copyLibs
If true, also copies to the output directory dependent shared libraries (link and preload).
|
(package private) boolean |
copyResources
If true, also copies to the output directory resources listed in properties.
|
(package private) boolean |
deleteJniFiles
If true, preserves the generated C++ JNI files after compilation.
|
(package private) String |
encoding
The name of the character encoding used for input files as well as output files.
|
(package private) Map<String,String> |
environmentVariables
User specified environment variables to pass to the native compiler.
|
(package private) boolean |
generate
If true, attempts to generate C++ JNI files, but if false, only attempts to parse header files.
|
(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.
|
(package private) File |
workingDirectory
User specified working directory to execute build subprocesses under.
|
Constructor and Description |
---|
Builder()
Default constructor that simply initializes everything.
|
Builder(Logger logger)
Constructor that simply initializes everything.
|
Modifier and Type | Method and Description |
---|---|
Builder |
addProperty(String key,
String... values)
Adds values to a given property key, seperating them with "platform.path.separator".
|
File[] |
build()
Starts the build process and returns an array of
File produced. |
Builder |
buildCommand(String[] buildCommand)
Sets the
buildCommand field to the argument. |
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 |
clean(boolean clean)
Sets the
clean field to the argument. |
(package private) void |
cleanOutputDirectory()
Deletes
outputDirectory if clean is true. |
Builder |
commandExecutor(CommandExecutor commandExecutor)
Sets the
commandExecutor field to the argument. |
Builder |
compile(boolean compile)
Sets the
compile field to the argument. |
(package private) int |
compile(String[] sourceFilenames,
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 |
configDirectory(File configDirectory)
Sets the
configDirectory field to the argument. |
Builder |
configDirectory(String configDirectory)
Sets the
configDirectory field to the argument. |
Builder |
copyLibs(boolean copyLibs)
Sets the
copyLibs field to the argument. |
Builder |
copyResources(boolean copyResources)
Sets the
copyResources 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 |
encoding(String encoding)
Sets the
encoding field to the argument. |
Builder |
environmentVariables(Map<String,String> environmentVariables)
Sets the
environmentVariables field to the argument. |
Builder |
generate(boolean generate)
Sets the
generate field to the argument. |
(package private) File[] |
generateAndCompile(Class[] classes,
String outputName,
boolean first,
boolean last)
Generates C++ source files for classes, and compiles everything in
one shared library when
compile == true . |
(package private) File |
getOutputPath(Class[] classes,
String[] sourcePrefixes)
Creates and returns the directory where output files should be placed.
|
Properties |
getProperties()
Returns
properties . |
String |
getProperty(String key)
Returns
properties.getProperty(key) . |
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. |
Builder |
workingDirectory(File workingDirectory)
Sets the
workingDirectory field to the argument. |
Builder |
workingDirectory(String workingDirectory)
Sets the
workingDirectory field to the argument. |
final Logger logger
String encoding
File outputDirectory
.class
file.String outputName
File configDirectory
null
.String jarPrefix
null
.boolean clean
outputDirectory
before writing anything in it.boolean generate
boolean compile
boolean deleteJniFiles
boolean header
boolean copyLibs
boolean copyResources
Properties properties
ClassScanner classScanner
String[] buildCommand
ProcessBuilder
to execute for the build, instead of JavaCPP itself.File workingDirectory
Map<String,String> environmentVariables
Collection<String> compilerOptions
CommandExecutor commandExecutor
public Builder()
public Builder(Logger logger)
logger
- where to send messagesvoid cleanOutputDirectory() throws IOException
outputDirectory
if clean
is true.IOException
File[] 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[] sourceFilenames, String outputFilename, ClassProperties properties, File workingDirectory) throws IOException, InterruptedException
sourceFilenames
- the C++ source filenamesoutputFilename
- the output filename of the shared libraryproperties
- the Properties detailing the compiler options to useProcess.waitFor()
IOException
InterruptedException
File getOutputPath(Class[] classes, String[] sourcePrefixes) throws IOException
outputDirectory
as is when available, but falls back
on the longest common path to the classes as well as the platform
specific library path when available, or the platform name itself
and the user provided extension when not.classes
- from which to derive the output pathsourcePrefixes
- returned, 2 strings without platform names, one from our class loader, the other from the common path of the classesIOException
File[] generateAndCompile(Class[] classes, String outputName, boolean first, boolean last) throws IOException, InterruptedException
compile == true
.classes
- the Class objects as input to GeneratoroutputName
- the output name of the shared libraryfirst
- of the batch, so generate jnijavacpp.cpplast
- of the batch, so delete jnijavacpp.cppIOException
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 copyResources(boolean copyResources)
copyResources
field to the argument.public Builder outputName(String outputName)
outputName
field to the argument.public Builder configDirectory(String configDirectory)
configDirectory
field to the argument.public Builder configDirectory(File configDirectory)
configDirectory
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 Properties getProperties()
properties
.public Builder addProperty(String key, String... values)
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 buildCommand(String[] buildCommand)
buildCommand
field to the argument.public Builder workingDirectory(String workingDirectory)
workingDirectory
field to the argument.public Builder workingDirectory(File workingDirectory)
workingDirectory
field to the argument.public Builder environmentVariables(Map<String,String> environmentVariables)
environmentVariables
field to the argument.public Builder compilerOptions(String... options)
compilerOptions
field.public Builder commandExecutor(CommandExecutor commandExecutor)
commandExecutor
field to the argument.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 © 2024. All rights reserved.