List of usage examples for org.apache.commons.cli CommandLine getOptionProperties
public Properties getOptionProperties(String opt)
From source file:com.facebook.LinkBench.LinkBenchDriver.java
/** * Process command line arguments and set static variables * exits program if invalid arguments provided * @param options/* www .ja va2s . c o m*/ * @param args * @throws ParseException */ private static void processArgs(String[] args) throws ParseException { Options options = initializeOptions(); CommandLine cmd = null; try { CommandLineParser parser = new GnuParser(); cmd = parser.parse(options, args); } catch (ParseException ex) { // Use Apache CLI-provided messages System.err.println(ex.getMessage()); printUsage(options); System.exit(EXIT_BADARGS); } /* * Apache CLI validates arguments, so can now assume * all required options are present, etc */ if (cmd.getArgs().length > 0) { System.err.print("Invalid trailing arguments:"); for (String arg : cmd.getArgs()) { System.err.print(' '); System.err.print(arg); } System.err.println(); printUsage(options); System.exit(EXIT_BADARGS); } // Set static option variables doLoad = cmd.hasOption('l'); doRequest = cmd.hasOption('r'); logFile = cmd.getOptionValue('L'); // May be null configFile = cmd.getOptionValue('c'); if (configFile == null) { // Try to find in usual location String linkBenchHome = ConfigUtil.findLinkBenchHome(); if (linkBenchHome != null) { configFile = linkBenchHome + File.separator + "config" + File.separator + "LinkConfigMysql.properties"; } else { System.err.println("Config file not specified through command " + "line argument and " + ConfigUtil.linkbenchHomeEnvVar + " environment variable not set to valid directory"); printUsage(options); System.exit(EXIT_BADARGS); } } String csvStatsFileName = cmd.getOptionValue("csvstats"); // May be null if (csvStatsFileName != null) { try { csvStatsFile = new PrintStream(new FileOutputStream(csvStatsFileName)); } catch (FileNotFoundException e) { System.err.println("Could not open file " + csvStatsFileName + " for writing"); printUsage(options); System.exit(EXIT_BADARGS); } } String csvStreamFileName = cmd.getOptionValue("csvstream"); // May be null if (csvStreamFileName != null) { try { csvStreamFile = new PrintStream(new FileOutputStream(csvStreamFileName)); // File is written to by multiple threads, first write header SampledStats.writeCSVHeader(csvStreamFile); } catch (FileNotFoundException e) { System.err.println("Could not open file " + csvStreamFileName + " for writing"); printUsage(options); System.exit(EXIT_BADARGS); } } cmdLineProps = cmd.getOptionProperties("D"); if (!(doLoad || doRequest)) { System.err.println("Did not select benchmark mode"); printUsage(options); System.exit(EXIT_BADARGS); } }
From source file:com.github.dakusui.symfonion.CLI.java
public void analyze(CommandLine cmd) throws CLIException { if (cmd.hasOption('O')) { String optionName = "O"; this.midiouts = initializeMidiPorts(cmd, optionName); }//from ww w .jav a2 s . c o m if (cmd.hasOption('I')) { String optionName = "I"; this.midiins = initializeMidiPorts(cmd, optionName); } if (cmd.hasOption('o')) { String sinkFilename = getSingleOptionValue(cmd, "o"); if (sinkFilename == null) { String msg = composeErrMsg("Output filename is required by this option.", "o", null); throw new CLIException(msg); } this.sink = new File(sinkFilename); } if (cmd.hasOption("V") || cmd.hasOption("version")) { this.mode = Mode.VERSION; } else if (cmd.hasOption("h") || cmd.hasOption("help")) { this.mode = Mode.HELP; } else if (cmd.hasOption("l") || cmd.hasOption("list")) { this.mode = Mode.LIST; } else if (cmd.hasOption("p") || cmd.hasOption("play")) { this.mode = Mode.PLAY; String sourceFilename = getSingleOptionValue(cmd, "p"); if (sourceFilename == null) { String msg = composeErrMsg("Input filename is required by this option.", "p", null); throw new CLIException(msg); } this.source = new File(sourceFilename); } else if (cmd.hasOption("c") || cmd.hasOption("compile")) { this.mode = Mode.COMPILE; String sourceFilename = getSingleOptionValue(cmd, "c"); if (sourceFilename == null) { String msg = composeErrMsg("Input filename is required by this option.", "c", null); throw new CLIException(msg); } this.source = new File(sourceFilename); } else if (cmd.hasOption("r") || cmd.hasOption("route")) { this.mode = Mode.ROUTE; Properties props = cmd.getOptionProperties("r"); if (props.size() != 1) { String msg = composeErrMsg("Route information is not given or specified multiple times.", "r", "route"); throw new CLIException(msg); } this.route = new Route(cmd.getOptionValues('r')[0], cmd.getOptionValues('r')[1]); } else { @SuppressWarnings("unchecked") List<String> leftovers = cmd.getArgList(); if (leftovers.size() == 0) { this.mode = Mode.HELP; } else if (leftovers.size() == 1) { this.mode = Mode.PLAY; this.source = new File(leftovers.get(0)); } else { String msg = composeErrMsg( String.format("Unrecognized arguments:%s", leftovers.subList(2, leftovers.size())), "-", null); throw new CLIException(msg); } } }
From source file:com.facebook.LinkBench.LinkBenchDriverInj.java
/** * Process command line arguments and set static variables * exits program if invalid arguments provided * @param options/*from w w w. j a v a 2 s .c om*/ * @param args * @throws ParseException */ private static void processArgs(String[] args) throws ParseException { Options options = initializeOptions(); CommandLine cmd = null; try { CommandLineParser parser = new GnuParser(); cmd = parser.parse(options, args); } catch (ParseException ex) { // Use Apache CLI-provided messages System.err.println(ex.getMessage()); printUsage(options); System.exit(EXIT_BADARGS); } /* * Apache CLI validates arguments, so can now assume * all required options are present, etc */ if (cmd.getArgs().length > 0) { System.err.print("Invalid trailing arguments:"); for (String arg : cmd.getArgs()) { System.err.print(' '); System.err.print(arg); } System.err.println(); printUsage(options); System.exit(EXIT_BADARGS); } // Set static option variables doLoad = cmd.hasOption('l'); doRequest = cmd.hasOption('r'); logFile = cmd.getOptionValue('L'); // May be null configFile = cmd.getOptionValue('c'); if (configFile == null) { // Try to find in usual location String linkBenchHome = ConfigUtil.findLinkBenchHome(); if (linkBenchHome != null) { configFile = linkBenchHome + File.separator + "config" + File.separator + "LinkConfigMysql.properties"; } else { System.err.println("Config file not specified through command " + "line argument and " + ConfigUtil.linkbenchHomeEnvVar + " environment variable not set to valid directory"); printUsage(options); System.exit(EXIT_BADARGS); } } String csvStatsFileName = cmd.getOptionValue("csvstats"); // May be null if (csvStatsFileName != null) { try { csvStatsFile = new PrintStream(new FileOutputStream(csvStatsFileName)); } catch (FileNotFoundException e) { System.err.println("Could not open file " + csvStatsFileName + " for writing"); printUsage(options); System.exit(EXIT_BADARGS); } } String csvStreamFileName = cmd.getOptionValue("csvstream"); // May be null if (csvStreamFileName != null) { try { csvStreamFile = new PrintStream(new FileOutputStream(csvStreamFileName)); // File is written to by multiple threads, first write header GlobalStats.writeCSVHeader(csvStreamFile); } catch (FileNotFoundException e) { System.err.println("Could not open file " + csvStreamFileName + " for writing"); printUsage(options); System.exit(EXIT_BADARGS); } } cmdLineProps = cmd.getOptionProperties("D"); if (!(doLoad || doRequest)) { System.err.println("Did not select benchmark mode"); printUsage(options); System.exit(EXIT_BADARGS); } }
From source file:com.aravind.flazr.android.rtmp.client.ClientOptions.java
public boolean parseCli(final String[] args) { CommandLineParser parser = new GnuParser(); CommandLine line = null; final Options options = getCliOptions(); try {// www . j a v a2 s . co m line = parser.parse(options, args); if (line.hasOption("help") || line.getArgs().length == 0) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("client [options] name [saveAs | fileToPublish]" + "\n(name can be stream name, URL or load testing script file)", options); return false; } if (line.hasOption("host")) { host = line.getOptionValue("host"); } if (line.hasOption("port")) { port = Integer.valueOf(line.getOptionValue("port")); } if (line.hasOption("app")) { appName = line.getOptionValue("app"); } if (line.hasOption("start")) { start = Integer.valueOf(line.getOptionValue("start")); } if (line.hasOption("length")) { length = Integer.valueOf(line.getOptionValue("length")); } if (line.hasOption("buffer")) { buffer = Integer.valueOf(line.getOptionValue("buffer")); } if (line.hasOption("rtmpe")) { rtmpe = true; } if (line.hasOption("live")) { publishLive(); } if (line.hasOption("record")) { publishRecord(); } if (line.hasOption("append")) { publishAppend(); } if (line.hasOption("version")) { clientVersionToUse = Utils.fromHex(line.getOptionValue("version")); if (clientVersionToUse.length != 4) { throw new RuntimeException("client version to use has to be 4 bytes long"); } } if (line.hasOption("D")) { // TODO integers, TODO extra args for 'play' command params = new HashMap(line.getOptionProperties("D")); } if (line.hasOption("load")) { load = Integer.valueOf(line.getOptionValue("load")); if (publishType != null && load > 1) { throw new RuntimeException("cannot publish in load testing mode"); } } if (line.hasOption("threads")) { threads = Integer.valueOf(line.getOptionValue("threads")); } if (line.hasOption("loop")) { loop = Integer.valueOf(line.getOptionValue("loop")); if (publishType == null && loop > 1) { throw new RuntimeException("cannot loop when not in publish mode"); } } } catch (Exception e) { System.err.println("parsing failed: " + e.getMessage()); return false; } String[] actualArgs = line.getArgs(); if (line.hasOption("file")) { String fileName = actualArgs[0]; File file = new File(fileName); if (!file.exists()) { throw new RuntimeException("file does not exist: '" + fileName + "'"); } logger.info("parsing file: {}", file); try { FileInputStream fis = new FileInputStream(file); BufferedReader reader = new BufferedReader(new InputStreamReader(fis)); int i = 0; String s; clientOptionsList = new ArrayList<ClientOptions>(); while ((s = reader.readLine()) != null) { i++; logger.debug("parsing line {}: {}", i, s); String[] tempArgs = s.split("\\s"); ClientOptions tempOptions = new ClientOptions(); if (!tempOptions.parseCli(tempArgs)) { throw new RuntimeException("aborting, parsing failed at line " + i); } clientOptionsList.add(tempOptions); } reader.close(); fis.close(); } catch (Exception e) { throw new RuntimeException(e); } } else { Matcher matcher = URL_PATTERN.matcher(actualArgs[0]); if (matcher.matches()) { parseUrl(actualArgs[0]); } else { streamName = actualArgs[0]; } } if (publishType != null) { if (actualArgs.length < 2) { System.err.println("fileToPublish is required for publish mode"); return false; } fileToPublish = actualArgs[1]; } else if (actualArgs.length > 1) { saveAs = actualArgs[1]; } logger.info("options: {}", this); return true; }
From source file:cmd.ArgumentHandler.java
/** * Parses the options in the command line arguments and returns an array of * strings corresponding to the filenames given as arguments only * * @param args// w ww. j a v a 2 s . c om * @throws org.apache.commons.cli.ParseException */ @SuppressWarnings("static-access") public void parseCommandLineOptions(String[] args) throws ParseException { options = new Options(); options.addOption("h", "help", false, "Help page for command usage"); options.addOption("s", false, "SubStructure detection"); options.addOption("a", false, "Add Hydrogen"); options.addOption("x", false, "Match Atom Type"); options.addOption("r", false, "Remove Hydrogen"); options.addOption("z", false, "Ring matching"); options.addOption("b", false, "Match Bond types (Single, Double etc)"); options.addOption( OptionBuilder.hasArg().withDescription("Query filename").withArgName("filepath").create("q")); options.addOption( OptionBuilder.hasArg().withDescription("Target filename").withArgName("filepath").create("t")); options.addOption(OptionBuilder.hasArg().withDescription("Add suffix to the files").withArgName("suffix") .create("S")); options.addOption("g", false, "create png of the mapping"); options.addOption(OptionBuilder.hasArg().withDescription("Dimension of the image in pixels") .withArgName("WIDTHxHEIGHT").create("d")); options.addOption("m", false, "Report all Mappings"); String filterDescr = "Default: 0, Stereo: 1, " + "Stereo+Fragment: 2, Stereo+Fragment+Energy: 3"; options.addOption(OptionBuilder.hasArg().withDescription(filterDescr).withArgName("number").create("f")); options.addOption("A", false, "Appends output to existing files, else creates new files"); options.addOption(OptionBuilder.withDescription("Do N-way MCS on the target SD file").create("N")); options.addOption(OptionBuilder.hasArg().withDescription("Query type (MOL, SMI, etc)").withArgName("type") .create("Q")); options.addOption(OptionBuilder.hasArg().withDescription("Target type (MOL, SMI, SMIF, etc)") .withArgName("type").create("T")); options.addOption(OptionBuilder.hasArg().withDescription("Output the substructure to a file") .withArgName("filename").create("o")); options.addOption( OptionBuilder.hasArg().withDescription("Output type (SMI, MOL)").withArgName("type").create("O")); options.addOption(OptionBuilder.hasOptionalArgs(2).withValueSeparator().withDescription("Image options") .withArgName("option=value").create("I")); PosixParser parser = new PosixParser(); CommandLine line = parser.parse(options, args, true); if (line.hasOption('Q')) { queryType = line.getOptionValue("Q"); } //else { // queryType = "MOL"; // } //XXX default type? if (line.hasOption('T')) { targetType = line.getOptionValue("T"); } else { targetType = "MOL"; } if (line.hasOption('a')) { this.setApplyHAdding(true); } if (line.hasOption('r')) { this.setApplyHRemoval(true); } if (line.hasOption('m')) { this.setAllMapping(true); } if (line.hasOption('s')) { this.setSubstructureMode(true); } if (line.hasOption('g')) { this.setImage(true); } if (line.hasOption('b')) { this.setMatchBondType(true); } if (line.hasOption('z')) { this.setMatchRingType(true); } if (line.hasOption('x')) { this.setMatchAtomType(true); } remainingArgs = line.getArgs(); if (line.hasOption('h') || line.getOptions().length == 0) { // System.out.println("Hello"); helpRequested = true; } if (line.hasOption('S')) { String[] suffix_reader = line.getOptionValues('S'); if (suffix_reader.length < 1) { System.out.println("Suffix required!"); helpRequested = true; } setSuffix(suffix_reader[0]); setApplySuffix(true); } if (line.hasOption('f')) { String[] filters = line.getOptionValues('f'); if (filters.length < 1) { System.out.println("Chemical filter required (Ranges: 0 to 3)!"); helpRequested = true; } setChemFilter((int) new Integer(filters[0])); } if (line.hasOption('q')) { queryFilepath = line.getOptionValue('q'); } if (line.hasOption('t')) { targetFilepath = line.getOptionValue('t'); } if (line.hasOption("A")) { this.setAppendMode(true); } if (line.hasOption("N")) { setNMCS(true); } if (line.hasOption("o")) { outputSubgraph = true; outputFilepath = line.getOptionValue("o"); } if (line.hasOption("O")) { outputFiletype = line.getOptionValue("O"); } else { outputFiletype = "MOL"; } if (line.hasOption("d")) { String dimensionString = line.getOptionValue("d"); if (dimensionString.contains("x")) { String[] parts = dimensionString.split("x"); try { setImageWidth(Integer.parseInt(parts[0])); setImageHeight(Integer.parseInt(parts[1])); System.out.println("set image dim to " + getImageWidth() + "x" + getImageHeight()); } catch (NumberFormatException nfe) { throw new ParseException("Malformed dimension string " + dimensionString); } } else { throw new ParseException("Malformed dimension string " + dimensionString); } } if (line.hasOption("I")) { imageProperties = line.getOptionProperties("I"); if (imageProperties.isEmpty()) { // used just "-I" by itself isImageOptionHelp = true; } } }
From source file:be.ugent.intec.halvade.HalvadeOptions.java
protected boolean parseArguments(String[] args, Configuration halvadeConf) throws ParseException { createOptions();/*from w w w.j a v a2 s . co m*/ CommandLineParser parser = new GnuParser(); CommandLine line = parser.parse(options, args); in = line.getOptionValue("I"); out = line.getOptionValue("O"); if (!out.endsWith("/")) out += "/"; ref = line.getOptionValue("R"); sites = line.getOptionValue("D"); halvadeBinaries = line.getOptionValue("B"); hdfsSites = sites.split(","); if (line.hasOption("bam")) { useBamInput = true; } if (line.hasOption("rna")) { rnaPipeline = true; if (line.hasOption("star")) STARGenome = line.getOptionValue("star"); if (!useBamInput && STARGenome == null) { throw new ParseException( "the '-rna' option requires --star pointing to the location of the STAR reference directory if alignment with STAR aligner is required (fastq)."); } } if (line.hasOption("tmp")) { tmpDir = line.getOptionValue("tmp"); } if (line.hasOption("stargtf")) { stargtf = line.getOptionValue("stargtf"); } if (line.hasOption("refdir")) { localRefDir = line.getOptionValue("refdir"); if (!localRefDir.endsWith("/")) localRefDir += "/"; } if (line.hasOption("nodes")) { nodes = Integer.parseInt(line.getOptionValue("nodes")); } if (line.hasOption("vcores")) { vcores = Integer.parseInt(line.getOptionValue("vcores")); } if (line.hasOption("smt")) { smtEnabled = true; } if (line.hasOption("remove_dups")) { keepDups = false; } if (line.hasOption("mem")) { mem = Double.parseDouble(line.getOptionValue("mem")); } if (line.hasOption("rpr")) { readCountsPerRegionFile = line.getOptionValue("rpr"); } if (line.hasOption("mpn")) { setMapContainers = false; mapContainersPerNode = Integer.parseInt(line.getOptionValue("mpn")); } if (line.hasOption("rpn")) { setReduceContainers = false; reducerContainersPerNode = Integer.parseInt(line.getOptionValue("rpn")); } if (line.hasOption("mapmem")) { overrideMapMem = (int) (Double.parseDouble(line.getOptionValue("mapmem")) * 1024); } if (line.hasOption("redmem")) { overrideRedMem = (int) (Double.parseDouble(line.getOptionValue("redmem")) * 1024); } if (line.hasOption("scc")) { stand_call_conf = Integer.parseInt(line.getOptionValue("scc")); } if (line.hasOption("sec")) { stand_emit_conf = Integer.parseInt(line.getOptionValue("sec")); } if (line.hasOption("count")) { countOnly = true; } if (line.hasOption("report_all")) { reportAll = true; } if (line.hasOption("illumina")) { fixQualEnc = true; } if (line.hasOption("keep")) { keepFiles = true; } if (line.hasOption("update_rg")) { updateRG = true; } if (line.hasOption("redistribute")) { redistribute = true; } if (line.hasOption("single")) { paired = false; } if (line.hasOption("justalign")) { justAlign = true; combineVcf = false; } if (line.hasOption("aln")) { aln = Integer.parseInt(line.getOptionValue("aln")); if (aln < 0 || aln > 3) aln = 0; // default value } if (line.hasOption("J")) { java = line.getOptionValue("J"); } if (line.hasOption("gff")) { gff = line.getOptionValue("gff"); } if (line.hasOption("dryrun")) { dryRun = true; combineVcf = false; } if (line.hasOption("drop")) { keepChrSplitPairs = false; } // if (line.hasOption("cov")) { // coverage = Double.parseDouble(line.getOptionValue("cov")); // } if (line.hasOption("merge_bam")) { mergeBam = true; } if (line.hasOption("c")) { justCombine = true; combineVcf = true; } if (line.hasOption("filter_dbsnp")) { filterDBSnp = true; } if (line.hasOption("reorder_regions")) { reorderRegions = true; } if (line.hasOption("haplotypecaller")) { useGenotyper = false; } if (line.hasOption("elprep")) { useElPrep = true; } if (line.hasOption("id")) { RGID = line.getOptionValue("id"); } if (line.hasOption("lb")) { RGLB = line.getOptionValue("lb"); } if (line.hasOption("pl")) { RGPL = line.getOptionValue("pl"); } if (line.hasOption("pu")) { RGPU = line.getOptionValue("pu"); } if (line.hasOption("sm")) { RGSM = line.getOptionValue("sm"); } if (line.hasOption("bed")) { bedFile = line.getOptionValue("bed"); } if (line.hasOption("fbed")) { filterBed = line.getOptionValue("fbed"); } if (line.hasOption("v")) { Logger.SETLEVEL(Integer.parseInt(line.getOptionValue("v"))); } if (line.hasOption("CA")) { Properties props = line.getOptionProperties("CA"); Enumeration names = props.propertyNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); addCustomArguments(halvadeConf, name, props.getProperty(name)); } } return true; }
From source file:neurord.StochDiff.java
public static void main(String[] argv) throws Exception { File modelFile, outputFile;/*from ww w . ja v a 2 s .c o m*/ CommandLineParser parser = new DefaultParser(); Options options = buildOptions(); List<String> args = Arrays.asList(argv); boolean help_requested = args.contains("-h") || args.contains("--help"); if (help_requested || argv.length == 0) help_exit(options, !help_requested); CommandLine cmd = parser.parse(options, argv); Settings.augmentProperties(cmd.getOptionProperties("D")); if (cmd.hasOption("version")) { System.out.println(Settings.getProgramVersion()); System.exit(0); } final int verbose = Settings.optionCount(cmd, argv, "verbose", "v"); if (verbose > 0) { Level level = verbose == 1 ? Level.INFO : Level.DEBUG; Logging.setLogLevel(null, LogManager.ROOT_LOGGER_NAME, level); } Logging.configureConsoleLogging(); argv = cmd.getArgs(); if (argv.length == 0) { log.fatal("at least one argument is required"); System.exit(1); } modelFile = new File(argv[0]); if (!modelFile.exists()) { log.fatal("no such file: {}", modelFile); System.exit(2); } final File unsuffixed; if (argv[0].indexOf(".") > 0) unsuffixed = new File(argv[0].substring(0, argv[0].lastIndexOf("."))); else unsuffixed = new File(argv[0]); if (argv.length > 1) { if (argv[1].endsWith(".h5") || argv[1].endsWith(".txt") || argv[1].endsWith(".log")) outputFile = new File(argv[1].substring(0, argv[1].lastIndexOf("."))); else outputFile = new File(argv[1]); if (outputFile.isDirectory()) outputFile = new File(outputFile, unsuffixed.getName()); } else outputFile = unsuffixed; final String logfile = cmd.getOptionValue("log", outputFile + ".log"); Logging.configureFileLogging(logfile); /* Write out the version, after creating the log appenders. */ log.info("{}", Settings.getProgramVersion()); if (!logfile.equals("no")) log.info("Writing logs to {}", logfile); final File ic_file = Settings.getOption(cmd, "ic", null); final int ic_trial = Settings.getOption(cmd, "ic-trial", 0); final double ic_time = Settings.getOption(cmd, "ic-time", Double.NaN); SDRun model = null; try { model = SDRun.loadFromFile(modelFile, ic_file, ic_trial, ic_time); } catch (XMLUnmarshallingFailure e) { System.exit(2); } double runtime = Settings.getOption(cmd, "runtime", Double.NaN); if (!Double.isNaN(runtime)) model.overrideRuntime(runtime); String statistics = cmd.getOptionValue("statistics"); if (statistics != null) { Double interval = null; String[] parts = statistics.split(":", 2); if (parts.length > 1) { statistics = parts[0]; interval = Double.valueOf(parts[1]); } model.overrideStatistics(statistics, interval); } SDCalc calc = new SDCalc(model, outputFile); int ret = calc.run(); CustomFileAppender.close(); System.exit(ret); }
From source file:org.agiso.tempel.starter.Bootstrap.java
@Override public void run(String... args) throws Exception { // Konfiguracja opcji i parsowanie argumentw: Options options = configureTempelOptions(); // Parsowanie parametrw wejciowych: CommandLine cmd = parseTempelCommandArgs(options, args); // Wywietlanie pomocy dla wywoania z parametrem 'help': if (cmd.hasOption('h')) { printTempelHelp(options);/*from ww w . ja v a2s. co m*/ System.exit(0); } // Okrelanie katalogu roboczego i katalogu repozytorium: String workDir = determineWorkDir(cmd); // Pobieranie nazwy szablonu do wykonania: String templateName; if (cmd.getArgList().size() != 1) { System.err.println("Incorrect params. Use \"tpl --help\" for help."); System.exit(-1); } templateName = String.valueOf(cmd.getArgList().get(0)); // Budowanie mapy parametrw dodatkowych (okrelanych przez -Dkey=value): Map<String, String> params = new HashMap<String, String>(); Properties properties = cmd.getOptionProperties("D"); Enumeration<?> propertiesEnumeration = properties.propertyNames(); while (propertiesEnumeration.hasMoreElements()) { String key = (String) propertiesEnumeration.nextElement(); params.put(key, properties.getProperty(key)); } // Uruchamianie generatora dla okrelonego szablonu: starterLogger.info(Logs.LOG_01, ansiString(GREEN, templateName)); try { if (PARAM_READER != null) { tempel.setParamReader(PARAM_READER); } tempel.startTemplate(templateName, params, workDir); starterLogger.info(Logs.LOG_02, ansiString(GREEN, templateName)); } catch (Exception e) { starterLogger.error(e, Logs.LOG_06, ansiString(RED, e.getMessage())); System.exit(-4); } }
From source file:org.apache.easyant.core.EasyAntMain.java
/** * Process command line arguments. When ant is started from Launcher, launcher-only arguments do not get passed * through to this routine.//from ww w .j a v a 2 s. c o m * * @since Ant 1.6 */ private void processArgs(CommandLine line) { String searchForThis; PrintStream logTo = null; if (line.hasOption("help")) { printUsage(); return; } if (easyAntConfiguration.getMsgOutputLevel() >= Project.MSG_VERBOSE || line.hasOption("version")) { printVersion(); if (line.hasOption("version")) { return; } } if (line.hasOption("showMemoryDetails")) { easyAntConfiguration.setShowMemoryDetails(true); } if (line.hasOption("diagnostics")) { Diagnostics.doReport(System.out, easyAntConfiguration.getMsgOutputLevel()); return; } if (line.hasOption("quiet")) { easyAntConfiguration.setMsgOutputLevel(Project.MSG_WARN); } if (line.hasOption("verbose")) { easyAntConfiguration.setMsgOutputLevel(Project.MSG_VERBOSE); } if (line.hasOption("debug")) { easyAntConfiguration.setMsgOutputLevel(Project.MSG_DEBUG); } if (line.hasOption("noinput")) { easyAntConfiguration.setAllowInput(false); } if (line.hasOption("logfile")) { try { File logFile = new File(line.getOptionValue("logfile")); logTo = new PrintStream(new FileOutputStream(logFile)); isLogFileUsed = true; } catch (IOException ioe) { String msg = "Cannot write on the specified log file. " + "Make sure the path exists and you have write " + "permissions."; throw new BuildException(msg); } catch (ArrayIndexOutOfBoundsException aioobe) { String msg = "You must specify a log file when " + "using the -log argument"; throw new BuildException(msg); } } if (line.hasOption("buildmodule")) { File buildModule = new File(line.getOptionValue("buildmodule").replace('/', File.separatorChar)); easyAntConfiguration.setBuildModule(buildModule); } if (line.hasOption("buildfile")) { File buildFile = new File(line.getOptionValue("buildfile").replace('/', File.separatorChar)); easyAntConfiguration.setBuildFile(buildFile); } if (line.hasOption("buildconf")) { easyAntConfiguration.getActiveBuildConfigurations().add(line.getOptionValue("buildconf")); } File easyantConfFile = null; if (line.hasOption("configfile")) { easyantConfFile = new File(line.getOptionValue("configfile").replace('/', File.separatorChar)); } else { // if no command line switch is specified check the default location File easyantHome = new File( System.getProperty(EasyAntMagicNames.EASYANT_HOME).replace('/', File.separatorChar)); File defaultGlobalEasyantConfFile = new File(easyantHome, EasyAntConstants.DEFAULT_GLOBAL_EASYANT_CONF_FILE); if (defaultGlobalEasyantConfFile.exists()) { easyantConfFile = defaultGlobalEasyantConfFile; } } if (easyantConfFile != null) { try { easyAntConfiguration = EasyantConfigurationFactory.getInstance() .createConfigurationFromFile(easyAntConfiguration, easyantConfFile.toURI().toURL()); } catch (Exception e) { throw new BuildException(e); } } if (line.hasOption("listener")) { easyAntConfiguration.getListeners().add(line.getOptionValue("listener")); } if (line.hasOption("D")) { easyAntConfiguration.getDefinedProps().putAll(line.getOptionProperties("D")); } if (line.hasOption("logger")) { if (easyAntConfiguration.getLoggerClassname() != null) { throw new BuildException("Only one logger class may be specified."); } easyAntConfiguration.setLoggerClassname(line.getOptionValue("logger")); } if (line.hasOption("inputhandler")) { if (easyAntConfiguration.getInputHandlerClassname() != null) { throw new BuildException("Only one input handler class may " + "be specified."); } easyAntConfiguration.setInputHandlerClassname(line.getOptionValue("inputhandler")); } if (line.hasOption("emacs")) { easyAntConfiguration.setEmacsMode(true); } if (line.hasOption("projecthelp")) { // set the flag to display the targets and quit projectHelp = true; } if (line.hasOption("find")) { // eat up next arg if present, default to module.ivy if (line.getOptionValues("find").length > 0) { searchForThis = line.getOptionValue("find"); } else { searchForThis = EasyAntConstants.DEFAULT_BUILD_MODULE; } easyAntConfiguration.setBuildModule(new File(searchForThis)); easyAntConfiguration.setBuildModuleLookupEnabled(true); } if (line.hasOption("propertyfile")) { propertyFiles.add(line.getOptionValue("propertyfile")); } if (line.hasOption("keep-going")) { easyAntConfiguration.setKeepGoingMode(true); } if (line.hasOption("offline")) { easyAntConfiguration.setOffline(true); } if (line.hasOption("nice")) { easyAntConfiguration.setThreadPriority(Integer.decode(line.getOptionValue("nice"))); if (easyAntConfiguration.getThreadPriority() < Thread.MIN_PRIORITY || easyAntConfiguration.getThreadPriority() > Thread.MAX_PRIORITY) { throw new BuildException("Niceness value is out of the range 1-10"); } } if (line.hasOption("autoproxy")) { easyAntConfiguration.setProxy(true); } if (!line.getArgList().isEmpty()) { for (Object o : line.getArgList()) { String target = (String) o; easyAntConfiguration.getTargets().add(target); } } // Load the property files specified by -propertyfile loadPropertyFiles(); if (logTo != null) { easyAntConfiguration.setOut(logTo); easyAntConfiguration.setErr(logTo); System.setOut(easyAntConfiguration.getOut()); System.setErr(easyAntConfiguration.getErr()); } readyToRun = true; }
From source file:org.apache.flink.container.entrypoint.StandaloneJobClusterConfigurationParserFactory.java
@Override public StandaloneJobClusterConfiguration createResult(@Nonnull CommandLine commandLine) { final String configDir = commandLine.getOptionValue(CONFIG_DIR_OPTION.getOpt()); final Properties dynamicProperties = commandLine.getOptionProperties(DYNAMIC_PROPERTY_OPTION.getOpt()); final String restPortString = commandLine.getOptionValue(REST_PORT_OPTION.getOpt(), "-1"); final int restPort = Integer.parseInt(restPortString); final String hostname = commandLine.getOptionValue(HOST_OPTION.getOpt()); final String jobClassName = commandLine.getOptionValue(JOB_CLASS_NAME_OPTION.getOpt()); final SavepointRestoreSettings savepointRestoreSettings = CliFrontendParser .createSavepointRestoreSettings(commandLine); return new StandaloneJobClusterConfiguration(configDir, dynamicProperties, commandLine.getArgs(), hostname, restPort, jobClassName, savepointRestoreSettings); }