Package com.igormaznitsa.jcp.ant
Class PreprocessTask
- java.lang.Object
-
- org.apache.tools.ant.ProjectComponent
-
- org.apache.tools.ant.Task
-
- com.igormaznitsa.jcp.ant.PreprocessTask
-
- All Implemented Interfaces:
SpecialVariableProcessor
,PreprocessorLogger
,java.lang.Cloneable
public class PreprocessTask extends org.apache.tools.ant.Task implements PreprocessorLogger, SpecialVariableProcessor
The class implements an ANT task to allow calls for preprocessing from ANT build scripts. Also it allows to out messages from preprocessor directives into the ANT log and read ANT properties as global variables (with the "ant." prefix)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PreprocessTask.CfgFile
Inside class describes a "cfgfile" item, it has the only attribute "file", the attribute must be definedstatic class
PreprocessTask.Global
Inside class describes a "global" item, it describes a global variable which will be added into the preprocessor context It has attributes "name" and "value", be careful in the value attribute usage because you have to use """ instead of \" symbol inside string values
-
Field Summary
Fields Modifier and Type Field Description private boolean
allowWhitespace
private java.util.Map<java.lang.String,Value>
antVariables
private boolean
careForLastNextLine
private boolean
clearDstFlag
private boolean
compareDestination
private java.util.List<PreprocessTask.CfgFile>
configFiles
private boolean
copyFileAttributes
private java.io.File
destinationDirectory
private boolean
disableOut
private java.lang.String
excludedExtensions
private java.lang.String
excludedFolders
private java.util.List<PreprocessTask.Global>
globalVariables
private java.lang.String
inCharSet
private boolean
keepLines
private java.lang.String
outCharSet
private boolean
preserveIndent
private java.lang.String
processing
private boolean
removeComments
private java.io.File
sourceDirectory
private boolean
unknownVarAsFalse
private boolean
verbose
-
Constructor Summary
Constructors Constructor Description PreprocessTask()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PreprocessTask.CfgFile
createCfgFile()
PreprocessTask.Global
createGlobal()
void
debug(java.lang.String message)
Log a debug messagevoid
error(java.lang.String message)
Log an error messagevoid
execute()
private void
fillAntVariables()
private void
fillCfgFiles(PreprocessorContext context)
private void
fillGlobalVars(PreprocessorContext context)
(package private) PreprocessorContext
generatePreprocessorContext()
Value
getVariable(java.lang.String varName, PreprocessorContext context)
Get the value for the variablejava.lang.String[]
getVariableNames()
Get all variable names allowed by the processor as an array, all names must be in lower casevoid
info(java.lang.String message)
Log an information messagevoid
setAllowWhitespace(boolean flag)
Set the "allowWhitespace", it allows to manage the mode to allow whitespace between the // and the #.void
setCareForLastNextLine(boolean flag)
Set the "careforlastnextline" attribute, it allows to make precise processing of last next line charvoid
setClear(boolean flag)
Set the "clear" attribute, it is a boolean attribute allows to make the preprocessor to clear the destination directory before its workvoid
setCompareDestiation(boolean flag)
Set the "compareDestination" attribute, it allows to turn on the mode to compare destination file content and to not override the file by generated one if there is the same content.void
setCopyFileAttributes(boolean flag)
Set the "copyfileattributes", it turns on mode to copy file attributes if file generated or copied.void
setDestination(java.io.File dst)
Set the "destination" attribute, it allows to define the destination directory where the preprocessed files will be placed invoid
setDisableOut(boolean flag)
Set the "disableOut" attribute, it is a boolean attribute allows to disable any output operations into the destination directoryvoid
setExcluded(java.lang.String ext)
Set the "excluded" attribute, it defines the excluded file extensions which will be ignored by the preprocessor in its work (also those files will not be copied)void
setExcludedFolders(java.lang.String value)
Set the "excludedfolders" attribute, sub-folders in source folders to be excluded from preprocessing, ANT patterns allowed, ${path.separator} should be used for multiple itemsvoid
setInCharset(java.lang.String charSet)
Set the "inCharset" attribute, it allows to define the text encoding for the reading text filesvoid
setKeepLines(boolean flag)
Set the "keepLines" attribute, it is a boolean attribute to keep non-executing lines as commented ones in the outputvoid
setOutCharset(java.lang.String charSet)
Set the "outCharset" attribute, it allows to define the text encoding for the writing text filesvoid
setPreserveIndent(boolean flag)
Set the "preserveident" attribute, to preserve spaces occupied by '//$' and '//$$' directives.void
setProcessing(java.lang.String ext)
Set the "processing" attribute, it defines the file extensions to be processedvoid
setRemoveComments(boolean flag)
Set the "removeComments" attribute, it is a boolean attribute allows to make the preprocessor to remove all Java-like comments from the result filesvoid
setSource(java.io.File src)
Set the "source" attribute, it allows to define the source directory to be preprocessedvoid
setUnknownVarAsFalse(boolean flag)
Set the "unknownVarAsFalse" attribute, it allows to interpret unknown variables as FALSE.void
setVariable(java.lang.String varName, Value value, PreprocessorContext context)
Set a value to the variablevoid
setVerbose(boolean flag)
Set the "verbose" attribute, it is a boolean attribute allows to set the verbose level of preprocessor messagesvoid
warning(java.lang.String message)
Log a warning message-
Methods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
-
-
-
-
Field Detail
-
sourceDirectory
private java.io.File sourceDirectory
-
destinationDirectory
private java.io.File destinationDirectory
-
inCharSet
private java.lang.String inCharSet
-
outCharSet
private java.lang.String outCharSet
-
excludedExtensions
private java.lang.String excludedExtensions
-
processing
private java.lang.String processing
-
excludedFolders
private java.lang.String excludedFolders
-
disableOut
private boolean disableOut
-
verbose
private boolean verbose
-
clearDstFlag
private boolean clearDstFlag
-
removeComments
private boolean removeComments
-
keepLines
private boolean keepLines
-
careForLastNextLine
private boolean careForLastNextLine
-
compareDestination
private boolean compareDestination
-
allowWhitespace
private boolean allowWhitespace
-
preserveIndent
private boolean preserveIndent
-
copyFileAttributes
private boolean copyFileAttributes
-
unknownVarAsFalse
private boolean unknownVarAsFalse
-
antVariables
private java.util.Map<java.lang.String,Value> antVariables
-
globalVariables
private final java.util.List<PreprocessTask.Global> globalVariables
-
configFiles
private final java.util.List<PreprocessTask.CfgFile> configFiles
-
-
Method Detail
-
setCopyFileAttributes
public void setCopyFileAttributes(boolean flag)
Set the "copyfileattributes", it turns on mode to copy file attributes if file generated or copied.- Parameters:
flag
- true if to copy attributes, false otherwise
-
setAllowWhitespace
public void setAllowWhitespace(boolean flag)
Set the "allowWhitespace", it allows to manage the mode to allow whitespace between the // and the #.- Parameters:
flag
- true if whitespace is allowed, false otherwise
-
setPreserveIndent
public void setPreserveIndent(boolean flag)
Set the "preserveident" attribute, to preserve spaces occupied by '//$' and '//$$' directives.- Parameters:
flag
- true to preserve positions of tail chars in lines marked by '//$$' and '//$', false otherwise
-
setCompareDestiation
public void setCompareDestiation(boolean flag)
Set the "compareDestination" attribute, it allows to turn on the mode to compare destination file content and to not override the file by generated one if there is the same content.- Parameters:
flag
- true if to compare destination file content, false otherwise
-
setSource
public void setSource(java.io.File src)
Set the "source" attribute, it allows to define the source directory to be preprocessed- Parameters:
src
- a directory to be used as the source one, must not be null
-
setCareForLastNextLine
public void setCareForLastNextLine(boolean flag)
Set the "careforlastnextline" attribute, it allows to make precise processing of last next line char- Parameters:
flag
- shows to turn on or turn off the mode
-
setDestination
public void setDestination(java.io.File dst)
Set the "destination" attribute, it allows to define the destination directory where the preprocessed files will be placed in- Parameters:
dst
- a directory to be used as the destination one, must not be null
-
setInCharset
public void setInCharset(java.lang.String charSet)
Set the "inCharset" attribute, it allows to define the text encoding for the reading text files- Parameters:
charSet
- the character set to be used to decode read texts, must not be null
-
setOutCharset
public void setOutCharset(java.lang.String charSet)
Set the "outCharset" attribute, it allows to define the text encoding for the writing text files- Parameters:
charSet
- the character set to be used to encode written texts, must not be null
-
setUnknownVarAsFalse
public void setUnknownVarAsFalse(boolean flag)
Set the "unknownVarAsFalse" attribute, it allows to interpret unknown variables as FALSE.- Parameters:
flag
- true to turn on the mode, false otherwise.
-
setExcluded
public void setExcluded(java.lang.String ext)
Set the "excluded" attribute, it defines the excluded file extensions which will be ignored by the preprocessor in its work (also those files will not be copied)- Parameters:
ext
- the list of ignored file extensions, must not be null
-
setProcessing
public void setProcessing(java.lang.String ext)
Set the "processing" attribute, it defines the file extensions to be processed- Parameters:
ext
- the list of file extensions which should be preprocessed, must not be null
-
setExcludedFolders
public void setExcludedFolders(java.lang.String value)
Set the "excludedfolders" attribute, sub-folders in source folders to be excluded from preprocessing, ANT patterns allowed, ${path.separator} should be used for multiple items- Parameters:
value
- folder names as string
-
setClear
public void setClear(boolean flag)
Set the "clear" attribute, it is a boolean attribute allows to make the preprocessor to clear the destination directory before its work- Parameters:
flag
- true if the destination directory must be cleared before preprocessing, otherwise false
-
setRemoveComments
public void setRemoveComments(boolean flag)
Set the "removeComments" attribute, it is a boolean attribute allows to make the preprocessor to remove all Java-like comments from the result files- Parameters:
flag
- true if the result file must be cleared from comments, otherwise false
-
setVerbose
public void setVerbose(boolean flag)
Set the "verbose" attribute, it is a boolean attribute allows to set the verbose level of preprocessor messages- Parameters:
flag
- true if the verbose level must be set, otherwise false
-
setKeepLines
public void setKeepLines(boolean flag)
Set the "keepLines" attribute, it is a boolean attribute to keep non-executing lines as commented ones in the output- Parameters:
flag
- true if preprocessor should keep the lines as commented ones, false otherwise
-
setDisableOut
public void setDisableOut(boolean flag)
Set the "disableOut" attribute, it is a boolean attribute allows to disable any output operations into the destination directory- Parameters:
flag
- true if the output operations must be disabled, otherwise false
-
createGlobal
@ImplementationNote("Do not change because for ANT!") public PreprocessTask.Global createGlobal()
-
createCfgFile
@ImplementationNote("Do not change because for ANT!") public PreprocessTask.CfgFile createCfgFile()
-
fillCfgFiles
private void fillCfgFiles(PreprocessorContext context)
-
fillGlobalVars
private void fillGlobalVars(PreprocessorContext context)
-
generatePreprocessorContext
PreprocessorContext generatePreprocessorContext()
-
execute
public void execute() throws org.apache.tools.ant.BuildException
- Overrides:
execute
in classorg.apache.tools.ant.Task
- Throws:
org.apache.tools.ant.BuildException
-
error
public void error(java.lang.String message)
Description copied from interface:PreprocessorLogger
Log an error message- Specified by:
error
in interfacePreprocessorLogger
- Parameters:
message
- the text to be output into the error log
-
info
public void info(java.lang.String message)
Description copied from interface:PreprocessorLogger
Log an information message- Specified by:
info
in interfacePreprocessorLogger
- Parameters:
message
- the text to be output into the information log
-
debug
public void debug(java.lang.String message)
Description copied from interface:PreprocessorLogger
Log a debug message- Specified by:
debug
in interfacePreprocessorLogger
- Parameters:
message
- the text to be output into the information log
-
warning
public void warning(java.lang.String message)
Description copied from interface:PreprocessorLogger
Log a warning message- Specified by:
warning
in interfacePreprocessorLogger
- Parameters:
message
- the text to be output into the warning log
-
fillAntVariables
private void fillAntVariables()
-
getVariableNames
@MustNotContainNull public java.lang.String[] getVariableNames()
Description copied from interface:SpecialVariableProcessor
Get all variable names allowed by the processor as an array, all names must be in lower case- Specified by:
getVariableNames
in interfaceSpecialVariableProcessor
- Returns:
- allowed variable names as a String array
-
getVariable
public Value getVariable(java.lang.String varName, PreprocessorContext context)
Description copied from interface:SpecialVariableProcessor
Get the value for the variable- Specified by:
getVariable
in interfaceSpecialVariableProcessor
- Parameters:
varName
- the variable name, must not be nullcontext
- the preprocessor context, it can be null- Returns:
- the value, it must not return null because it will notified preprocessor that it supports the variable
-
setVariable
public void setVariable(java.lang.String varName, Value value, PreprocessorContext context)
Description copied from interface:SpecialVariableProcessor
Set a value to the variable- Specified by:
setVariable
in interfaceSpecialVariableProcessor
- Parameters:
varName
- the variable name, must not be nullvalue
- the value to be set to the variable, must not be nullcontext
- the preprocessor context, it can be null
-
-