org.h2.build
Class BuildBase

java.lang.Object
  extended by org.h2.build.BuildBase
Direct Known Subclasses:
Build

public class BuildBase
extends java.lang.Object

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
static class BuildBase.FileList
          A list of files.
static class BuildBase.StringList
          A list of strings.
 
Field Summary
protected  boolean quiet
          If output should be disabled.
protected  java.io.PrintStream sysOut
          The output stream (System.out).
 
Constructor Summary
BuildBase()
           
 
Method Summary
protected  void all()
          This method is called if no other target is specified in the command line.
protected static BuildBase.StringList args(java.lang.String... args)
          Create a string list.
protected  void beep()
          Emit a beep.
protected  void copy(java.lang.String targetDir, BuildBase.FileList files, java.lang.String baseDir)
          Copy files to the specified target directory.
protected  void delete(BuildBase.FileList files)
          Delete all files in the list.
protected  void delete(java.lang.String dir)
          Delete all files in the given directory and all subdirectories.
protected  void download(java.lang.String target, java.lang.String fileURL, java.lang.String sha1Checksum)
          Download a file if it does not yet exist.
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.
protected  int exec(java.lang.String command, BuildBase.StringList args)
          Execute a program in a separate process.
protected  int execScript(java.lang.String script, BuildBase.StringList args)
          Execute a script in a separate process.
protected  BuildBase.FileList files(java.lang.String dir)
          Get the list of files in the given directory and all subdirectories.
protected static java.lang.String getJavaSpecVersion()
          Get the current java specification version (for example, 1.4).
protected  java.lang.String getLocalMavenDir()
           
protected static java.lang.String getSHA1(byte[] data)
          Generate the SHA1 checksum of a byte array.
protected static java.lang.String getStaticField(java.lang.String className, java.lang.String fieldName)
          Read a final static field in a class using reflection.
protected static java.lang.String getStaticValue(java.lang.String className, java.lang.String methodName)
          Reads the value from a static method of a class using reflection.
protected  long jar(java.lang.String destFile, BuildBase.FileList files, java.lang.String basePath)
          Create a jar file.
protected  void java(java.lang.String className, BuildBase.StringList args)
          Call the main method of the given Java class using reflection.
protected  void javac(BuildBase.StringList args, BuildBase.FileList files)
          Compile the files.
protected  void javadoc(java.lang.String... args)
          Run a Javadoc task.
protected static void mkdir(java.lang.String dir)
          Create the directory including the parent directories if they don't exist.
protected  void print(java.lang.String s)
          Print a message to the output unless the quiet mode is enabled.
protected  void println(java.lang.String s)
          Print a line to the output unless the quiet mode is enabled.
protected  void projectHelp()
          Lists all targets (all public methods non-static methods without parameters).
static byte[] readFile(java.io.File file)
          Read a file.
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.
protected  void run(java.lang.String... args)
          This method should be called by the main method.
static void writeFile(java.io.File file, byte[] data)
          Create or overwrite a file.
protected  void zip(java.lang.String destFile, BuildBase.FileList files, java.lang.String basePath, boolean storeOnly, boolean sortBySuffix)
          Create a zip file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sysOut

protected final java.io.PrintStream sysOut
The output stream (System.out).


quiet

protected boolean quiet
If output should be disabled.

Constructor Detail

BuildBase

public BuildBase()
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).


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 run
args - the command line parameters
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 run
args - 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 class
fieldName - the field name
Returns:
the value as a string

getStaticValue

protected static java.lang.String getStaticValue(java.lang.String className,
                                                 java.lang.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

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 directory
files - the list of files to copy
baseDir - 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 name
group - the Maven group id
artifact - the Maven artifact id
version - the Maven version id
sha1Checksum - 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 name
fileURL - the source url of the file
sha1Checksum - 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.io.File file,
                             byte[] data)
Create or overwrite a file.

Parameters:
file - the file
data - the data to write

readFile

public static byte[] readFile(java.io.File 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 name
files - the file list
basePath - 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 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

getJavaSpecVersion

protected static java.lang.String getJavaSpecVersion()
Get the current java specification version (for example, 1.4).

Returns:
the java specification version

javac

protected void javac(BuildBase.StringList args,
                     BuildBase.FileList files)
Compile the files.

Parameters:
args - the command line parameters
files - 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 name
args - 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

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 text
before - the old substring
after - 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