Package org.h2.build

Class BuildBase

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

public class BuildBase extends 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.
  • Field Details

    • sysOut

      protected final PrintStream sysOut
      The output stream (System.out).
    • quiet

      protected boolean quiet
      If output should be disabled.
    • javaExecutable

      protected final String javaExecutable
      The full path to the executable of the current JRE.
    • javaToolsJar

      protected final String javaToolsJar
      The full path to the tools jar of the current JDK.
  • Constructor Details

    • BuildBase

      public BuildBase()
  • Method Details

    • run

      protected void run(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(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
    • 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(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 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
    • copy

      protected 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
    • javadoc

      protected void javadoc(String... args)
      Run a Javadoc task.
      Parameters:
      args - the command line arguments to pass
    • getSHA1

      protected static 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(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
    • getLocalMavenDir

      protected String getLocalMavenDir()
    • download

      protected 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
    • files

      protected 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
    • args

      protected static BuildBase.StringList args(String... args)
      Create a string list.
      Parameters:
      args - the arguments
      Returns:
      the string list
    • writeFile

      public static void writeFile(Path file, byte[] data)
      Create or overwrite a file.
      Parameters:
      file - the file
      data - the data to write
    • readFile

      public static byte[] readFile(Path file)
      Read a file. The maximum file size is Integer.MAX_VALUE.
      Parameters:
      file - the file
      Returns:
      the data
    • jar

      protected 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
    • zip

      protected 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
    • getJavaSpecVersion

      protected static 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 parameters
      files - the file list
    • java

      protected 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
    • mkdir

      protected static void mkdir(String dir)
      Create the directory including the parent directories if they don't exist.
      Parameters:
      dir - the directory to create
    • delete

      protected void delete(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(Path file)
      Delete a file or a directory with its content.
      Parameters:
      file - the file or directory to delete
    • replaceAll

      protected 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
    • println

      protected void println(String s)
      Print a line to the output unless the quiet mode is enabled.
      Parameters:
      s - the text to write
    • print

      protected void print(String s)
      Print a message to the output unless the quiet mode is enabled.
      Parameters:
      s - the message to write