gov.nasa.pds.tools
Class VTool

java.lang.Object
  extended by gov.nasa.pds.tools.VTool
All Implemented Interfaces:
VToolConfigKeys, ToolsFlags, Status, ExitStatus, StyleSheet

public class VTool
extends java.lang.Object
implements VToolConfigKeys, ToolsFlags, ExitStatus, Status, StyleSheet

Class to perform automated validation to determine if a given data product is PDS compliant.

This replaces LVTool functionality.

Version:
$Revision: 2666 $
Author:
mcayanan

Field Summary
 
Fields inherited from interface gov.nasa.pds.tools.config.VToolConfigKeys
ALIASKEY, DICTKEY, FOLLOWKEY, FORCEKEY, IGNOREDIRKEY, IGNOREFILEKEY, INCLUDESKEY, LOGKEY, PROGRESSKEY, RECURSEKEY, REGEXPKEY, REPORTKEY, SHOWLOGKEY, STYLEKEY, TARGETKEY, VERBOSEKEY
 
Fields inherited from interface gov.nasa.pds.tools.flags.ToolsFlags
ALIAS, CONFIG, DATAOBJ, DICT, FOLLOW, HELP, IGNOREDIR, IGNOREFILE, INCLUDES, LOCAL, LOG, LONG, PARTIAL, PROGRESS, REGEXP, REPORT, RPTSTYLE, SHORT, TARGET, VERBOSE, VERSION
 
Fields inherited from interface gov.nasa.pds.tools.status.ExitStatus
BADRUN, GOODRUN, TOOLFAILURE
 
Fields inherited from interface gov.nasa.pds.tools.label.validate.Status
FAIL, PASS, UNKNOWN
 
Fields inherited from interface gov.nasa.pds.tools.xsl.StyleSheet
FULLXSL, MINXSL, SUMXSL
 
Constructor Summary
VTool()
          Default constructor.
 
Method Summary
 void buildOpts()
          Builds the set of configurable parameters for VTool.
 void closehandle()
          Closes the handlers that were set for the logger.
 void doReporting(java.io.File log, java.io.File report, java.lang.String level, java.lang.String style)
          Creates a human-readable report.
 boolean getAlias()
          Get aliasing flag.
 java.util.List getDictionaries()
          Get a list of dictionary files passed into VTool.
 int getExitStatus()
          Returns an exit status code based on the validation results.
 boolean getFollowPtrs()
          Get flag status that determines whether to follow pointers found in a label.
 boolean getForcePartial()
          Get flag status that determines whether standalone label fragment validation is enabled.
 java.util.List getIncludePaths()
          Get the paths to search for files referenced by pointers in a label.
 java.io.File getLogFile()
          Get the machine-readable log file name.
 java.util.List getNoDirs()
          Get the file name that contains the list of directories and/or directory patterns to ignore during validation.
 java.util.List getNoFiles()
          Get the file name that contains the list of files and/or file patterns.
 boolean getProgress()
          Get the progress reporting flag.
 java.util.List getRegexp()
          Get the patterns to be matched when searching for files to validate in a directory.
 java.io.File getRptFile()
          Get the report file name for the human-readable report.
 java.lang.String getRptStyle()
          Get the output style that was set for the validation report.
 boolean getShowLog()
          Get the flag that determines whether to write the log to standard out.
 java.util.List getTargets()
          Get the list of targets
 short getVerbose()
          Get the verbosity level.
 void logRptHeader()
          Logs report header information such as version of the tool, execution time, and flag settings.
static void main(java.lang.String[] argv)
          Implementation to perform automated PDS validation.
 void parseLine(java.lang.String[] argv)
          Parses the VTool command-line.
 FileList processTarget(java.lang.String target, boolean getSubDirs)
          Processes a target.
 void queryCmdLine()
          Queries the VTool command-line.
 void readConfigFile(java.net.URL file)
          Reads a configuration file to set the default behaviors for VTool.
 Dictionary readDictionaries(java.util.List dictionary)
          Parse the dictionary files.
 void setAlias(boolean a)
          Set aliasing flag.
 void setDictionaries(java.util.List d)
          Set the dictionary file names passed into VTool .
 void setFollowPtrs(boolean f)
          Set the flag that determines whether to follow pointers found in a label.
 void setForcePartial(boolean f)
          Set the flag that determines whether to validate standalone label.
 void setIncludePaths(java.util.List i)
          Set the paths to search for files referenced by pointers.
 void setLogFile(java.io.File f)
          Set the file name for the machine-readable log.
 void setNoDirs(java.util.List f)
          Set the flag to ignore specified directories.
 void setNoFiles(java.util.List f)
          Set the flag to ignore specified files.
 void setProgress(boolean p)
          Set the progress reporting flag.
 void setRecursive(boolean r)
          Set the recursive flag.
 void setRegexp(java.util.List e)
          Set the patterns flag.
 void setRptFile(java.io.File f)
          Set the file for the human-readable report.
 void setRptStyle(java.lang.String style)
          Set the output style for the report.
 void setShowLog(boolean l)
          Set the flag to write the log to standard out.
 void setTargets(java.util.List t)
          Set the targets flag.
 void setupLogger()
          Configures the logger appropriately.
 void setVerbose(short v)
          Set the verbosity level and above to include in the reporting.
 void showHelp()
          Display VTool usage and help information
 void showProgress(java.net.URL file)
          Prints out the current directory being validated and represents each file being validated by an asterisk.
 void showVersion()
          Show the version and disclaimer notice for VTool.
 java.lang.String validateLabel(java.net.URL file, Dictionary dict)
          Validate a label file.
 void validateLabels(java.util.List targets, Dictionary dict)
          Validate labels found in the specified targets.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VTool

public VTool()
Default constructor.

Method Detail

showVersion

public void showVersion()
Show the version and disclaimer notice for VTool.


showHelp

public void showHelp()
Display VTool usage and help information


buildOpts

public void buildOpts()
Builds the set of configurable parameters for VTool.


parseLine

public void parseLine(java.lang.String[] argv)
Parses the VTool command-line.

Parameters:
argv - arguments given on the command-line

queryCmdLine

public void queryCmdLine()
Queries the VTool command-line.


getAlias

public boolean getAlias()
Get aliasing flag.

Returns:
'true' if aliasing is ON, 'false' otherwise

setAlias

public void setAlias(boolean a)
Set aliasing flag.

Parameters:
a - 'false' if aliasing should be turned off, 'true' otherwise

getDictionaries

public java.util.List getDictionaries()
Get a list of dictionary files passed into VTool.

Returns:
a List object of dictionary file names

setDictionaries

public void setDictionaries(java.util.List d)
Set the dictionary file names passed into VTool .

Parameters:
d - a List object of dictionary files

getFollowPtrs

public boolean getFollowPtrs()
Get flag status that determines whether to follow pointers found in a label.

Returns:
'true' to follow, 'false' otherwise

setFollowPtrs

public void setFollowPtrs(boolean f)
Set the flag that determines whether to follow pointers found in a label.

Parameters:
f - 'true' to follow, 'false' otherwise

getForcePartial

public boolean getForcePartial()
Get flag status that determines whether standalone label fragment validation is enabled.

Returns:
'true' to enable, 'false' otherwise

setForcePartial

public void setForcePartial(boolean f)
Set the flag that determines whether to validate standalone label. fragments

Parameters:
f - 'true' to enable, 'false' otherwise

getIncludePaths

public java.util.List getIncludePaths()
Get the paths to search for files referenced by pointers in a label.

Returns:
Start paths

setIncludePaths

public void setIncludePaths(java.util.List i)
Set the paths to search for files referenced by pointers.

Default is to always look first in the same directory as the label, then search specified directories.

Parameters:
i - List of paths

getNoDirs

public java.util.List getNoDirs()
Get the file name that contains the list of directories and/or directory patterns to ignore during validation.

Returns:
a list of directory names/patterns to exclude from validation

setNoDirs

public void setNoDirs(java.util.List f)
Set the flag to ignore specified directories.

Parameters:
f - a text file containing a list of directories and/or directory patterns to ignore during validation. The names must be listed one name per line.

getNoFiles

public java.util.List getNoFiles()
Get the file name that contains the list of files and/or file patterns. to ignore during validation

Returns:
a list of files/file patterns to exclude from validation

setNoFiles

public void setNoFiles(java.util.List f)
Set the flag to ignore specified files.

Parameters:
f - a list of files/file patterns to ignore during validation.

getLogFile

public java.io.File getLogFile()
Get the machine-readable log file name.

Returns:
log file

setLogFile

public void setLogFile(java.io.File f)
Set the file name for the machine-readable log.

Parameters:
f - file name of the log

getShowLog

public boolean getShowLog()
Get the flag that determines whether to write the log to standard out.

Returns:
'true' to show log, 'false' to not show log

setShowLog

public void setShowLog(boolean l)
Set the flag to write the log to standard out.

Parameters:
l -

getRptFile

public java.io.File getRptFile()
Get the report file name for the human-readable report.

Returns:
Report file name

setRptFile

public void setRptFile(java.io.File f)
Set the file for the human-readable report.

Parameters:
f - file name

getRptStyle

public java.lang.String getRptStyle()
Get the output style that was set for the validation report.

Returns:
'full' for a full report, 'sum' for a summary report or 'min' for minimal detail

setRptStyle

public void setRptStyle(java.lang.String style)
Set the output style for the report.

Parameters:
style - 'sum' for a summary report, 'min' for a minimal report, and 'full' for a full report

getProgress

public boolean getProgress()
Get the progress reporting flag.

Returns:
'true' if progress reporting is enabled, 'false' otherwise

setProgress

public void setProgress(boolean p)
Set the progress reporting flag.

Parameters:
p -

getRegexp

public java.util.List getRegexp()
Get the patterns to be matched when searching for files to validate in a directory.

Returns:
a List object of patterns

setRegexp

public void setRegexp(java.util.List e)
Set the patterns flag.

Parameters:
e - a List of patterns to be matched when searching for files to validate in a directory

setRecursive

public void setRecursive(boolean r)
Set the recursive flag.

Parameters:
r - 'true' to recursively traverse down a directory and all its sub-directories, 'false' otherwise

getTargets

public java.util.List getTargets()
Get the list of targets

Returns:
a List object of files, URLs, and/or directories

setTargets

public void setTargets(java.util.List t)
Set the targets flag.

Parameters:
t - a List of files, URLs, and/or directories to be validated

getVerbose

public short getVerbose()
Get the verbosity level.

Returns:
an integer value where '1' for info, '2' for warnings' and '3' for errors

setVerbose

public void setVerbose(short v)
Set the verbosity level and above to include in the reporting.

Parameters:
v - '1' for info, '2' for warnings, and '3' for errors

readConfigFile

public void readConfigFile(java.net.URL file)
Reads a configuration file to set the default behaviors for VTool.

Flags set on the command-line will override flags set in the configuration file

Parameters:
file - a file containing keyword/value statements

logRptHeader

public void logRptHeader()
Logs report header information such as version of the tool, execution time, and flag settings.


setupLogger

public void setupLogger()
Configures the logger appropriately.

If a log file was specified on the command-line, the log will be written to that file. If the log flag was specified with no file spec, then the log will be written to standard out. Otherwise, the log will be written to memory (ByteArrayOutputStream).


readDictionaries

public Dictionary readDictionaries(java.util.List dictionary)
Parse the dictionary files.

Parameters:
dictionary - a list of dictionary URLs
Returns:
a Dictionary object that includes all the dictionary information from all the dictionary files passed in.

validateLabels

public void validateLabels(java.util.List targets,
                           Dictionary dict)
Validate labels found in the specified targets. If the target is a directory, this method will validate all labels found within the directory and its sub-directories. If recursion is turned OFF, then sub-directories will not be looked into.

Parameters:
targets - a list of files, directories, and/or URLs
dict - the dictionary file

getExitStatus

public int getExitStatus()
Returns an exit status code based on the validation results.

Returns:
'0' if files "passed" and a '1' if any of the following occurs:
  • one or more files failed validation
  • one or more files skipped validation and in addition, no other files passed validation
  • dictionary validation failed

processTarget

public FileList processTarget(java.lang.String target,
                              boolean getSubDirs)
Processes a target.

Parameters:
target - The file or URL to process
getSubDirs - 'True' to look for sub-directories, 'false' otherwise
Returns:
A FileList object containing the sub-directories and files found in the target, if any

validateLabel

public java.lang.String validateLabel(java.net.URL file,
                                      Dictionary dict)
Validate a label file.

Parameters:
file - The URL of the file to be validated
dict - a Dictionary object needed for semantic validation. If null, only syntactic validation will be performed.
Returns:
'PASS' if the label passed the PDS validation step, 'FAIL' if the label failed the PDS validation step, or 'UNKOWN' if the label skipped the PDS validation step

showProgress

public void showProgress(java.net.URL file)
Prints out the current directory being validated and represents each file being validated by an asterisk. This is used when progress reporting is enabled.

Parameters:
file - The URL being validated

doReporting

public void doReporting(java.io.File log,
                        java.io.File report,
                        java.lang.String level,
                        java.lang.String style)
Creates a human-readable report.

Parameters:
log - Where the xml log is located. If null, then the xml log will be read from memory.
report - Where the human-readable report will be written to. If null, then it goes to standard out.
level - The severity level to include in the report. Can be "INFO", "WARNING", or "ERROR".
style - The reporting style to generate. Can be either "full", "sum", or "min" for a full, summary, or minimal report, respectively.

closehandle

public void closehandle()
Closes the handlers that were set for the logger.


main

public static void main(java.lang.String[] argv)
Implementation to perform automated PDS validation.

The main calls the following methods (in this order):

To setup the flags and parse the command-line options:

To setup the logger and log the report header information:

To perform validation:

To create the final report:

Reporting is not generated if the log flag was specified with no file spec and the report file flag was not specified

VTool returns an appropriate exit status based on validation results.
In general, the following is returned:

Parameters:
argv - Arguments passed on the command-line


Copyright © 2005-2007 NASA Jet Propulsion Laboratory, California Institute of Technology. All Rights Reserved.