BuildBase

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.

Methods
static BuildBase.StringList args(String... args)
Create a string list.
static BuildBase.StringList args(String... args)
Create a string list.
Parameters:
args - the arguments
Returns:
the string list
static String getJavaSpecVersion()
Get the current java specification version (for example, 1.4).
static String getJavaSpecVersion()
Get the current java specification version (for example, 1.4).
Returns:
the java specification version
static String getSHA1(byte[] data)
Generate the SHA1 checksum of a byte array.
static String getSHA1(byte[] data)
Generate the SHA1 checksum of a byte array.
Parameters:
data - the byte array
Returns:
the SHA1 checksum
static String getStaticField(String className, String fieldName)
Read a final static field in a class using reflection.
static String getStaticField(String className, String fieldName)
Read a final static field in a class using reflection.
Parameters:
className - the name of the class
fieldName - the field name
Returns:
the value as a string
static String getStaticValue(String className, String methodName)
Reads the value from a static method of a class using reflection.
static String getStaticValue(String className, String methodName)
Reads the value from a static method of a class using reflection.
Parameters:
className - the name of the class
methodName - the field name
Returns:
the value as a string
static String getSuffix(String fileName)
Get the file name suffix.
static String getSuffix(String fileName)
Get the file name suffix.
Parameters:
fileName - the file name
Returns:
the suffix or an empty string if there is none
static void mkdir(String dir)
Create the directory including the parent directories if they don't exist.
static void mkdir(String dir)
Create the directory including the parent directories if they don't exist.
Parameters:
dir - the directory to create
static byte[] readFile(File file)
Read a file.
static byte[] readFile(File file)
Read a file. The maximum file size is Integer.MAX_VALUE.
Parameters:
file - the file
Returns:
the data
static String replaceAll(String s, String before, String after)
Replace each substring in a given string.
static String replaceAll(String s, String before, String after)
Replace each substring in a given string. Regular expression is not used.
Parameters:
s - the original text
before - the old substring
after - the new substring
Returns:
the string with the string replaced
static void writeFile(File file, byte[] data)
Create or overwrite a file.
static void writeFile(File file, byte[] data)
Create or overwrite a file.
Parameters:
file - the file
data - the data to write
void all()
This method is called if no other target is specified in the command line.
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.
void beep()
Emit a beep.
void beep()
Emit a beep.
void copy(String targetDir, BuildBase.FileList files, String baseDir)
Copy files to the specified target directory.
void copy(String targetDir, BuildBase.FileList files, String baseDir)
Copy files to the specified target directory.
Parameters:
targetDir - the target directory
files - the list of files to copy
baseDir - the base directory
void delete(String dir)
Delete all files in the given directory and all subdirectories.
void delete(String dir)
Delete all files in the given directory and all subdirectories.
Parameters:
dir - the name of the directory
void delete(BuildBase.FileList files)
Delete all files in the list.
void delete(BuildBase.FileList files)
Delete all files in the list.
Parameters:
files - the name of the files to delete
void download(String target, String fileURL, String sha1Checksum)
Download a file if it does not yet exist.
void download(String target, String fileURL, 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 name
fileURL - the source url of the file
sha1Checksum - the SHA-1 checksum or null
void downloadUsingMaven(String target, String group, String artifact, String version, String sha1Checksum)
Download a file if it does not yet exist.
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 name
group - the Maven group id
artifact - the Maven artifact id
version - the Maven version id
sha1Checksum - the SHA-1 checksum or null
int exec(String command, BuildBase.StringList args)
Execute a program in a separate process.
int exec(String command, BuildBase.StringList args)
Execute a program in a separate process.
Parameters:
command - the program to run
args - the command line parameters
Returns:
the exit value
int execJava(BuildBase.StringList args)
Execute java in a separate process, but using the java executable of the current JRE.
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
int execScript(String script, BuildBase.StringList args)
Execute a script in a separate process.
int execScript(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 run
args - the command line parameters
Returns:
the exit value
BuildBase.FileList files(String dir)
Get the list of files in the given directory and all subdirectories.
BuildBase.FileList files(String dir)
Get the list of files in the given directory and all subdirectories.
Parameters:
dir - the source directory
Returns:
the file list
String getLocalMavenDir()
String getLocalMavenDir()
long jar(String destFile, BuildBase.FileList files, String basePath)
Create a jar file.
long jar(String destFile, BuildBase.FileList files, String basePath)
Create a jar file.
Parameters:
destFile - the target file name
files - the file list
basePath - the base path
Returns:
the size of the jar file in KB
void java(String className, BuildBase.StringList args)
Call the main method of the given Java class using reflection.
void java(String className, BuildBase.StringList args)
Call the main method of the given Java class using reflection.
Parameters:
className - the class name
args - the command line parameters to pass
void javac(BuildBase.StringList args, BuildBase.FileList files)
Compile the files.
void javac(BuildBase.StringList args, BuildBase.FileList files)
Compile the files.
Parameters:
args - the command line parameters
files - the file list
void javadoc(String... args)
Run a Javadoc task.
void javadoc(String... args)
Run a Javadoc task.
Parameters:
args - the command line arguments to pass
void print(String s)
Print a message to the output unless the quiet mode is enabled.
void print(String s)
Print a message to the output unless the quiet mode is enabled.
Parameters:
s - the message to write
void println(String s)
Print a line to the output unless the quiet mode is enabled.
void println(String s)
Print a line to the output unless the quiet mode is enabled.
Parameters:
s - the text to write
void projectHelp()
Lists all targets (all public methods non-static methods without parameters).
void projectHelp()
Lists all targets (all public methods non-static methods without parameters).
void run(String... args)
This method should be called by the main method.
void run(String... args)
This method should be called by the main method.
Parameters:
args - the command line parameters
void zip(String destFile, BuildBase.FileList files, String basePath, boolean storeOnly, boolean sortBySuffix)
Create a zip file.
void zip(String destFile, BuildBase.FileList files, String basePath, boolean storeOnly, boolean sortBySuffix)
Create a zip file.
Parameters:
destFile - the target file name
files - the file list
basePath - the base path
storeOnly - if the files should not be compressed
sortBySuffix - if the file should be sorted by the file suffix

Fields
static String javaExecutable
static String javaToolsJar
static boolean quiet
static PrintStream sysOut

javaExecutable

The full path to the executable of the current JRE.

javaToolsJar

The full path to the tools jar of the current JDK.

quiet

If output should be disabled.

sysOut

The output stream (System.out).