Package org.h2.build
Class BuildBase
java.lang.Object
org.h2.build.BuildBase
- Direct Known Subclasses:
Build
This class is a complete pure Java build tool. It allows to build this
project without any external dependencies except a JDK.
Advantages: ability to debug the build, extensible, flexible,
no XML, a bit faster.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic @interfaceStores descriptions for methods which can be invoked as build targets.static classA list of files.static classA list of strings. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final StringThe full path to the executable of the current JRE.protected final StringThe full path to the tools jar of the current JDK.protected booleanIf output should be disabled.protected final PrintStreamThe output stream (System.out). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidall()This method is called if no other target is specified in the command line.protected static BuildBase.StringListCreate a string list.protected voidbeep()Emit a beep.protected voidcopy(String targetDir, BuildBase.FileList files, String baseDir) Copy files to the specified target directory.protected voidDelete all files in the given directory and all subdirectories.protected voiddelete(BuildBase.FileList files) Delete all files in the list.static voiddeleteRecursive(Path file) Delete a file or a directory with its content.protected voidDownload a file if it does not yet exist.protected voiddownloadUsingMaven(String target, String group, String artifact, String version, String sha1Checksum) Download a file if it does not yet exist.protected intexec(String command, BuildBase.StringList args) Execute a program in a separate process.protected intexecJava(BuildBase.StringList args) Execute java in a separate process, but using the java executable of the current JRE.protected intexecScript(String script, BuildBase.StringList args) Execute a script in a separate process.protected BuildBase.FileListGet the list of files in the given directory and all subdirectories.protected static StringGet the current java specification version (for example, 1.8).static intGet the current Java version as integer value.protected Stringprotected static StringgetSHA1(byte[] data) Generate the SHA1 checksum of a byte array.protected static StringgetStaticField(String className, String fieldName) Read a final static field in a class using reflection.protected static booleanprotected longjar(String destFile, BuildBase.FileList files, String basePath) Create a jar file.protected voidjava(String className, BuildBase.StringList args) Call the main method of the given Java class using reflection.protected voidjavac(BuildBase.StringList args, BuildBase.FileList files) Compile the files.protected voidRun a Javadoc task.protected static voidCreate the directory including the parent directories if they don't exist.protected voidPrint a message to the output unless the quiet mode is enabled.protected voidPrint a line to the output unless the quiet mode is enabled.protected voidLists all targets (all public methods non-static methods without parameters).static byte[]Read a file.protected static StringreplaceAll(String s, String before, String after) Replace each substring in a given string.protected voidThis method should be called by the main method.static voidCreate or overwrite a file.protected voidzip(String destFile, BuildBase.FileList files, String basePath, boolean storeOnly, boolean sortBySuffix) Create a zip file.
-
Field Details
-
sysOut
The output stream (System.out). -
quiet
protected boolean quietIf output should be disabled. -
javaExecutable
The full path to the executable of the current JRE. -
javaToolsJar
The full path to the tools jar of the current JDK.
-
-
Constructor Details
-
BuildBase
public BuildBase()
-
-
Method Details
-
run
This method should be called by the main method.- Parameters:
args- the command line parameters
-
all
protected void all()This method is called if no other target is specified in the command line. The default behavior is to call projectHelp(). Override this method if you want another default behavior. -
beep
protected void beep()Emit a beep. -
projectHelp
protected void projectHelp()Lists all targets (all public methods non-static methods without parameters). -
isWindows
protected static boolean isWindows() -
execScript
Execute a script in a separate process. In Windows, the batch file with this name (.bat) is run.- Parameters:
script- the program to runargs- the command line parameters- Returns:
- the exit value
-
execJava
Execute java in a separate process, but using the java executable of the current JRE.- Parameters:
args- the command line parameters for the java command- Returns:
- the exit value
-
exec
Execute a program in a separate process.- Parameters:
command- the program to runargs- the command line parameters- Returns:
- the exit value
-
getStaticField
Read a final static field in a class using reflection.- Parameters:
className- the name of the classfieldName- the field name- Returns:
- the value as a string
-
copy
Copy files to the specified target directory.- Parameters:
targetDir- the target directoryfiles- the list of files to copybaseDir- the base directory
-
javadoc
Run a Javadoc task.- Parameters:
args- the command line arguments to pass
-
getSHA1
Generate the SHA1 checksum of a byte array.- Parameters:
data- the byte array- Returns:
- the SHA1 checksum
-
downloadUsingMaven
protected void downloadUsingMaven(String target, String group, String artifact, String version, String sha1Checksum) Download a file if it does not yet exist. Maven is used if installed, so that the file is first downloaded to the local repository and then copied from there.- Parameters:
target- the target file namegroup- the Maven group idartifact- the Maven artifact idversion- the Maven version idsha1Checksum- the SHA-1 checksum or null
-
getLocalMavenDir
-
download
Download a file if it does not yet exist. If no checksum is used (that is, if the parameter is null), the checksum is printed. For security, checksums should always be used.- Parameters:
target- the target file namefileURL- the source url of the filesha1Checksum- the SHA-1 checksum or null
-
files
Get the list of files in the given directory and all subdirectories.- Parameters:
dir- the source directory- Returns:
- the file list
-
args
Create a string list.- Parameters:
args- the arguments- Returns:
- the string list
-
writeFile
Create or overwrite a file.- Parameters:
file- the filedata- the data to write
-
readFile
Read a file. The maximum file size is Integer.MAX_VALUE.- Parameters:
file- the file- Returns:
- the data
-
jar
Create a jar file.- Parameters:
destFile- the target file namefiles- the file listbasePath- the base path- Returns:
- the size of the jar file in KB
-
zip
protected void zip(String destFile, BuildBase.FileList files, String basePath, boolean storeOnly, boolean sortBySuffix) Create a zip file.- Parameters:
destFile- the target file namefiles- the file listbasePath- the base pathstoreOnly- if the files should not be compressedsortBySuffix- if the file should be sorted by the file suffix
-
getJavaSpecVersion
Get the current java specification version (for example, 1.8).- Returns:
- the java specification version
-
getJavaVersion
public static int getJavaVersion()Get the current Java version as integer value.- Returns:
- the Java version (8, 9, 10, 11, 12, 13, etc)
-
javac
Compile the files.- Parameters:
args- the command line parametersfiles- the file list
-
java
Call the main method of the given Java class using reflection.- Parameters:
className- the class nameargs- the command line parameters to pass
-
mkdir
Create the directory including the parent directories if they don't exist.- Parameters:
dir- the directory to create
-
delete
Delete all files in the given directory and all subdirectories.- Parameters:
dir- the name of the directory
-
delete
Delete all files in the list.- Parameters:
files- the name of the files to delete
-
deleteRecursive
Delete a file or a directory with its content.- Parameters:
file- the file or directory to delete
-
replaceAll
Replace each substring in a given string. Regular expression is not used.- Parameters:
s- the original textbefore- the old substringafter- the new substring- Returns:
- the string with the string replaced
-
println
Print a line to the output unless the quiet mode is enabled.- Parameters:
s- the text to write
-
print
Print a message to the output unless the quiet mode is enabled.- Parameters:
s- the message to write
-