List of usage examples for org.apache.commons.cli DefaultParser DefaultParser
DefaultParser
From source file:com.github.sdnwiselab.sdnwise.mote.standalone.Loader.java
/** * @param args the command line arguments *///from w w w .ja v a 2 s . c om public static void main(final String[] args) { Options options = new Options(); options.addOption(Option.builder("n").argName("net").hasArg().required().desc("Network ID of the node") .numberOfArgs(1).build()); options.addOption(Option.builder("a").argName("address").hasArg().required() .desc("Address of the node <0-65535>").numberOfArgs(1).build()); options.addOption(Option.builder("p").argName("port").hasArg().required().desc("Listening UDP port") .numberOfArgs(1).build()); options.addOption(Option.builder("t").argName("filename").hasArg().required() .desc("Use given file for neighbors discovery").numberOfArgs(1).build()); options.addOption(Option.builder("c").argName("ip:port").hasArg() .desc("IP address and TCP port of the controller. (SINK ONLY)").numberOfArgs(1).build()); options.addOption(Option.builder("sp").argName("port").hasArg() .desc("Port number of the switch. (SINK ONLY)").numberOfArgs(1).build()); options.addOption(Option.builder("sm").argName("mac").hasArg() .desc("MAC address of the switch. Example: <00:00:00:00:00:00>." + " (SINK ONLY)").numberOfArgs(1) .build()); options.addOption(Option.builder("sd").argName("dpid").hasArg().desc("DPID of the switch (SINK ONLY)") .numberOfArgs(1).build()); options.addOption(Option.builder("l").argName("level").hasArg() .desc("Use given log level. Values: SEVERE, WARNING, INFO, " + "CONFIG, FINE, FINER, FINEST.") .numberOfArgs(1).optionalArg(true).build()); // create the parser CommandLineParser parser = new DefaultParser(); try { CommandLine line = parser.parse(options, args); Thread th; byte cmdNet = (byte) Integer.parseInt(line.getOptionValue("n")); NodeAddress cmdAddress = new NodeAddress(Integer.parseInt(line.getOptionValue("a"))); int cmdPort = Integer.parseInt(line.getOptionValue("p")); String cmdTopo = line.getOptionValue("t"); String cmdLevel; if (!line.hasOption("l")) { cmdLevel = "SEVERE"; } else { cmdLevel = line.getOptionValue("l"); } if (line.hasOption("c")) { if (!line.hasOption("sd")) { throw new ParseException("-sd option missing"); } if (!line.hasOption("sp")) { throw new ParseException("-sp option missing"); } if (!line.hasOption("sm")) { throw new ParseException("-sm option missing"); } String cmdSDpid = line.getOptionValue("sd"); String cmdSMac = line.getOptionValue("sm"); long cmdSPort = Long.parseLong(line.getOptionValue("sp")); String[] ipport = line.getOptionValue("c").split(":"); th = new Thread(new Sink(cmdNet, cmdAddress, cmdPort, new InetSocketAddress(ipport[0], Integer.parseInt(ipport[1])), cmdTopo, cmdLevel, cmdSDpid, cmdSMac, cmdSPort)); } else { th = new Thread(new Mote(cmdNet, cmdAddress, cmdPort, cmdTopo, cmdLevel)); } th.start(); th.join(); } catch (InterruptedException | ParseException ex) { System.out.println("Parsing failed. Reason: " + ex.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("sdn-wise-data -n id -a address -p port" + " -t filename [-l level] [-sd dpid -sm mac -sp port]", options); } }
From source file:ch.epfl.leb.sass.commandline.CommandLineInterface.java
/** * Shows help, launches the interpreter and executes scripts according to input args. * @param args input arguments/*from ww w. j av a2 s.c o m*/ */ public static void main(String args[]) { // parse input arguments CommandLineParser parser = new DefaultParser(); CommandLine line = null; try { line = parser.parse(options, args); } catch (ParseException ex) { System.err.println("Parsing of arguments failed. Reason: " + ex.getMessage()); System.err.println("Use -help for usage."); System.exit(1); } // decide how do we make the interpreter available based on options Interpreter interpreter = null; // show help and exit if (line.hasOption("help")) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("java -jar <jar-name>", options, true); System.exit(0); // launch interpreter inside current terminal } else if (line.hasOption("interpreter")) { // assign in, out and err streams to the interpreter interpreter = new Interpreter(new InputStreamReader(System.in), System.out, System.err, true); interpreter.setShowResults(true); // if a script was given, execute it before giving access to user if (line.hasOption("script")) { try { interpreter.source(line.getOptionValue("script")); } catch (IOException ex) { Logger.getLogger(BeanShellConsole.class.getName()).log(Level.SEVERE, "IOException while executing shell script.", ex); } catch (EvalError ex) { Logger.getLogger(BeanShellConsole.class.getName()).log(Level.SEVERE, "EvalError while executing shell script.", ex); } } // give access to user new Thread(interpreter).start(); // only execute script and exit } else if (line.hasOption("script")) { interpreter = new Interpreter(); try { interpreter.source(line.getOptionValue("script")); System.exit(0); } catch (IOException ex) { Logger.getLogger(BeanShellConsole.class.getName()).log(Level.SEVERE, "IOException while executing shell script.", ex); System.exit(1); } catch (EvalError ex) { Logger.getLogger(BeanShellConsole.class.getName()).log(Level.SEVERE, "EvalError while executing shell script.", ex); System.exit(1); } // Launches the RPC server with the model contained in the file whose // filename was passed by argument. } else if (line.hasOption("rpc_server")) { IJPluginModel model = new IJPluginModel(); File file = new File(line.getOptionValue("rpc_server")); try { FileInputStream stream = new FileInputStream(file); model = IJPluginModel.read(stream); } catch (FileNotFoundException ex) { System.out.println("Error: " + file.getName() + " not found."); System.exit(1); } catch (Exception ex) { ex.printStackTrace(); } // Check whether a port number was specified. if (line.hasOption("port")) { try { port = Integer.valueOf(line.getOptionValue("port")); System.out.println("Using port: " + String.valueOf(port)); } catch (java.lang.NumberFormatException ex) { System.out.println("Error: the port number argument is not a number."); System.exit(1); } } else { System.out.println("No port number provided. Using default port: " + String.valueOf(port)); } RPCServer server = new RPCServer(model, port); System.out.println("Starting RPC server..."); server.serve(); } else if (line.hasOption("port") & !line.hasOption("rpc_server")) { System.out.println("Error: Port number provided without requesting the RPC server. Exiting..."); System.exit(1); // if System.console() returns null, it means we were launched by // double-clicking the .jar, so launch own BeanShellConsole // if System.console() returns null, it means we were launched by // double-clicking the .jar, so launch own ConsoleFrame } else if (System.console() == null) { BeanShellConsole cframe = new BeanShellConsole("SASS BeanShell Prompt"); interpreter = cframe.getInterpreter(); cframe.setVisible(true); System.setOut(cframe.getInterpreter().getOut()); System.setErr(cframe.getInterpreter().getErr()); new Thread(cframe.getInterpreter()).start(); // otherwise, show help } else { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("java -jar <jar-name>", options, true); System.exit(0); } if (interpreter != null) { printWelcomeText(interpreter.getOut()); } }
From source file:com.bialx.ebics.FDL.java
public static void main(String[] args) throws Exception { String userId = ""; Boolean isTest = false;/*from w w w . jav a 2 s. c om*/ Date startDate = null; Date endDate = null; SimpleDateFormat dtFormat = new SimpleDateFormat("yyyyMMdd"); CommandLineParser parser = new DefaultParser(); BialxOptions options = new BialxOptions(); // Parse the program arguments CommandLine commandLine = parser.parse(options, args); // optional values if (commandLine.hasOption('s')) { startDate = dtFormat.parse(commandLine.getOptionValue('s')); } if (commandLine.hasOption('e')) { endDate = dtFormat.parse(commandLine.getOptionValue('e')); } if (commandLine.hasOption('t')) { isTest = true; } FDL fdl; PasswordCallback pwdHandler; Product product; fdl = new FDL(); pwdHandler = new UserPasswordHandler(userId, CERT_PASSWORD); product = new Product("Bial-x EBICS FDL", Locale.FRANCE, null); if (commandLine.hasOption(BialxOptions.OPTION_CREATION) && !commandLine.hasOption(BialxOptions.OPTION_DOWNLOAD)) { if (options.checkCreationOptions(commandLine)) { CreationOptions co = options.loadCreationOptions(commandLine); fdl.configuration.getLogger().info(String.format("Banque : %s", co.getBankName())); fdl.configuration.getLogger().info(String.format("Host : %s", co.getHostId())); fdl.configuration.getLogger().info(String.format("URL : %s", co.getBankUrl())); fdl.configuration.getLogger().info(String.format("Partner : %s", co.getPartnerId())); fdl.configuration.getLogger().info(String.format("User : %s", co.getUserId())); User user = fdl.createUser(co.getUserId(), co.getHostId(), co.getPartnerId(), co.getBankName(), co.getBankUrl(), pwdHandler); fdl.sendHPBRequest(user, product); } else { fdl.configuration.getLogger().info("Vrifiez les paramtres de la commande."); System.exit(0); } } if (!commandLine.hasOption(BialxOptions.OPTION_CREATION) && commandLine.hasOption(BialxOptions.OPTION_DOWNLOAD)) { if (options.checkDownloadOptions(commandLine)) { DownloadOptions dop = options.loadDownloadOptions(commandLine); fdl.configuration.getLogger().info(String.format("Banque : %s", dop.getHostId())); fdl.configuration.getLogger().info(String.format("Host : %s", dop.getHostId())); fdl.configuration.getLogger().info(String.format("Partner : %s", dop.getPartnerId())); fdl.configuration.getLogger().info(String.format("User : %s", dop.getUserId())); fdl.configuration.getLogger().info(String.format("Format : %s", dop.getFormat())); fdl.configuration.getLogger().info(String.format("Destination : %s", dop.getDestination())); if (startDate != null) { fdl.configuration.getLogger() .info(String.format("Date dbut : %s", dtFormat.format(startDate))); } if (endDate != null) { fdl.configuration.getLogger().info(String.format("Date fin : %s", dtFormat.format(endDate))); } fdl.loadUser(dop.getHostId(), dop.getPartnerId(), dop.getUserId(), pwdHandler); fdl.fetchFile(dop.getDestination(), dop.getUserId(), dop.getFormat(), product, OrderType.FDL, isTest, startDate, endDate); } else { fdl.configuration.getLogger().info("Vrifiez les paramtres de la commande."); System.exit(0); } } if (commandLine.hasOption(BialxOptions.OPTION_DOWNLOAD) && commandLine.hasOption(BialxOptions.OPTION_CREATION)) { fdl.configuration.getLogger().error("Impossible d'avoir les options C et D dans la mme commande."); System.exit(0); } fdl.quit(); }
From source file:com.quanticate.opensource.pdftkbox.PDFtkBox.java
public static void main(String[] args) throws Exception { // For printing help Options optsHelp = new Options(); optsHelp.addOption(Option.builder("help").required().desc("print this message").build()); // Normal-style import/export Options optsNormal = new Options(); OptionGroup normal = new OptionGroup(); Option optExport = Option.builder("export").required().hasArg().desc("export bookmarks from pdf") .argName("source-pdf").build(); normal.addOption(optExport);/*from w w w . j a v a 2 s . co m*/ Option optImport = Option.builder("import").required().hasArg().desc("import bookmarks into pdf") .argName("source-pdf").build(); normal.addOption(optImport); optsNormal.addOptionGroup(normal); Option optBookmarks = Option.builder("bookmarks").hasArg().desc("bookmarks definition file") .argName("bookmarks").build(); optsNormal.addOption(optBookmarks); Option optOutput = Option.builder("output").hasArg().desc("output to new pdf").argName("pdf").build(); optsNormal.addOption(optOutput); // PDFtk style options Options optsPDFtk = new Options(); OptionGroup pdftk = new OptionGroup(); Option optDumpData = Option.builder("dump_data").required().desc("dump bookmarks from pdf").build(); pdftk.addOption(optDumpData); Option optUpdateInfo = Option.builder("update_info").required().hasArg().desc("update bookmarks in pdf") .argName("bookmarks").build(); pdftk.addOption(optUpdateInfo); optsPDFtk.addOptionGroup(pdftk); optsPDFtk.addOption(optOutput); // What are we doing? CommandLineParser parser = new DefaultParser(); // Did they want help? try { parser.parse(optsHelp, args); // If we get here, they asked for help doPrintHelp(optsHelp, optsNormal, optsPDFtk); return; } catch (ParseException pe) { } // Normal-style import/export? try { CommandLine line = parser.parse(optsNormal, args); // Export if (line.hasOption(optExport.getOpt())) { doExport(line.getOptionValue(optExport.getOpt()), line.getOptionValue(optBookmarks.getOpt()), line.getArgs()); return; } // Import with explicit output filename if (line.hasOption(optImport.getOpt()) && line.hasOption(optOutput.getOpt())) { doImport(line.getOptionValue(optImport.getOpt()), line.getOptionValue(optBookmarks.getOpt()), line.getOptionValue(optOutput.getOpt()), null); return; } // Import with implicit output filename if (line.hasOption(optImport.getOpt()) && line.getArgs().length > 0) { doImport(line.getOptionValue(optImport.getOpt()), line.getOptionValue(optBookmarks.getOpt()), null, line.getArgs()); return; } } catch (ParseException pe) { } // PDFtk-style if (args.length > 1) { // Nobble things for PDFtk-style options and Commons CLI for (int i = 1; i < args.length; i++) { for (Option opt : optsPDFtk.getOptions()) { if (args[i].equals(opt.getOpt())) { args[i] = "-" + args[i]; } } } try { // Input file comes first, then arguments String input = args[0]; String[] pargs = new String[args.length - 1]; System.arraycopy(args, 1, pargs, 0, pargs.length); // Parse what's left and check CommandLine line = parser.parse(optsPDFtk, pargs); if (line.hasOption(optDumpData.getOpt())) { doExport(input, line.getOptionValue(optOutput.getOpt()), line.getArgs()); return; } if (line.hasOption(optUpdateInfo.getOpt())) { doImport(input, line.getOptionValue(optUpdateInfo.getOpt()), line.getOptionValue(optOutput.getOpt()), line.getArgs()); return; } } catch (ParseException pe) { } } // If in doubt, print help doPrintHelp(optsHelp, optsNormal, optsPDFtk); }
From source file:com.github.s4ke.moar.cli.Main.java
public static void main(String[] args) throws ParseException, IOException { // create Options object Options options = new Options(); options.addOption("rf", true, "file containing the regexes to test against (multiple regexes are separated by one empty line)"); options.addOption("r", true, "regex to test against"); options.addOption("mf", true, "file/folder to read the MOA from"); options.addOption("mo", true, "folder to export the MOAs to (overwrites if existent)"); options.addOption("sf", true, "file to read the input string(s) from"); options.addOption("s", true, "string to test the MOA/Regex against"); options.addOption("m", false, "multiline matching mode (search in string for regex)"); options.addOption("ls", false, "treat every line of the input string file as one string"); options.addOption("t", false, "trim lines if -ls is set"); options.addOption("d", false, "only do determinism check"); options.addOption("help", false, "prints this dialog"); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); if (args.length == 0 || cmd.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("moar-cli", options); return;/*from ww w.ja va2 s .com*/ } List<String> patternNames = new ArrayList<>(); List<MoaPattern> patterns = new ArrayList<>(); List<String> stringsToCheck = new ArrayList<>(); if (cmd.hasOption("r")) { String regexStr = cmd.getOptionValue("r"); try { patterns.add(MoaPattern.compile(regexStr)); patternNames.add(regexStr); } catch (Exception e) { System.out.println(e.getMessage()); } } if (cmd.hasOption("rf")) { String fileName = cmd.getOptionValue("rf"); List<String> regexFileContents = readFileContents(new File(fileName)); int emptyLineCountAfterRegex = 0; StringBuilder regexStr = new StringBuilder(); for (String line : regexFileContents) { if (emptyLineCountAfterRegex >= 1) { if (regexStr.length() > 0) { patterns.add(MoaPattern.compile(regexStr.toString())); patternNames.add(regexStr.toString()); } regexStr.setLength(0); emptyLineCountAfterRegex = 0; } if (line.trim().equals("")) { if (regexStr.length() > 0) { ++emptyLineCountAfterRegex; } } else { regexStr.append(line); } } if (regexStr.length() > 0) { try { patterns.add(MoaPattern.compile(regexStr.toString())); patternNames.add(regexStr.toString()); } catch (Exception e) { System.out.println(e.getMessage()); return; } regexStr.setLength(0); } } if (cmd.hasOption("mf")) { String fileName = cmd.getOptionValue("mf"); File file = new File(fileName); if (file.isDirectory()) { System.out.println(fileName + " is a directory, using all *.moar files as patterns"); File[] moarFiles = file.listFiles(pathname -> pathname.getName().endsWith(".moar")); for (File moar : moarFiles) { String jsonString = readWholeFile(moar); patterns.add(MoarJSONSerializer.fromJSON(jsonString)); patternNames.add(moar.getAbsolutePath()); } } else { System.out.println(fileName + " is a single file. using it directly (no check for *.moar suffix)"); String jsonString = readWholeFile(file); patterns.add(MoarJSONSerializer.fromJSON(jsonString)); patternNames.add(fileName); } } if (cmd.hasOption("s")) { String str = cmd.getOptionValue("s"); stringsToCheck.add(str); } if (cmd.hasOption("sf")) { boolean treatLineAsString = cmd.hasOption("ls"); boolean trim = cmd.hasOption("t"); String fileName = cmd.getOptionValue("sf"); StringBuilder stringBuilder = new StringBuilder(); boolean firstLine = true; for (String str : readFileContents(new File(fileName))) { if (treatLineAsString) { if (trim) { str = str.trim(); if (str.length() == 0) { continue; } } stringsToCheck.add(str); } else { if (!firstLine) { stringBuilder.append("\n"); } if (firstLine) { firstLine = false; } stringBuilder.append(str); } } if (!treatLineAsString) { stringsToCheck.add(stringBuilder.toString()); } } if (cmd.hasOption("d")) { //at this point we have already built the Patterns //so just give the user a short note. System.out.println("All Regexes seem to be deterministic."); return; } if (patterns.size() == 0) { System.out.println("no patterns to check"); return; } if (cmd.hasOption("mo")) { String folder = cmd.getOptionValue("mo"); File folderFile = new File(folder); if (!folderFile.exists()) { System.out.println(folder + " does not exist. creating..."); if (!folderFile.mkdirs()) { System.out.println("folder " + folder + " could not be created"); } } int cnt = 0; for (MoaPattern pattern : patterns) { String patternAsJSON = MoarJSONSerializer.toJSON(pattern); try (BufferedWriter writer = new BufferedWriter( new FileWriter(new File(folderFile, "pattern" + ++cnt + ".moar")))) { writer.write(patternAsJSON); } } System.out.println("stored " + cnt + " patterns in " + folder); } if (stringsToCheck.size() == 0) { System.out.println("no strings to check"); return; } boolean multiline = cmd.hasOption("m"); for (String string : stringsToCheck) { int curPattern = 0; for (MoaPattern pattern : patterns) { MoaMatcher matcher = pattern.matcher(string); if (!multiline) { if (matcher.matches()) { System.out.println("\"" + patternNames.get(curPattern) + "\" matches \"" + string + "\""); } else { System.out.println( "\"" + patternNames.get(curPattern) + "\" does not match \"" + string + "\""); } } else { StringBuilder buffer = new StringBuilder(string); int additionalCharsPerMatch = ("<match>" + "</match>").length(); int matchCount = 0; while (matcher.nextMatch()) { buffer.replace(matcher.getStart() + matchCount * additionalCharsPerMatch, matcher.getEnd() + matchCount * additionalCharsPerMatch, "<match>" + string.substring(matcher.getStart(), matcher.getEnd()) + "</match>"); ++matchCount; } System.out.println(buffer.toString()); } } ++curPattern; } }
From source file:de.unirostock.sems.caro.CaRo.java
/** * The main method to be called by the command line. * /* w w w . j a v a 2 s . com*/ * @param args * the arguments */ public static void main(String[] args) { Options options = new Options(); options.addOption(new Option("h", "help", false, "print the help message")); options.addOption( Option.builder().longOpt("roca").desc("convert a research object into a combine archive").build()); options.addOption( Option.builder().longOpt("caro").desc("convert a combine archive into a research object").build()); options.addOption(Option.builder("i").longOpt("in").required().argName("FILE").hasArg() .desc("source container to be converted").build()); options.addOption(Option.builder("o").longOpt("out").required().argName("FILE").hasArg() .desc("target container to be created").build()); CommandLineParser parser = new DefaultParser(); CommandLine line = null; try { line = parser.parse(options, args); if (line.hasOption("help")) { help(options, null); return; } } catch (ParseException e) { help(options, "Parsing of command line options failed. Reason: " + e.getMessage()); return; } File in = new File(line.getOptionValue("in")); File out = new File(line.getOptionValue("out")); if (!in.exists()) { help(options, "file " + in + " does not exist"); return; } if (out.exists()) { help(options, "file " + out + " already exist"); return; } if (line.hasOption("caro") && line.hasOption("roca")) { help(options, "only one of --roca and --caro is allowed"); return; } CaRoConverter conv = null; if (line.hasOption("caro")) conv = new CaToRo(in); else if (line.hasOption("roca")) conv = new RoToCa(in); else { help(options, "you need to either supply --roca or --caro"); return; } conv.convertTo(out); if (conv.hasErrors()) System.err.println("There were errors!"); if (conv.hasWarnings()) System.err.println("There were warnings!"); List<CaRoNotification> notifications = conv.getNotifications(); for (CaRoNotification note : notifications) System.out.println(note); }
From source file:androidimporter.AndroidImporter.java
public static void main(String[] args) throws ParseException { //"/usr/local/apache-ant/bin/ant" String antPath = System.getProperty("ANT_PATH", System.getenv("ANT_PATH")); if (antPath == null || !new File(antPath).exists()) { throw new RuntimeException("Cannot find ant at " + antPath + ". Please specify location to ant via the ANT_PATH environment variable or java system property."); }/* ww w . ja v a 2 s . c o m*/ Options opts = new Options() .addOption("i", "android-resource-dir", true, "Android project res directory path") .addOption("o", "cn1-project-dir", true, "Path to the CN1 output project directory.") .addOption("r", "cn1-resource-file", false, "Path to CN1 output .res file. Defaults to theme.res in project dir") .addOption("p", "package", true, "Java package to place GUI forms in.") .addOption("h", "help", false, "Usage instructions"); CommandLineParser parser = new DefaultParser(); CommandLine line = parser.parse(opts, args); if (line.hasOption("help")) { showHelp(opts); System.exit(0); } args = line.getArgs(); if (args.length < 1) { System.out.println("No command provided."); showHelp(opts); System.exit(0); } switch (args[0]) { case "import-project": { if (!line.hasOption("android-resource-dir") || !line.hasOption("cn1-project-dir") || !line.hasOption("package")) { System.out.println("Please provide android-resource-dir, package, and cn1-project-dir options"); showHelp(opts); System.exit(1); } File resDir = findResDir(new File(line.getOptionValue("android-resource-dir"))); if (resDir == null || !resDir.isDirectory()) { System.out.println("Failed to find android resource directory from provided value"); showHelp(opts); System.exit(1); } File projDir = new File(line.getOptionValue("cn1-project-dir")); File resFile = new File(projDir, "src" + File.separator + "theme.res"); if (line.hasOption("cn1-resource-file")) { resFile = new File(line.getOptionValue("cn1-resource-file")); } JavaSEPort.setShowEDTViolationStacks(false); JavaSEPort.setShowEDTWarnings(false); JFrame frm = new JFrame("Placeholder"); frm.setVisible(false); Display.init(frm.getContentPane()); JavaSEPort.setBaseResourceDir(resFile.getParentFile()); try { System.out.println("About to import project at " + resDir.getAbsolutePath()); System.out.println("Codename One Output Project: " + projDir.getAbsolutePath()); System.out.println("Resource file: " + resFile.getAbsolutePath()); System.out.println("Java Package: " + line.getOptionValue("package")); AndroidProjectImporter.importProject(resDir, projDir, resFile, line.getOptionValue("package")); Runtime.getRuntime().exec(new String[] { antPath, "init" }, new String[] {}, resFile.getParentFile().getParentFile()); //runAnt(new File(resFile.getParentFile().getParentFile(), "build.xml"), "init"); System.exit(0); } catch (Exception ex) { ex.printStackTrace(); } finally { System.exit(0); } break; } default: System.out.println("Unknown command " + args[0]); showHelp(opts); break; } }
From source file:de.bayern.gdi.App.java
/** * @param args the command line arguments *//* www .j ava2 s . c o m*/ public static void main(String[] args) { Options options = new Options(); Option help = Option.builder("?").hasArg(false).longOpt("help").desc("Print this message and exit.") .build(); Option headless = Option.builder("h").hasArg(false).longOpt("headless").desc("Start command line tool.") .build(); Option conf = Option.builder("c").hasArg(true).longOpt("config") .desc("Directory to overwrite default configuration.").build(); Option user = Option.builder("u").hasArg(true).longOpt("user").desc("User name for protected services.") .build(); Option password = Option.builder("p").hasArg(true).longOpt("password") .desc("Password for protected services.").build(); options.addOption(help); options.addOption(headless); options.addOption(conf); options.addOption(user); options.addOption(password); CommandLineParser parser = new DefaultParser(); try { CommandLine line = parser.parse(options, args); if (line.hasOption("?")) { usage(options, 0); } if (line.hasOption("h")) { // First initialize log4j for headless execution final String pid = getProcessId("0"); System.setProperty("logfilename", "logdlc-" + pid + ".txt"); } // use configuration for gui and headless mode initConfig(line.getOptionValue("c")); if (line.hasOption("h")) { System.exit(Headless.main(line.getArgs(), line.getOptionValue("u"), line.getOptionValue("p"))); } startGUI(); } catch (ParseException pe) { System.err.println("Cannot parse input: " + pe.getMessage()); usage(options, 1); } }
From source file:fr.tpt.s3.mcdag.generator.MainGenerator.java
/** * Main method for the generator: it launches a given number of threads with the parameters * given/*w ww . ja va 2 s .c om*/ * @param args */ public static void main(String[] args) { /* ============================ Command line ================= */ Options options = new Options(); Option o_hi = new Option("mu", "max_utilization", true, "Upper bound utilization"); o_hi.setRequired(true); options.addOption(o_hi); Option o_tasks = new Option("nt", "nb_tasks", true, "Number of tasks for the system"); o_tasks.setRequired(true); options.addOption(o_tasks); Option o_eprob = new Option("e", "eprobability", true, "Probability of edges"); o_eprob.setRequired(true); options.addOption(o_eprob); Option o_levels = new Option("l", "levels", true, "Number of criticality levels"); o_levels.setRequired(true); options.addOption(o_levels); Option o_para = new Option("p", "parallelism", true, "Max parallelism for the DAGs"); o_para.setRequired(true); options.addOption(o_para); Option o_nbdags = new Option("nd", "num_dags", true, "Number of DAGs"); o_nbdags.setRequired(true); options.addOption(o_nbdags); Option o_nbfiles = new Option("nf", "num_files", true, "Number of files"); o_nbfiles.setRequired(true); options.addOption(o_nbfiles); Option o_rfactor = new Option("rf", "reduc_factor", true, "Reduction factor for criticality modes"); o_rfactor.setRequired(false); options.addOption(o_rfactor); Option o_out = new Option("o", "output", true, "Output file for the DAG"); o_out.setRequired(true); options.addOption(o_out); Option graphOpt = new Option("g", "graphviz", false, "Generate a graphviz DOT file"); graphOpt.setRequired(false); options.addOption(graphOpt); Option debugOpt = new Option("d", "debug", false, "Enabling debug"); debugOpt.setRequired(false); options.addOption(debugOpt); Option jobsOpt = new Option("j", "jobs", true, "Number of jobs"); jobsOpt.setRequired(false); options.addOption(jobsOpt); CommandLineParser parser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException e) { System.out.println(e.getMessage()); formatter.printHelp("DAG Generator", options); System.exit(1); return; } double maxU = Double.parseDouble(cmd.getOptionValue("max_utilization")); int edgeProb = Integer.parseInt(cmd.getOptionValue("eprobability")); int levels = Integer.parseInt(cmd.getOptionValue("levels")); int nbDags = Integer.parseInt(cmd.getOptionValue("num_dags")); int nbFiles = Integer.parseInt(cmd.getOptionValue("num_files")); int para = Integer.parseInt(cmd.getOptionValue("parallelism")); int nbTasks = Integer.parseInt(cmd.getOptionValue("nb_tasks")); boolean graph = cmd.hasOption("graphviz"); boolean debug = cmd.hasOption("debug"); String output = cmd.getOptionValue("output"); int nbJobs = 1; if (cmd.hasOption("jobs")) nbJobs = Integer.parseInt(cmd.getOptionValue("jobs")); double rfactor = 2.0; if (cmd.hasOption("reduc_factor")) rfactor = Double.parseDouble(cmd.getOptionValue("reduc_factor")); /* ============================= Generator parameters ============================= */ if (nbFiles < 0 || nbDags < 0 || nbJobs < 0) { System.err.println("[ERROR] Generator: Number of files & DAGs need to be positive."); formatter.printHelp("DAG Generator", options); System.exit(1); return; } Thread threads[] = new Thread[nbJobs]; int nbFilesCreated = 0; int count = 0; while (nbFilesCreated != nbFiles) { int launched = 0; for (int i = 0; i < nbJobs && count < nbFiles; i++) { String outFile = output.substring(0, output.lastIndexOf('.')).concat("-" + count + ".xml"); GeneratorThread gt = new GeneratorThread(maxU, nbTasks, edgeProb, levels, para, nbDags, rfactor, outFile, graph, debug); threads[i] = new Thread(gt); threads[i].setName("GeneratorThread-" + i); launched++; count++; threads[i].start(); } for (int i = 0; i < launched; i++) { try { threads[i].join(); nbFilesCreated++; } catch (InterruptedException e) { e.printStackTrace(); } } } }
From source file:de.bamamoto.mactools.png2icns.Scaler.java
public static void main(String[] args) { Options options = new Options(); options.addOption("i", "input-filename", true, "Filename ofthe image containing the icon. The image should be a square with at least 1024x124 pixel in PNG format."); options.addOption("o", "iconset-foldername", true, "Name of the folder where the iconset will be stored. The extension .iconset will be added automatically."); String folderName;/*from w w w .ja v a 2 s. com*/ CommandLineParser parser = new DefaultParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); if (cmd.hasOption("i")) { if (new File(cmd.getOptionValue("i")).isFile()) { if (cmd.hasOption("o")) { folderName = cmd.getOptionValue("o"); } else { folderName = "/tmp/noname.iconset"; } if (!folderName.endsWith(".iconset")) { folderName = folderName + ".iconset"; } new File(folderName).mkdirs(); BufferedImage source = ImageIO.read(new File(cmd.getOptionValue("i"))); BufferedImage resized = resize(source, 1024, 1024); save(resized, folderName + "/icon_512x512@2x.png"); resized = resize(source, 512, 512); save(resized, folderName + "/icon_512x512.png"); save(resized, folderName + "/icon_256x256@2x.png"); resized = resize(source, 256, 256); save(resized, folderName + "/icon_256x256.png"); save(resized, folderName + "/icon_128x128@2x.png"); resized = resize(source, 128, 128); save(resized, folderName + "/icon_128x128.png"); resized = resize(source, 64, 64); save(resized, folderName + "/icon_32x32@2x.png"); resized = resize(source, 32, 32); save(resized, folderName + "/icon_32x32.png"); save(resized, folderName + "/icon_16x16@2x.png"); resized = resize(source, 16, 16); save(resized, folderName + "/icon_16x16.png"); Scaler.runProcess(new String[] { "/usr/bin/iconutil", "-c", "icns", folderName }); } } } catch (IOException e) { System.out.println("Error reading image: " + cmd.getOptionValue("i")); e.printStackTrace(); } catch (ParseException ex) { Logger.getLogger(Scaler.class.getName()).log(Level.SEVERE, null, ex); } }