Class BuildUtils

java.lang.Object
org.kissweb.builder.BuildUtils

public class BuildUtils extends Object
  • Field Details

    • isWindows

      public static boolean isWindows
    • isLinux

      public static boolean isLinux
    • isMacOS

      public static boolean isMacOS
    • isSunOS

      public static boolean isSunOS
    • isHaiku

      public static boolean isHaiku
    • isFreeBSD

      public static boolean isFreeBSD
  • Constructor Details

    • BuildUtils

      public BuildUtils()
  • Method Details

    • build

      public static void build(String[] args, Class<?> tasksClass) throws Exception
      Throws:
      Exception
    • getJavaPathOnWindows

      public static String getJavaPathOnWindows()
    • getTomcatPath

      public static String getTomcatPath()
    • exists

      public static boolean exists(String fname)
    • download

      public static void download(String fname, String targetDir, String sourcePath)
    • getcwd

      public static String getcwd()
    • printlnIfVerbose

      public static void printlnIfVerbose(String str)
    • println

      public static void println(String str)
    • printError

      public static void printError(String str)
    • move

      public static void move(String from, String to)
      Move a file from one location to another.
      Parameters:
      from - a file name with a path
      to - a file name with a path
    • mkdir

      public static void mkdir(String dname)
      Creates a directory including any missing parent directories.
      Parameters:
      dname -
    • copy

      public static void copy(String source, String dest)
      Copy file only if missing or earlier date.
      Parameters:
      source - file
      dest - file or directory
    • copyForce

      public static void copyForce(String source, String dest)
      Copy file regardless of file date
      Parameters:
      source - file
      dest - file or directory
    • copyRegex

      public static void copyRegex(String srcDir, String targetDir, String includeRegex, String excludeRegex, boolean force)
      Copies all files that match a (Java!) regex from one directory to another excluding another (Java!) regex.

      Normally only copies files that have a later date unless force is true
      Parameters:
      srcDir -
      targetDir -
      includeRegex - or null if all
      excludeRegex - or null of no exclusions
      force - if true ignore file dates
    • rmRegex

      public static void rmRegex(String dirName, String fnameRegex)
      Delete all files in a directory that match a (Java!) regex.
      Parameters:
      dirName -
      fnameRegex -
    • copyTree

      public static void copyTree(String source, String dest)
      Copy one directory tree to another
      Parameters:
      source -
      dest -
    • copyTreeForce

      public static void copyTreeForce(String source, String dest)
      Copy one directory tree to another. Force copy regardless of file dates.
      Parameters:
      source -
      dest -
    • copyTreeRegex

      public static void copyTreeRegex(String source, String dest, String includeRegex)
      Copy one directory tree to another

      The regular expression applies to file names and not directory names. If includeRegex is null, all files are included.
      Parameters:
      source -
      dest -
      includeRegex - regular expression for files to include or null
    • copyTreeRegex

      public static void copyTreeRegex(String source, String dest, String includeRegex, String excludeRegex)
      Copy one directory tree to another The regular expression applies to file names and not directory names. If includeRegex is null, all files are included. If excludeRegex is null, no files are excluded.
      Parameters:
      source -
      dest -
      includeRegex - regular expression for files to include or null
      excludeRegex - regular expression for files to exclude or null
    • copyTreeRegex

      public static void copyTreeRegex(String source, String dest, String includeRegex, String excludeRegex, boolean force)
      Copy one directory tree to another

      The regular expression applies to file names and not directory names. If includeRegex is null, all files are included. If excludeRegex is null, no files are excluded.
      Parameters:
      source -
      dest -
      includeRegex - regular expression for files to include or null
      excludeRegex - regular expression for files to exclude or null
      force - force copy regardless of date
    • rm

      public static void rm(String file)
      Remove a file or empty directory
      Parameters:
      file -
    • rmdir

      public static void rmdir(String file)
      Remove a file or empty directory
      Parameters:
      file -
    • rmTree

      public static void rmTree(String name)
      Remove a file or entire directory tree
      Parameters:
      name -
    • writeToFile

      public static void writeToFile(String fname, String txt)
      Writes a string to file if it doesn't already exist.
      Parameters:
      fname -
      txt -
    • createManifest

      public static void createManifest(String manifest, String mainClass)
      Create a Java manifest file
      Parameters:
      manifest -
      mainClass -
    • makeExecutable

      public static void makeExecutable(String file)
      Set a file to executable
      Parameters:
      file -
    • writeArgsToFile

      public static String writeArgsToFile(ArrayList<File> lst)
      Create a command line input file (used in Windows)
      Parameters:
      lst -
      Returns:
    • writeDocArgsToFile

      public static String writeDocArgsToFile(ArrayList<File> libs, ArrayList<File> lst)
    • buildJava

      public static void buildJava(String srcPath, String destDir, BuildUtils.LocalDependencies localLibs, org.kissweb.builder.BuildUtils.ForeignDependencies foreignLibs, String additionalSourceRoot)
    • buildJavadoc

      public static void buildJavadoc(String srcPath, String libPath, String destDir, String overviewFile)
      Build JavaDocs
      Parameters:
      srcPath -
      libPath -
      destDir -
    • readChar

      public static int readChar()
    • run

      public static Process run(boolean useShell, boolean wait, boolean echoCmd, boolean showOutput, String startDir, String cmd)
      This is the main driving method for all external procedure calls.

      If useShell is true than normal shell processing (such as >file and <file) is performed. Otherwise exec is called (which is faster).

      If wait is true than this method waits for the process to complete. Otherwise, it returns immediately with the process object.

      If echoCmd is true then the command being executed will be echoed to stdout.

      If showOutput is true the output of the process is displayed to stdout. Otherwise, it is silent.

      startDir provides the starting directory for the process. If null, then the current directory is used.

      cmd represents the command (with arguments) to be executed. If useShell is true, then cmd can also use the shell syntax.
      Parameters:
      useShell -
      wait -
      echoCmd -
      showOutput -
      startDir -
      cmd -
      Returns:
      the process either running or completed (depending on wait)
    • runWait

      public static void runWait(boolean showOutput, String startDir, String cmd)
      Run a command in the underlying OS in the foreground. Wait till it is done. This command does not support shell processing such as > and < etc.
      Parameters:
      showOutput - true if output should be shown
      startDir - starting directory or null
      cmd - the command to execute
      See Also:
    • runShell

      public static void runShell(String startDir, String cmd)
      Run a command in the underlying OS shell in the foreground. Wait till it is done. This command supports all of the shell processing such as > and < etc.
      Parameters:
      startDir - starting directory or null
      cmd - the command to execute
      See Also:
    • runWait

      public static void runWait(boolean showOutput, String cmd)
      Run a command in the underlying OS in the foreground.
      Parameters:
      showOutput -
      cmd -
      See Also:
    • runShell

      public static void runShell(String cmd)
      Run a command in the underlying OS shell in the foreground.
      Parameters:
      cmd -
      See Also:
    • runBackground

      public static Process runBackground(String cmd)
      Run a command in the underlying OS in the background. Does not wait till it is done. The Process is returned so that it can be killed.
      Parameters:
      cmd - the command to execute
      Returns:
      the Process
      See Also:
    • killProcess

      public static void killProcess(Process proc)
    • createJar

      public static void createJar(String rootDir, String jarFile)
      Create a JAR file
      Parameters:
      rootDir - to be jar'ed up
      jarFile - name of the JAR file
    • unJar

      public static void unJar(String rootDir, String jarFile)
      Unpack a JAR file.

      A tag file is also created in order to track the date of the unjar vs. the date of the jar file.
      Parameters:
      rootDir - where to unjar the files
      jarFile - the jar file
    • touch

      public static void touch(String fname, long millisecs)
    • touch

      public static void touch(String fname)
    • unJarAllLibs

      public static void unJarAllLibs(String rootDir, BuildUtils.LocalDependencies ld, org.kissweb.builder.BuildUtils.ForeignDependencies fd)
    • javac

      public static void javac(BuildUtils.LocalDependencies ldep, org.kissweb.builder.BuildUtils.ForeignDependencies fdep, String sourcePath, String destPath, String filelist, String additionalSourceRoot)
    • buildWS

      public static void buildWS(BuildUtils.LocalDependencies ldep, org.kissweb.builder.BuildUtils.ForeignDependencies fdep, String dest, String sdir, String service)
    • gunzip

      public static void gunzip(String fname, String dir, int nPathsElementsToDelete)
      gunzip and untar a .gz file into the specified directory
      Parameters:
      fname -
      dir -
      nPathsElementsToDelete - number of leading path elements in tar file to eliminate
    • cwd

      public static String cwd()
    • removeFromCache

      public static void removeFromCache(String fname)
    • tail

      public static void tail(String fileName) throws Exception
      Works like Unix "tail -F" command. It never exits. Useful for continuous display of a log file that may rotate.
      Parameters:
      fileName -
      Throws:
      Exception
    • convertToCamelCase

      public static String convertToCamelCase(String input)
      Convert a string from dashed notation to camel case notation.
      Parameters:
      input - The string in dashed notation.
      Returns:
      The string in camel case notation.