List of usage examples for org.apache.commons.cli Options Options
Options
From source file:com.alexoree.jenkins.Main.java
public static void main(String[] args) throws Exception { // create Options object Options options = new Options(); options.addOption("t", false, "throttle the downloads, waits 5 seconds in between each d/l"); // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("jenkins-sync", options); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); boolean throttle = cmd.hasOption("t"); String plugins = "https://updates.jenkins-ci.org/latest/"; List<String> ps = new ArrayList<String>(); Document doc = Jsoup.connect(plugins).get(); for (Element file : doc.select("td a")) { //System.out.println(file.attr("href")); if (file.attr("href").endsWith(".hpi") || file.attr("href").endsWith(".war")) { ps.add(file.attr("href")); }//from w w w.ja v a 2 s .c o m } File root = new File("."); //https://updates.jenkins-ci.org/latest/AdaptivePlugin.hpi new File("./latest").mkdirs(); //output zip file String zipFile = "jenkinsSync.zip"; // create byte buffer byte[] buffer = new byte[1024]; FileOutputStream fos = new FileOutputStream(zipFile); ZipOutputStream zos = new ZipOutputStream(fos); //download the plugins for (int i = 0; i < ps.size(); i++) { System.out.println("[" + i + "/" + ps.size() + "] downloading " + plugins + ps.get(i)); String outputFile = download(root.getAbsolutePath() + "/latest/" + ps.get(i), plugins + ps.get(i)); FileInputStream fis = new FileInputStream(outputFile); // begin writing a new ZIP entry, positions the stream to the start of the entry data zos.putNextEntry(new ZipEntry(outputFile.replace(root.getAbsolutePath(), "") .replace("updates.jenkins-ci.org/", "").replace("https:/", ""))); int length; while ((length = fis.read(buffer)) > 0) { zos.write(buffer, 0, length); } zos.closeEntry(); fis.close(); if (throttle) Thread.sleep(WAIT); new File(root.getAbsolutePath() + "/latest/" + ps.get(i)).deleteOnExit(); } //download the json metadata plugins = "https://updates.jenkins-ci.org/"; ps = new ArrayList<String>(); doc = Jsoup.connect(plugins).get(); for (Element file : doc.select("td a")) { //System.out.println(file.attr("href")); if (file.attr("href").endsWith(".json")) { ps.add(file.attr("href")); } } for (int i = 0; i < ps.size(); i++) { download(root.getAbsolutePath() + "/" + ps.get(i), plugins + ps.get(i)); FileInputStream fis = new FileInputStream(root.getAbsolutePath() + "/" + ps.get(i)); // begin writing a new ZIP entry, positions the stream to the start of the entry data zos.putNextEntry(new ZipEntry(plugins + ps.get(i))); int length; while ((length = fis.read(buffer)) > 0) { zos.write(buffer, 0, length); } zos.closeEntry(); fis.close(); new File(root.getAbsolutePath() + "/" + ps.get(i)).deleteOnExit(); if (throttle) Thread.sleep(WAIT); } // close the ZipOutputStream zos.close(); }
From source file:jparser.JParser.java
/** * @param args the command line arguments *//* w w w . j a v a 2s . c o m*/ public static void main(String[] args) { Options options = new Options(); CommandLineParser parser = new DefaultParser(); options.addOption( Option.builder().longOpt("to").desc("Indica el tipo de archivo al que debera convertir: JSON / XML") .hasArg().argName("tipo").build()); options.addOption(Option.builder().longOpt("path") .desc("Indica la ruta donde se encuentra el archivo origen").hasArg().argName("origen").build()); options.addOption( Option.builder().longOpt("target").desc("Indica la ruta donde se guardara el archivo resultante") .hasArg().argName("destino").build()); options.addOption("h", "help", false, "Muestra la guia de como usar la aplicacion"); try { CommandLine command = parser.parse(options, args); Path source = null; Path target = null; FactoryFileParse.TypeParce type = FactoryFileParse.TypeParce.NULL; Optional<Customer> customer = Optional.empty(); if (command.hasOption("h")) { HelpFormatter helper = new HelpFormatter(); helper.printHelp("JParser", options); System.exit(0); } if (command.hasOption("to")) type = FactoryFileParse.TypeParce.fromValue(command.getOptionValue("to", "")); if (command.hasOption("path")) source = Paths.get(command.getOptionValue("path", "")); if (command.hasOption("target")) target = Paths.get(command.getOptionValue("target", "")); switch (type) { case JSON: customer = FactoryFileParse.createNewInstance(FactoryFileParse.TypeParce.XML).read(source); break; case XML: customer = FactoryFileParse.createNewInstance(FactoryFileParse.TypeParce.JSON).read(source); break; } if (customer.isPresent()) { Customer c = customer.get(); boolean success = FactoryFileParse.createNewInstance(type).write(c, target); System.out.println(String.format("Operatation was: %s", success ? "success" : "fails")); } } catch (ParseException ex) { Logger.getLogger(JParser.class.getSimpleName()).log(Level.SEVERE, ex.getMessage(), ex); System.exit(-1); } }
From source file:com.trovit.hdfstree.HdfsTree.java
public static void main(String... args) { Options options = new Options(); options.addOption("l", false, "Use local filesystem."); options.addOption("p", true, "Path used as root for the tree."); options.addOption("s", false, "Display the size of the directory"); options.addOption("d", true, "Maximum depth of the tree (when displaying)"); CommandLineParser parser = new PosixParser(); TreeBuilder treeBuilder;/*from ww w . j a v a 2 s . co m*/ FSInspector fsInspector = null; String rootPath = null; Displayer displayer = new ConsoleDisplayer(); try { CommandLine cmd = parser.parse(options, args); // local or hdfs. if (cmd.hasOption("l")) { fsInspector = new LocalFSInspector(); } else { fsInspector = new HDFSInspector(); } // check that it has the root path. if (cmd.hasOption("p")) { rootPath = cmd.getOptionValue("p"); } else { throw new ParseException("Mandatory option (-p) is not specified."); } if (cmd.hasOption("d")) { displayer.setMaxDepth(Integer.parseInt(cmd.getOptionValue("d"))); } if (cmd.hasOption("s")) { displayer.setDisplaySize(); } } catch (ParseException e) { System.out.println(e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("hdfstree", options); System.exit(1); } treeBuilder = new TreeBuilder(rootPath, fsInspector); TreeNode tree = treeBuilder.buildTree(); displayer.display(tree); }
From source file:com.google.api.codegen.configgen.ConfigGeneratorTool.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption("h", "help", false, "show usage"); options.addOption(Option.builder().longOpt("descriptor_set") .desc("The descriptor set representing the compiled input protos.").hasArg() .argName("DESCRIPTOR-SET").required(true).build()); options.addOption(//from w w w . j ava2 s. co m Option.builder().longOpt("service_yaml").desc("The service YAML configuration file or files.") .hasArg().argName("SERVICE-YAML").required(true).build()); options.addOption( Option.builder("o").longOpt("output").desc("The directory in which to output the generated config.") .hasArg().argName("OUTPUT-FILE").required(true).build()); CommandLine cl = (new DefaultParser()).parse(options, args); if (cl.hasOption("help")) { HelpFormatter formater = new HelpFormatter(); formater.printHelp("ConfigGeneratorTool", options); } generate(cl.getOptionValue("descriptor_set"), cl.getOptionValues("service_yaml"), cl.getOptionValue("output")); }
From source file:de.iritgo.aktario.framework.IritgoServer.java
/** * The server main method.//from w w w . j av a 2 s.co m * * @param args The program args. */ public static void main(String[] args) { Options options = new Options(); IritgoEngine.create(IritgoEngine.START_SERVER, options, args); }
From source file:PlyBounder.java
public static void main(String[] args) { // Get the commandline arguments Options options = new Options(); // Available options Option plyPath = OptionBuilder.withArgName("dir").hasArg() .withDescription("directory containing input .ply files").create("plyPath"); Option boundingbox = OptionBuilder.withArgName("string").hasArg() .withDescription("bounding box in WKT notation").create("boundingbox"); Option outputPlyFile = OptionBuilder.withArgName("file").hasArg().withDescription("output PLY file name") .create("outputPlyFile"); options.addOption(plyPath);/*from w w w. j av a 2 s.c o m*/ options.addOption(boundingbox); options.addOption(outputPlyFile); String plydir = "."; String boundingboxstr = ""; String outputfilename = ""; CommandLineParser parser = new DefaultParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); boundingboxstr = line.getOptionValue("boundingbox"); outputfilename = line.getOptionValue("outputPlyFile"); if (line.hasOption("plyPath")) { // print the value of block-size plydir = line.getOptionValue("plyPath"); System.out.println("Using plyPath=" + plydir); } else { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("PlyBounder", options); } //System.out.println( "plyPath=" + line.getOptionValue( "plyPath" ) ); } catch (ParseException exp) { System.err.println("Error getting arguments: " + exp.getMessage()); } // input directory // Get list of files File dir = new File(plydir); //System.out.println("Getting all files in " + dir.getCanonicalPath()); List<File> files = (List<File>) FileUtils.listFiles(dir, new String[] { "ply", "PLY" }, false); for (File file : files) { try { System.out.println("file=" + file.getCanonicalPath()); } catch (IOException e) { e.printStackTrace(); } } String sometempfile = "magweg.wkt"; String s = null; // Loop through .ply files in directory for (File file : files) { try { String cmdl[] = { "./ply-tool.py", "intersection", file.getCanonicalPath(), boundingboxstr, sometempfile }; //System.out.println("Running: " + Arrays.toString(cmdl)); Process p = Runtime.getRuntime().exec(cmdl); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); // read the output from the command System.out.println("cmdout:\n"); while ((s = stdInput.readLine()) != null) { System.out.println(s); } // read any errors from the attempted command System.out.println("cmderr:\n"); while ((s = stdError.readLine()) != null) { System.out.println(s); } } catch (IOException e) { e.printStackTrace(); } } // Write new .ply file //ply-tool write setfile outputPlyFile try { String cmdl = "./ply-tool.py write " + sometempfile + " " + outputfilename; System.out.println("Running: " + cmdl); Process p = Runtime.getRuntime().exec(cmdl); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); // read the output from the command System.out.println("cmdout:\n"); while ((s = stdInput.readLine()) != null) { System.out.println(s); } // read any errors from the attempted command System.out.println("cmderr:\n"); while ((s = stdError.readLine()) != null) { System.out.println(s); } } catch (IOException e) { e.printStackTrace(); } // Done System.out.println("Done"); }
From source file:graphgen.GraphGen.java
/** * @param args the command line arguments *//*www. ja v a 2 s. co m*/ public static void main(String[] args) { Options options = new Options(); HelpFormatter formatter = new HelpFormatter(); options.addOption(OPTION_EDGES, true, OPTION_EDGES_MSG); options.addOption(OPTION_NODES, true, OPTION_NODES_MSG); options.addOption(OPTION_OUTPUT, true, OPTION_OUTPUT_MSG); CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); int edgeCount = Integer.valueOf(cmd.getOptionValue(OPTION_EDGES)); int nodeCount = Integer.valueOf(cmd.getOptionValue(OPTION_NODES)); String outputFile = cmd.getOptionValue(OPTION_OUTPUT); if ((nodeCount < edgeCount) || (outputFile != null)) { String graph = generateGraph(nodeCount, edgeCount); saveGraph(graph, outputFile); } else { formatter.printHelp(HELP_NAME, options); } } catch (NumberFormatException | ParseException e) { formatter.printHelp(HELP_NAME, options); } catch (IllegalArgumentException | FileNotFoundException e) { System.err.println(e.getMessage()); } }
From source file:com.level3.hiper.dyconn.be.Main.java
public static void main(String... args) { try {/* ww w.ja va2 s. co m*/ String bootstrap = "/dyconn-be-toml.cfg"; CommandLineParser parser = new DefaultParser(); Options options = new Options(); options.addOption("c", "config-file", true, "configuration for hapi dyconn module"); try { CommandLine line = parser.parse(options, args); if (line.hasOption("config-file")) { bootstrap = line.getOptionValue("config-file"); } } catch (ParseException ex) { log.error("command line", ex); return; } // read config file log.info("loading configuration"); Config.instance().initialize(bootstrap); // initialize queue subsystem log.info("initializing messaging"); Broker.instance().initialize(); // initilaize persistence log.info("starting exector"); ExecutorService executor = Executors.newSingleThreadExecutor(); executor.submit(new MsgReceiver()); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.anthonypoon.ngram.rollingregression.Main.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption("a", "action", true, "Action"); options.addOption("i", "input", true, "input"); options.addOption("o", "output", true, "output"); //options.addOption("f", "format", true, "Format"); options.addOption("u", "upbound", true, "Year up bound"); options.addOption("l", "lowbound", true, "Year low bound"); options.addOption("r", "range", true, "Range"); options.addOption("T", "threshold", true, "Threshold - min count for regression"); options.addOption("p", "positive-only", false, "Write positive slope only"); // default faluse CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); Configuration conf = new Configuration(); if (cmd.hasOption("range")) { conf.set("range", cmd.getOptionValue("range")); }/*w w w . j a va2 s . c om*/ if (cmd.hasOption("upbound")) { conf.set("upbound", cmd.getOptionValue("upbound")); } else { conf.set("upbound", "9999"); } if (cmd.hasOption("lowbound")) { conf.set("lowbound", cmd.getOptionValue("lowbound")); } else { conf.set("lowbound", "0"); } if (cmd.hasOption("threshold")) { conf.set("threshold", cmd.getOptionValue("threshold")); } if (cmd.hasOption("positive-only")) { conf.set("positive-only", "true"); } Job job = Job.getInstance(conf); /** if (cmd.hasOption("format")) { switch (cmd.getOptionValue("format")) { case "compressed": job.setInputFormatClass(SequenceFileAsTextInputFormat.class); break; case "text": job.setInputFormatClass(KeyValueTextInputFormat.class); break; } }**/ job.setJarByClass(Main.class); switch (cmd.getOptionValue("action")) { case "get-regression": job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); for (String inputPath : cmd.getOptionValue("input").split(",")) { MultipleInputs.addInputPath(job, new Path(inputPath), KeyValueTextInputFormat.class, RollingRegressionMapper.class); } job.setReducerClass(RollingRegressionReducer.class); break; default: throw new IllegalArgumentException("Missing action"); } String timestamp = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new Date()); //FileInputFormat.setInputPaths(job, new Path(cmd.getOptionValue("input"))); FileOutputFormat.setOutputPath(job, new Path(cmd.getOptionValue("output") + "/" + timestamp)); System.exit(job.waitForCompletion(true) ? 0 : 1); /** double[] nazismBaseLine = {3, 12, 12, 18, 233, 239, 386, 333, 593, 1244, 1925, 3013, 3120, 3215, 3002, 3355, 2130, 1828, 1406, 1751, 1433, 1033, 881, 1330, 1029, 760, 1288, 1013, 1014}; InputStream inStream = Main.class.getResourceAsStream("/1g-matrix.txt"); BufferedReader br = new BufferedReader(new InputStreamReader(inStream)); String line = ""; Map<String, Double> result = new HashMap(); while ((line = br.readLine()) != null) { String[] strArray = line.split("\t"); double[] compareArray = new double[nazismBaseLine.length]; for (int i = 0; i < nazismBaseLine.length; i ++) { compareArray[i] = Double.valueOf(strArray[i + 24]); } result.put(strArray[0], new PearsonsCorrelation().correlation(nazismBaseLine, compareArray)); } List<Map.Entry<String, Double>> toBeSorted = new ArrayList(); for (Map.Entry pair : result.entrySet()) { toBeSorted.add(pair); } Collections.sort(toBeSorted, new Comparator<Map.Entry<String, Double>>(){ @Override public int compare(Map.Entry<String, Double> o1, Map.Entry<String, Double> o2) { return o2.getValue().compareTo(o1.getValue()); } }); for (Map.Entry<String, Double> pair : toBeSorted) { if (!Double.isNaN(pair.getValue())) { System.out.println(pair.getKey() + "\t" + pair.getValue()); } }**/ }
From source file:com.ibm.rdf.store.sparql11.DB2RDFQuery.java
public static void main(String[] args) { Options options = new Options(); try {//w w w . ja v a2 s. c om // create Options object options.addOption("jdbcurl", true, "jdbc url"); options.addOption("schema", true, "schema name"); options.addOption("kb", true, "knowledge base"); options.addOption("username", true, "db user name"); options.addOption("password", true, "db password"); options.addOption("queryFile", true, "query file"); options.addOption("defaultUnionGraph", false, "default Union Graph semantics"); CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); boolean defUnion = cmd.hasOption("defaultUnionGraph") ? Boolean.parseBoolean(cmd.getOptionValue("defaultUnionGraph")) : false; DB2TestData data = new DB2TestData(cmd.getOptionValue("jdbcurl"), cmd.getOptionValue("kb"), cmd.getOptionValue("username"), cmd.getOptionValue("password"), cmd.getOptionValue("schemaName"), defUnion); DB2RDFQuery q = new DB2RDFQuery(new DB2Engine(), data); q.executeQuery(cmd.getOptionValue("queryFile")); } catch (Exception e) { e.printStackTrace(); HelpFormatter help = new HelpFormatter(); help.printHelp("DB2RDFQuery", options); } }