List of usage examples for org.apache.commons.cli ParseException ParseException
public ParseException(String message)
ParseException
with the specified detail message. From source file:com.archivas.clienttools.arcmover.cli.ManagedCLIJob.java
private ManagedJobImpl getManagedJobImplFromCmdLine(CommandLine cmdLine, String whichCmd) throws ParseException, DatabaseException, JobException { JobId reRunJobID = null;// w ww.ja va2 s .co m String jobName = cmdLine.getOptionValue(whichCmd); // If no option was provided get the last job run if (jobName == null) { // Get the last jobID try { reRunJobID = getLastJobID(); } catch (NumberFormatException e) { throw new ParseException( "Last job not found. Either no jobs have been run or the job was deleted."); } if (reRunJobID == null) { throw new ParseException("Error determining the last job run."); } } else { List<ManagedJobSummary> jobList = arcMover.getAllManagedJobs(); for (ManagedJobSummary job : jobList) { if (job.getJobName().equals(jobName)) { if (!job.getJobType().equals(getJobType())) { throw new ParseException( "Job name: " + jobName + " provided is not of type " + getJobType().getUiName()); } reRunJobID = job.getJobId(); break; } } if (reRunJobID == null) { throw new ParseException("Job name not found in job list."); } } return arcMover.loadManagedJob(reRunJobID, getJobType()); }
From source file:gov.nih.nci.ncicb.tcga.dcc.QCLiveTestDataGenerator.java
/** * Main entry point for the application. Configures the Spring context and calls the {@link QCLiveTestDataGenerator} * bean to load and generate test data for a specific archive name. * //from w w w .ja v a 2 s. co m * @param args - list of arguments to be passed to the {@link QCLiveTestDataGenerator} bean */ public static void main(final String[] args) { // Display help if no arguments are provided, otherwise parse the arguments if (args.length == 0) displayHelp(); else { try { // Parse the command line arguments final CommandLine commandLine = new GnuParser().parse(CommandLineOptionType.getOptions(), args); // If the command line instance contains the -? (--help) option display help, otherwise call the QCLiveTestDataGenerator // to process the command line arguments if (commandLine.hasOption(CommandLineOptionType.HELP.name().toLowerCase())) { displayHelp(); } else { final String archiveNameOption = CommandLineOptionType.ARCHIVE_NAME.getOptionValue().getOpt(); final String sqlScriptFileOption = CommandLineOptionType.SQL_SCRIPT_FILE.getOptionValue() .getOpt(); final String schemaOption = CommandLineOptionType.SCHEMA.getOptionValue().getOpt(); // Initialize the Spring context final ApplicationContext appCtx = new ClassPathXmlApplicationContext(APP_CONTEXT_FILE_NAME); // Retrieve the QCLiveTestDataGenerator from the Spring context final QCLiveTestDataGenerator qcLiveTestDataGenerator = (QCLiveTestDataGenerator) appCtx .getBean("qcLiveTestDataGenerator"); // Get the archive name from the command line argument(s) (if provided) and generate the test data if (commandLine.hasOption(archiveNameOption)) { qcLiveTestDataGenerator.generateTestData(commandLine.getOptionValue(archiveNameOption)); } // If the SQL script file and schema options are provided, execute the script if (commandLine.hasOption(sqlScriptFileOption)) { if (commandLine.hasOption(schemaOption)) { // Try to resolve the schema type from the provided schema name. If it cannot be resolved, throw an exception that // indicates the supported schema types final String schemaOptionValue = commandLine.getOptionValue(schemaOption); SchemaType schemaTpye = null; try { schemaTpye = SchemaType.valueOf(schemaOptionValue.toUpperCase()); } catch (IllegalArgumentException iae) { throw new ParseException("Could not resolve schema name '" + schemaOptionValue + "' to a supported schema type " + "when attempting to execute SQL script file '" + commandLine.getOptionValue(sqlScriptFileOption) + "'. " + "Supported types are '" + SchemaType.getSupportedSchemaTypes() + "'"); } qcLiveTestDataGenerator.executeSQLScriptFile(schemaTpye, new FileSystemResource(commandLine.getOptionValue(sqlScriptFileOption))); } else throw new ParseException( "Setting the -f (or -sql_script_file) option also requires the -s (or -schema) to be set."); } } } catch (ParseException pe) { System.err.println("\nParsing failed. Reason: " + pe.getMessage()); displayHelp(); } catch (IOException ioe) { logger.error(ioe.getMessage()); } catch (SQLException sqle) { logger.error(sqle.getMessage()); } } }
From source file:be.ugent.intec.halvade.HalvadeOptions.java
protected void addCustomArguments(Configuration halvadeConf, String name, String property) throws ParseException { boolean found = false; int i = 0;/*from w ww. java 2s . c o m*/ while (!found && i < programNames.length) { if (name.equalsIgnoreCase(programNames[i])) { found = true; } i++; } if (found) { String[] split = name.split("_"); String program = split[0]; String tool = ""; if (split.length > 1) { tool = split[1]; } HalvadeConf.setCustomArgs(halvadeConf, program, tool, property); Logger.DEBUG("Custom arguments for " + name + ": \"" + property + "\""); } else { Logger.DEBUG("Unknown program: " + name + ", custom arguments [" + property + "] ignored"); throw new ParseException("Program " + name + " not found, please use a valid name."); } }
From source file:de.clusteval.serverclient.BackendClient.java
/** * This method is responsible for creating all the appender that are added * to the logger./* w w w .ja v a2s . com*/ * <p> * Three appenders are created: * <ul> * <li><b>ConsoleAppender</b>: Writes the logging output to the standard out * </li> * <li><b>FileAppender</b>: Writes the logging output as formatter text to * the file clustevalClient.log</li> * <li><b>FileAppender</b>: Writes the logging output in lilith binary * format to the file clustevalClient.lilith</li> * </ul> * * @param cmd * The command line parameters including possible options of * logging * @throws ParseException */ private static void initLogging(CommandLine cmd) throws ParseException { Logger log = LoggerFactory.getLogger(BackendClient.class); Level logLevel; if (cmd.hasOption("logLevel")) { switch (Integer.parseInt(cmd.getOptionValue("logLevel"))) { case 0: logLevel = Level.ALL; break; case 1: logLevel = Level.TRACE; break; case 2: logLevel = Level.DEBUG; break; case 3: logLevel = Level.INFO; break; case 4: logLevel = Level.WARN; break; case 5: logLevel = Level.ERROR; break; case 6: logLevel = Level.OFF; break; default: throw new ParseException("The logLevel argument requires one of the value of [0,1,2,3,4,5,6]"); } } else { logLevel = Level.INFO; } ch.qos.logback.classic.Logger logger = ((ch.qos.logback.classic.Logger) LoggerFactory .getLogger(Logger.ROOT_LOGGER_NAME)); logger.setLevel(logLevel); // file appender for clustevalServer.log plaintext file FileAppender<ILoggingEvent> fileApp = new FileAppender<ILoggingEvent>(); fileApp.setName("clientLogFile"); String logFilePath = FileUtils.buildPath(System.getProperty("user.dir"), "clustevalClient.log"); fileApp.setFile(logFilePath); fileApp.setAppend(true); fileApp.setContext((LoggerContext) LoggerFactory.getILoggerFactory()); fileApp.setEncoder(new PatternLayoutEncoder()); PatternLayout layout = new PatternLayout(); layout.setPattern("%date{dd MMM yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{35} - %msg%n"); layout.setContext((LoggerContext) LoggerFactory.getILoggerFactory()); layout.start(); fileApp.setLayout(layout); fileApp.start(); logger.addAppender(fileApp); // file appender for clustevalServer.lilith binary file // removed 30.01.2013 // FileAppender fileAppLilith = new FileAppender(); // fileAppLilith.setName("clientLogFileLilith"); // logFilePath = FileUtils.buildPath(System.getProperty("user.dir"), // "clustevalClient.lilith"); // fileAppLilith.setFile(logFilePath); // // fileAppLilith.setAppend(true); // fileAppLilith.setContext((LoggerContext) LoggerFactory // .getILoggerFactory()); // ClassicLilithEncoder encoder = new ClassicLilithEncoder(); // encoder.setIncludeCallerData(true); // fileAppLilith.setEncoder(encoder); // // fileAppLilith.start(); // logger.addAppender(fileAppLilith); log.debug("Using log level " + logLevel); }
From source file:com.symbian.driver.core.environment.TDConfig.java
/** * @param aKey/*from w w w . ja v a2 s . c o m*/ * @param aUri * @throws ParseException */ public void setPreferenceURI(final int aKey, URI aUri) throws ParseException { if (aKey != ENTRY_POINT_ADDRESS) { throw new ParseException("This preference " + aKey + " cannot use the setPreferenceURI() method. It must be of type " + URI.class); } setPreference(aKey, aUri.toString()); }
From source file:com.symbian.driver.core.environment.TDConfig.java
/** * @param aKey/* w ww. j a v a 2 s . c o m*/ * @return The preference as a URI. * @throws ParseException */ public URI getPreferenceURI(final int aKey) throws ParseException { if (aKey != ENTRY_POINT_ADDRESS) { throw new ParseException("This preference " + aKey + " cannot use the getPreferenceURI() method. It must be of type " + URI.class); } return URI.createURI(getPreference(aKey)); }
From source file:com.symbian.driver.core.environment.TDConfig.java
/** * @return The Test Execute (TEF) dependencies. * @throws ParseException//w w w . j av a 2s . co m */ public Map<String, String> getTEFOptionalDependencies() throws ParseException { Map<String, String> lOptionalDeps = new HashMap<String, String>(); try { String[] lTefOptDepsList = TEF_DEPENDENCIES_OPT_EKA2.split(";"); // optional dependencies is separated by ";" and each has // a [Filename]\t[Condition] format String lFileStr = null; String lConditionStr = null; for (String lTefOptDepStr : lTefOptDepsList) { lFileStr = lTefOptDepStr.split("\t")[0]; lConditionStr = lTefOptDepStr.split("\t")[1]; lOptionalDeps.put(lFileStr, lConditionStr); } } catch (Exception e) { throw new ParseException("Incorrect TEF optional dependencies describing format!"); } return lOptionalDeps; }
From source file:nl.knaw.huygens.timbuctoo.tools.other.SearchResultTool.java
private static Date getThreshold(String value) throws ParseException { Date threshold = null;//www .ja va2 s .co m if (!"all".equals(value)) { threshold = UTCUtils.stringToDate(value); if (threshold == null) { String message = String.format("Use ISO date format, e.g. '%s', or 'all'", UTCUtils.now()); throw new ParseException(message); } } return threshold; }
From source file:nl.systemsgenetics.cellTypeSpecificAlleleSpecificExpression.MainEntryPoint.java
public static void main(String... args) throws Exception { //Required Arguments String outputLocation = new String(); //ASreads specific arguments String bamFile = new String(); String couplingLocation = new String(); String genotypeLocation = new String(); String snpsLocation = new String(); String regionLocation = new String(); //BINOMTEST and BETABINOMTEST specific arguments String asFile = new String(); //Cell type specific locations String phenoTypeLocation = new String(); try {//from ww w . jav a 2 s . com CommandLineParser parser = new PosixParser(); final CommandLine commandLine = parser.parse(OPTIONS, args, true); try { //Read outputLocation if (commandLine.hasOption('O')) { outputLocation = commandLine.getOptionValue('O'); } else { throw new ParseException("Required command line input: --output "); } // Optional arguments that are not passed to the Entry constructors // But are saved in the GlobalVariables class. if (commandLine.hasOption("minimum_hets")) { GlobalVariables.minHets = Integer.parseInt(commandLine.getOptionValue("minimum_hets")); //Check if this is bigger than 0, otherwise exit if (GlobalVariables.minHets <= 0) { throw new IllegalDataException( "Minimum Number of hets cannot be smaller than one for AS testing\n" + "Exitting"); } } if (commandLine.hasOption("minimum_reads")) { GlobalVariables.minReads = Integer.parseInt(commandLine.getOptionValue("minimum_reads")); //Check if this is bigger than 0, otherwise exit if (GlobalVariables.minReads <= 0) { throw new IllegalDataException( "Minimum Number of reads cannot be smaller than one for AS testing\n" + "Exitting"); } } if (commandLine.hasOption('A')) { String programAction = commandLine.getOptionValue('A').toUpperCase(); if (programAction.equals("ASREADS") || programAction.equals("1")) { //Do the AS determination part of the program //read genotype from options if (commandLine.hasOption('G')) { genotypeLocation = commandLine.getOptionValue('G'); } else { throw new ParseException( "Required command line input --genotype_location when --action is ASreads"); } //Read binomTest arguments if (commandLine.hasOption('C')) { couplingLocation = commandLine.getOptionValue('C'); } else { throw new ParseException( "Required command line input --coupling_file when --action is ASreads"); } if (commandLine.hasOption('B')) { bamFile = commandLine.getOptionValue('B'); } else { throw new ParseException( "Required command line input --bam_file when --action is ASreads"); } if (commandLine.hasOption("snp_list")) { snpsLocation = commandLine.getOptionValue("snp_list"); } else { snpsLocation = ""; } /* START reading for AS reads. */ readGenoAndAsFromIndividual(bamFile, genotypeLocation, couplingLocation, outputLocation, snpsLocation); } else if (programAction.equals("ASEPERSNP") || programAction.equals("2")) { if (commandLine.hasOption('L')) { asFile = commandLine.getOptionValue('L'); } else { throw new ParseException( "Required command line input --as_location when --action is ASEperSNP"); } if (commandLine.hasOption('P')) { phenoTypeLocation = commandLine.getOptionValue('P'); } else { phenoTypeLocation = null; } /* START BINOMIAL CELL TYPE SPECIFIC TEST */ NonPhasedEntry a = new NonPhasedEntry(asFile, phenoTypeLocation, outputLocation); } else if (programAction.equals("ASEPERREGION") || programAction.equals("3")) { if (commandLine.hasOption('L')) { asFile = commandLine.getOptionValue('L'); } else { throw new ParseException( "Required command line input --as_location when --action is ASEperRegion"); } if (commandLine.hasOption('C')) { couplingLocation = commandLine.getOptionValue('C'); } else { throw new ParseException( "Required command line input --coupling_file when --action is ASEperRegion"); } if (commandLine.hasOption('P')) { phenoTypeLocation = commandLine.getOptionValue('P'); } else { phenoTypeLocation = null; } if (commandLine.hasOption('G')) { genotypeLocation = commandLine.getOptionValue('G'); } else { throw new ParseException( "Required command line input --genotype_Location when --action is ASEperRegion"); } if (commandLine.hasOption('R')) { regionLocation = commandLine.getOptionValue('R'); } else { throw new ParseException( "Required command line input --region_file when --action is ASEperRegion"); } PhasedEntry a = new PhasedEntry(asFile, couplingLocation, outputLocation, phenoTypeLocation, genotypeLocation, regionLocation); } else { throw new ParseException( "Unable to determine what to do. Please specify a correct value to --Action"); } } } catch (ParseException ex) { LOGGER.fatal("Invalid command line arguments"); LOGGER.fatal(ex.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(" ", OPTIONS); } } catch (ParseException ex) { LOGGER.fatal("Invalid command line arguments: "); LOGGER.fatal(ex.getMessage()); System.err.println(); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(" ", OPTIONS); } }
From source file:org.apache.accumulo.core.util.shell.commands.FateCommand.java
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws ParseException, KeeperException, InterruptedException, IOException { Instance instance = shellState.getInstance(); String[] args = cl.getArgs(); if (args.length <= 0) { throw new ParseException("Must provide a command to execute"); }// www . ja va 2s .com String cmd = args[0]; boolean failedCommand = false; AdminUtil<FateCommand> admin = new AdminUtil<FateCommand>(false); String path = ZooUtil.getRoot(instance) + Constants.ZFATE; String masterPath = ZooUtil.getRoot(instance) + Constants.ZMASTER_LOCK; IZooReaderWriter zk = getZooReaderWriter(shellState.getInstance(), cl.getOptionValue(secretOption.getOpt())); ZooStore<FateCommand> zs = new ZooStore<FateCommand>(path, zk); if ("fail".equals(cmd)) { if (args.length <= 1) { throw new ParseException("Must provide transaction ID"); } for (int i = 1; i < args.length; i++) { if (!admin.prepFail(zs, zk, masterPath, args[i])) { System.out.printf("Could not fail transaction: %s%n", args[i]); failedCommand = true; } } } else if ("delete".equals(cmd)) { if (args.length <= 1) { throw new ParseException("Must provide transaction ID"); } for (int i = 1; i < args.length; i++) { if (admin.prepDelete(zs, zk, masterPath, args[i])) { admin.deleteLocks(zs, zk, ZooUtil.getRoot(instance) + Constants.ZTABLE_LOCKS, args[i]); } else { System.out.printf("Could not delete transaction: %s%n", args[i]); failedCommand = true; } } } else if ("list".equals(cmd) || "print".equals(cmd)) { // Parse transaction ID filters for print display Set<Long> filterTxid = null; if (args.length >= 2) { filterTxid = new HashSet<Long>(args.length); for (int i = 1; i < args.length; i++) { try { Long val = Long.parseLong(args[i], 16); filterTxid.add(val); } catch (NumberFormatException nfe) { // Failed to parse, will exit instead of displaying everything since the intention was to potentially filter some data System.out.printf("Invalid transaction ID format: %s%n", args[i]); return 1; } } } // Parse TStatus filters for print display EnumSet<TStatus> filterStatus = null; if (cl.hasOption(statusOption.getOpt())) { filterStatus = EnumSet.noneOf(TStatus.class); String[] tstat = cl.getOptionValues(statusOption.getOpt()); for (int i = 0; i < tstat.length; i++) { try { filterStatus.add(TStatus.valueOf(tstat[i])); } catch (IllegalArgumentException iae) { System.out.printf("Invalid transaction status name: %s%n", tstat[i]); return 1; } } } StringBuilder buf = new StringBuilder(8096); Formatter fmt = new Formatter(buf); admin.print(zs, zk, ZooUtil.getRoot(instance) + Constants.ZTABLE_LOCKS, fmt, filterTxid, filterStatus); shellState.printLines(Collections.singletonList(buf.toString()).iterator(), true); } else { throw new ParseException("Invalid command option"); } return failedCommand ? 1 : 0; }