public class ConversionDriver
extends java.lang.Object
This program provides a command line interface. See main(java.lang.String[])
for the
syntax.
Modifier and Type | Class and Description |
---|---|
private class |
ConversionDriver.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.
|
private static class |
ConversionDriver.ListType
Form in which to obtain the list of files.
|
private static class |
ConversionDriver.RunMode
Container class that aggregates a set of options to control a run of
the conversion driver.
|
private class |
ConversionDriver.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 |
---|---|
private FileList |
asts
The list of Progress AST (abstract syntax tree) files.
|
private static java.lang.String |
codenames
Match list for source code name conversion.
|
private static char[] |
DANGER_LIST
Chars that must be escaped to eliminate regular expression meaning.
|
private static java.lang.String |
datanames
Match list for database name conversion.
|
private int |
debug
The debug level to honor throughout the process.
|
private static java.lang.String |
DIALECT_H2
H2 dialect name
|
private FileList |
dicts
The list of database dictionary files.
|
private FileList |
dmos
The list of DMO files.
|
private FileList |
dp2os
The list of database P2O files.
|
private FileList |
dschemas
The list of database schema files.
|
private java.lang.String[] |
frames
Java ASTs (abstract syntax trees) created during frame generation.
|
private java.util.List<java.lang.String> |
generatedProgramFiles
The list of new Progress file names generated by TRPL rules.
|
private FileList |
jasts
The list of Java AST (abstract syntax tree) files.
|
private static java.util.logging.Logger |
LOG
Logger
|
private java.lang.String[] |
menus
Java ASTs (abstract syntax trees) created during menus generation.
|
private static java.util.Map<java.lang.String,ConversionDriver.RunMode> |
modes
Associates mode names with detailed mode definitions.
|
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.
|
private FileList |
sdicts
The list of Progress source file specific dictionary files.
|
private FileList |
source
The list of Progress source files (command line input).
|
private FileList |
sp2os
The list of Progress source file specific P2O files.
|
private static java.lang.String |
spacer
Spacer for section headers and output.
|
private FileList |
sschemas
The list of Progress source file specific schema files.
|
Constructor and Description |
---|
ConversionDriver(FileList source,
int debug)
Creates an instance with a specific configuration.
|
Modifier and Type | Method and Description |
---|---|
private java.lang.String[] |
appendText(java.lang.String[] input,
java.lang.String text)
Appends the given text to every entry in the array and returns
a new array with the result.
|
private void |
back()
Drive the back end of the conversion process using the file list
of Progress AST files that is already defined in this instance.
|
private void |
brew(FileList files,
java.lang.String extra)
Convert Java AST (JAST) files into Java source code (
.java
files). |
private 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.
|
private 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. |
private FileList |
convertSourceNamesToDictNames(java.lang.String append)
Using the source name list as input, this method creates a duplicate
list with the given file suffix on each entry.
|
private void |
convertSourceNamesToJavaAstNames()
Using the source name list as input, this method creates duplicate
lists with the proper
.ast or .jast file
suffixes on each entry. |
private FileList |
createDatabaseList(java.lang.String append,
boolean omitMeta)
Creates a list of all schema files in the project's
data/namespace directory by the given extension that are
not associated with the special meta-data dictionary. |
private void |
deleteFiles(java.lang.String[] list)
Delete the file associated with each name in the list.
|
private void |
deleteFileSpecs(java.lang.String[] speclist,
ConversionDriver.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.
|
private 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.
|
private void |
front(boolean preproc,
boolean schema,
boolean callgraph,
boolean abortScanOnError,
int threads)
Drive the front end of the conversion process using the file list
of Progress source files that is already defined in this instance.
|
private void |
generateDDL(java.lang.String ddlType,
java.util.List<java.lang.String> schemas,
java.lang.String dialectList,
java.lang.String ruleset)
For each .p2o file associated with a schema and for each specified dialect, generate the
specified type of DDL.
|
private FileList |
generateDMOs(boolean skipDBSchema)
Drives the execution of the DMO creation rule-set using the P2O lists
as input and capturing the list of Java AST files generated.
|
private void |
generateFrames()
Drives the execution of the frame generator rule-set using the Progress
ASTs as input and capturing the list of Java AST files generated.
|
private void |
generateMenus()
Drives the execution of the frame generator rule-set using the Progress
ASTs as input and capturing the list of Java AST files generated.
|
private static ConversionDriver.RunMode |
interpretRunMode(java.lang.String mode)
Interpret the mode command line argument and convert this into the
effective run mode object.
|
static void |
main(java.lang.String[] args)
Provides a command line interface for an end user to drive the scanning harness.
|
private void |
middle(boolean length,
boolean skipDBSchema)
Drive the middle of the conversion process using the schema dictionary
lists generated from the output of the
SchemaLoader and
the file list of Progress AST files that is already defined in this
instance. |
private boolean |
omitSchemaMetadata()
Determine whether we should omit the metadata schema when processing and persisting schema
information.
|
private static void |
printElapsed(long elapsed)
Print out a simple elapsed time counter.
|
private 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). |
private 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.
|
private 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.
|
private 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.
|
private void |
runCallGraphGenerator()
Runs the
CallGraphGenerator using the project's defined
root nodes list to create a call graph for each root node. |
private void |
runScanDriver(boolean preproc,
boolean schema,
boolean abortOnError,
int threads)
Runs the
ScanDriver class to convert Progress source
files into an AST form. |
private void |
runSchemaLoader()
Runs the
SchemaLoader class to convert .df
files into an AST form which can be read by the
SchemaDictionary . |
private static void |
syntax(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 void |
zapFiles(java.lang.String[] files,
java.lang.String[] extslist)
Concatenate all extensions with all of 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
private static final java.lang.String spacer
private static final java.lang.String codenames
private static final java.lang.String datanames
private static final java.util.Map<java.lang.String,ConversionDriver.RunMode> modes
private static final char[] DANGER_LIST
private static final java.lang.String DIALECT_H2
private static final java.util.logging.Logger LOG
private FileList source
private FileList asts
private java.util.List<java.lang.String> generatedProgramFiles
.ast
extension.private FileList jasts
private java.lang.String[] frames
private java.lang.String[] menus
private FileList dicts
private FileList sdicts
private FileList dschemas
private FileList sschemas
private FileList dp2os
private FileList sp2os
private FileList dmos
private int debug
ConversionDriver(FileList source, int debug)
source
- The list of Progress source files to process.debug
- The debug level (must be one of the MSG_ constants in this
class).private void front(boolean preproc, boolean schema, boolean callgraph, boolean abortScanOnError, int threads) 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:
preproc
- true
if the Preprocessor
should
should be run. false
if previously cached
preprocessor results should be used.schema
- true
if the SchemaLoader
and
schema/fixups.rules
should be run.callgraph
- true
if the CallGraphGenerator
should be run.abortScanOnError
- 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.ConfigurationException
AstException
SchemaException
java.io.IOException
java.lang.Exception
private 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
SchemaException
java.io.IOException
private 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
private 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
private void zapFiles(java.lang.String[] files, java.lang.String[] extslist)
files
- The list of file base names.extslist
- The list of extensions to zap.private java.lang.String[] escapeRegex(java.lang.String[] list)
list
- List of literal strings that may need to be escaped.private 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
java.io.IOException
AstException
private void middle(boolean length, boolean skipDBSchema) throws ConfigurationException, AstException, SchemaException, java.io.IOException
SchemaLoader
and
the file list of Progress AST files that is already defined in this
instance.
This runs the following:
.java
)
length
- true
if the length statistics step must be run
(it takes a VERY long time).skipDBSchema
- true
if the physical DB schemas are not processed.ConfigurationException
AstException
SchemaException
java.io.IOException
private void generateDDL(java.lang.String ddlType, java.util.List<java.lang.String> schemas, java.lang.String dialectList, java.lang.String ruleset) throws ConfigurationException
This is done by calling the ruleset specified and setting the dbName
and
targetDb
parameters accordingly.
ddlType
- Type of DDL being generated (used only for console message).schemas
- List of names of schemas to process.dialectList
- List of database dialects for which to generate DDL or null
if this
information is to be read from the configuration.ruleset
- Name of ruleset to execute (without file extension suffix).ConfigurationException
- if the schema configuration can't be loaded.private FileList generateDMOs(boolean skipDBSchema) throws AstException, ConfigurationException
skipDBSchema
- true
if the physical DB schemas are not processed.AstException
ConfigurationException
private void back() throws ConfigurationException, AstException, SchemaException, java.io.IOException
This runs the following:
.java
)
ConfigurationException
AstException
SchemaException
java.io.IOException
private void generateFrames() throws AstException, ConfigurationException
AstException
ConfigurationException
private void generateMenus() throws AstException, ConfigurationException
AstException
ConfigurationException
private void brew(FileList files, java.lang.String extra) throws ConfigurationException, AstException
.java
files). The output is written into the configured project's output
path.files
- The list of JAST files to process.extra
- Text to append to the displayed header.ConfigurationException
AstException
private 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
AstException
private 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
AstException
private void deleteFiles(java.lang.String[] list) throws java.io.IOException
list
- List of explicit filenames to delete.java.io.IOException
private void deleteFileSpecs(java.lang.String[] speclist, ConversionDriver.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
private static void printHeader(java.lang.String section, int debug)
MSG_NONE
then spacers are printed).section
- The section name.debug
- The debug level.private void convertSourceNamesToAstNames()
.ast
or .jast
file
suffixes on each entry. The results are saved into the Progress AST
name list.private void convertSourceNamesToJavaAstNames()
.ast
or .jast
file
suffixes on each entry. Appended to this list is the list of Java ASTs
created during frame generation. The results are saved into the
Java AST name list.private FileList createDatabaseList(java.lang.String append, boolean omitMeta) throws ConfigurationException
data/namespace
directory by the given extension that are
not associated with the special meta-data dictionary.append
- 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
private boolean omitSchemaMetadata()
true
if no metadata tables are specified by the project configuration,
else false
.private FileList convertSourceNamesToDictNames(java.lang.String append)
append
- The file extension to search for (usually .dict
or .schema
).private java.lang.String[] appendText(java.lang.String[] input, java.lang.String text)
input
- The array of strings to modify.text
- The text to append to each element.private 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.private static ConversionDriver.RunMode interpretRunMode(java.lang.String mode)
mode
- The mode command line argument.private static void printElapsed(long elapsed)
elapsed
- Number of milliseconds of time elapsed.private static void syntax(java.lang.String msg, int rc)
stderr
, then exit the process with the specified return
code. This method is called from main(java.lang.String[])
when the user passes
command line parameters which are not viable.msg
- Optional error message; may be null
.rc
- Process return code used with System.exit()
.public static void main(java.lang.String[] args)
The program will return a non-zero code if there is a fatal error running the conversion.
Syntax:
java -DP2J_HOME=<home> ConversionDriver <mode> [options] <filelist> java -DP2J_HOME=<home> ConversionDriver <mode> -F[options] <filename> java -DP2J_HOME=<home> ConversionDriver <mode> -S[options] <directory> <"filespec">Where:
args
- List of command line arguments.