Package org.h2.build
Class BuildBase
- java.lang.Object
-
- org.h2.build.BuildBase
-
- Direct Known Subclasses:
Build
public class BuildBase extends java.lang.ObjectThis 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 Classes Modifier and Type Class Description static interfaceBuildBase.DescriptionStores descriptions for methods which can be invoked as build targets.static classBuildBase.FileListA list of files.static classBuildBase.StringListA list of strings.
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringjavaExecutableThe full path to the executable of the current JRE.protected java.lang.StringjavaToolsJarThe full path to the tools jar of the current JDK.protected booleanquietIf output should be disabled.protected java.io.PrintStreamsysOutThe output stream (System.out).
-
Constructor Summary
Constructors Constructor Description BuildBase()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidall()This method is called if no other target is specified in the command line.protected static BuildBase.StringListargs(java.lang.String... args)Create a string list.protected voidbeep()Emit a beep.protected voidcopy(java.lang.String targetDir, BuildBase.FileList files, java.lang.String baseDir)Copy files to the specified target directory.protected voiddelete(java.lang.String dir)Delete all files in the given directory and all subdirectories.protected voiddelete(BuildBase.FileList files)Delete all files in the list.static voiddeleteRecursive(java.nio.file.Path file)Delete a file or a directory with its content.protected voiddownload(java.lang.String target, java.lang.String fileURL, java.lang.String sha1Checksum)Download a file if it does not yet exist.protected voiddownloadUsingMaven(java.lang.String target, java.lang.String group, java.lang.String artifact, java.lang.String version, java.lang.String sha1Checksum)Download a file if it does not yet exist.protected intexec(java.lang.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(java.lang.String script, BuildBase.StringList args)Execute a script in a separate process.protected BuildBase.FileListfiles(java.lang.String dir)Get the list of files in the given directory and all subdirectories.protected static java.lang.StringgetJavaSpecVersion()Get the current java specification version (for example, 1.8).static intgetJavaVersion()Get the current Java version as integer value.protected java.lang.StringgetLocalMavenDir()protected static java.lang.StringgetSHA1(byte[] data)Generate the SHA1 checksum of a byte array.protected static java.lang.StringgetStaticField(java.lang.String className, java.lang.String fieldName)Read a final static field in a class using reflection.protected static booleanisWindows()protected longjar(java.lang.String destFile, BuildBase.FileList files, java.lang.String basePath)Create a jar file.protected voidjava(java.lang.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 voidjavadoc(java.lang.String... args)Run a Javadoc task.protected static voidmkdir(java.lang.String dir)Create the directory including the parent directories if they don't exist.protected voidprint(java.lang.String s)Print a message to the output unless the quiet mode is enabled.protected voidprintln(java.lang.String s)Print a line to the output unless the quiet mode is enabled.protected voidprojectHelp()Lists all targets (all public methods non-static methods without parameters).static byte[]readFile(java.nio.file.Path file)Read a file.protected static java.lang.StringreplaceAll(java.lang.String s, java.lang.String before, java.lang.String after)Replace each substring in a given string.protected voidrun(java.lang.String... args)This method should be called by the main method.static voidwriteFile(java.nio.file.Path file, byte[] data)Create or overwrite a file.protected voidzip(java.lang.String destFile, BuildBase.FileList files, java.lang.String basePath, boolean storeOnly, boolean sortBySuffix)Create a zip file.
-
-
-
Field Detail
-
sysOut
protected final java.io.PrintStream sysOut
The output stream (System.out).
-
quiet
protected boolean quiet
If output should be disabled.
-
javaExecutable
protected final java.lang.String javaExecutable
The full path to the executable of the current JRE.
-
javaToolsJar
protected final java.lang.String javaToolsJar
The full path to the tools jar of the current JDK.
-
-
Method Detail
-
run
protected void run(java.lang.String... args)
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
protected int execScript(java.lang.String script, BuildBase.StringList args)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
protected int execJava(BuildBase.StringList args)
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
protected int exec(java.lang.String command, BuildBase.StringList args)Execute a program in a separate process.- Parameters:
command- the program to runargs- the command line parameters- Returns:
- the exit value
-
getStaticField
protected static java.lang.String getStaticField(java.lang.String className, java.lang.String fieldName)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
protected void copy(java.lang.String targetDir, BuildBase.FileList files, java.lang.String baseDir)Copy files to the specified target directory.- Parameters:
targetDir- the target directoryfiles- the list of files to copybaseDir- the base directory
-
javadoc
protected void javadoc(java.lang.String... args)
Run a Javadoc task.- Parameters:
args- the command line arguments to pass
-
getSHA1
protected static java.lang.String getSHA1(byte[] data)
Generate the SHA1 checksum of a byte array.- Parameters:
data- the byte array- Returns:
- the SHA1 checksum
-
downloadUsingMaven
protected void downloadUsingMaven(java.lang.String target, java.lang.String group, java.lang.String artifact, java.lang.String version, java.lang.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
protected java.lang.String getLocalMavenDir()
-
download
protected void download(java.lang.String target, java.lang.String fileURL, java.lang.String sha1Checksum)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
protected BuildBase.FileList files(java.lang.String dir)
Get the list of files in the given directory and all subdirectories.- Parameters:
dir- the source directory- Returns:
- the file list
-
args
protected static BuildBase.StringList args(java.lang.String... args)
Create a string list.- Parameters:
args- the arguments- Returns:
- the string list
-
writeFile
public static void writeFile(java.nio.file.Path file, byte[] data)Create or overwrite a file.- Parameters:
file- the filedata- the data to write
-
readFile
public static byte[] readFile(java.nio.file.Path file)
Read a file. The maximum file size is Integer.MAX_VALUE.- Parameters:
file- the file- Returns:
- the data
-
jar
protected long jar(java.lang.String destFile, BuildBase.FileList files, java.lang.String basePath)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(java.lang.String destFile, BuildBase.FileList files, java.lang.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
protected static java.lang.String 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
protected void javac(BuildBase.StringList args, BuildBase.FileList files)
Compile the files.- Parameters:
args- the command line parametersfiles- the file list
-
java
protected void java(java.lang.String className, BuildBase.StringList args)Call the main method of the given Java class using reflection.- Parameters:
className- the class nameargs- the command line parameters to pass
-
mkdir
protected static void mkdir(java.lang.String dir)
Create the directory including the parent directories if they don't exist.- Parameters:
dir- the directory to create
-
delete
protected void delete(java.lang.String dir)
Delete all files in the given directory and all subdirectories.- Parameters:
dir- the name of the directory
-
delete
protected void delete(BuildBase.FileList files)
Delete all files in the list.- Parameters:
files- the name of the files to delete
-
deleteRecursive
public static void deleteRecursive(java.nio.file.Path file)
Delete a file or a directory with its content.- Parameters:
file- the file or directory to delete
-
replaceAll
protected static java.lang.String replaceAll(java.lang.String s, java.lang.String before, java.lang.String after)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
protected void println(java.lang.String s)
Print a line to the output unless the quiet mode is enabled.- Parameters:
s- the text to write
-
print
protected void print(java.lang.String s)
Print a message to the output unless the quiet mode is enabled.- Parameters:
s- the message to write
-
-