| java.lang.Object jenable.JEnable
JEnable | public class JEnable (Code) | | Source configuration processor program. This program processes a set of Java
source files (or standard input to standard output, if no source files are
specified), scanning for configuration control lines. A control line is a
line that starts with "//#token*" (valid only as the first line of a
file), "//#token{" (beginning an option block), "//#}token{" (inverting an
option block), or "//#token} (closing an option block). The first two formats
also allow a '!' immediately before the token in order to invert the token
state.
The token strings to be processed are specified on the command line as
either enabled or disabled. See the program documentation for more details
of the command line options and usage.
Nested option blocks are allowed, but overlapping option blocks are an
error. In order to ensure proper processing of nested option blocks, the
user should generally specify every token used for the nested blocks
as either enabled or disabled if any of them are either enabled or
disabled. It is an error if an indeterminant beginning of block token (one
with a token which is not on either list) is immediately contained within
a block with an enabled token. In other words, the case:
//#a{
//#b{
//#c{
//#c}
//#b}
//#a}
gives an error if "a" is on the enabled list and "b" is not on either list,
or if "a" is not on the disabled list, "b" is on the enabled list, and "c"
is not on either list.
author: Dennis M. Sosnoski version: 0.8 |
Constructor Summary | |
protected | JEnable(boolean keep, boolean mark, boolean mods, boolean quiet, boolean verbose, File backup, Hashtable enabled, Hashtable disabled) Constructor. |
Method Summary | |
protected int | checkOptionLine(int lnum, String line) Check if line is an option. | protected boolean | isNameMatch(String name, String pattern) Checks if file name matches a pattern. | protected boolean | isPathMatch(String name, String pattern) Checks if file or directory name directly matches a pattern. | protected static boolean | isTokenBodyChar(char chr) Checks for valid body character of token. | protected static boolean | isTokenLeadChar(char chr) Checks for valid first character of token. | public static void | main(String[] argv) Test driver, just reads the input parameters and executes the source
checks. | protected void | matchPathSegment(File base, String path) Process files matching path segment. | protected static void | parseTokenList(String list, Vector tokens) Parse comma-separated token list. | protected boolean | processFile(File file) Processes source options for a file. | protected void | processPath(String path) Process all files matching path and print summary. | protected boolean | processStream(BufferedReader in, String lead, BufferedWriter out) Processes source options for a text stream. | protected void | throwError(int lnum, String line, String msg) Convenience method for generating an error report exception. |
BACKUP_DIR_ERR | final protected static String BACKUP_DIR_ERR(Code) | | Error text for unable to rename file to backup directory.
|
BACKUP_FILE_ERR | final protected static String BACKUP_FILE_ERR(Code) | | Error text for unable to rename file within directory.
|
BADELSE_ERR | final protected static String BADELSE_ERR(Code) | | Error text for block else token not matching block start token.
|
BLOCK_COMMENT_OPTION | final protected static int BLOCK_COMMENT_OPTION(Code) | | Return code for block comment option line.
|
BLOCK_ELSE_OPTION | final protected static int BLOCK_ELSE_OPTION(Code) | | Return code for block else option line.
|
BLOCK_END_OPTION | final protected static int BLOCK_END_OPTION(Code) | | Return code for block end option line.
|
BLOCK_START_OPTION | final protected static int BLOCK_START_OPTION(Code) | | Return code for block start option line.
|
COPY_BUFFER_SIZE | final protected static int COPY_BUFFER_SIZE(Code) | | Size of buffer used to copy file.
|
DELETE_ERR | final protected static String DELETE_ERR(Code) | | Error text for unable to delete original file.
|
DUAL_USE_ERR | final protected static String DUAL_USE_ERR(Code) | | Error text for token in both sets.
|
EXTENSION_ERR | final protected static String EXTENSION_ERR(Code) | | Error text for file option line with unknown file extension.
|
FILE_OPTION | final protected static int FILE_OPTION(Code) | | Return code for file option line.
|
FILE_OPTION_ERR | final protected static String FILE_OPTION_ERR(Code) | | Error text for file option not on first line.
|
INDETERM_ERR | final protected static String INDETERM_ERR(Code) | | Error text for indeterminant token nested in enabled block.
|
LEAD_LENGTH | final protected static int LEAD_LENGTH(Code) | | Length of lead text for option token.
|
NESTED_SAME_ERR | final protected static String NESTED_SAME_ERR(Code) | | Error text for token nested within block for same token.
|
NOT_OPTION | final protected static int NOT_OPTION(Code) | | Return code for not an option line.
|
OLD_BACKUP_ERR | final protected static String OLD_BACKUP_ERR(Code) | | Error text for unable to delete old backup file.
|
OPTION_LEAD | final protected static String OPTION_LEAD(Code) | | Lead text for option token.
|
RENAME_ERR | final protected static String RENAME_ERR(Code) | | Error text for unable to rename original file.
|
STAMP_ERR | final protected static String STAMP_ERR(Code) | | Error text for unable to change file modify timestamp.
|
TEMP_DELETE_ERR | final protected static String TEMP_DELETE_ERR(Code) | | Error text for unable to delete temporary file.
|
TEMP_RENAME_ERR | final protected static String TEMP_RENAME_ERR(Code) | | Error text for unable to rename temp file.
|
UNBALANCED_ERR | final protected static String UNBALANCED_ERR(Code) | | Error text for block end token not matching block start token.
|
UNCLOSED_ERR | final protected static String UNCLOSED_ERR(Code) | | Error text for end of file with open block.
|
UNKNOWN_OPTION_ERR | final protected static String UNKNOWN_OPTION_ERR(Code) | | Error text for unknown option token type.
|
m_backupDir | protected File m_backupDir(Code) | | Backup root path (null if not backing up).
|
m_disabledTokens | protected Hashtable m_disabledTokens(Code) | | Map for disabled tokens (values same as keys).
|
m_enabledTokens | protected Hashtable m_enabledTokens(Code) | | Map for enabled tokens (values same as keys).
|
m_keepStamp | protected boolean m_keepStamp(Code) | | Preserve timestamp on modified files flag.
|
m_listModified | protected boolean m_listModified(Code) | | List modified files flag.
|
m_listProcessed | protected boolean m_listProcessed(Code) | | List all files processed flag.
|
m_listSummary | protected boolean m_listSummary(Code) | | List file summary by path flag.
|
m_markBackup | protected boolean m_markBackup(Code) | | Mark backup file with tilde flag.
|
m_matchedCount | protected int m_matchedCount(Code) | | Number of files matched.
|
m_modifiedCount | protected int m_modifiedCount(Code) | | Number of files modified.
|
JEnable | protected JEnable(boolean keep, boolean mark, boolean mods, boolean quiet, boolean verbose, File backup, Hashtable enabled, Hashtable disabled)(Code) | | Constructor.
Parameters: keep - preserve timestamp on modified files flag Parameters: mark - mark backup files with tilde flag Parameters: mods - list modified files flag Parameters: quiet - do not list file summaries by path flag Parameters: verbose - list all files processed flag Parameters: backup - root back for backup directory tree (null ifno backups) Parameters: enabled - map of enabled tokens Parameters: disabled - map of disabled tokens |
checkOptionLine | protected int checkOptionLine(int lnum, String line) throws IOException(Code) | | Check if line is an option. Returns a code for the option line type
(or "not an option line"), with the actual token from the line stored
in the instance variable. Ugly technique, but the only easy way to
return multiple results without using another class.
Parameters: lnum - line number within file (used for error reporting) Parameters: line - source line to check for option return code for option line type throws: IOException - on option line error |
isNameMatch | protected boolean isNameMatch(String name, String pattern)(Code) | | Checks if file name matches a pattern. This works a little differently
from the general path matching in that if the pattern does not include
an extension both ".java" and ".javx" file extensions are matched. If
the pattern includes an extension ending in '*' it is blocked from
matching with a tilde final character in the file name as a special case.
Parameters: name - file or directory name Parameters: pattern - match pattern true if any file modified, false if not |
isPathMatch | protected boolean isPathMatch(String name, String pattern)(Code) | | Checks if file or directory name directly matches a pattern. This
method accepts one or more '*' wildcard characters in the pattern,
calling itself recursively in order to handle multiple wildcards.
Parameters: name - file or directory name Parameters: pattern - match pattern true if any pattern matched, false if not |
isTokenBodyChar | protected static boolean isTokenBodyChar(char chr)(Code) | | Checks for valid body character of token. All body characters must be
an alpha, digits, or underscore.
Parameters: chr - character to be validated true if valid body character, false if not |
isTokenLeadChar | protected static boolean isTokenLeadChar(char chr)(Code) | | Checks for valid first character of token. The first character must be
an alpha or underscore.
Parameters: chr - character to be validated true if valid first character, false if not |
main | public static void main(String[] argv)(Code) | | Test driver, just reads the input parameters and executes the source
checks.
Parameters: argv - command line arguments |
matchPathSegment | protected void matchPathSegment(File base, String path)(Code) | | Process files matching path segment. This method matches a single step
(directory specification) in a path for each call, calling itself
recursively to match the complete path.
Parameters: base - base directory for path match Parameters: path - file path remaining to be processed |
parseTokenList | protected static void parseTokenList(String list, Vector tokens)(Code) | | Parse comma-separated token list. Parses and validates the tokens,
adding them to the supplied list. errors are signalled by throwing
IllegalArgumentException .
Parameters: list - comma-separated token list to be parsed Parameters: tokens - list of tokens to add to throws: IllegalArgumentException - on error in supplied list |
processFile | protected boolean processFile(File file)(Code) | | Processes source options for a file. Starts by checking the first line
of the file for a file option and processing that. If, after processing
the file option, the file has a ".java" extension, it is processed for
other option lines.
This saves the output to a temporary file, then if processing is
completed successfully first renames or moves the original file (if
backup has been requested), or deletes it (if backup not requested),
and then renames the temporary file to the original file name.
Processing errors are printed to System.err , and any
results are discarded without being saved.
Parameters: file - source file to be processed true if source modified, false if not |
processPath | protected void processPath(String path)(Code) | | Process all files matching path and print summary. The file path
format is similar to Ant, supporting arbitrary directory recursion using
'**' separators between '/' separators. Single '*'s may be used within
names for wildcarding, but aside from the special case of the directory
recursion matcher only one '*' may be used per name.
If an extension is
not specified for the final name in the path both ".java" and ".javx"
extensions are checked, but after checking for file option lines (which
may change the file extension) only ".java" extensions are processed for
other source options.
Parameters: path - file path to be processed |
processStream | protected boolean processStream(BufferedReader in, String lead, BufferedWriter out) throws IOException(Code) | | Processes source options for a text stream. If an error occurs in
processing, this generates an IOException with the error
information (including input line number).
Parameters: in - input reader for source data Parameters: lead - first line of file (previously read for checking file enableor disable) Parameters: out - output writer for modified source data true if source modified, false if not |
throwError | protected void throwError(int lnum, String line, String msg) throws IOException(Code) | | Convenience method for generating an error report exception.
Parameters: lnum - line number within file Parameters: line - source line to check for option Parameters: msg - error message text throws: IOException - wrapping the error information |
|
|