Cleanup: add support for non-public fields. Track matches as state of parsing engine as well as definitions.
Made fields of command-line argument system non-public by default. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@606 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
f5eae98af2
commit
98716138e9
|
|
@ -24,49 +24,49 @@ public class GenomeAnalysisTK extends CommandLineProgram {
|
|||
|
||||
// parameters and their defaults
|
||||
@Argument(fullName="input_file",shortName="I",doc="SAM or BAM file(s)",required=false)
|
||||
public List<File> INPUT_FILES = null;
|
||||
protected List<File> INPUT_FILES = null;
|
||||
|
||||
@Argument(fullName="maximum_reads",shortName="M",doc="Maximum number of reads to process before exiting",required=false)
|
||||
public String MAX_READS_ARG = "-1";
|
||||
protected String MAX_READS_ARG = "-1";
|
||||
|
||||
@Argument(fullName="validation_strictness",shortName="S",doc="How strict should we be with validation (LENIENT|SILENT|STRICT)",required=false)
|
||||
public String STRICTNESS_ARG = "strict";
|
||||
protected String STRICTNESS_ARG = "strict";
|
||||
|
||||
@Argument(fullName="reference_sequence", shortName="R",doc="Reference sequence file",required=false)
|
||||
public File REF_FILE_ARG = null;
|
||||
protected File REF_FILE_ARG = null;
|
||||
|
||||
@Argument(fullName="genome_region", shortName="L", doc="Genome region to operation on: from chr:start-end",required=false)
|
||||
public String REGION_STR = null;
|
||||
protected String REGION_STR = null;
|
||||
|
||||
@Argument(fullName="analysis_type", shortName="T", doc="Type of analysis to run")
|
||||
public String Analysis_Name = null;
|
||||
protected String Analysis_Name = null;
|
||||
|
||||
@Argument(fullName="DBSNP",shortName="D",doc="DBSNP file",required=false)
|
||||
public String DBSNP_FILE = null;
|
||||
protected String DBSNP_FILE = null;
|
||||
|
||||
@Argument(fullName="hapmap",shortName="H",doc="Hapmap file",required=false)
|
||||
public String HAPMAP_FILE = null;
|
||||
protected String HAPMAP_FILE = null;
|
||||
|
||||
@Argument(fullName="hapmap_chip",shortName="hc",doc="Hapmap chip file",required=false)
|
||||
public String HAPMAP_CHIP_FILE = null;
|
||||
protected String HAPMAP_CHIP_FILE = null;
|
||||
|
||||
@Argument(fullName="threaded_IO",shortName="P",doc="If set, enables threaded I/O operations",required=false)
|
||||
public Boolean ENABLED_THREADED_IO = false;
|
||||
protected Boolean ENABLED_THREADED_IO = false;
|
||||
|
||||
@Argument(fullName="unsafe",shortName="U",doc="If set, enables unsafe operations, nothing will be checked at runtime.",required=false)
|
||||
public Boolean UNSAFE = false;
|
||||
protected Boolean UNSAFE = false;
|
||||
|
||||
@Argument(fullName="sort_on_the_fly",shortName="sort",doc="Maximum number of reads to sort on the fly",required=false)
|
||||
public String MAX_ON_FLY_SORTS = null;
|
||||
protected String MAX_ON_FLY_SORTS = null;
|
||||
|
||||
@Argument(fullName="downsample_to_fraction",shortName="dfrac",doc="Fraction [0.0-1.0] of reads to downsample to",required=false)
|
||||
public String DOWNSAMPLE_FRACTION = null;
|
||||
protected String DOWNSAMPLE_FRACTION = null;
|
||||
|
||||
@Argument(fullName="downsample_to_coverage",shortName="dcov",doc="Coverage [integer] to downsample to",required=false)
|
||||
public String DOWNSAMPLE_COVERAGE = null;
|
||||
protected String DOWNSAMPLE_COVERAGE = null;
|
||||
|
||||
@Argument(fullName="intervals_file",shortName="V",doc="File containing list of genomic intervals to operate on. line := <contig> <start> <end>",required=false)
|
||||
public String INTERVALS_FILE = null;
|
||||
protected String INTERVALS_FILE = null;
|
||||
|
||||
// our walker manager
|
||||
private WalkerManager walkerManager = null;
|
||||
|
|
@ -76,34 +76,34 @@ public class GenomeAnalysisTK extends CommandLineProgram {
|
|||
public boolean DEBUGGING = false;
|
||||
|
||||
@Argument(fullName="all_loci",shortName="A",doc="Should we process all loci, not just those covered by reads",required=false)
|
||||
public Boolean WALK_ALL_LOCI = false;
|
||||
protected Boolean WALK_ALL_LOCI = false;
|
||||
|
||||
@Argument(fullName="disablethreading",shortName="dt",doc="Disable experimental threading support.",required=false)
|
||||
public Boolean DISABLE_THREADING = false;
|
||||
protected Boolean DISABLE_THREADING = false;
|
||||
|
||||
/**
|
||||
* An output file presented to the walker.
|
||||
*/
|
||||
@Argument(fullName="out",shortName="o",doc="An output file presented to the walker. Will overwrite contents if file exists.",required=false)
|
||||
public String outFileName = null;
|
||||
protected String outFileName = null;
|
||||
|
||||
/**
|
||||
* An error output file presented to the walker.
|
||||
*/
|
||||
@Argument(fullName="err",shortName="e",doc="An error output file presented to the walker. Will overwrite contents if file exists.",required=false)
|
||||
public String errFileName = null;
|
||||
protected String errFileName = null;
|
||||
|
||||
/**
|
||||
* A joint file for both 'normal' and error output presented to the walker.
|
||||
*/
|
||||
@Argument(fullName="outerr",shortName="oe",doc="A joint file for 'normal' and error output presented to the walker. Will overwrite contents if file exists.",required=false)
|
||||
public String outErrFileName = null;
|
||||
protected String outErrFileName = null;
|
||||
|
||||
/**
|
||||
* How many threads should be allocated to this analysis.
|
||||
*/
|
||||
@Argument(fullName="numthreads",shortName="nt",doc="How many threads should be allocated to running this analysis.",required=false)
|
||||
public int numThreads = 1;
|
||||
protected int numThreads = 1;
|
||||
|
||||
/**
|
||||
* Collection of output streams used by the walker.
|
||||
|
|
@ -116,7 +116,7 @@ public class GenomeAnalysisTK extends CommandLineProgram {
|
|||
private static Logger logger = Logger.getLogger(GenomeAnalysisTK.class);
|
||||
|
||||
@Argument(fullName="rodBind",shortName="B",doc="",required=false)
|
||||
public static ArrayList<String> ROD_BINDINGS = new ArrayList<String>();
|
||||
protected static ArrayList<String> ROD_BINDINGS = new ArrayList<String>();
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ public abstract class CommandLineProgram {
|
|||
* The command-line program and the arguments it returned.
|
||||
*/
|
||||
private ParsingEngine parser = null;
|
||||
private ArgumentMatches parameters = null;
|
||||
|
||||
/**
|
||||
* our log, which we want to capture anything from org.broadinstitute.sting
|
||||
|
|
@ -44,7 +43,7 @@ public abstract class CommandLineProgram {
|
|||
shortName="l",
|
||||
doc="Set the minimum level of logging, i.e. setting INFO get's you INFO up to FATAL, setting ERROR gets you ERROR and FATAL level logging. (DEBUG, INFO, WARN, ERROR, FATAL, OFF). ",
|
||||
required=false)
|
||||
public String logging_level = "ERROR";
|
||||
protected String logging_level = "ERROR";
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -54,7 +53,7 @@ public abstract class CommandLineProgram {
|
|||
shortName="log",
|
||||
doc="Set the logging location",
|
||||
required=false)
|
||||
public String toFile = null;
|
||||
protected String toFile = null;
|
||||
|
||||
/**
|
||||
* do we want to silence the command line output
|
||||
|
|
@ -63,7 +62,7 @@ public abstract class CommandLineProgram {
|
|||
shortName="quiet",
|
||||
doc="Set the logging to quiet mode, no output to stdout",
|
||||
required=false)
|
||||
public Boolean quietMode = false;
|
||||
protected Boolean quietMode = false;
|
||||
|
||||
/**
|
||||
* do we want to generate debugging information with the logs
|
||||
|
|
@ -72,7 +71,7 @@ public abstract class CommandLineProgram {
|
|||
shortName="debug",
|
||||
doc="Set the logging file string to include a lot of debugging information (SLOW!)",
|
||||
required=false)
|
||||
public Boolean debugMode = false;
|
||||
protected Boolean debugMode = false;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -135,23 +134,24 @@ public abstract class CommandLineProgram {
|
|||
|
||||
// setup the parser
|
||||
ParsingEngine parser = clp.parser = new ParsingEngine();
|
||||
parser.addArgumentSources( clp.getClass() );
|
||||
parser.addArgumentSource( clp.getClass() );
|
||||
|
||||
// process the args
|
||||
if( clp.canAddArgumentsDynamically() ) {
|
||||
// if the command-line program can toss in extra args, fetch them and reparse the arguments.
|
||||
clp.parameters = parser.parse(args);
|
||||
parser.validate( clp.parameters, EnumSet.of(ParsingEngine.ValidationType.InvalidArgument) );
|
||||
parser.loadArgumentsIntoObject( clp, clp.parameters );
|
||||
parser.parse(args);
|
||||
parser.validate( EnumSet.of(ParsingEngine.ValidationType.InvalidArgument) );
|
||||
parser.loadArgumentsIntoObject( clp );
|
||||
|
||||
Class[] argumentSources = clp.getArgumentSources();
|
||||
parser.addArgumentSources( argumentSources );
|
||||
clp.parameters = parser.parse(args);
|
||||
parser.validate( clp.parameters );
|
||||
for( Class argumentSource: argumentSources )
|
||||
parser.addArgumentSource( argumentSource );
|
||||
parser.parse(args);
|
||||
parser.validate();
|
||||
}
|
||||
else {
|
||||
clp.parameters = parser.parse(args);
|
||||
parser.validate( clp.parameters );
|
||||
parser.parse(args);
|
||||
parser.validate();
|
||||
}
|
||||
|
||||
// if we're in debug mode, set the mode up
|
||||
|
|
@ -224,7 +224,7 @@ public abstract class CommandLineProgram {
|
|||
* @param obj Object to inspect for command line arguments.
|
||||
*/
|
||||
public void loadArgumentsIntoObject( Object obj ) {
|
||||
parser.loadArgumentsIntoObject( obj, parameters );
|
||||
parser.loadArgumentsIntoObject( obj );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -41,6 +41,13 @@ public class ParsingEngine {
|
|||
*/
|
||||
ArgumentDefinitions argumentDefinitions = new ArgumentDefinitions();
|
||||
|
||||
/**
|
||||
* A list of matches from defined arguments to command-line text.
|
||||
* Indicates as best as possible where command-line text remains unmatched
|
||||
* to existing arguments.
|
||||
*/
|
||||
ArgumentMatches argumentMatches = null;
|
||||
|
||||
/**
|
||||
* Techniques for parsing and for argument lookup.
|
||||
*/
|
||||
|
|
@ -61,18 +68,19 @@ public class ParsingEngine {
|
|||
/**
|
||||
* Add an argument source. Argument sources are expected to have
|
||||
* any number of fields with an @Argument annotation attached.
|
||||
* @param sources A list of argument sources from which to extract
|
||||
* command-line arguments.
|
||||
* @param source An argument source from which to extract
|
||||
* command-line arguments.
|
||||
*/
|
||||
public void addArgumentSources( Class... sources ) {
|
||||
for( Class source: sources ) {
|
||||
Field[] fields = source.getFields();
|
||||
public void addArgumentSource( Class source ) {
|
||||
do {
|
||||
Field[] fields = source.getDeclaredFields();
|
||||
for( Field field: fields ) {
|
||||
Argument argument = field.getAnnotation(Argument.class);
|
||||
Argument argument = field.getAnnotation(Argument.class);
|
||||
if(argument != null)
|
||||
argumentDefinitions.add( argument, source, field );
|
||||
}
|
||||
}
|
||||
source = source.getSuperclass();
|
||||
} while( source != null );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -84,10 +92,9 @@ public class ParsingEngine {
|
|||
* @return A object indicating which matches are best. Might return
|
||||
* an empty object, but will never return null.
|
||||
*/
|
||||
public ArgumentMatches parse( String[] tokens ) {
|
||||
ArgumentMatches argumentMatches = parseArguments( tokens );
|
||||
public void parse( String[] tokens ) {
|
||||
argumentMatches = parseArguments( tokens );
|
||||
fitValuesToArguments( argumentMatches, tokens );
|
||||
return argumentMatches;
|
||||
}
|
||||
|
||||
public enum ValidationType { MissingRequiredArgument,
|
||||
|
|
@ -97,19 +104,17 @@ public class ParsingEngine {
|
|||
|
||||
/**
|
||||
* Validates the list of command-line argument matches.
|
||||
* @param argumentMatches Matches to validate.
|
||||
*/
|
||||
public void validate( ArgumentMatches argumentMatches ) {
|
||||
validate( argumentMatches, EnumSet.noneOf(ValidationType.class) );
|
||||
public void validate() {
|
||||
validate( EnumSet.noneOf(ValidationType.class) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the list of command-line argument matches. On failure throws an exception with detailed info about the
|
||||
* particular failures. Takes an EnumSet indicating which validation checks to skip.
|
||||
* @param argumentMatches Matches to validate.
|
||||
* @param skipValidationOf List of validation checks to skip.
|
||||
*/
|
||||
public void validate( ArgumentMatches argumentMatches, EnumSet<ValidationType> skipValidationOf ) {
|
||||
public void validate( EnumSet<ValidationType> skipValidationOf ) {
|
||||
// Find missing required arguments.
|
||||
if( !skipValidationOf.contains(ValidationType.MissingRequiredArgument) ) {
|
||||
Collection<ArgumentDefinition> requiredArguments =
|
||||
|
|
@ -156,10 +161,9 @@ public class ParsingEngine {
|
|||
/**
|
||||
* Loads a set of matched command-line arguments into the given object.
|
||||
* @param object Object into which to add arguments.
|
||||
* @param matches List of matches.
|
||||
*/
|
||||
public void loadArgumentsIntoObject( Object object, ArgumentMatches matches ) {
|
||||
for( ArgumentMatch match: matches ) {
|
||||
public void loadArgumentsIntoObject( Object object ) {
|
||||
for( ArgumentMatch match: argumentMatches ) {
|
||||
ArgumentDefinition definition = match.definition;
|
||||
|
||||
// A null definition might be in the list if some invalid arguments were passed in but we
|
||||
|
|
@ -167,8 +171,9 @@ public class ParsingEngine {
|
|||
if( definition == null )
|
||||
continue;
|
||||
|
||||
if( object.getClass().equals(definition.sourceClass) ) {
|
||||
if( definition.sourceClass.isAssignableFrom(object.getClass()) ) {
|
||||
try {
|
||||
definition.sourceField.setAccessible(true);
|
||||
if( !isArgumentFlag(definition) )
|
||||
definition.sourceField.set( object, constructFromString( definition.sourceField, match.values() ) );
|
||||
else
|
||||
|
|
|
|||
|
|
@ -42,12 +42,12 @@ public class ParsingEngineTest extends BaseTest {
|
|||
public void shortNameArgumentTest() {
|
||||
final String[] commandLine = new String[] {"-I","na12878.bam"};
|
||||
|
||||
parsingEngine.addArgumentSources( InputFileArgProvider.class );
|
||||
ArgumentMatches argumentMatches = parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate(argumentMatches);
|
||||
parsingEngine.addArgumentSource( InputFileArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
|
||||
InputFileArgProvider argProvider = new InputFileArgProvider();
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider, argumentMatches);
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider );
|
||||
|
||||
Assert.assertEquals("Argument is not correctly initialized", "na12878.bam", argProvider.inputFile );
|
||||
}
|
||||
|
|
@ -56,12 +56,12 @@ public class ParsingEngineTest extends BaseTest {
|
|||
public void shortNameCompositeArgumentTest() {
|
||||
final String[] commandLine = new String[] {"-Ina12878.bam"};
|
||||
|
||||
parsingEngine.addArgumentSources( InputFileArgProvider.class );
|
||||
ArgumentMatches argumentMatches = parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate(argumentMatches);
|
||||
parsingEngine.addArgumentSource( InputFileArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
|
||||
InputFileArgProvider argProvider = new InputFileArgProvider();
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider, argumentMatches);
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider );
|
||||
|
||||
Assert.assertEquals("Argument is not correctly initialized", "na12878.bam", argProvider.inputFile );
|
||||
}
|
||||
|
|
@ -70,12 +70,12 @@ public class ParsingEngineTest extends BaseTest {
|
|||
public void multiCharShortNameArgumentTest() {
|
||||
final String[] commandLine = new String[] {"-out","out.txt"};
|
||||
|
||||
parsingEngine.addArgumentSources( MultiCharShortNameArgProvider.class );
|
||||
ArgumentMatches argumentMatches = parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate(argumentMatches);
|
||||
parsingEngine.addArgumentSource( MultiCharShortNameArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
|
||||
MultiCharShortNameArgProvider argProvider = new MultiCharShortNameArgProvider();
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider, argumentMatches);
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider );
|
||||
|
||||
Assert.assertEquals("Argument is not correctly initialized", "out.txt", argProvider.outputFile );
|
||||
}
|
||||
|
|
@ -90,12 +90,12 @@ public class ParsingEngineTest extends BaseTest {
|
|||
public void longNameArgumentTest() {
|
||||
final String[] commandLine = new String[] {"--input_file", "na12878.bam"};
|
||||
|
||||
parsingEngine.addArgumentSources( InputFileArgProvider.class );
|
||||
ArgumentMatches argumentMatches = parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate(argumentMatches);
|
||||
parsingEngine.addArgumentSource( InputFileArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
|
||||
InputFileArgProvider argProvider = new InputFileArgProvider();
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider, argumentMatches);
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider );
|
||||
|
||||
Assert.assertEquals("Argument is not correctly initialized", "na12878.bam", argProvider.inputFile );
|
||||
}
|
||||
|
|
@ -104,12 +104,12 @@ public class ParsingEngineTest extends BaseTest {
|
|||
public void extraWhitespaceTest() {
|
||||
final String[] commandLine = new String[] {" --input_file ", "na12878.bam"};
|
||||
|
||||
parsingEngine.addArgumentSources( InputFileArgProvider.class );
|
||||
ArgumentMatches argumentMatches = parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate(argumentMatches);
|
||||
parsingEngine.addArgumentSource( InputFileArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
|
||||
InputFileArgProvider argProvider = new InputFileArgProvider();
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider, argumentMatches);
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider );
|
||||
|
||||
Assert.assertEquals("Argument is not correctly initialized", "na12878.bam", argProvider.inputFile );
|
||||
}
|
||||
|
|
@ -118,12 +118,12 @@ public class ParsingEngineTest extends BaseTest {
|
|||
public void flagTest() {
|
||||
final String[] commandLine = new String[] {"--all_loci"};
|
||||
|
||||
parsingEngine.addArgumentSources( AllLociArgProvider.class );
|
||||
ArgumentMatches argumentMatches = parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate(argumentMatches);
|
||||
parsingEngine.addArgumentSource( AllLociArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
|
||||
AllLociArgProvider argProvider = new AllLociArgProvider();
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider, argumentMatches);
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider );
|
||||
|
||||
Assert.assertTrue("Argument is not correctly initialized", argProvider.allLoci );
|
||||
}
|
||||
|
|
@ -137,12 +137,12 @@ public class ParsingEngineTest extends BaseTest {
|
|||
public void arrayTest() {
|
||||
final String[] commandLine = new String[] {"-Ifoo.txt", "--input_file", "bar.txt"};
|
||||
|
||||
parsingEngine.addArgumentSources( MultiValueArgProvider.class );
|
||||
ArgumentMatches argumentMatches = parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate(argumentMatches);
|
||||
parsingEngine.addArgumentSource( MultiValueArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
|
||||
MultiValueArgProvider argProvider = new MultiValueArgProvider();
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider, argumentMatches);
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider );
|
||||
|
||||
Assert.assertEquals("Argument array is of incorrect length", 2, argProvider.inputFile.length);
|
||||
Assert.assertEquals("1st filename is incorrect", "foo.txt", argProvider.inputFile[0] );
|
||||
|
|
@ -158,12 +158,12 @@ public class ParsingEngineTest extends BaseTest {
|
|||
public void typedCollectionTest() {
|
||||
final String[] commandLine = new String[] { "-N2", "-N4", "-N6", "-N8", "-N10" };
|
||||
|
||||
parsingEngine.addArgumentSources( IntegerListArgProvider.class );
|
||||
ArgumentMatches argumentMatches = parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate(argumentMatches);
|
||||
parsingEngine.addArgumentSource( IntegerListArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
|
||||
IntegerListArgProvider argProvider = new IntegerListArgProvider();
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider, argumentMatches);
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider );
|
||||
|
||||
Assert.assertNotNull("Argument array is null",argProvider.integers);
|
||||
Assert.assertEquals("Argument array is of incorrect length", 5, argProvider.integers.size());
|
||||
|
|
@ -183,12 +183,12 @@ public class ParsingEngineTest extends BaseTest {
|
|||
public void untypedCollectionTest() {
|
||||
final String[] commandLine = new String[] { "-N2", "-N4", "-N6", "-N8", "-N10" };
|
||||
|
||||
parsingEngine.addArgumentSources( UntypedListArgProvider.class );
|
||||
ArgumentMatches argumentMatches = parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate(argumentMatches);
|
||||
parsingEngine.addArgumentSource( UntypedListArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
|
||||
UntypedListArgProvider argProvider = new UntypedListArgProvider();
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider, argumentMatches);
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider );
|
||||
|
||||
Assert.assertNotNull("Argument array is null",argProvider.integers);
|
||||
Assert.assertEquals("Argument array is of incorrect length", 5, argProvider.integers.size());
|
||||
|
|
@ -208,9 +208,9 @@ public class ParsingEngineTest extends BaseTest {
|
|||
public void requiredArgTest() {
|
||||
final String[] commandLine = new String[0];
|
||||
|
||||
parsingEngine.addArgumentSources( RequiredArgProvider.class );
|
||||
ArgumentMatches argumentMatches = parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate( argumentMatches );
|
||||
parsingEngine.addArgumentSource( RequiredArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
}
|
||||
|
||||
private class RequiredArgProvider {
|
||||
|
|
@ -222,12 +222,12 @@ public class ParsingEngineTest extends BaseTest {
|
|||
public void disableValidationOfRequiredArgTest() {
|
||||
final String[] commandLine = new String[0];
|
||||
|
||||
parsingEngine.addArgumentSources( RequiredArgProvider.class );
|
||||
ArgumentMatches argumentMatches = parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate( argumentMatches, EnumSet.of(ParsingEngine.ValidationType.MissingRequiredArgument) );
|
||||
parsingEngine.addArgumentSource( RequiredArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate( EnumSet.of(ParsingEngine.ValidationType.MissingRequiredArgument) );
|
||||
|
||||
RequiredArgProvider argProvider = new RequiredArgProvider();
|
||||
parsingEngine.loadArgumentsIntoObject(argProvider, argumentMatches);
|
||||
parsingEngine.loadArgumentsIntoObject(argProvider );
|
||||
|
||||
Assert.assertNull("Value should have remain unset",argProvider.value);
|
||||
}
|
||||
|
|
@ -236,12 +236,12 @@ public class ParsingEngineTest extends BaseTest {
|
|||
public void unrequiredArgTest() {
|
||||
final String[] commandLine = new String[0];
|
||||
|
||||
parsingEngine.addArgumentSources( UnrequiredArgProvider.class );
|
||||
ArgumentMatches argumentMatches = parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate( argumentMatches );
|
||||
parsingEngine.addArgumentSource( UnrequiredArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
|
||||
UnrequiredArgProvider argProvider = new UnrequiredArgProvider();
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider, argumentMatches);
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider );
|
||||
|
||||
Assert.assertNull( "Value was unrequired and unspecified; contents should be null", argProvider.value );
|
||||
}
|
||||
|
|
@ -255,14 +255,14 @@ public class ParsingEngineTest extends BaseTest {
|
|||
public void invalidArgTest() {
|
||||
final String[] commandLine = new String[] { "--foo" };
|
||||
|
||||
parsingEngine.addArgumentSources( UnrequiredArgProvider.class );
|
||||
ArgumentMatches argumentMatches = parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate( argumentMatches );
|
||||
parsingEngine.addArgumentSource( UnrequiredArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
}
|
||||
|
||||
@Test(expected=StingException.class)
|
||||
public void duplicateLongNameTest() {
|
||||
parsingEngine.addArgumentSources( DuplicateLongNameProvider.class );
|
||||
parsingEngine.addArgumentSource( DuplicateLongNameProvider.class );
|
||||
}
|
||||
|
||||
private class DuplicateLongNameProvider {
|
||||
|
|
@ -275,7 +275,7 @@ public class ParsingEngineTest extends BaseTest {
|
|||
|
||||
@Test(expected=StingException.class)
|
||||
public void duplicateShortNameTest() {
|
||||
parsingEngine.addArgumentSources( DuplicateShortNameProvider.class );
|
||||
parsingEngine.addArgumentSource( DuplicateShortNameProvider.class );
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -291,9 +291,9 @@ public class ParsingEngineTest extends BaseTest {
|
|||
public void missingArgumentNameTest() {
|
||||
final String[] commandLine = new String[] {"foo.txt"};
|
||||
|
||||
parsingEngine.addArgumentSources( NoArgProvider.class );
|
||||
ArgumentMatches argumentMatches = parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate(argumentMatches);
|
||||
parsingEngine.addArgumentSource( NoArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
}
|
||||
|
||||
private class NoArgProvider {
|
||||
|
|
@ -304,40 +304,39 @@ public class ParsingEngineTest extends BaseTest {
|
|||
public void extraValueTest() {
|
||||
final String[] commandLine = new String[] {"-Ifoo.txt", "bar.txt"};
|
||||
|
||||
parsingEngine.addArgumentSources( InputFileArgProvider.class );
|
||||
ArgumentMatches argumentMatches = parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate(argumentMatches);
|
||||
parsingEngine.addArgumentSource( InputFileArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
}
|
||||
|
||||
@Test(expected=MissingArgumentException.class)
|
||||
public void multipleInvalidArgTest() {
|
||||
final String[] commandLine = new String[] {"-N1", "-N2", "-N3"};
|
||||
|
||||
parsingEngine.addArgumentSources( RequiredArgProvider.class );
|
||||
ArgumentMatches argumentMatches = parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate( argumentMatches );
|
||||
parsingEngine.addArgumentSource( RequiredArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
}
|
||||
|
||||
@Test(expected=TooManyValuesForArgumentException.class)
|
||||
public void invalidArgCountTest() {
|
||||
final String[] commandLine = new String[] {"--value","1","--value","2","--value","3"};
|
||||
|
||||
parsingEngine.addArgumentSources( RequiredArgProvider.class );
|
||||
ArgumentMatches argumentMatches = parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate( argumentMatches );
|
||||
parsingEngine.addArgumentSource( RequiredArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
}
|
||||
|
||||
/*
|
||||
@Test
|
||||
public void packageProtectedArgTest() {
|
||||
final String[] commandLine = new String[] {"--foo", "1"};
|
||||
|
||||
parsingEngine.addArgumentSources( PackageProtectedArgProvider.class );
|
||||
ArgumentMatches argumentMatches = parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate(argumentMatches);
|
||||
parsingEngine.addArgumentSource( PackageProtectedArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
|
||||
PackageProtectedArgProvider argProvider = new PackageProtectedArgProvider();
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider, argumentMatches);
|
||||
parsingEngine.loadArgumentsIntoObject(argProvider);
|
||||
|
||||
Assert.assertEquals("Argument is not correctly initialized", 1, argProvider.foo.intValue() );
|
||||
}
|
||||
|
|
@ -346,11 +345,32 @@ public class ParsingEngineTest extends BaseTest {
|
|||
@Argument(doc="foo")
|
||||
Integer foo;
|
||||
}
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void derivedArgTest() {
|
||||
final String[] commandLine = new String[] {"--bar", "5"};
|
||||
|
||||
parsingEngine.addArgumentSource( DerivedArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
|
||||
DerivedArgProvider argProvider = new DerivedArgProvider();
|
||||
parsingEngine.loadArgumentsIntoObject(argProvider);
|
||||
|
||||
Assert.assertEquals("Argument is not correctly initialized", 5, argProvider.bar.intValue() );
|
||||
}
|
||||
|
||||
private class DerivedArgProvider extends BaseArgProvider {
|
||||
}
|
||||
|
||||
private class BaseArgProvider {
|
||||
@Argument(doc="bar")
|
||||
public Integer bar;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void correctDefaultArgNameTest() {
|
||||
parsingEngine.addArgumentSources( CamelCaseArgProvider.class );
|
||||
parsingEngine.addArgumentSource( CamelCaseArgProvider.class );
|
||||
|
||||
DefinitionMatcher matcher = ArgumentDefinitions.FullNameDefinitionMatcher;
|
||||
ArgumentDefinition definition = parsingEngine.argumentDefinitions.findArgumentDefinition("myarg", matcher);
|
||||
|
|
@ -367,9 +387,9 @@ public class ParsingEngineTest extends BaseTest {
|
|||
public void booleanWithParameterTest() {
|
||||
final String[] commandLine = new String[] {"--mybool", "true"};
|
||||
|
||||
parsingEngine.addArgumentSources( BooleanArgProvider.class );
|
||||
ArgumentMatches argumentMatches = parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate(argumentMatches);
|
||||
parsingEngine.addArgumentSource( BooleanArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate();
|
||||
}
|
||||
|
||||
private class BooleanArgProvider {
|
||||
|
|
@ -381,12 +401,12 @@ public class ParsingEngineTest extends BaseTest {
|
|||
public void testValidParseForAnalysisType() {
|
||||
final String[] commandLine = new String[] {"--analysis_type", "Pileup" };
|
||||
|
||||
parsingEngine.addArgumentSources( AnalysisTypeArgProvider.class );
|
||||
ArgumentMatches argumentMatches = parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate(argumentMatches, EnumSet.of(ParsingEngine.ValidationType.MissingRequiredArgument) );
|
||||
parsingEngine.addArgumentSource( AnalysisTypeArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate( EnumSet.of(ParsingEngine.ValidationType.MissingRequiredArgument) );
|
||||
|
||||
AnalysisTypeArgProvider argProvider = new AnalysisTypeArgProvider();
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider, argumentMatches );
|
||||
parsingEngine.loadArgumentsIntoObject( argProvider );
|
||||
|
||||
Assert.assertEquals("Argument is not correctly initialized", "Pileup", argProvider.Analysis_Name );
|
||||
}
|
||||
|
|
@ -400,9 +420,9 @@ public class ParsingEngineTest extends BaseTest {
|
|||
public void testInvalidParseForAnalysisType() {
|
||||
final String[] commandLine = new String[] {"--analysis_type", "Pileup", "-TCountReads" };
|
||||
|
||||
parsingEngine.addArgumentSources( AnalysisTypeArgProvider.class );
|
||||
ArgumentMatches argumentMatches = parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate(argumentMatches, EnumSet.of(ParsingEngine.ValidationType.MissingRequiredArgument) );
|
||||
parsingEngine.addArgumentSource( AnalysisTypeArgProvider.class );
|
||||
parsingEngine.parse( commandLine );
|
||||
parsingEngine.validate( EnumSet.of(ParsingEngine.ValidationType.MissingRequiredArgument) );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue