public abstract class TransformDriver
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
protected class |
TransformDriver.ExcludeCheck
Enables delegation of list processing to another method while providing
a callback to determine if a given list entry needs to be excluded from
processing.
|
protected static class |
TransformDriver.JobDefinition
Container for the details of a driver run.
|
protected static class |
TransformDriver.ListType
Form in which to obtain the list of files.
|
protected class |
TransformDriver.ScanCheck
Helper to only exclude the generated preprocessor files (cache and
preprocessor hints) conditionally and to always exclude the manually
coded hints files.
|
Modifier and Type | Field and Description |
---|---|
protected FileList |
asts
The list of Progress AST (abstract syntax tree) files.
|
protected static char[] |
DANGER_LIST
Chars that must be escaped to eliminate regular expression meaning.
|
protected static java.lang.String |
datanames
Match list for database name conversion.
|
protected int |
debug
The debug level to honor throughout the process.
|
protected FileList |
dicts
The list of database dictionary files.
|
protected TransformDriver.JobDefinition |
job
Full details of this run.
|
protected static java.util.logging.Logger |
LOG
Logger
|
protected RunMode |
mode
The details of which features this job run must implement.
|
static int |
MSG_DEBUG
Output debug and status messages.
|
static int |
MSG_NONE
No message output - quiet mode.
|
static int |
MSG_STATUS
Output status messages only.
|
static int |
MSG_TRACE
Full debug trace output.
|
protected FileList |
sdicts
The list of Progress source file specific dictionary files.
|
protected FileList |
source
The list of Progress source files (command line input).
|
protected static java.lang.String |
spacer
Spacer for section headers and output.
|
Constructor and Description |
---|
TransformDriver(TransformDriver.JobDefinition job)
Creates an instance with a specific configuration.
|
Modifier and Type | Method and Description |
---|---|
protected abstract void |
back()
Drive the back end of the transformation process using the file list of Progress AST files
that is already defined in this instance.
|
protected void |
cleanScanResults(boolean preproc,
boolean schema)
Remove some or all scan driver output files associated with the
current Progress source file list AND in the list of fakeout files
that represent the built-in 4GL classes/interfaces or .NET classes
that can be accessed.
|
protected void |
convertSourceNamesToAstNames()
Using the source name list as input, this method creates duplicate
lists with the proper
.ast or .jast file
suffixes on each entry. |
protected FileList |
convertSourceNamesToDictNames(java.lang.String suffix)
Using the source name list as input, this method creates a duplicate
list with the given file suffix on each entry.
|
protected FileList |
createDatabaseList(java.lang.String extension,
boolean omitMeta)
Scans the configuration file and create a list of artefacts containing a specific file for each declared
namespace from the default profile, if such file exists.
|
protected void |
deleteFiles(java.lang.String[] list)
Delete the file associated with each name in the list.
|
protected void |
deleteFileSpecs(java.lang.String[] speclist,
TransformDriver.ExcludeCheck check)
For each element in the spec list, generate a list of matching files
(each spec may contain traditional file system wildcard characters)
and delete each of these files.
|
protected java.lang.String[] |
escapeRegex(java.lang.String[] list)
Process each input element and escape characters that would be
interpreted as part of a regular expression to convert them all into
a literal match.
|
protected void |
executeJob(java.lang.String title)
Handle the execution of the front, middle and back of the transformation process
as defined in the job details.
|
protected void |
front()
Drive the front end of the conversion process using the file list
of Progress source files that is already defined in this instance.
|
protected static RunMode |
interpretRunMode(java.lang.String key,
java.util.Map<java.lang.String,RunMode> modes,
java.lang.String[] help)
Interpret the mode command line argument and convert this into the
effective run mode object.
|
protected abstract void |
middle()
Drive the middle of the transformation process using the file list of Progress AST files
that is already defined in this instance.
|
protected boolean |
omitSchemaMetadata()
Determine whether we should omit the metadata schema when processing and persisting schema
information.
|
protected static void |
printElapsed(long elapsed)
Print out a simple elapsed time counter.
|
protected static void |
printHeader(java.lang.String section,
int debug)
Print a section header and optionally spacers, depending on debug
level (if level >
MSG_NONE then spacers are printed). |
protected static TransformDriver.JobDefinition |
processCommandLine(java.lang.String[] args,
java.util.Map<java.lang.String,RunMode> modes,
java.lang.String[] help)
Process the command line interface for the driver.
|
protected static java.util.List<java.lang.String> |
processTrees(java.lang.String section,
java.lang.String rules,
java.lang.String matches,
boolean db,
FileList files,
int debug)
Run the pattern engine using the given rules filename as the program
and the list of files are the ASTs (abstract syntax trees) to process.
|
protected void |
processTrees(java.lang.String section,
java.lang.String rules,
java.lang.String matches,
boolean db,
FileList files,
int debug,
java.util.Map vars)
Run the pattern engine using the given rules filename as the program
and the list of files are the ASTs (abstract syntax trees) to process.
|
protected java.lang.String |
replaceFilenameExtension(java.lang.String filename,
java.lang.String append)
Replace the filename extension with the given extension and return the new string.
|
protected void |
runCallGraphGenerator()
Runs the
CallGraphGenerator using the project's defined
root nodes list to create a call graph for each root node. |
protected void |
runScanDriver(boolean preproc,
boolean schema,
boolean abortOnError,
int threads)
Runs the
ScanDriver class to convert Progress source
files into an AST form. |
protected void |
runSchemaLoader()
Runs the
SchemaLoader class to convert .df
files into an AST form which can be read by the
SchemaDictionary . |
private static java.util.List<java.lang.String> |
sortLegacyClasses(java.util.Set<java.lang.String> sources)
Sort all legacy classes in the specified sources, by computed the class hierarchy and
performing a BFS walk starting from
Progress.Lang.Object . |
protected static void |
syntax(java.lang.String[] helpText,
java.lang.String msg,
int rc)
Emit a syntax statement and optional error message to
stderr , then exit the
process with the specified return code. |
private static java.util.List<java.lang.String> |
walkHierarchy(java.util.Map<java.lang.String,java.util.Set<java.lang.String>> hierarchy,
java.lang.String parent)
Perform a BFS walk of the class hierarchy.
|
protected void |
zapFiles(java.lang.String[] files,
java.lang.String[] extslist)
Concatenate all extensions with all the files and if any resulting
names exist, delete the matching file from the file system.
|
public static final int MSG_NONE
public static final int MSG_STATUS
public static final int MSG_DEBUG
public static final int MSG_TRACE
protected static final java.lang.String spacer
protected static final java.lang.String datanames
protected static final char[] DANGER_LIST
protected static final java.util.logging.Logger LOG
protected FileList source
protected FileList asts
protected FileList dicts
protected FileList sdicts
protected int debug
protected RunMode mode
protected TransformDriver.JobDefinition job
public TransformDriver(TransformDriver.JobDefinition job)
job
- The details of the job to execute.protected void front() throws ConfigurationException, AstException, SchemaException, java.io.IOException, java.lang.Exception
Once the scanning of the source files is complete, this processing will modify the files list to create one that exposes AST files instead of Progress source files.
This runs the following:
ConfigurationException
- If there is problem reading/parsing the configuration.AstException
- If there is an problem processing ASTs.SchemaException
- If there is a problem with the schema.java.io.IOException
- If there is a problem with I/O.java.lang.Exception
- For any other problem.protected void runSchemaLoader() throws ConfigurationException, SchemaException, java.io.IOException
SchemaLoader
class to convert .df
files into an AST form which can be read by the
SchemaDictionary
. Files left by previous runs, if any,
are removed first.ConfigurationException
- If there is problem reading/parsing the configuration.SchemaException
- If there is a problem with the schema.java.io.IOException
- If there is a problem with I/O.protected void runScanDriver(boolean preproc, boolean schema, boolean abortOnError, int threads) throws java.lang.Exception
ScanDriver
class to convert Progress source
files into an AST form. This corresponds to preprocessing, lexing,
parsing and AST persistence.preproc
- true
if the Preprocessor
should
should be forced to run. false
if previously
cached preprocessor results should be honored.schema
- true
if the SchemaLoader
and
schema/fixups.rules
should be run. Note this
is only to assist with cleaning files as the schema
processing itself is not handled here.abortOnError
- true
to end the scanning run if an error is encountered,
else false
.threads
- Number of threads to use for the scan. A non-positive value will enable
the default behavior of a work-stealing thread pool with one thread per
per available CPU. A positive value will create a fixed size thread pool.java.lang.Exception
- If there is a problem.protected void cleanScanResults(boolean preproc, boolean schema) throws java.io.IOException
preproc
- true
means that cached preprocessor files should
be deleted.schema
- true
means that schema related generated files
should be deleted.java.io.IOException
- If there is a problem with I/O.protected void zapFiles(java.lang.String[] files, java.lang.String[] extslist)
files
- The list of file base names.extslist
- The list of extensions to zap.protected java.lang.String[] escapeRegex(java.lang.String[] list)
list
- List of literal strings that may need to be escaped.protected void runCallGraphGenerator() throws ConfigurationException, java.io.IOException, AstException
CallGraphGenerator
using the project's defined
root nodes list to create a call graph for each root node.ConfigurationException
- If there is problem reading/parsing the configuration.AstException
- If there is an problem processing ASTs.java.io.IOException
- If there is a problem with I/O.protected static java.util.List<java.lang.String> processTrees(java.lang.String section, java.lang.String rules, java.lang.String matches, boolean db, FileList files, int debug) throws ConfigurationException, AstException
section
- The section name (for the header);rules
- The pattern engine program (known as a rules file) to run.matches
- The match list name to use or null
to use the
project default.db
- Load default database name mappings.files
- The list of ASTs to process.debug
- The debug level to use with the pattern engine.PatternEngine.getNewProgramFiles()
.ConfigurationException
- If there is problem reading/parsing the configuration.AstException
- If there is an problem processing ASTs.protected void processTrees(java.lang.String section, java.lang.String rules, java.lang.String matches, boolean db, FileList files, int debug, java.util.Map vars) throws ConfigurationException, AstException
Also, set the variable initializers using the given map.
section
- The section name (for the header);rules
- The pattern engine program (known as a rules file) to run.matches
- The match list name to use or null
to use the
project default.db
- Load default database name mappings.files
- The list of ASTs to process.debug
- The debug level to use with the pattern engine.vars
- The variable initializers.ConfigurationException
- If there is problem reading/parsing the configuration.AstException
- If there is a problem processing ASTs.protected void deleteFiles(java.lang.String[] list) throws java.io.IOException
list
- List of explicit filenames to delete.java.io.IOException
- If there is a problem with I/O.protected void deleteFileSpecs(java.lang.String[] speclist, TransformDriver.ExcludeCheck check) throws java.io.IOException
ExcludeCheck
instance is used to remove results from the list on a callback basis.speclist
- List of file specifications.check
- If null
, no callback occurs. Otherwise, the
exclude
method will be called on the passed instance.java.io.IOException
- If there is a problem with I/O.protected static void printHeader(java.lang.String section, int debug)
MSG_NONE
then spacers are printed).section
- The section name.debug
- The debug level.protected void convertSourceNamesToAstNames()
.ast
or .jast
file
suffixes on each entry. The results are saved into the Progress AST
name list.protected FileList createDatabaseList(java.lang.String extension, boolean omitMeta) throws ConfigurationException
xmlFile
attribute of the
namespace
because all these artefacts are generated in same location.
xmlFile
attribute is specified for a namespace in the configuration, the
project's data/namespace
is assumed.extension
- The file extension to search for (usually .dict
, .schema
, or .p2o
).omitMeta
- true
to omit the metadata filename from the resulting list; false
to retain it.ConfigurationException
- If there is problem reading/parsing the configuration.protected boolean omitSchemaMetadata()
true
if no metadata tables are specified by the project configuration,
else false
.protected FileList convertSourceNamesToDictNames(java.lang.String suffix)
suffix
- The file extension to search for (usually .dict
or .schema
).protected java.lang.String replaceFilenameExtension(java.lang.String filename, java.lang.String append)
filename
- File name; may not be null
.append
- Extension to append after the filename's existing extension is removed. Must
begin with the dot (.
) character.protected void executeJob(java.lang.String title)
title
- Title for this driver's job.protected abstract void middle() throws ConfigurationException, AstException, SchemaException, java.io.IOException
ConfigurationException
- If there is problem reading/parsing the configuration.AstException
- If there is an problem processing ASTs.SchemaException
- If there is a problem with the schema.java.io.IOException
- If there is a problem with I/O.protected abstract void back() throws ConfigurationException, AstException, SchemaException, java.io.IOException
ConfigurationException
- If there is problem reading/parsing the configuration.AstException
- If there is an problem processing ASTs.SchemaException
- If there is a problem with the schema.java.io.IOException
- If there is a problem with I/O.protected static RunMode interpretRunMode(java.lang.String key, java.util.Map<java.lang.String,RunMode> modes, java.lang.String[] help)
key
- The mode command line argument.modes
- Valid run modes.help
- Help text for syntax display.protected static void printElapsed(long elapsed)
elapsed
- Number of milliseconds of time elapsed.protected static void syntax(java.lang.String[] helpText, java.lang.String msg, int rc)
stderr
, then exit the
process with the specified return code. This method is called when the user passes command
line parameters which are not viable.helpText
- Help text for syntax display.msg
- Optional error message; may be null
.rc
- Process return code used with System.exit()
.protected static TransformDriver.JobDefinition processCommandLine(java.lang.String[] args, java.util.Map<java.lang.String,RunMode> modes, java.lang.String[] help)
The program will return a non-zero code if there is a fatal error during the transformation processing. Each child class implements its own command line syntax, but the options, modes and 4GL source file lists are handled in a common way. The mode names are driver- specific, however the various front end modes are common since all drivers need to be able to create ASTs.
Syntax:
java -DP2J_HOME=<home> <TransformDriverChildClass> [-options]* <mode> [user_defined_rule_set] <file-specs>
Where:
MSG_NONE
(0) and
MSG_TRACE
(3) inclusive
<file-specs>
is a <filename>
containing a custom FILE-LIST, instead of
using the explicit command line file list
<file-specs>
is composed of a root <directory>
and a "<file-filter>"
, to select SPECIFIC files instead of an explicit command line file list
<file-specs>
is similar to S but has an additional custom EXCLUDE list file
"<filename>"
to be ignored
<file-filter>
(S/X options)
<file-set>
is a <filename>
containing the definition file list and
Include plus eXclude operations to be applied on it
>=
0; defaults to 1; set to 0 to use 1 thread per available CPU)
WARNING: this mode is not compatible if there are legacy .cls files
<name>
of the configuration PROFILE follows the option
mode
(one or more of the following values, use '+' to delimit if there are two or more
values; don't insert spaces!)
user_defined_rule_set
specifies the user-defined rule-set filename to execute
(only some modes support this, see sub-class documentation for details)
<filelist>
is arbitrary list of absolute and/or relative file names to scan, this
list is hard coded in the command line itself
<filename>
is a single absolute or relative filename of a text file that contains a
custom list of absolute and/or relative file names of files to scan
<directory>
is the root directory to search for files
"filespec"
is the file specification that will be used to create a list of files to
process, should be enclosed in double quotes if any of the wildcard characters '*' or '?'
are used
<file-set>
configuration from p2j.cfg.xml
will
be used (the Z mode is used implicitly). If there is no file-set, then the program stops.
<directory>
is the root directory to search for files
"filespec"
" is the file specification that will be used to create a list of files
to process, should be enclosed in double quotes if any of the wildcard characters '*' or
'?' are used
<filename>
is a single absolute or relative filename of a text file that contains a
custom list of specifications of file names to ignore
filespec
which are not matched by the ignore list
are scanned as they would be in filespec
mode.
args
- List of command line arguments.modes
- Valid run modes.help
- Help text for syntax display.private static java.util.List<java.lang.String> sortLegacyClasses(java.util.Set<java.lang.String> sources)
Progress.Lang.Object
. Interfaces are not
included in this sort.sources
- The sources to sort.private static java.util.List<java.lang.String> walkHierarchy(java.util.Map<java.lang.String,java.util.Set<java.lang.String>> hierarchy, java.lang.String parent)
hierarchy
- A map of classes to their direct sub-classes.parent
- The root class to start the walk.