Example usage for org.apache.commons.cli MissingArgumentException MissingArgumentException

List of usage examples for org.apache.commons.cli MissingArgumentException MissingArgumentException

Introduction

In this page you can find the example usage for org.apache.commons.cli MissingArgumentException MissingArgumentException.

Prototype

public MissingArgumentException(Option option) 

Source Link

Document

Construct a new MissingArgumentException with the specified detail message.

Usage

From source file:com.spectralogic.ds3cli.command.ModifyJob.java

@Override
public CliCommand init(final Arguments args) throws Exception {
    processCommandOptions(requiredArgs, optionalArgs, args);

    this.jobId = args.getId();
    this.jobPriority = args.getPriority();
    this.jobName = args.getOptionValue(JOB_NAME.getLongOpt());
    if (Guard.isStringNullOrEmpty(this.jobName) && this.jobPriority == null) {
        throw new MissingArgumentException(
                "Must set at least one of: " + PRIORITY.getLongOpt() + ", " + JOB_NAME.getLongOpt());
    }/*from  ww w .  j  a  va2s  . co m*/
    return this;
}

From source file:edu.ksu.cis.indus.staticanalyses.dependency.DependencyXMLizerCLI.java

/**
 * This is the entry point via command-line.
 * /*from  w w w . j  a  v  a 2  s .c o  m*/
 * @param args is the command line arguments.
 * @throws RuntimeException when an Throwable exception beyond our control occurs.
 * @pre args != null
 */
public static void main(final String[] args) {
    final Options _options = new Options();
    Option _option = new Option("o", "output", true,
            "Directory into which xml files will be written into.  Defaults to current directory if omitted");
    _option.setArgs(1);
    _option.setArgName("output-directory");
    _options.addOption(_option);
    _option = new Option("j", "jimple", false, "Dump xmlized jimple.");
    _options.addOption(_option);

    final DivergenceDA _fidda = DivergenceDA.getDivergenceDA(IDependencyAnalysis.Direction.FORWARD_DIRECTION);
    _fidda.setConsiderCallSites(true);

    final DivergenceDA _bidda = DivergenceDA.getDivergenceDA(IDependencyAnalysis.Direction.BACKWARD_DIRECTION);
    _bidda.setConsiderCallSites(true);

    final NonTerminationSensitiveEntryControlDA _ncda = new NonTerminationSensitiveEntryControlDA();
    final Object[][] _dasOptions = {
            { "ibdda1", "Identifier based data dependence (Soot)", new IdentifierBasedDataDA() },
            { "ibdda2", "Identifier based data dependence (Indus)", new IdentifierBasedDataDAv2() },
            { "ibdda3", "Identifier based data dependence (Indus Optimized)", new IdentifierBasedDataDAv3() },
            { "rbdda", "Reference based data dependence", new ReferenceBasedDataDA() },
            { "nscda", "Non-termination sensitive Entry control dependence", _ncda },
            { "nicda", "Non-termination insensitive Entry control dependence",
                    new NonTerminationInsensitiveEntryControlDA(), },
            { "xcda", "Exit control dependence", new ExitControlDA() },
            { "sda", "Synchronization dependence", new SynchronizationDA() },
            { "frda1", "Forward Ready dependence v1", ReadyDAv1.getForwardReadyDA() },
            { "brda1", "Backward Ready dependence v1", ReadyDAv1.getBackwardReadyDA() },
            { "frda2", "Forward Ready dependence v2", ReadyDAv2.getForwardReadyDA() },
            { "brda2", "Backward Ready dependence v2", ReadyDAv2.getBackwardReadyDA() },
            { "frda3", "Forward Ready dependence v3", ReadyDAv3.getForwardReadyDA() },
            { "brda3", "Backward Ready dependence v3", ReadyDAv3.getBackwardReadyDA() },
            { "ida1", "Interference dependence v1", new InterferenceDAv1() },
            { "ida2", "Interference dependence v2", new InterferenceDAv2() },
            { "ida3", "Interference dependence v3", new InterferenceDAv3() },
            { "fdda", "Forward Intraprocedural Divergence dependence",
                    DivergenceDA.getDivergenceDA(IDependencyAnalysis.Direction.FORWARD_DIRECTION), },
            { "bdda", "Backward Intraprocedural Divergence dependence",
                    DivergenceDA.getDivergenceDA(IDependencyAnalysis.Direction.BACKWARD_DIRECTION), },
            { "fidda", "Forward Intra+Interprocedural Divergence dependence", _fidda },
            { "bidda", "Backward Intra+Interprocedural Divergence dependence", _bidda },
            { "fpidda", "Forward Interprocedural Divergence dependence",
                    InterProceduralDivergenceDA
                            .getDivergenceDA(IDependencyAnalysis.Direction.FORWARD_DIRECTION), },
            { "bpidda", "Backward Interprocedural Divergence dependence", InterProceduralDivergenceDA
                    .getDivergenceDA(IDependencyAnalysis.Direction.BACKWARD_DIRECTION), }, };
    _option = new Option("h", "help", false, "Display message.");
    _option.setOptionalArg(false);
    _options.addOption(_option);
    _option = new Option("p", "soot-classpath", false, "Prepend this to soot class path.");
    _option.setArgs(1);
    _option.setArgName("classpath");
    _option.setOptionalArg(false);
    _options.addOption(_option);
    _option = new Option("aliasedusedefv1", false, "Use version 1 of aliased use-def info.");
    _options.addOption(_option);
    _option = new Option("safelockanalysis", false, "Use safe-lock-analysis for ready dependence.");
    _options.addOption(_option);
    _option = new Option("ofaforinterference", false, "Use OFA for interference dependence.");
    _options.addOption(_option);
    _option = new Option("ofaforready", false, "Use OFA for ready dependence.");
    _options.addOption(_option);
    _option = new Option("exceptionalexits", false, "Consider exceptional exits for control dependence.");
    _options.addOption(_option);
    _option = new Option("commonuncheckedexceptions", false, "Consider common unchecked exceptions.");
    _options.addOption(_option);
    _option = new Option("S", "scope", true, "The scope that should be analyzed.");
    _option.setArgs(1);
    _option.setArgName("scope");
    _option.setRequired(false);
    _options.addOption(_option);

    for (int _i = 0; _i < _dasOptions.length; _i++) {
        final String _shortOption = _dasOptions[_i][0].toString();
        final String _description = _dasOptions[_i][1].toString();
        _option = new Option(_shortOption, false, _description);
        _options.addOption(_option);
    }

    final CommandLineParser _parser = new GnuParser();

    try {
        final CommandLine _cl = _parser.parse(_options, args);

        if (_cl.hasOption("h")) {
            printUsage(_options);
            System.exit(1);
        }

        final DependencyXMLizerCLI _xmlizerCLI = new DependencyXMLizerCLI();
        String _outputDir = _cl.getOptionValue('o');

        if (_outputDir == null) {
            if (LOGGER.isWarnEnabled()) {
                LOGGER.warn("Defaulting to current directory for output.");
            }
            _outputDir = ".";
        }

        _xmlizerCLI.xmlizer.setXmlOutputDir(_outputDir);

        if (_cl.hasOption('p')) {
            _xmlizerCLI.addToSootClassPath(_cl.getOptionValue('p'));
        }

        if (_cl.hasOption('S')) {
            _xmlizerCLI.setScopeSpecFile(_cl.getOptionValue('S'));
        }

        _xmlizerCLI.dumpJimple = _cl.hasOption('j');
        _xmlizerCLI.useAliasedUseDefv1 = _cl.hasOption("aliasedusedefv1");
        _xmlizerCLI.useSafeLockAnalysis = _cl.hasOption("safelockanalysis");
        _xmlizerCLI.exceptionalExits = _cl.hasOption("exceptionalexits");
        _xmlizerCLI.commonUncheckedException = _cl.hasOption("commonuncheckedexceptions");

        final List<String> _classNames = _cl.getArgList();

        if (_classNames.isEmpty()) {
            throw new MissingArgumentException("Please specify atleast one class.");
        }
        _xmlizerCLI.setClassNames(_classNames);

        final int _exitControlDAIndex = 6;

        if (_cl.hasOption(_dasOptions[_exitControlDAIndex][0].toString())) {
            _xmlizerCLI.das.add(_ncda);

            for (final Iterator<DependenceSort> _i = _ncda.getIds().iterator(); _i.hasNext();) {
                final DependenceSort _id = _i.next();
                MapUtils.putIntoCollectionInMapUsingFactory(_xmlizerCLI.info, _id, _ncda,
                        SetUtils.getFactory());
            }
        }

        if (!parseForDependenceOptions(_dasOptions, _cl, _xmlizerCLI)) {
            throw new ParseException("Atleast one dependence analysis must be requested.");
        }

        _xmlizerCLI.<ITokens>execute();
    } catch (final ParseException _e) {
        LOGGER.error("Error while parsing command line.", _e);
        System.out.println("Error while parsing command line." + _e);
        printUsage(_options);
    } catch (final Throwable _e) {
        LOGGER.error("Beyond our control. May day! May day!", _e);
        throw new RuntimeException(_e);
    }
}

From source file:de.tudarmstadt.lt.n2n.hadoop.FilterByVocabularyJob.java

@Override
public int run(String[] args) throws Exception {
    JobConf conf = new JobConf(getConf(), FilterByVocabularyJob.class);
    conf.setJobName(FilterByVocabularyJob.class.getSimpleName());

    conf.setMapperClass(FilterByVocabularyMapper.class);
    conf.setReducerClass(IdentityReducer.class);

    conf.setInputFormat(KeyValueTextInputFormat.class);
    conf.setOutputFormat(TextOutputFormat.class);

    conf.setOutputKeyClass(Text.class);
    conf.setOutputValueClass(Text.class);

    String word_list_file = conf.get(SHARED_CONSTANTS.PARAM_WORD_LIST);
    if (word_list_file == null)
        throw new MissingArgumentException(
                "Please specify word list with '-Dnlkg.filterbywordsfile=<path-to-file-in-hdfs>'.");

    DistributedCache.addFileToClassPath(new Path(word_list_file), conf);

    FileInputFormat.setInputPaths(conf, new Path(args[0]));
    FileOutputFormat.setOutputPath(conf, new Path(args[1]));

    JobClient.runJob(conf);/*from  w  ww.  j  a va 2s  .c o m*/
    return 0;
}

From source file:com.falcon.orca.handlers.SlaveHandler.java

@Override
public void handle() {
    CommandLine commandLine;//www .j  a v a 2s  .c  o m
    CommandLineParser commandLineParser = new DefaultParser();
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));
    Options options = createSlaveOptions();
    printOnCmd("Welcome to ORCA type help to see what ORCA can do.");
    try {
        String command = br.readLine();
        while (command != null) {
            if (!StringUtils.isEmpty(command)) {
                try {
                    String[] treatedCommandParts = treatCommands(command);
                    commandLine = commandLineParser.parse(options, treatedCommandParts);
                    if (commandLine.hasOption("connect")) {
                        String masterHost;
                        if (commandLine.hasOption("masterHost")) {
                            masterHost = commandLine.getOptionValue("masterHost");
                        } else {
                            throw new MissingArgumentException("Master host is required to connect");
                        }

                        Integer masterPort;
                        if (commandLine.hasOption("masterPort")) {
                            masterPort = Integer.valueOf(commandLine.getOptionValue("masterPort"));
                        } else {
                            throw new MissingArgumentException("Master port is required to connect");
                        }
                        nodeManager = actorSystem.actorOf(NodeManager.props(masterHost, masterPort),
                                "node_manager");
                    } else if (commandLine.hasOption("disconnect")) {
                        if (nodeManager == null || nodeManager.isTerminated()) {
                            printOnCmd("node is not part of any cluster");
                        } else {
                            NodeManagerCommand nodeManagerCommand = new NodeManagerCommand();
                            nodeManagerCommand.setType(NodeManagerCommandType.UNREGISTER_FROM_MASTER);
                            nodeManager.tell(nodeManagerCommand, nodeManager);
                        }
                    } else if (commandLine.hasOption("exit")) {
                        if (nodeManager != null && !nodeManager.isTerminated()) {
                            NodeManagerCommand nodeManagerCommand = new NodeManagerCommand();
                            nodeManagerCommand.setType(NodeManagerCommandType.EXIT);
                            nodeManager.tell(nodeManagerCommand, nodeManager);
                        }
                        actorSystem.shutdown();
                        actorSystem.awaitTermination(new FiniteDuration(1, TimeUnit.MINUTES));
                        break;
                    } else {
                        printOnCmd(printHelpSlaveMode());
                    }
                } catch (ParseException pe) {
                    printOnCmd(printHelpSlaveMode());
                }
            } else {
                printOnCmd("", false);
            }
            command = br.readLine();
        }
    } catch (IOException e) {
        printOnCmd("Failed to read input from command line, please try again.");
    }
}

From source file:com.coprtools.core.CopyrightToolsEngine.java

@Override
public void run() {
    LOGGER.setLevel(Level.SEVERE);
    try {/*  w ww  . ja va2  s .c  o  m*/
        this.cli.parse();

        if (cli.hasOption(OptionConstants.HELP_SHORT)) {
            cli.showUsage();
        } else if (cli.getArguments().length == 0) {
            throw new MissingArgumentException("Missing command!");
        } else {
            String textConsoleCommand = cli.getArguments()[0];

            String rootFolderPath = cli.getOptionValue(OptionConstants.ROOT_SHORT);
            String noticePath = cli.getOptionValue(OptionConstants.NOTICE_SHORT);
            String[] extensions = cli.getOptionValues(OptionConstants.EXTENSION_SHORT);
            String newNotice = null;

            if (cli.hasOption(OptionConstants.NEW_NOTICE_SHORT)
                    && !cli.hasOption(OptionConstants.STRING_SHORT)) {
                String newNoticePath = cli.getOptionValue(OptionConstants.NEW_NOTICE_SHORT);
                File newNoticeFile = new File(newNoticePath);
                newNotice = this.manipulator.readFromFile(newNoticeFile);
            }

            File rootDir = new File(rootFolderPath);
            File destinationFolder = null;

            if (cli.hasOption(OptionConstants.OUTPUT_SHORT)) {
                String destinationPath = cli.getOptionValue(OptionConstants.OUTPUT_SHORT);
                destinationFolder = new File(destinationPath);
                this.manipulator.copyFolder(rootDir, destinationFolder);
                rootDir = destinationFolder;
            }

            // Enables logging and creates a log file in the root path
            if (cli.hasOption(OptionConstants.INFO_LONG)) {
                this.enableLogging(rootDir.getAbsolutePath());
            }

            String notice = null;
            if (cli.hasOption(OptionConstants.STRING_SHORT)) {
                notice = cli.getOptionValue(OptionConstants.NOTICE_SHORT);
                newNotice = cli.getOptionValue(OptionConstants.NEW_NOTICE_SHORT);
            } else {
                File noticeFile = new File(noticePath);
                notice = this.manipulator.readFromFile(noticeFile);
                if (cli.hasOption(OptionConstants.BLANK_SHORT)) {
                    notice = insertBlankSpace(notice);
                }
            }

            CommandType commandType = resolveCommandType(textConsoleCommand);

            AbstractCommand command = commandFactory.create(commandType, notice, extensions, this.manipulator,
                    newNotice);

            command.executeRecursively(rootDir);

            if (!command.isHasError()) {
                writer.writeLine(UserMessagesConstants.SUCCESFULL_OPERATION_MESSAGE);
            } else {
                writer.writeLine(UserMessagesConstants.FAILD_OPERTION_MESSAGE,
                        rootDir.getAbsolutePath() + File.separator + InserterConstants.LOG_FILENAME);
            }
            if (this.fileHandler != null) {
                this.fileHandler.close();
                LOGGER.removeHandler(this.fileHandler);
            }
        }

    } catch (MissingArgumentException e) {
        LOGGER.log(Level.SEVERE, e.getMessage());
    } catch (ArgumentParseException e) {
        LOGGER.log(Level.SEVERE, "Error while parsing arguments: " + e.getMessage());
    } catch (FileNotFoundException e) {
        LOGGER.log(Level.SEVERE, e.getMessage());
    } catch (SecurityException e) {
        LOGGER.log(Level.SEVERE, "Security violation has occurred: " + e.getMessage());
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, e.getMessage());
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Unknown exception: " + e.getClass().getName() + " " + e.getMessage());
    }
}

From source file:com.spectralogic.autogen.cli.CLI.java

private void validateArguments(final Arguments arguments) throws MissingArgumentException {
    if (arguments.isHelp())
        return; // Nothing else to verify
    if (arguments.getTargetDir() == null)
        throw new MissingArgumentException("'-d' is a required argument");
    if (arguments.getType() == null)
        throw new MissingArgumentException("'-l' is a required argument");
    if (arguments.getInputSpec() == null)
        throw new MissingArgumentException("'-i' is a required argument");
}

From source file:com.cloudera.sqoop.cli.SqoopParser.java

@Override
/**/*ww w .  j a va  2  s  .  c om*/
 * Processes arguments to options but only strips matched quotes.
 */
public void processArgs(Option opt, ListIterator iter) throws ParseException {
    // Loop until an option is found.
    while (iter.hasNext()) {
        String str = (String) iter.next();

        if (getOptions().hasOption(str) && str.startsWith("-")) {
            // found an Option, not an argument.
            iter.previous();
            break;
        }

        // Otherwise, this is a value.
        try {
            // Note that we only strip matched quotes here.
            addValForProcessing.invoke(opt, stripMatchedQuotes(str));
        } catch (IllegalAccessException iae) {
            throw new RuntimeException(iae);
        } catch (java.lang.reflect.InvocationTargetException ite) {
            // Any runtime exception thrown within addValForProcessing()
            // will be wrapped in an InvocationTargetException.
            iter.previous();
            break;
        } catch (RuntimeException re) {
            iter.previous();
            break;
        }
    }

    if (opt.getValues() == null && !opt.hasOptionalArg()) {
        throw new MissingArgumentException(opt);
    }
}

From source file:com.spectralogic.ds3contractcomparator.cli.CLI.java

private void validateArguments(final Arguments arguments) throws MissingArgumentException {
    if (arguments.isHelp())
        return; //Nothing else to verify
    if (arguments.getOldApiSpec() == null)
        throw new MissingArgumentException("-o is a required argument");
    if (arguments.getNewApiSpec() == null)
        throw new MissingArgumentException("-n is a required argument");
    if (arguments.getOutputFile() == null)
        throw new MissingArgumentException("-d is a required argument");
}

From source file:com.predic8.membrane.balancer.client.LBNotificationClient.java

private String getArgument(CommandLine cl, int clArgPos, char option, String prop, String def, String errMsg)
        throws Exception {
    if (clArgPos != -1 && cl.getArgs().length > clArgPos) {
        return cl.getArgs()[clArgPos];
    }//  w w w.  j a  v  a2s. c  o  m

    if (option != '-' && cl.hasOption(option)) {
        return cl.getOptionValue(option);
    }

    if (prop != null && new File(propertiesFile).exists()) {
        Properties props = new Properties();
        InputStream is = new FileInputStream(propertiesFile);
        try {
            props.load(is);
        } finally {
            is.close();
        }
        if (props.containsKey(prop)) {
            return props.getProperty(prop);
        }
    }

    if (def != null) {
        return def;
    }

    throw new MissingArgumentException(errMsg);
}

From source file:br.ufpb.dicomflow.integrationAPI.tools.SendService.java

private static void configureService(ServiceIF service, CommandLine cl)
        throws ParseException, JAXBException, ClassNotFoundException {

    Logger.v(rb.getString("start-service-config"));
    if (!cl.hasOption(SERVICE_OPTION))
        throw new MissingArgumentException(rb.getString("missing-content-opt"));

    JAXBContext jaxbContext;/*  w w w  .  ja  va2 s  .c o m*/
    if (cl.hasOption(SERVICE_CLASS_OPTION)) {

        String serviceClass = cl.getOptionValue(SERVICE_CLASS_OPTION);
        jaxbContext = JAXBContext.newInstance(Class.forName(serviceClass));
        Logger.v(rb.getString("jaxb-context") + Class.forName(serviceClass));

    } else {

        jaxbContext = JAXBContext.newInstance(CONTEXT_PATH);
        Logger.v(rb.getString("jaxb-context") + CONTEXT_PATH);

    }

    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();

    service = (ServiceIF) jaxbUnmarshaller.unmarshal(new File(cl.getOptionValue(SERVICE_OPTION)));

    Logger.v(rb.getString("loaded-service") + service.getName() + " - " + service.getAction() + " - "
            + service.getMessageID());

    Logger.v(rb.getString("finish-service-config"));

}