public final class PreprocessorContext
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private boolean |
allowWhitespace |
private boolean |
careForLastNextLine |
private boolean |
clearDestinationDirectoryBefore |
private boolean |
cloned |
private boolean |
compareDestination |
private java.util.List<java.io.File> |
configFiles |
private boolean |
copyFileAttributes |
private TextFileDataContainer |
currentInCloneSource |
private PreprocessingState |
currentState |
static java.lang.String |
DEFAULT_CHARSET |
static java.lang.String |
DEFAULT_DEST_DIRECTORY |
static java.lang.String |
DEFAULT_EXCLUDED_EXTENSIONS |
static java.lang.String |
DEFAULT_PROCESSING_EXTENSIONS |
static java.lang.String |
DEFAULT_SOURCE_DIRECTORY |
private java.lang.String |
destinationDirectory |
private java.io.File |
destinationDirectoryFile |
private java.util.Set<java.lang.String> |
excludedFileExtensions |
private java.lang.String[] |
excludedFolderPatterns |
private boolean |
fileOutputDisabled |
private java.util.Map<java.lang.String,Value> |
globalVarTable |
private java.lang.String |
inCharacterEncoding |
private boolean |
keepNonExecutingLines |
private java.util.Map<java.lang.String,Value> |
localVarTable |
private java.util.Map<java.lang.String,SpecialVariableProcessor> |
mapVariableNameToSpecialVarProcessor |
private java.lang.String |
outCharacterEncoding |
private PreprocessorExtension |
preprocessorExtension |
private PreprocessorLogger |
preprocessorLogger |
private boolean |
preserveIndent |
private java.util.Set<java.lang.String> |
processingFileExtensions |
private boolean |
removeComments |
private java.util.Map<java.lang.String,java.lang.Object> |
sharedResources |
private java.lang.String |
sourceDirectories |
private java.io.File[] |
sourceDirectoryFiles |
private boolean |
unknownVariableAsFalse |
private boolean |
verbose |
| Constructor and Description |
|---|
PreprocessorContext()
The constructor
|
PreprocessorContext(PreprocessorContext context)
Make clone of a preprocessor context but without cloning state.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addConfigFile(java.io.File file)
Add a configuration file, it is a file which contains directives and global variable definitions
|
PreprocessorContext |
clearLocalVariables()
Remove all local variables from the inside storage
|
boolean |
containsGlobalVariable(java.lang.String name)
Check that there is a named global variable in the inside storage
|
boolean |
containsLocalVariable(java.lang.String name)
Check that a local variable for a name is presented
|
java.io.File |
createDestinationFileForPath(java.lang.String path)
It allows to create a File object for its path subject to the destination directory path
|
boolean |
doesClearDestinationDirBefore()
Get the flag to clear the destination directory before preprocessing
|
java.io.File |
findFileInSourceFolder(java.lang.String path)
It finds a file for its path among files in source folder, it is prohibited to return files out of preprocessing folders.
|
Value |
findVariableForName(java.lang.String name,
boolean enforceUnknownVarAsNull)
Find value among local and global variables for a name.
|
java.io.File[] |
getConfigFiles()
Get array of current registered configuration files
|
java.lang.String |
getDestinationDirectory()
Get the string representation of the destination directory
|
java.io.File |
getDestinationDirectoryAsFile()
Get the current destination directory as a File object
|
java.lang.String[] |
getExcludedFileExtensions()
Get excluded file extension list as a string array
|
java.lang.String[] |
getExcludedFolderPatterns()
Get patterns for excluded folders.
|
java.lang.String |
getInCharacterEncoding()
Get the current character encoding for text reading
|
Value |
getLocalVariable(java.lang.String name)
Get a local variable value
|
java.lang.String |
getOutCharacterEncoding()
Get the current character encoding for text writing
|
private java.io.File[] |
getParsedSourceDirectoryAsFiles()
Inside auxiliary method to parse the source directories list into file array
|
PreprocessingState |
getPreprocessingState()
Get the last generated preprocessing state, it is the current one
|
PreprocessorExtension |
getPreprocessorExtension()
Get the current preprocessor extension
|
java.lang.String[] |
getProcessingFileExtensions()
Get file extensions of files to be preprocessed as a string array
|
java.lang.Object |
getSharedResource(java.lang.String name)
Get a shared source from inside map
|
java.lang.String |
getSourceDirectories()
Get the source directories as semi separated string
|
java.io.File[] |
getSourceDirectoryAsFiles()
Get the current source directories as a file array
|
boolean |
isAllowWhitespace()
Get flag that whitespace allowed between directive and comment.
|
boolean |
isCareForLastNextLine() |
boolean |
isCloned()
Check that the preprocessor context is a clone of another context.
|
boolean |
isCompareDestination()
Check the flag to check content of existing file before saving.
|
boolean |
isCopyFileAttributes()
Check that the preprocessor must copy file attributes.
|
boolean |
isFileAllowedToBeProcessed(java.io.File file)
Check that a file is allowed to be preprocessed fo its extension
|
boolean |
isFileExcludedFromProcess(java.io.File file)
Check that a file is excluded from preprocessing and coping actions
|
boolean |
isFileOutputDisabled()
Check that writing operations is disabled
|
boolean |
isGlobalVariable(java.lang.String variableName)
Check that there is a global variable with such name.
|
boolean |
isKeepLines()
Check that the preprocessor must keep lines as commented ones
|
boolean |
isLocalVariable(java.lang.String variableName)
Check that there is a local variable with such name.
|
boolean |
isPreserveIndent()
Get flag indicating whether preserve-indent is enabled or disabled.
|
boolean |
isRemoveComments()
It returns the flag shows that all comments must be removed from the result
|
boolean |
isUnknownVariableAsFalse()
Get flag shows that unknown variable is recognized as FALSE.
|
boolean |
isVerbose()
Check the verbose flag
|
void |
logDebug(java.lang.String text)
Print some debug info into the current log
|
void |
logError(java.lang.String text)
Print an information about an error into the current log
|
void |
logForVerbose(java.lang.String str) |
void |
logInfo(java.lang.String text)
Print an information into the current log
|
void |
logWarning(java.lang.String text)
Print an information about a warning situation into the current log
|
PreprocessorException |
makeException(java.lang.String text,
java.lang.Throwable cause)
Prepare exception with message and cause, or return cause if it is a preprocessor exception
|
private static java.lang.String |
makeStackView(TextFileDataContainer cloneSource,
boolean cloned,
java.util.List<TextFileDataContainer> list) |
PreprocessingState |
produceNewPreprocessingState(FileInfoContainer fileContainer,
int phaseIndex)
Generate new preprocessing state object, also the new preprocessing state will be saved as the current one in the context
|
PreprocessingState |
produceNewPreprocessingState(FileInfoContainer fileContainer,
TextFileDataContainer textContainer)
Generate new preprocessing state for a file container and a text container, also the new preprocessing state will be saved as the current one in the context
|
void |
registerSpecialVariableProcessor(SpecialVariableProcessor processor)
It allows to register a special variable processor which can process some special global variables
|
PreprocessorContext |
removeGlobalVariable(java.lang.String name)
Remove a global variable value from the context.
|
PreprocessorContext |
removeLocalVariable(java.lang.String name)
Remove a local variable value from the context.
|
java.lang.Object |
removeSharedResource(java.lang.String name)
Remove a shared object from the inside map for its name
|
void |
setAllowWhitespace(boolean flag)
Set flag to allow whitespace between directive and comment chars.
|
void |
setCareForLastNextLine(boolean flag)
Set the flag to care to be precise in processing the last file next line char
|
PreprocessorContext |
setClearDestinationDirBefore(boolean flag)
Set the flag to clear the destination directory before preprocessing
|
PreprocessorContext |
setCompareDestination(boolean flag)
Set the flag to check before saving if the content changed.
|
PreprocessorContext |
setCopyFileAttributes(boolean value)
Set the flag to copy file attributes.
|
PreprocessorContext |
setDestinationDirectory(java.lang.String directory)
Set a destination directory for result files
|
PreprocessorContext |
setExcludedFileExtensions(java.lang.String extensions)
Set comma separated list of file extensions to be excluded from preprocessing
|
void |
setExcludedFolderPatterns(java.lang.String... patterns)
Set patterns for excluded folders.
|
void |
setFileOutputDisabled(boolean flag)
It allows to disable all writing operations of the preprocessor
|
PreprocessorContext |
setGlobalVariable(java.lang.String name,
Value value)
Set a global variable value
|
PreprocessorContext |
setInCharacterEncoding(java.lang.String characterEncoding)
Set the character encoding for reading texts, it must be supported by the Java platform else an exception will be thrown
|
PreprocessorContext |
setKeepLines(boolean flag)
Set the flag to keep lines as commented ones
|
PreprocessorContext |
setLocalVariable(java.lang.String name,
Value value)
Set a local variable value
|
PreprocessorContext |
setOutCharacterEncoding(java.lang.String characterEncoding)
Set the output texts character encoding, it must be supported by the Java platform else an exception will be thrown
|
PreprocessorContext |
setPreprocessorExtension(PreprocessorExtension extension)
Set a preprocessor extension, it is a module implements the PreprocessorExtension interface which can process and get some calls from a preprocessor during its work
|
void |
setPreprocessorLogger(PreprocessorLogger logger)
Set the logger to print information and error messages
|
void |
setPreserveIndent(boolean flag)
Set flag to control whether prefixes "//$", "//$$" should replaced
with equal length whitespace strings rather than just removed.
|
PreprocessorContext |
setProcessingFileExtensions(java.lang.String extensions)
Set file extensions of files to be preprocessed, it is a comma separated list
|
PreprocessorContext |
setRemoveComments(boolean removingComments)
Set the remove comments flag
|
void |
setSharedResource(java.lang.String name,
java.lang.Object obj)
Set a shared source, it is an object saved into the inside map for a name
|
PreprocessorContext |
setSourceDirectories(java.lang.String directories)
Set source directories
|
void |
setUnknownVariableAsFalse(boolean flag)
Set flag to interpret unknown variable value as FALSE.
|
PreprocessorContext |
setVerbose(boolean flag)
Set the verbose flag
|
public static final java.lang.String DEFAULT_SOURCE_DIRECTORY
public static final java.lang.String DEFAULT_DEST_DIRECTORY
public static final java.lang.String DEFAULT_PROCESSING_EXTENSIONS
public static final java.lang.String DEFAULT_EXCLUDED_EXTENSIONS
public static final java.lang.String DEFAULT_CHARSET
private boolean verbose
private boolean removeComments
private boolean clearDestinationDirectoryBefore
private boolean fileOutputDisabled
private boolean keepNonExecutingLines
private boolean careForLastNextLine
private boolean compareDestination
private boolean allowWhitespace
private boolean preserveIndent
private boolean copyFileAttributes
private boolean unknownVariableAsFalse
private java.lang.String sourceDirectories
private java.lang.String destinationDirectory
private java.io.File destinationDirectoryFile
private java.io.File[] sourceDirectoryFiles
private java.util.Set<java.lang.String> processingFileExtensions
private java.util.Set<java.lang.String> excludedFileExtensions
private PreprocessorExtension preprocessorExtension
private java.lang.String inCharacterEncoding
private java.lang.String outCharacterEncoding
private final java.util.Map<java.lang.String,Value> globalVarTable
private final java.util.Map<java.lang.String,Value> localVarTable
private final java.util.Map<java.lang.String,SpecialVariableProcessor> mapVariableNameToSpecialVarProcessor
private final java.util.Map<java.lang.String,java.lang.Object> sharedResources
private PreprocessorLogger preprocessorLogger
private final java.util.List<java.io.File> configFiles
private transient PreprocessingState currentState
private final boolean cloned
private final TextFileDataContainer currentInCloneSource
private java.lang.String[] excludedFolderPatterns
public PreprocessorContext()
public PreprocessorContext(PreprocessorContext context)
context - the context to be cloned, must not be null.public void setExcludedFolderPatterns(@MustNotContainNull java.lang.String... patterns)
patterns - array contains Ant path patterns@MustNotContainNull public java.lang.String[] getExcludedFolderPatterns()
public void setCareForLastNextLine(boolean flag)
flag - true to turn on the mode, false to turn offpublic boolean isCareForLastNextLine()
public boolean isCloned()
public void setPreprocessorLogger(PreprocessorLogger logger)
logger - a logger to be used for output, it can be nullpublic void registerSpecialVariableProcessor(SpecialVariableProcessor processor)
processor - a variable processor to be registered, it must not be nullSpecialVariableProcessorpublic void logInfo(java.lang.String text)
text - a String to be printed into the information log, it can be nullpublic void logError(java.lang.String text)
text - a String to be printed into the error log, it can be nullpublic void logDebug(java.lang.String text)
text - a String to be printed into the error log, it can be nullpublic void logWarning(java.lang.String text)
text - a String to be printed into the warning log, it can be nullpublic PreprocessorContext setRemoveComments(boolean removingComments)
removingComments - the flag to set, true if comments must be removed from the result files, otherwise elsepublic boolean isRemoveComments()
public void setFileOutputDisabled(boolean flag)
flag - true if preprocessor must not make any writing operations, otherwise falsepublic boolean isFileOutputDisabled()
public void setAllowWhitespace(boolean flag)
flag - true if whitespace allowed, false otherwisepublic boolean isAllowWhitespace()
public void setUnknownVariableAsFalse(boolean flag)
flag - true to turn on mode when unknown variable will be recognized as FALSEpublic boolean isUnknownVariableAsFalse()
public void setPreserveIndent(boolean flag)
flag - true enables preserve-indent, false disables itpublic boolean isPreserveIndent()
public PreprocessorContext setSourceDirectories(java.lang.String directories)
directories - semi separated list of source directories, must not be nullpublic void setSharedResource(java.lang.String name,
java.lang.Object obj)
name - the name for the saved project, must not be nullobj - the object to be saved in, must not be nullpublic java.lang.Object getSharedResource(java.lang.String name)
name - the name of the needed object, it must not be nullpublic java.lang.Object removeSharedResource(java.lang.String name)
name - the object name, it must not be nullpublic java.lang.String getSourceDirectories()
@MustNotContainNull public java.io.File[] getSourceDirectoryAsFiles()
@MustNotContainNull private java.io.File[] getParsedSourceDirectoryAsFiles()
public PreprocessorContext setDestinationDirectory(java.lang.String directory)
directory - a path to the directory as String, it must not be nullpublic java.io.File getDestinationDirectoryAsFile()
public java.lang.String getDestinationDirectory()
public PreprocessorContext setProcessingFileExtensions(java.lang.String extensions)
extensions - comma separated extensions list of file extensions to be preprocessed, must not be null@MustNotContainNull public java.lang.String[] getProcessingFileExtensions()
public final boolean isFileAllowedToBeProcessed(java.io.File file)
file - a file to be checkedpublic final boolean isFileExcludedFromProcess(java.io.File file)
file - a file to be checkedpublic PreprocessorContext setExcludedFileExtensions(java.lang.String extensions)
extensions - a comma separated file extension list, it must not be null@MustNotContainNull public java.lang.String[] getExcludedFileExtensions()
public PreprocessorContext setClearDestinationDirBefore(boolean flag)
flag - true if the directory must be cleaned, otherwise falsepublic boolean doesClearDestinationDirBefore()
public PreprocessorContext setLocalVariable(java.lang.String name, Value value)
name - the variable name, must not be null, remember that the name will be normalized and will be entirely in lower casevalue - the value for the variable, it must not be nullValuepublic PreprocessorContext removeLocalVariable(java.lang.String name)
name - the variable name, must not be null, remember that the name will be normalized and will be entirely in lower caseValuepublic PreprocessorContext removeGlobalVariable(java.lang.String name)
name - the variable name, must not be null, remember that the name will be normalized and will be entirely in lower caseValuepublic Value getLocalVariable(java.lang.String name)
name - the name for the variable, it can be null. The name will be normalized to allowed one.public boolean containsLocalVariable(java.lang.String name)
name - the checking name, it will be normalized to the support format and can be nullpublic PreprocessorContext clearLocalVariables()
public PreprocessorContext setGlobalVariable(java.lang.String name, Value value)
name - the variable name, it must not be null and will be normalized to the supported formatvalue - the variable value, it must not be nullpublic boolean containsGlobalVariable(java.lang.String name)
name - the checking name, it will be normalized to the supported format, it can be nullpublic Value findVariableForName(java.lang.String name, boolean enforceUnknownVarAsNull)
name - the name for the needed variable, it will be normalized to the supported formatenforceUnknownVarAsNull - if true then state of the unknownVariableAsFalse flag in context will be ignoredpublic boolean isGlobalVariable(java.lang.String variableName)
variableName - a name to be checked, can be nullpublic boolean isLocalVariable(java.lang.String variableName)
variableName - a name to be checked, can be nullpublic PreprocessorContext setVerbose(boolean flag)
flag - true if the preprocessor must be verbose, otherwise falsepublic boolean isVerbose()
public PreprocessorContext setCompareDestination(boolean flag)
flag - true if to check, false otherwisepublic boolean isCompareDestination()
public PreprocessorContext setKeepLines(boolean flag)
flag - true if the preprocessor must keep non-executing lines, otherwise falsepublic boolean isKeepLines()
public boolean isCopyFileAttributes()
public PreprocessorContext setCopyFileAttributes(boolean value)
value - true if file attributes must be copied, false otherwise.public PreprocessorContext setPreprocessorExtension(PreprocessorExtension extension)
extension - an object implements the PreprocessorExtension interface, it can be nullPreprocessorExtensionpublic PreprocessorExtension getPreprocessorExtension()
PreprocessorExtensionpublic PreprocessorContext setInCharacterEncoding(java.lang.String characterEncoding)
characterEncoding - a character encoding as a String, it must not be null and must be supported by the Java platformpublic PreprocessorContext setOutCharacterEncoding(java.lang.String characterEncoding)
characterEncoding - a character encoding as a String, it must not be null and must be supported by the Java platformpublic java.lang.String getInCharacterEncoding()
public java.lang.String getOutCharacterEncoding()
public java.io.File createDestinationFileForPath(java.lang.String path)
path - the path to the file, it must not be nullpublic java.io.File findFileInSourceFolder(java.lang.String path)
throws java.io.IOException
path - the path to the needed file, it must not be null and the file must exist and be a file and be among files in preprocessing source foldersjava.io.IOException - if it is impossible to find a file for the pathpublic void addConfigFile(java.io.File file)
file - a file, it must not be null@MustNotContainNull public java.io.File[] getConfigFiles()
public PreprocessingState produceNewPreprocessingState(FileInfoContainer fileContainer, int phaseIndex) throws java.io.IOException
fileContainer - a file container which will be using the preprocessor state, it must not be nullphaseIndex - index of phase (0 - global, 1 - preprocessing)java.io.IOException - it will be throws if there is any error in opening and reading operationspublic PreprocessingState produceNewPreprocessingState(FileInfoContainer fileContainer, TextFileDataContainer textContainer)
fileContainer - the file container to be used to create the new preprocessing state, it must not be nulltextContainer - the text container to be used to create the new preprocessing state, it must not be nullpublic PreprocessingState getPreprocessingState()
public PreprocessorException makeException(java.lang.String text, java.lang.Throwable cause)
text - the message text, must not be nullcause - the cause, it can be nullpublic void logForVerbose(java.lang.String str)
private static java.lang.String makeStackView(TextFileDataContainer cloneSource, boolean cloned, @MustNotContainNull java.util.List<TextFileDataContainer> list)