cpmake
Class CPMake

java.lang.Object
  extended bycpmake.CPMake

public class CPMake
extends java.lang.Object

General Comments


Field Summary
static int INCLUDE_PATH
          Use with createFileList.
static int RECURSE
          Use with createFileList.
static int RELATIVE_PATH
          Use with createFileList and in conjunction with INCLUDE_PATH.
 
Constructor Summary
CPMake(CPMake make, java.lang.String buildFile, java.lang.String primaryTarget)
          Creates a CPMake object.
CPMake(java.lang.String buildFile, java.lang.String primaryTarget)
          Creaes a CPMake object.
 
Method Summary
 void addClassPath(java.lang.String path)
           
 void addSearchPath(java.lang.String path)
          Adds a path to search when looking for targets.
 void addSearchPath(java.lang.String pattern, java.lang.String path)
          Adds a path to search when looking for targets that match the given pattern.
 void addSearchPaths(java.lang.String[] paths)
          Adds search paths to look in when trying to find files.
 void addSearchPaths(java.lang.String pattern, java.lang.String[] paths)
          Adss paths to search when looking for targets that match the given pattern
static java.lang.String arrayToString(java.lang.String[] array)
          Converts an array into a string seperated by spaces.
 void autoClean()
          Automatically cleans the build area by removing targets that are specified in the build file.
 void buildTarget(java.lang.String target)
          Processes the rule for the given target.
 void buildTarget(java.lang.String target, boolean prep)
          Processes the rule for the given target.
 void clearMakeRules()
          Clears all rules and dependencies.
static java.lang.String[] combine(java.lang.String[] arr1, java.lang.String[] arr2)
          Combines two String arrays into one.
 void copy(java.lang.String source, java.lang.String dest)
          Performs a file copy.
 void copy(java.lang.String sourceDir, java.lang.String filePattern, java.lang.String dest)
          Copies all files in the source directory that match the file pattern to the destination directory.
 int copyIfNewer(java.lang.String[] fileList, java.lang.String dest)
          Copies a list of files to the destination directory.
 boolean copyIfNewer(java.lang.String source, java.lang.String dest)
          Performes a file copy if the source is newer then the destination
 int copyIfNewer(java.lang.String sourceDir, java.lang.String[] fileList, java.lang.String dest)
          Copies files specified in fileList parameter from the source directory to the destination directory.
 int copyIfNewer(java.lang.String sourceDir, java.lang.String filePattern, java.lang.String dest)
          Copies all files in the source directory that match the file pattern to the destination directory if they are newer.
 void createCopyRule(java.lang.String ruleName, java.lang.String[] prerequisites, java.lang.String[] sourceList, java.lang.String destDir)
          Creates a copy rule.
 void createCopyRule(java.lang.String ruleName, java.lang.String[] prerequisites, java.lang.String[] sourceList, java.lang.String destDir, java.lang.String message)
          Creates a copy rule.
 void createCopyRule(java.lang.String ruleName, java.lang.String[] prerequisites, java.lang.String sourceDir, java.lang.String filePattern, java.lang.String destDir)
          Creates a copy rule.
 void createCopyRule(java.lang.String ruleName, java.lang.String[] prerequisites, java.lang.String sourceDir, java.lang.String filePattern, java.lang.String destDir, java.lang.String message)
          Creates a copy rule.
 void createDirectoryRule(java.lang.String directory, java.lang.String[] prerequisites, boolean echo)
          Creates a rule where the target is adirectory that needs to be created.
 void createExplicitDependency(java.lang.String target, java.lang.String prerequisites)
          Creates dependecies for the given target.
 void createExplicitDependency(java.lang.String target, java.lang.String[] prerequisites)
          Creates dependecies for the given target.
 void createExplicitRule(java.lang.String target, java.lang.String[] prerequisites, java.lang.String scriptCall, boolean verify)
          Creates an explicit rule for building a target.
 void createExplicitRule(java.lang.String target, java.lang.String prerequisites, java.lang.String scriptCall, boolean verify)
          Creates an explicit rule for building a target.
 java.lang.String[] createFileList(java.lang.String rootDirectory, java.lang.String regexFilePattern)
          This calls createFileList(String, String, int) but with 0 as the flags.
 java.lang.String[] createFileList(java.lang.String rootDirectory, java.lang.String regexFilePattern, boolean recurse, boolean filePath)
          Deprecated.  
 java.lang.String[] createFileList(java.lang.String rootDirectory, java.lang.String regexFilePattern, int flags)
          Creates a list of files in rootDirectory that match the pattern denoted by regexFilePattern.
 java.lang.String[] createFileList(java.lang.String rootDirectory, java.lang.String regexFilePattern, java.lang.String[] excludeList, int flags)
          Creates a list of files that matche the given regular expression.
 java.lang.String[] createFileList(java.lang.String rootDirectory, java.lang.String regexFilePattern, java.lang.String[] excludeList, java.lang.String excludePattern, int flags)
          Creates a list of files that matche the given regular expression.
 java.lang.String[] createFileList(java.lang.String rootDirectory, java.lang.String regexFilePattern, java.lang.String excludePattern, int flags)
          Creates a list of files that matche the given regular expression.
 void createPatternDependency(java.lang.String pattern, java.lang.String replacement)
          Creates a pattern dependency.
 void createPatternDependency(java.lang.String pattern, java.lang.String[] prerequisites)
          Creates a pattern dependency Calling this is the same as calling createPatternDependency(String, String) over and over for each string in the prerequisite array.
 void createPatternRule(java.lang.String pattern, java.lang.String replacement, java.lang.String scriptCall, boolean verify)
          Creates a pattern rule for building a target.
 void createPhonyRule(java.lang.String target, java.lang.String[] prerequisites, java.lang.String scriptCall)
          Creates a phony target rule.
 void createPhonyRule(java.lang.String target, java.lang.String prerequisites, java.lang.String scriptCall)
          Creates a phony target rule.
 void createRecursiveCopyRule(java.lang.String ruleName, java.lang.String[] prerequisites, java.lang.String sourceDir, java.lang.String filePattern, java.lang.String destDir)
          Creates a copy rule.
 void createRecursiveCopyRule(java.lang.String ruleName, java.lang.String[] prerequisites, java.lang.String sourceDir, java.lang.String filePattern, java.lang.String destDir, java.lang.String message)
          Creates a copy rule.
static void debugPrint(java.lang.String msg)
           
 void del(java.lang.String file)
          Added for use in Rhino script
 void delete(java.lang.String file)
          Deletes a file
 void deltree(java.lang.String directory)
          Deletes the entire sub tree including the directory.
 void exec(java.lang.String cmd)
          Executes a command and waits until it is finnished.
 void exec(java.lang.String[] cmd)
          Executes a command and waits until it is finnished.
 void exec(java.lang.String[] cmd, boolean exitOnError)
          Executes a command and waits until it is finnished.
 void exec(java.lang.String[] cmd, boolean exitOnError, java.lang.String logFile)
          Executes a command and waits until it is finnished.
 void exec(java.lang.String[] cmd, java.lang.String logFile)
          Executes a command and waits until it is finnished.
 void exec(java.lang.String cmd, boolean exitOnError)
          Executes a command and waits until it is finnished.
 void exec(java.lang.String cmd, boolean exitOnError, java.lang.String logFile)
          Executes a command and waits until it is finnished.
 void exec(java.lang.String cmd, java.lang.String logFile)
          Executes a command and waits until it is finnished.
 void exec(java.lang.String cwd, java.lang.String[] cmd, boolean exitOnError)
          Executes a command and waits until it is finnished.
 void exec(java.lang.String cwd, java.lang.String[] cmdArr, boolean exitOnError, java.lang.String logFile, java.lang.String redirect)
          Executes a command and waits until it is finnished.
 void exec(java.lang.String cwd, java.lang.String cmd, boolean exitOnError)
          Executes a command and waits until it is finnished.
 void exec(java.lang.String cwd, java.lang.String cmd, boolean exitOnError, java.lang.String logFile, java.lang.String redirect)
          Executes a command and waits until it is finnished.
static java.lang.String fixPath(java.lang.String path)
          Fixes the directory seperators for the current platform.
static java.lang.String[] fixPath(java.lang.String[] paths)
          Fixes the directory seperators for the current platform.
 java.lang.String fullPath(java.lang.String relPath)
          Returns the absolute path from a relative path
 java.lang.String getPrimaryTarget()
          Returns the primary build target.
 java.util.Properties getProperties()
          Returns the CPMake properites object.
 java.lang.String getProperty(java.lang.String name)
          Gets a property from CPMake.
 java.lang.String getProperty(java.lang.String name, java.lang.String def)
          Gets a property from CPMake.
 int getThreadCount()
          Reutrns the number of threads to be used when processing the build queue
static GrepResult grep(java.lang.String file, java.lang.String regexPattern)
          This function will search the input file for lines that match the given regular expression.
 void include(java.lang.String fileName)
          Includes an additional script file that has a rule to generate it.
 java.io.File locateFile(java.lang.String file)
          Tries to locate a file by looking in the search paths.
static void main(java.lang.String[] args)
          Creates an instance of CPMake and process the targets on the command line.
 void mkdir(java.lang.String directory)
          Creates a directory
 void processBuildFile()
          Processes the build file and builds the primary target.
 void processMakeDependencyFile(java.lang.String file, boolean create, boolean soft)
          Reads a GNU make file and addes the dependencies to the build.
 void processMakeDependencyFiles(java.lang.String[] files, boolean create, boolean soft)
          Reads a list of GNU style dependency files and adds them to the CPMake dependency list.
 void setDefaultTarget(java.lang.String target)
          Sets the target that will be build if none is specified on the command line.
 void setObject(java.lang.String name, java.lang.Object obj)
          Sets variables in script namespace.
 void setProperty(java.lang.String name, java.lang.String value)
          Sets properties for this instance of CPMake
 void setThreadCount(int threadCount)
          Sets the number of threads to be used when processing the build queue.
 void setVerbose(boolean verbose)
          Tells CPMake to echo out build information
static java.lang.String[] substitute(java.lang.String srcPattern, java.lang.String destPattern, java.lang.String[] srcList)
          Perform pattern substitution on the srcList String array.
static void throwException(java.lang.String msg)
          Throws and exception.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RECURSE

public static final int RECURSE
Use with createFileList. Recurse into sub directories when creating file list.

See Also:
Constant Field Values

INCLUDE_PATH

public static final int INCLUDE_PATH
Use with createFileList. Includes the full path when listing files.

See Also:
Constant Field Values

RELATIVE_PATH

public static final int RELATIVE_PATH
Use with createFileList and in conjunction with INCLUDE_PATH. This makes the path relative to the first parameter of createFileList

See Also:
Constant Field Values
Constructor Detail

CPMake

public CPMake(java.lang.String buildFile,
              java.lang.String primaryTarget)
Creaes a CPMake object.

Parameters:
buildFile - Build file to process in order to build the primary target
primaryTarget - After reading the build file this target will be passed to buildTarget. If this is null the default target will be built if one is set in the build file.

CPMake

public CPMake(CPMake make,
              java.lang.String buildFile,
              java.lang.String primaryTarget)
Creates a CPMake object.

Parameters:
make - CPMake object to inherit settings from.
buildFile - Build file to process in order to build the primary target
primaryTarget - After reading the build file this target will be passed to buildTarget. If this is null the default target will be built if one is set in the build file.
Method Detail

main

public static void main(java.lang.String[] args)
Creates an instance of CPMake and process the targets on the command line. The options main takes are:
-v Verbose mode. This will echo every command passed to exec and every file copy
-f Build file. If no file is specified "build.bsh" is the default.
-t Number of threads to use. This is the number of threads to use when building a target.
After the options are the list of targets to build.

Property files. CPMake loads properties from three locations and makes them available to the script via the getProperty methods. First the system properties are read. Second a cpmake.properties file is read if it exists. Third an env.properties file is read if it exists. In order to gain access to the environment variables the last properties file is used. To use this file you will need to echo the environment to this file before calling CPMake.
An example of this would be to write a script as follows
(windows)
set > env.properties
java -jar cpmake.jar
or
(linux)
env > env.properties
java -jar cpmake.jar
Then for neetness cpmake will delete the env.properties file when it is done.

Properties that effect cpmake
(note the underscore versions are for linux envoronment variable compatibility)
cpmake.threadCount or cpmake_threadCount - Setting this property will tell cpmake the number of threads to use while building a target.


debugPrint

public static void debugPrint(java.lang.String msg)

processBuildFile

public void processBuildFile()
                      throws cpmake.CPMakeException
Processes the build file and builds the primary target.

Throws:
cpmake.CPMakeException

getPrimaryTarget

public java.lang.String getPrimaryTarget()
Returns the primary build target. This may be null if no primary target has been given and a default has not yet been set.

Returns:
Primary build target or null.

createPatternRule

public void createPatternRule(java.lang.String pattern,
                              java.lang.String replacement,
                              java.lang.String scriptCall,
                              boolean verify)
Creates a pattern rule for building a target.

Example:
createPatternRule("(.*)\.obj", "$1.cpp", "compile", true);
In this example to build any .obj file the corosponding .cpp file is the prerequisite and the script method compile is called to build this target. Also the target will be verified afterwards.

Parameters:
pattern - Regex pattern of the target
replacement - Replacement string used to identify the prerequisite of the target.
scriptCall - The name of the method in the make file to call in order to process this rule.
verify - Verify the target after the script call is made

createExplicitRule

public void createExplicitRule(java.lang.String target,
                               java.lang.String prerequisites,
                               java.lang.String scriptCall,
                               boolean verify)
                        throws cpmake.CPMakeException
Creates an explicit rule for building a target.

The target can either be a file or a directory in the file system. This rule is excercised if any of the prerequisites are new then the target.

Parameters:
target - The file or directory to create by this rule.
prerequisites - This can either be a single prerequisite or a list that is sperated by spaces. Can be null.
scriptCall - The name of the method in the make file to call in order to process this rule.
verify - Verify the target after the script call is made.
Throws:
cpmake.CPMakeException

createExplicitRule

public void createExplicitRule(java.lang.String target,
                               java.lang.String[] prerequisites,
                               java.lang.String scriptCall,
                               boolean verify)
                        throws cpmake.CPMakeException
Creates an explicit rule for building a target.

The target can either be a file or a directory in the file system. This rule is excercised if any of the prerequisites are new then the target.

Parameters:
target - The file or directory to create by this rule.
prerequisites - An array of prerequisites for this target.
scriptCall - The name of the method in the make file to call in order to process this rule.
verify - Verify the target after the script call is made.
Throws:
cpmake.CPMakeException

createDirectoryRule

public void createDirectoryRule(java.lang.String directory,
                                java.lang.String[] prerequisites,
                                boolean echo)
                         throws cpmake.CPMakeException
Creates a rule where the target is adirectory that needs to be created. Creating directories this way also helps CPMake to know what can be cleaned up when perfomring an auto clean of the project.

Parameters:
directory - Directory to create.
prerequisites - Any prerequisites to do before creating this directory.
echo - If true it prints a nice little message when it creates the directory.
Throws:
cpmake.CPMakeException
Since:
1.2

createPhonyRule

public void createPhonyRule(java.lang.String target,
                            java.lang.String prerequisites,
                            java.lang.String scriptCall)
Creates a phony target rule. If the phony rule has no prerequisites it is excersized all the time. If the prerequisites are up to date then this rule is not processed.

Parameters:
target - Phony target
prerequisites - A list of prerequisites that are sperated by spaces. Can be null.
scriptCall - The name of the method in the make file to call in order to process this rule.

createPhonyRule

public void createPhonyRule(java.lang.String target,
                            java.lang.String[] prerequisites,
                            java.lang.String scriptCall)
Creates a phony target rule. If the phony rule has no prerequisites it is excersized all the time. If the prerequisites are up to date then this rule is not processed.

Parameters:
target - Phony target
prerequisites - An array of prerequisites.
scriptCall - The name of the method in the make file to call in order to process this rule.

createCopyRule

public void createCopyRule(java.lang.String ruleName,
                           java.lang.String[] prerequisites,
                           java.lang.String sourceDir,
                           java.lang.String filePattern,
                           java.lang.String destDir)
Creates a copy rule. A copy rule only runs if the files in the source directory are newer then those in the destination directory.

Parameters:
ruleName - CopyRule rule name.
prerequisites - An array of targets that need to be taken care of before running this rule.
sourceDir - Source directory of the copy.
filePattern - Regular expression for matching files to copy.
destDir - Destination directory of the copy.
Since:
1.2

createCopyRule

public void createCopyRule(java.lang.String ruleName,
                           java.lang.String[] prerequisites,
                           java.lang.String sourceDir,
                           java.lang.String filePattern,
                           java.lang.String destDir,
                           java.lang.String message)
Creates a copy rule. A copy rule only runs if the files in the source directory are newer then those in the destination directory.

Parameters:
ruleName - CopyRule rule name.
prerequisites - An array of targets that need to be taken care of before running this rule.
sourceDir - Source directory of the copy.
filePattern - Regular expression for matching files to copy.
destDir - Destination directory of the copy.
message - Message to print while copying
Since:
1.3.1

createRecursiveCopyRule

public void createRecursiveCopyRule(java.lang.String ruleName,
                                    java.lang.String[] prerequisites,
                                    java.lang.String sourceDir,
                                    java.lang.String filePattern,
                                    java.lang.String destDir)
Creates a copy rule. A copy rule only runs if the files in the source directory are newer then those in the destination directory. This will recurse when copying files.

Parameters:
ruleName - CopyRule rule name.
prerequisites - An array of targets that need to be taken care of before running this rule.
sourceDir - Source directory of the copy.
filePattern - Regular expression for matching files to copy.
destDir - Destination directory of the copy.
Since:
1.2

createRecursiveCopyRule

public void createRecursiveCopyRule(java.lang.String ruleName,
                                    java.lang.String[] prerequisites,
                                    java.lang.String sourceDir,
                                    java.lang.String filePattern,
                                    java.lang.String destDir,
                                    java.lang.String message)
Creates a copy rule. A copy rule only runs if the files in the source directory are newer then those in the destination directory. This will recurse when copying files.

Parameters:
ruleName - CopyRule rule name.
prerequisites - An array of targets that need to be taken care of before running this rule.
sourceDir - Source directory of the copy.
filePattern - Regular expression for matching files to copy.
destDir - Destination directory of the copy.
message - Message to print while copying
Since:
1.3.1

createCopyRule

public void createCopyRule(java.lang.String ruleName,
                           java.lang.String[] prerequisites,
                           java.lang.String[] sourceList,
                           java.lang.String destDir)
Creates a copy rule. A copy rule only runs if the files in the source directory are newer then those in the destination directory.

Parameters:
ruleName - CopyRule rule name.
prerequisites - An array of targets that need to be taken care of before running this rule.
sourceList - Source file list.
destDir - Destination directory of the copy.
Since:
1.2

createCopyRule

public void createCopyRule(java.lang.String ruleName,
                           java.lang.String[] prerequisites,
                           java.lang.String[] sourceList,
                           java.lang.String destDir,
                           java.lang.String message)
Creates a copy rule. A copy rule only runs if the files in the source directory are newer then those in the destination directory.

Parameters:
ruleName - CopyRule rule name.
prerequisites - An array of targets that need to be taken care of before running this rule.
sourceList - Source file list.
destDir - Destination directory of the copy.
message - Message to print while copying
Since:
1.3.1

createPatternDependency

public void createPatternDependency(java.lang.String pattern,
                                    java.lang.String replacement)
Creates a pattern dependency. Example
createPatternDependency("(.*)\\.obj", "$1.h");
This states that all obj files are dependent on a corrosponding h file. I the h file is newer then the obj file a rule will be located to rebuild the obj file. These prerequisites are not passed to the script file.

Parameters:
pattern - Pattern of the target files to add dependencies to.
replacement - The dependency of the target. This can either be a replacement pattern as the one in the example above or the name of a target.

createPatternDependency

public void createPatternDependency(java.lang.String pattern,
                                    java.lang.String[] prerequisites)
Creates a pattern dependency Calling this is the same as calling createPatternDependency(String, String) over and over for each string in the prerequisite array.

Parameters:
pattern - Pattern of the target files to add depenencies to.
prerequisites - List of dependencies to add to this pattern.

createExplicitDependency

public void createExplicitDependency(java.lang.String target,
                                     java.lang.String prerequisites)
Creates dependecies for the given target. These prerequisites are not passed to the script file.

Parameters:
target - Target to add dependencies to.
prerequisites - A list of prerequisites seperated by spaces. Can be null.

createExplicitDependency

public void createExplicitDependency(java.lang.String target,
                                     java.lang.String[] prerequisites)
Creates dependecies for the given target. These prerequisites are not passed to the script file.

Parameters:
target - Target to add dependencies to.
prerequisites - An array of prerequisites.

buildTarget

public void buildTarget(java.lang.String target)
                 throws cpmake.CPMakeException
Processes the rule for the given target. Before the build queue is generated for the specified target an attempt is made to call a script function that matches the following signiture
void prepForTarget(String target);

This allows the script to set up any special varaibles for the target.

Parameters:
target - Target to be built.
Throws:
cpmake.CPMakeException

buildTarget

public void buildTarget(java.lang.String target,
                        boolean prep)
                 throws cpmake.CPMakeException
Processes the rule for the given target. Before the build queue is generated for the specified target an attempt is made to call a script function that matches the following signiture
void prepForTarget(String target);

This allows the script to set up any special varaibles for the target.

Parameters:
target - Target to be built.
prep - If true prepForTarget is called otherwise it is not
Throws:
cpmake.CPMakeException

arrayToString

public static java.lang.String arrayToString(java.lang.String[] array)
Converts an array into a string seperated by spaces. There is also a space left on the end of the string.

{"foo", "bar"} would become "foo bar "

Parameters:
array - Array to be turned into a string.

addSearchPath

public void addSearchPath(java.lang.String path)
Adds a path to search when looking for targets.

Parameters:
path - Path to search for targets and prerequisites.

setVerbose

public void setVerbose(boolean verbose)
Tells CPMake to echo out build information

Parameters:
verbose - Whether to be verbose or not.

addSearchPath

public void addSearchPath(java.lang.String pattern,
                          java.lang.String path)
Adds a path to search when looking for targets that match the given pattern.

Parameters:
pattern - File pattern (regex) for this search path.
path - Path to search

addSearchPaths

public void addSearchPaths(java.lang.String[] paths)
Adds search paths to look in when trying to find files.

Parameters:
paths - Array of file paths to search

addSearchPaths

public void addSearchPaths(java.lang.String pattern,
                           java.lang.String[] paths)
Adss paths to search when looking for targets that match the given pattern

Parameters:
pattern - File pattern (regex) for this search path.
paths - Paths to search

locateFile

public java.io.File locateFile(java.lang.String file)
Tries to locate a file by looking in the search paths.

Parameters:
file - The file name to look for.
Returns:
The file object or null if none is found.

fixPath

public static java.lang.String fixPath(java.lang.String path)
Fixes the directory seperators for the current platform. It is encuraged to use only forward slashes in make files and then call this function when the path will be handed to a platform specific call.

Parameters:
path - Path to be checked for correct seperators
Returns:
The path with the directory sperators appropriat for the platform.

fixPath

public static java.lang.String[] fixPath(java.lang.String[] paths)
Fixes the directory seperators for the current platform. It is encuraged to use only forward slashes in make files and then call this function when the path will be handed to a platform specific call.

Parameters:
paths - Array of paths to be checked for correct seperators
Returns:
The path with the directory sperators appropriat for the platform.

setDefaultTarget

public void setDefaultTarget(java.lang.String target)
Sets the target that will be build if none is specified on the command line.

Parameters:
target - Target to be built.

getThreadCount

public int getThreadCount()
Reutrns the number of threads to be used when processing the build queue

Returns:
thread count

setThreadCount

public void setThreadCount(int threadCount)
Sets the number of threads to be used when processing the build queue.

Parameters:
threadCount - Number of threads to use.

setProperty

public void setProperty(java.lang.String name,
                        java.lang.String value)
Sets properties for this instance of CPMake

Parameters:
name - Property name.
value - Value of the property.

getProperty

public java.lang.String getProperty(java.lang.String name,
                                    java.lang.String def)
Gets a property from CPMake. These propeties are a combination of the System properties, cpmake.properties and any properties files that are specified on the command line.

Parameters:
name - Name of the property to get.
def - Default value to return if no property is found.
Returns:
property value of the property or the default if none is found.

getProperty

public java.lang.String getProperty(java.lang.String name)
Gets a property from CPMake. These propeties are a combination of the System properties, cpmake.properties and any properties files that are specified on the command line.

Parameters:
name - Name of the property to get.
Returns:
property value of the property.

getProperties

public java.util.Properties getProperties()
Returns the CPMake properites object.


exec

public void exec(java.lang.String cmd,
                 java.lang.String logFile)
          throws cpmake.CPMakeException
Executes a command and waits until it is finnished. Executes a command and then pipes the stdin and stdout of the process to System.in and System.out.

Parameters:
cmd - command line of the process to start.
logFile - Output is sent to this log file as well
Throws:
cpmake.CPMakeException

exec

public void exec(java.lang.String[] cmd,
                 java.lang.String logFile)
          throws cpmake.CPMakeException
Executes a command and waits until it is finnished. Executes a command and then pipes the stdin and stdout of the process to System.in and System.out.

Parameters:
cmd - command line of the process to start.
logFile - Output is sent to this log file as well
Throws:
cpmake.CPMakeException
Since:
1.3.1

exec

public void exec(java.lang.String cmd)
          throws cpmake.CPMakeException
Executes a command and waits until it is finnished. Executes a command and then pipes the stdin and stdout of the process to System.in and System.out.

Parameters:
cmd - command line of the process to start.
Throws:
cpmake.CPMakeException

exec

public void exec(java.lang.String[] cmd)
          throws cpmake.CPMakeException
Executes a command and waits until it is finnished. Executes a command and then pipes the stdin and stdout of the process to System.in and System.out.

Parameters:
cmd - command line of the process to start.
Throws:
cpmake.CPMakeException
Since:
1.3.1

exec

public void exec(java.lang.String cmd,
                 boolean exitOnError,
                 java.lang.String logFile)
          throws cpmake.CPMakeException
Executes a command and waits until it is finnished. Executes a command and then pipes the stdin and stdout of the process to System.in and System.out.

Parameters:
cmd - command line of the process to start.
exitOnError - If the process reutrns an error the make will stop.
logFile - Output is sent to this log file as well
Throws:
cpmake.CPMakeException

exec

public void exec(java.lang.String[] cmd,
                 boolean exitOnError,
                 java.lang.String logFile)
          throws cpmake.CPMakeException
Executes a command and waits until it is finnished. Executes a command and then pipes the stdin and stdout of the process to System.in and System.out.

Parameters:
cmd - command line of the process to start.
exitOnError - If the process reutrns an error the make will stop.
logFile - Output is sent to this log file as well
Throws:
cpmake.CPMakeException
Since:
1.3.1

exec

public void exec(java.lang.String cmd,
                 boolean exitOnError)
          throws cpmake.CPMakeException
Executes a command and waits until it is finnished. Executes a command and then pipes the stdin and stdout of the process to System.in and System.out.

Parameters:
cmd - command line of the process to start.
exitOnError - If the process reutrns an error the make will stop.
Throws:
cpmake.CPMakeException

exec

public void exec(java.lang.String[] cmd,
                 boolean exitOnError)
          throws cpmake.CPMakeException
Executes a command and waits until it is finnished. Executes a command and then pipes the stdin and stdout of the process to System.in and System.out.

Parameters:
cmd - command line of the process to start.
exitOnError - If the process reutrns an error the make will stop.
Throws:
cpmake.CPMakeException
Since:
1.3.1

exec

public void exec(java.lang.String cwd,
                 java.lang.String cmd,
                 boolean exitOnError)
          throws cpmake.CPMakeException
Executes a command and waits until it is finnished. Executes a command and then pipes the stdin and stdout of the process to System.in and System.out. Passing in a current working directory requires the path in cmd to be the absolute path. You can use the fullPath method to aid in retrieving the absolute path.

Parameters:
cwd - Sets the current working directory of the process.
cmd - command line of the process to start.
exitOnError - If the process reutrns an error the make will stop.
Throws:
cpmake.CPMakeException

exec

public void exec(java.lang.String cwd,
                 java.lang.String[] cmd,
                 boolean exitOnError)
          throws cpmake.CPMakeException
Executes a command and waits until it is finnished. Executes a command and then pipes the stdin and stdout of the process to System.in and System.out. Passing in a current working directory requires the path in cmd to be the absolute path. You can use the fullPath method to aid in retrieving the absolute path.

Parameters:
cwd - Sets the current working directory of the process.
cmd - command line of the process to start.
exitOnError - If the process reutrns an error the make will stop.
Throws:
cpmake.CPMakeException
Since:
1.3.1

exec

public void exec(java.lang.String cwd,
                 java.lang.String cmd,
                 boolean exitOnError,
                 java.lang.String logFile,
                 java.lang.String redirect)
          throws cpmake.CPMakeException
Executes a command and waits until it is finnished. Executes a command and then pipes the stdin and stdout of the process to System.in and System.out. Passing in a current working directory requires the path in cmd to be the absolute path. You can use the fullPath method to aid in retrieving the absolute path.

Parameters:
cwd - Sets the current working directory of the process. My be null.
cmd - command line of the process to start.
exitOnError - If the process reutrns an error the make will stop.
logFile - Output is sent to this log file as well. May be null.
redirect - File to redirect output to. May be null.
Throws:
cpmake.CPMakeException

exec

public void exec(java.lang.String cwd,
                 java.lang.String[] cmdArr,
                 boolean exitOnError,
                 java.lang.String logFile,
                 java.lang.String redirect)
          throws cpmake.CPMakeException
Executes a command and waits until it is finnished. Executes a command and then pipes the stdin and stdout of the process to System.in and System.out. Passing in a current working directory requires the path in cmd to be the absolute path. You can use the fullPath method to aid in retrieving the absolute path.

Parameters:
cwd - Sets the current working directory of the process. My be null.
cmdArr - command line of the process to start.
exitOnError - If the process reutrns an error the make will stop.
logFile - Output is sent to this log file as well. May be null.
redirect - File to redirect output to. May be null.
Throws:
cpmake.CPMakeException
Since:
1.3.1

createFileList

public java.lang.String[] createFileList(java.lang.String rootDirectory,
                                         java.lang.String regexFilePattern)
This calls createFileList(String, String, int) but with 0 as the flags.


createFileList

public java.lang.String[] createFileList(java.lang.String rootDirectory,
                                         java.lang.String regexFilePattern,
                                         boolean recurse,
                                         boolean filePath)
Deprecated.  


createFileList

public java.lang.String[] createFileList(java.lang.String rootDirectory,
                                         java.lang.String regexFilePattern,
                                         java.lang.String[] excludeList,
                                         java.lang.String excludePattern,
                                         int flags)
Creates a list of files that matche the given regular expression.

Parameters:
rootDirectory - Starting directory to begin search for files.
regexFilePattern - Regular expression pattern used to match files returned from this call.
excludeList - List of files to exclude from the list. This list must match the file name exactly in order for it to be excluded. If the flags specify to include the path then this list must have the path as well.
excludePattern - Regular expression of files to exclude from the list.
flags - Flags can be any combination of RECURSE, INCLUDE_PATH or RELATIVE_PATH.
Since:
1.2

createFileList

public java.lang.String[] createFileList(java.lang.String rootDirectory,
                                         java.lang.String regexFilePattern,
                                         java.lang.String[] excludeList,
                                         int flags)
Creates a list of files that matche the given regular expression.

Parameters:
rootDirectory - Starting directory to begin search for files.
regexFilePattern - Regular expression pattern used to match files returned from this call.
excludeList - List of files to exclude from the list. This list must match the file name exactly in order for it to be excluded. If the flags specify to include the path then this list must have the path as well.
flags - Flags can be any combination of RECURSE, INCLUDE_PATH or RELATIVE_PATH.
Since:
1.2

createFileList

public java.lang.String[] createFileList(java.lang.String rootDirectory,
                                         java.lang.String regexFilePattern,
                                         java.lang.String excludePattern,
                                         int flags)
Creates a list of files that matche the given regular expression.

Parameters:
rootDirectory - Starting directory to begin search for files.
regexFilePattern - Regular expression pattern used to match files returned from this call.
excludePattern - Regular expression of files to exclude from the list.
flags - Flags can be any combination of RECURSE, INCLUDE_PATH or RELATIVE_PATH.
Since:
1.2

createFileList

public java.lang.String[] createFileList(java.lang.String rootDirectory,
                                         java.lang.String regexFilePattern,
                                         int flags)
Creates a list of files in rootDirectory that match the pattern denoted by regexFilePattern.

Parameters:
rootDirectory - Starting directory to begin search for files.
regexFilePattern - Regular expression pattern used to match files returned from this call.
flags - Flags can be any combination of RECURSE, INCLUDE_PATH or RELATIVE_PATH.
Since:
1.1

deltree

public void deltree(java.lang.String directory)
Deletes the entire sub tree including the directory.

Parameters:
directory - Directory you wish to delete.
Since:
1.0

delete

public void delete(java.lang.String file)
Deletes a file

Parameters:
file - File to delete.
Since:
1.0

del

public void del(java.lang.String file)
Added for use in Rhino script

Parameters:
file - File to delete.
Since:
1.2

copyIfNewer

public int copyIfNewer(java.lang.String sourceDir,
                       java.lang.String filePattern,
                       java.lang.String dest)
Copies all files in the source directory that match the file pattern to the destination directory if they are newer.

Parameters:
sourceDir - Source directory.
filePattern - Regex file pattern.
dest - Destination directory to copy files to.
Since:
1.1

copyIfNewer

public boolean copyIfNewer(java.lang.String source,
                           java.lang.String dest)
Performes a file copy if the source is newer then the destination

Parameters:
source - Source file to copy
dest - Destination directory or file to copy to
Returns:
Returns true if the file was copied.
Since:
1.1

copyIfNewer

public int copyIfNewer(java.lang.String sourceDir,
                       java.lang.String[] fileList,
                       java.lang.String dest)
Copies files specified in fileList parameter from the source directory to the destination directory. Files will retain relative paths when copied. This means that if the source directory were "src" and the destination were "build" and the file list contained {"cpmake/file1", "cpmake/file2"} the files src/cpmake/file1 and
src/cpmake/file2
will be copied to
build/cpmake/file1 and
build/cpmake/file2
And the files will only be copied if they are newer then the destination. Also the directories will be created automatically. It is good to use this with the output from createFileList to copy files.

Parameters:
sourceDir - Source directory
fileList - List of files to copy.
dest - Destination directory.
Since:
1.2

copyIfNewer

public int copyIfNewer(java.lang.String[] fileList,
                       java.lang.String dest)
Copies a list of files to the destination directory. File lists can be created using createFileList and then passed to this method. All of the files in the list will end up in the destination directory.

Parameters:
fileList - List of files to copy
dest - Destination directory to copy files to.
Since:
1.2

copy

public void copy(java.lang.String sourceDir,
                 java.lang.String filePattern,
                 java.lang.String dest)
Copies all files in the source directory that match the file pattern to the destination directory.

Parameters:
sourceDir - Source directory.
filePattern - Regex file pattern.
dest - Destination directory to copy files to.

copy

public void copy(java.lang.String source,
                 java.lang.String dest)
Performs a file copy. The file denoted by source is copied to dest. dest can either be a file name or a directory. The directory structure in the destination will be created automatically. This will not work if the destination is the directory to copy to and it does not exist.


processMakeDependencyFiles

public void processMakeDependencyFiles(java.lang.String[] files,
                                       boolean create,
                                       boolean soft)
                                throws cpmake.CPMakeException
Reads a list of GNU style dependency files and adds them to the CPMake dependency list. If a file does not exist and create is set to true CPMake will try and find a rule to build the file.

Parameters:
files - List of GNU style dependency files.
create - Attempst to create the file if it does not exist
soft - Tells CPMake that the dependencies in this file are to be treated as soft meaning if the file does not exist do not try to build it.
Throws:
cpmake.CPMakeException

processMakeDependencyFile

public void processMakeDependencyFile(java.lang.String file,
                                      boolean create,
                                      boolean soft)
                               throws cpmake.CPMakeException
Reads a GNU make file and addes the dependencies to the build. If the file does not exist and create is set to true CPMake will try and find a rule to build this file.

Parameters:
file - GNU make dependency file to include
create - Attempt to create the file if it does not exist
soft - Tells CPMake that the dependencies in this file are to be treated as soft meaning if the file does not exist do not try to build it.
Throws:
cpmake.CPMakeException

clearMakeRules

public void clearMakeRules()
Clears all rules and dependencies.


include

public void include(java.lang.String fileName)
             throws cpmake.CPMakeException
Includes an additional script file that has a rule to generate it. CPMake will call build target on the include file before processing it.

Parameters:
fileName - Name of the script file to include.
Throws:
cpmake.CPMakeException

substitute

public static java.lang.String[] substitute(java.lang.String srcPattern,
                                            java.lang.String destPattern,
                                            java.lang.String[] srcList)
Perform pattern substitution on the srcList String array. This method goes through each String in srcList and calls replaceAll on the string using srcPattern and destPattern as arguments.

Parameters:
srcPattern - Regular expression search pattern.
destPattern - Replacement pattern.
srcList - Array of strings to perform pattern substitution on.
Returns:
New string array containing the substituted strings

mkdir

public void mkdir(java.lang.String directory)
Creates a directory

Parameters:
directory - Directory to create

fullPath

public java.lang.String fullPath(java.lang.String relPath)
Returns the absolute path from a relative path

Parameters:
relPath - Relative Path
Returns:
absolute path.

throwException

public static void throwException(java.lang.String msg)
                           throws cpmake.CPMakeException
Throws and exception. This is for testing purposes only

Throws:
cpmake.CPMakeException
Since:
1.2

autoClean

public void autoClean()
               throws cpmake.CPMakeException
Automatically cleans the build area by removing targets that are specified in the build file. This can either be called directly or if the build file does not have a target for 'clean' and clean is specified CPMake will call this method.

Throws:
cpmake.CPMakeException
Since:
1.2

combine

public static java.lang.String[] combine(java.lang.String[] arr1,
                                         java.lang.String[] arr2)
Combines two String arrays into one.

Since:
1.2

setObject

public void setObject(java.lang.String name,
                      java.lang.Object obj)
Sets variables in script namespace. This can be used, when calling CPMake recursivly, to pass variables from one instance to the other.

Since:
1.2

addClassPath

public void addClassPath(java.lang.String path)
                  throws cpmake.CPMakeException
Throws:
cpmake.CPMakeException

grep

public static GrepResult grep(java.lang.String file,
                              java.lang.String regexPattern)
                       throws cpmake.CPMakeException
This function will search the input file for lines that match the given regular expression.

Parameters:
file - File to be searched.
regexPattern - Regular expression to be searched for.
Returns:
A GrepResult object containing the lines that match the grep pattern.
Throws:
cpmake.CPMakeException
Since:
1.3.1