Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Copyright (C) 2015 The Pennsylvania State University and the University of Wisconsin
   * Systems and Internet Infrastructure Security Laboratory
   * Author: Damien Octeau
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
 package edu.psu.cse.siis.coal;
An abstract parser for command line options. Subclasses should implement parseAnalysisSpecificArguments(org.apache.commons.cli.Options) and printHelp(org.apache.commons.cli.Options).

<A> A CommandLineArguments parameter.
 public abstract class CommandLineParser<A extends CommandLineArguments> {
   private final Logger logger = LoggerFactory.getLogger(getClass());

Parses the command line options. This method parses default options that are common to all analyses and it also causes analysis-specific options to be processed.

args The command line arguments.
clazz The class type of the CommandLineArguments that should be returned.
The parsed command line arguments.
   public A parseCommandLine(String[] argsClass<A> clazz) {
     Options options = new Options();
     CommandLine commandLine = null;
     try {
       org.apache.commons.cli.CommandLineParser commandLineParser = new GnuParser();
       commandLine = commandLineParser.parse(optionsargs);
     } catch (ParseException e) {
       .error("Could not parse command line arguments"e);
       return null;
     A commandLineArguments = null;
     try {
       commandLineArguments = clazz.newInstance();
     } catch (InstantiationException | IllegalAccessException e) {
       .error("Could not instantiate type " + clazze);
       return null;
     return commandLineArguments;

Populates the analysis-specific command line options.

options The options that should be populated.
   protected abstract void parseAnalysisSpecificArguments(Options options);

Specifies how the help message should be printed.

options The options that should be used to print the help message.
   protected abstract void printHelp(Options options);

Populates the default command line arguments that are common to all analyses.

options The command line options object that should be modified.
  private void parseDefaultCommandLineArguments(Options options) {
    OptionGroup modelGroup = new OptionGroup();
    modelGroup.addOption(OptionBuilder.withDescription("Path to the model directory.").hasArg()
        .withArgName("model directory").create("model"));
    modelGroup.addOption(OptionBuilder.withDescription("Path to the compiled model.").hasArg()
        .withArgName("compiled model").create("cmodel"));
    options.addOption(OptionBuilder.withDescription("The classpath for the analysis.").hasArg()
    options.addOption(OptionBuilder.withDescription("The input code for the analysis.").hasArg()
    options.addOption(OptionBuilder.withDescription("The output directory or file.").hasArg()
    options.addOption(OptionBuilder.withDescription("Propagate through modeled classes.")
    options.addOption("modeledtypesonly"false"Only infer modeled types.");
New to GrepCode? Check out our FAQ X