List of usage examples for org.apache.commons.cli Option setArgs
public void setArgs(int num)
From source file:de.topobyte.livecg.ShowVisualization.java
public static void main(String[] args) { EnumNameLookup<Visualization> visualizationSwitch = new EnumNameLookup<Visualization>(Visualization.class, true);/*from w w w. j a v a 2 s .c o m*/ // @formatter:off Options options = new Options(); OptionHelper.add(options, OPTION_CONFIG, true, false, "path", "config file"); OptionHelper.add(options, OPTION_VISUALIZATION, true, true, "type", "type of visualization. one of <" + VisualizationUtil.getListOfAvailableVisualizations() + ">"); OptionHelper.add(options, OPTION_STATUS, true, false, "status to " + "set the algorithm to. The format depends on the algorithm"); // @formatter:on Option propertyOption = new Option(OPTION_PROPERTIES, "set a special property"); propertyOption.setArgName("property=value"); propertyOption.setArgs(2); propertyOption.setValueSeparator('='); options.addOption(propertyOption); CommandLineParser clp = new GnuParser(); CommandLine line = null; try { line = clp.parse(options, args); } catch (ParseException e) { System.err.println("Parsing command line failed: " + e.getMessage()); new HelpFormatter().printHelp(HELP_MESSAGE, options); System.exit(1); } String[] extra = line.getArgs(); if (extra.length == 0) { System.out.println("Missing file argument"); new HelpFormatter().printHelp(HELP_MESSAGE, options); System.exit(1); } String input = extra[0]; StringOption argConfig = ArgumentHelper.getString(line, OPTION_CONFIG); if (argConfig.hasValue()) { String configPath = argConfig.getValue(); LiveConfig.setPath(configPath); } StringOption argVisualization = ArgumentHelper.getString(line, OPTION_VISUALIZATION); StringOption argStatus = ArgumentHelper.getString(line, OPTION_STATUS); Visualization visualization = visualizationSwitch.find(argVisualization.getValue()); if (visualization == null) { System.err.println("Unsupported visualization '" + argVisualization.getValue() + "'"); System.exit(1); } System.out.println("Visualization: " + visualization); ContentReader contentReader = new ContentReader(); Content content = null; try { content = contentReader.read(new File(input)); } catch (Exception e) { System.out.println("Error while reading input file '" + input + "'. Exception type: " + e.getClass().getSimpleName() + ", message: " + e.getMessage()); System.exit(1); } Properties properties = line.getOptionProperties(OPTION_PROPERTIES); ContentLauncher launcher = null; switch (visualization) { case GEOMETRY: { launcher = new ContentDisplayLauncher(); break; } case DCEL: { launcher = new DcelLauncher(); break; } case FREESPACE: { launcher = new FreeSpaceChainsLauncher(); break; } case DISTANCETERRAIN: { launcher = new DistanceTerrainChainsLauncher(); break; } case CHAN: { launcher = new ChanLauncher(); break; } case FORTUNE: { launcher = new FortunesSweepLauncher(); break; } case MONOTONE_PIECES: { launcher = new MonotonePiecesLauncher(); break; } case MONOTONE_TRIANGULATION: { launcher = new MonotoneTriangulationLauncher(); break; } case TRIANGULATION: { launcher = new MonotonePiecesTriangulationLauncher(); break; } case SPIP: { launcher = new ShortestPathInPolygonLauncher(); break; } case BUFFER: { launcher = new PolygonBufferLauncher(); break; } } try { launcher.launch(content, true); } catch (LaunchException e) { System.err.println("Unable to start visualization"); System.err.println("Error message: " + e.getMessage()); System.exit(1); } }
From source file:com.versusoft.packages.ooo.odt2daisy.gui.CommandLineGUI.java
public static void main(String args[]) throws IOException { Handler fh = new FileHandler(LOG_FILENAME_PATTERN); fh.setFormatter(new SimpleFormatter()); //removeAllLoggersHandlers(Logger.getLogger("")); Logger.getLogger("").addHandler(fh); Logger.getLogger("").setLevel(Level.FINEST); Options options = new Options(); Option option1 = new Option("in", "name of ODT file (required)"); option1.setRequired(true);// w w w. java 2 s .co m option1.setArgs(1); Option option2 = new Option("out", "name of DAISY DTB file (required)"); option2.setRequired(true); option2.setArgs(1); Option option3 = new Option("h", "show this help"); option3.setArgs(Option.UNLIMITED_VALUES); Option option4 = new Option("alt", "use alternate Level Markup"); Option option5 = new Option("u", "UID of DAISY DTB (optional)"); option5.setArgs(1); Option option6 = new Option("t", "Title of DAISY DTB"); option6.setArgs(1); Option option7 = new Option("c", "Creator of DAISY DTB"); option7.setArgs(1); Option option8 = new Option("p", "Publisher of DAISY DTB"); option8.setArgs(1); Option option9 = new Option("pr", "Producer of DAISY DTB"); option9.setArgs(1); Option option10 = new Option("pic", "set Picture directory"); option10.setArgs(1); Option option11 = new Option("page", "enable pagination"); option11.setArgs(0); Option option12 = new Option("css", "write CSS file"); option12.setArgs(0); options.addOption(option1); options.addOption(option2); options.addOption(option3); options.addOption(option4); options.addOption(option5); options.addOption(option6); options.addOption(option7); options.addOption(option8); options.addOption(option9); options.addOption(option10); options.addOption(option11); options.addOption(option12); CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { //System.out.println("***ERROR: " + e.getClass() + ": " + e.getMessage()); printHelp(); return; } if (cmd.hasOption("help")) { printHelp(); return; } try { Odt2Daisy odt2daisy = new Odt2Daisy(cmd.getOptionValue("in")); //@todo add initial output directory URL? odt2daisy.init(); if (odt2daisy.isEmptyDocument()) { logger.info("Cannot convert empty documents. Export Aborted..."); System.exit(1); } //System.out.println("Metadatas"); //System.out.println("- title: " + odt2daisy.getTitleMeta()); //System.out.println("- creator: " + odt2daisy.getCreatorMeta()); if (!odt2daisy.isUsingHeadings()) { logger.info("You SHOULD use Heading styles in your document. Export in a single level."); } //@todo Warning for incompatible image formats should go here. See UnoGui.java. if (cmd.hasOption("u")) { //System.out.println("arg uid:"+cmd.getOptionValue("u")); odt2daisy.setUidParam(cmd.getOptionValue("u")); } if (cmd.hasOption("t")) { //System.out.println("arg title:"+cmd.getOptionValue("t")); odt2daisy.setTitleParam(cmd.getOptionValue("t")); } if (cmd.hasOption("c")) { //System.out.println("arg creator:"+cmd.getOptionValue("c")); odt2daisy.setCreatorParam(cmd.getOptionValue("c")); } if (cmd.hasOption("p")) { //System.out.println("arg publisher:"+cmd.getOptionValue("p")); odt2daisy.setPublisherParam(cmd.getOptionValue("p")); } if (cmd.hasOption("pr")) { //System.out.println("arg producer:"+cmd.getOptionValue("pr")); odt2daisy.setProducerParam(cmd.getOptionValue("pr")); } if (cmd.hasOption("alt")) { //System.out.println("arg alt:"+cmd.getOptionValue("alt")); odt2daisy.setUseAlternateLevelParam(true); } if (cmd.hasOption("css")) { odt2daisy.setWriteCSSParam(true); } if (cmd.hasOption("page")) { odt2daisy.paginationProcessing(); } odt2daisy.correctionProcessing(); if (cmd.hasOption("pic")) { odt2daisy.convertAsDTBook(cmd.getOptionValue("out"), cmd.getOptionValue("pic")); } else { logger.info("Language detected: " + odt2daisy.getLangParam()); odt2daisy.convertAsDTBook(cmd.getOptionValue("out"), Configuration.DEFAULT_IMAGE_DIR); } boolean valid = odt2daisy.validateDTD(cmd.getOptionValue("out")); if (valid) { logger.info("DAISY DTBook produced is valid against DTD - Congratulations !"); } else { logger.info("DAISY Book produced isn't valid against DTD - You SHOULD NOT use this DAISY Book !"); logger.info("Error at line: " + odt2daisy.getErrorHandler().getLineNumber()); logger.info("Error Message: " + odt2daisy.getErrorHandler().getMessage()); } } catch (Exception e) { e.printStackTrace(); } finally { if (fh != null) { fh.flush(); fh.close(); } } }
From source file:edu.ksu.cis.indus.staticanalyses.concurrency.DeadlockAnalysisCLI.java
/** * The entry point to this class.// w ww .j a v a 2s . c om * * @param args command line arguments. * @throws RuntimeException when escape information and side-effect information calculation fails. */ public static void main(final String[] args) { final Options _options = new Options(); Option _option = new Option("h", "help", false, "Display message."); _option.setOptionalArg(false); _options.addOption(_option); _option = new Option("p", "soot-classpath", false, "Prepend this to soot class path."); _option.setArgs(1); _option.setArgName("classpath"); _option.setOptionalArg(false); _options.addOption(_option); _option = new Option("S", "scope", true, "The scope that should be analyzed."); _option.setArgs(1); _option.setArgName("scope"); _option.setRequired(false); _options.addOption(_option); final CommandLineParser _parser = new GnuParser(); try { final CommandLine _cl = _parser.parse(_options, args); if (_cl.hasOption("h")) { final String _cmdLineSyn = "java " + DeadlockAnalysisCLI.class.getName() + " <options> <classnames>"; (new HelpFormatter()).printHelp(_cmdLineSyn, _options); System.exit(1); } if (_cl.getArgList().isEmpty()) { throw new MissingArgumentException("Please specify atleast one class."); } final DeadlockAnalysisCLI _cli = new DeadlockAnalysisCLI(); if (_cl.hasOption('p')) { _cli.addToSootClassPath(_cl.getOptionValue('p')); } if (_cl.hasOption('S')) { _cli.setScopeSpecFile(_cl.getOptionValue('S')); } _cli.setClassNames(_cl.getArgList()); _cli.<ITokens>execute(); } catch (final ParseException _e) { LOGGER.error("Error while parsing command line.", _e); System.out.println("Error while parsing command line." + _e); final String _cmdLineSyn = "java " + DeadlockAnalysisCLI.class.getName() + " <options> <classnames>"; (new HelpFormatter()).printHelp(_cmdLineSyn, "Options are:", _options, ""); } catch (final Throwable _e) { LOGGER.error("Beyond our control. May day! May day!", _e); throw new RuntimeException(_e); } }
From source file:kellinwood.zipsigner.cmdline.Main.java
public static void main(String[] args) { try {// ww w . j a v a 2 s. co m Options options = new Options(); CommandLine cmdLine = null; Option helpOption = new Option("h", "help", false, "Display usage information"); Option modeOption = new Option("m", "keymode", false, "Keymode one of: auto, auto-testkey, auto-none, media, platform, shared, testkey, none"); modeOption.setArgs(1); Option keyOption = new Option("k", "key", false, "PCKS#8 encoded private key file"); keyOption.setArgs(1); Option pwOption = new Option("p", "keypass", false, "Private key password"); pwOption.setArgs(1); Option certOption = new Option("c", "cert", false, "X.509 public key certificate file"); certOption.setArgs(1); Option sbtOption = new Option("t", "template", false, "Signature block template file"); sbtOption.setArgs(1); Option keystoreOption = new Option("s", "keystore", false, "Keystore file"); keystoreOption.setArgs(1); Option aliasOption = new Option("a", "alias", false, "Alias for key/cert in the keystore"); aliasOption.setArgs(1); options.addOption(helpOption); options.addOption(modeOption); options.addOption(keyOption); options.addOption(certOption); options.addOption(sbtOption); options.addOption(pwOption); options.addOption(keystoreOption); options.addOption(aliasOption); Parser parser = new BasicParser(); try { cmdLine = parser.parse(options, args); } catch (MissingOptionException x) { System.out.println("One or more required options are missing: " + x.getMessage()); usage(options); } catch (ParseException x) { System.out.println(x.getClass().getName() + ": " + x.getMessage()); usage(options); } if (cmdLine.hasOption(helpOption.getOpt())) usage(options); Properties log4jProperties = new Properties(); log4jProperties.load(new FileReader("log4j.properties")); PropertyConfigurator.configure(log4jProperties); LoggerManager.setLoggerFactory(new Log4jLoggerFactory()); List<String> argList = cmdLine.getArgList(); if (argList.size() != 2) usage(options); ZipSigner signer = new ZipSigner(); signer.addAutoKeyObserver(new Observer() { @Override public void update(Observable observable, Object o) { System.out.println("Signing with key: " + o); } }); Class bcProviderClass = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider"); Provider bcProvider = (Provider) bcProviderClass.newInstance(); KeyStoreFileManager.setProvider(bcProvider); signer.loadProvider("org.spongycastle.jce.provider.BouncyCastleProvider"); PrivateKey privateKey = null; if (cmdLine.hasOption(keyOption.getOpt())) { if (!cmdLine.hasOption(certOption.getOpt())) { System.out.println("Certificate file is required when specifying a private key"); usage(options); } String keypw = null; if (cmdLine.hasOption(pwOption.getOpt())) keypw = pwOption.getValue(); else { keypw = new String(readPassword("Key password")); if (keypw.equals("")) keypw = null; } URL privateKeyUrl = new File(keyOption.getValue()).toURI().toURL(); privateKey = signer.readPrivateKey(privateKeyUrl, keypw); } X509Certificate cert = null; if (cmdLine.hasOption(certOption.getOpt())) { if (!cmdLine.hasOption(keyOption.getOpt())) { System.out.println("Private key file is required when specifying a certificate"); usage(options); } URL certUrl = new File(certOption.getValue()).toURI().toURL(); cert = signer.readPublicKey(certUrl); } byte[] sigBlockTemplate = null; if (cmdLine.hasOption(sbtOption.getOpt())) { URL sbtUrl = new File(sbtOption.getValue()).toURI().toURL(); sigBlockTemplate = signer.readContentAsBytes(sbtUrl); } if (cmdLine.hasOption(keyOption.getOpt())) { signer.setKeys("custom", cert, privateKey, sigBlockTemplate); signer.signZip(argList.get(0), argList.get(1)); } else if (cmdLine.hasOption(modeOption.getOpt())) { signer.setKeymode(modeOption.getValue()); signer.signZip(argList.get(0), argList.get(1)); } else if (cmdLine.hasOption((keystoreOption.getOpt()))) { String alias = null; if (!cmdLine.hasOption(aliasOption.getOpt())) { KeyStore keyStore = KeyStoreFileManager.loadKeyStore(keystoreOption.getValue(), (char[]) null); for (Enumeration<String> e = keyStore.aliases(); e.hasMoreElements();) { alias = e.nextElement(); System.out.println("Signing with key: " + alias); break; } } else alias = aliasOption.getValue(); String keypw = null; if (cmdLine.hasOption(pwOption.getOpt())) keypw = pwOption.getValue(); else { keypw = new String(readPassword("Key password")); if (keypw.equals("")) keypw = null; } CustomKeySigner.signZip(signer, keystoreOption.getValue(), null, alias, keypw.toCharArray(), "SHA1withRSA", argList.get(0), argList.get(1)); } else { signer.setKeymode("auto-testkey"); signer.signZip(argList.get(0), argList.get(1)); } } catch (Throwable t) { t.printStackTrace(); } }
From source file:edu.ksu.cis.indus.staticanalyses.concurrency.independence.IndependenceDetectionCLI.java
/** * The entry point to the program via command line. * // ww w . ja v a 2 s.co m * @param args is the command line arguments. * @throws RuntimeException when CLI fails. */ public static void main(final String[] args) { final Options _options = new Options(); Option _option = new Option("o", "output", true, "Directory into which jimple files will be written into. [required]"); _option.setArgs(1); _option.setArgName("ouput-directory"); _option.setRequired(true); _options.addOption(_option); _option = new Option("h", "help", false, "Display message."); _option.setOptionalArg(false); _options.addOption(_option); _option = new Option("p", "soot-classpath", false, "Prepend this to soot class path."); _option.setArgs(1); _option.setArgName("classpath"); _option.setOptionalArg(false); _options.addOption(_option); _option = new Option("useV2", false, "Use version 2 of the atomicity detection algorithm."); _options.addOption(_option); _option = new Option("scheme", false, "Scheme to indicate atomicity. Valid values are 'tag-stmt' and 'tag-region'. By default, 'tag-stmt' " + "scheme is used. "); _option.setArgs(1); _option.setArgName("scheme-name"); _options.addOption(_option); _option = new Option("S", "scope", true, "The scope that should be analyzed."); _option.setArgs(1); _option.setArgName("scope"); _option.setRequired(false); _options.addOption(_option); final CommandLineParser _parser = new GnuParser(); try { final CommandLine _cl = _parser.parse(_options, args); if (_cl.hasOption("h")) { final String _cmdLineSyn = "java " + IndependenceDetectionCLI.class.getName() + " <options> <classnames>"; (new HelpFormatter()).printHelp(_cmdLineSyn, _options); System.exit(1); } if (_cl.getArgList().isEmpty()) { throw new MissingArgumentException("Please specify atleast one class."); } final IndependenceDetectionCLI _cli; if (_cl.hasOption("useV2")) { _cli = new IndependenceDetectionCLI(new IndependentStmtDetectorv2()); } else { _cli = new IndependenceDetectionCLI(new IndependentStmtDetector()); } if (_cl.hasOption('p')) { _cli.addToSootClassPath(_cl.getOptionValue('p')); } if (_cl.hasOption('S')) { _cli.setScopeSpecFile(_cl.getOptionValue('S')); } _cli.setClassNames(_cl.getArgList()); _cli.setOutputDir(_cl.getOptionValue('o')); _cli.<ITokens>execute(_cl); } catch (final ParseException _e) { LOGGER.error("Error while parsing command line.", _e); System.out.println("Error while parsing command line." + _e); final String _cmdLineSyn = "java " + IndependenceDetectionCLI.class.getName() + " <options> <classnames>"; (new HelpFormatter()).printHelp(_cmdLineSyn, "Options are:", _options, ""); } catch (final Throwable _e) { LOGGER.error("Beyond our control. May day! May day!", _e); throw new RuntimeException(_e); } }
From source file:de.topobyte.livecg.CreateImage.java
public static void main(String[] args) { EnumNameLookup<ExportFormat> exportSwitch = new EnumNameLookup<ExportFormat>(ExportFormat.class, true); EnumNameLookup<Visualization> visualizationSwitch = new EnumNameLookup<Visualization>(Visualization.class, true);/*from w w w . ja v a 2 s .com*/ // @formatter:off Options options = new Options(); OptionHelper.add(options, OPTION_CONFIG, true, false, "path", "config file"); OptionHelper.add(options, OPTION_INPUT, true, true, "file", "input geometry file"); OptionHelper.add(options, OPTION_OUTPUT, true, true, "file", "output file"); OptionHelper.add(options, OPTION_OUTPUT_FORMAT, true, true, "type", "type of output. one of <png,svg,tikz,ipe>"); OptionHelper.add(options, OPTION_VISUALIZATION, true, true, "type", "type of visualization. one of <" + VisualizationUtil.getListOfAvailableVisualizations() + ">"); OptionHelper.add(options, OPTION_STATUS, true, false, "status to " + "set the algorithm to. The format depends on the algorithm"); // @formatter:on Option propertyOption = new Option(OPTION_PROPERTIES, "set a special property"); propertyOption.setArgName("property=value"); propertyOption.setArgs(2); propertyOption.setValueSeparator('='); options.addOption(propertyOption); CommandLineParser clp = new GnuParser(); CommandLine line = null; try { line = clp.parse(options, args); } catch (ParseException e) { System.err.println("Parsing command line failed: " + e.getMessage()); new HelpFormatter().printHelp(HELP_MESSAGE, options); System.exit(1); } StringOption argConfig = ArgumentHelper.getString(line, OPTION_CONFIG); if (argConfig.hasValue()) { String configPath = argConfig.getValue(); LiveConfig.setPath(configPath); } StringOption argInput = ArgumentHelper.getString(line, OPTION_INPUT); StringOption argOutput = ArgumentHelper.getString(line, OPTION_OUTPUT); StringOption argOutputFormat = ArgumentHelper.getString(line, OPTION_OUTPUT_FORMAT); StringOption argVisualization = ArgumentHelper.getString(line, OPTION_VISUALIZATION); StringOption argStatus = ArgumentHelper.getString(line, OPTION_STATUS); ExportFormat exportFormat = exportSwitch.find(argOutputFormat.getValue()); if (exportFormat == null) { System.err.println("Unsupported output format '" + argOutputFormat.getValue() + "'"); System.exit(1); } Visualization visualization = visualizationSwitch.find(argVisualization.getValue()); if (visualization == null) { System.err.println("Unsupported visualization '" + argVisualization.getValue() + "'"); System.exit(1); } System.out.println("Visualization: " + visualization); System.out.println("Output format: " + exportFormat); ContentReader contentReader = new ContentReader(); Content content = null; try { content = contentReader.read(new File(argInput.getValue())); } catch (Exception e) { System.out.println("Error while reading input file '" + argInput.getValue() + "'. Exception type: " + e.getClass().getSimpleName() + ", message: " + e.getMessage()); System.exit(1); } Properties properties = line.getOptionProperties(OPTION_PROPERTIES); double zoom = 1; String statusArgument = null; if (argStatus.hasValue()) { statusArgument = argStatus.getValue(); } VisualizationSetup setup = null; switch (visualization) { case GEOMETRY: { setup = new ContentVisualizationSetup(); break; } case DCEL: { setup = new DcelVisualizationSetup(); break; } case FREESPACE: { setup = new FreeSpaceVisualizationSetup(); break; } case DISTANCETERRAIN: { setup = new DistanceTerrainVisualizationSetup(); break; } case CHAN: { setup = new ChanVisualizationSetup(); break; } case MONOTONE_PIECES: { setup = new MonotonePiecesVisualizationSetup(); break; } case MONOTONE_TRIANGULATION: { setup = new MonotoneTriangulationVisualizationSetup(); break; } case TRIANGULATION: { setup = new MonotonePiecesTriangulationVisualizationSetup(); break; } case BUFFER: { setup = new BufferVisualizationSetup(); break; } case FORTUNE: { setup = new FortunesSweepVisualizationSetup(); break; } case SPIP: { setup = new ShortestPathVisualizationSetup(); break; } } if (setup == null) { System.err.println("Not yet implemented"); System.exit(1); } SetupResult setupResult = setup.setup(content, statusArgument, properties, zoom); int width = setupResult.getWidth(); int height = setupResult.getHeight(); VisualizationPainter visualizationPainter = setupResult.getVisualizationPainter(); File output = new File(argOutput.getValue()); visualizationPainter.setZoom(zoom); switch (exportFormat) { case IPE: { try { IpeExporter.exportIpe(output, visualizationPainter, width, height); } catch (Exception e) { System.err.println("Error while exporting. Exception type: " + e.getClass().getSimpleName() + ", message: " + e.getMessage()); System.exit(1); } break; } case PNG: { try { GraphicsExporter.exportPNG(output, visualizationPainter, width, height); } catch (IOException e) { System.err.println("Error while exporting. Exception type: " + e.getClass().getSimpleName() + ", message: " + e.getMessage()); System.exit(1); } break; } case SVG: { try { SvgExporter.exportSVG(output, visualizationPainter, width, height); } catch (Exception e) { System.err.println("Error while exporting. Exception type: " + e.getClass().getSimpleName() + ", message: " + e.getMessage()); System.exit(1); } break; } case TIKZ: { try { TikzExporter.exportTikz(output, visualizationPainter, width, height); } catch (Exception e) { System.err.println("Error while exporting. Exception type: " + e.getClass().getSimpleName() + ", message: " + e.getMessage()); System.exit(1); } break; } } }
From source file:edu.ksu.cis.indus.staticanalyses.concurrency.escape.EscapeAndReadWriteCLI.java
/** * The entry point to this class.//from w w w . j a va 2 s.c o m * * @param args command line arguments. * @throws RuntimeException when escape information and side-effect information calculation fails. */ public static void main(final String[] args) { final Options _options = new Options(); Option _option = new Option("h", "help", false, "Display message."); _option.setOptionalArg(false); _options.addOption(_option); _option = new Option("p", "soot-classpath", false, "Prepend this to soot class path."); _option.setArgs(1); _option.setArgName("classpath"); _option.setOptionalArg(false); _options.addOption(_option); _option = new Option("S", "scope", true, "The scope that should be analyzed."); _option.setArgs(1); _option.setArgName("scope"); _option.setRequired(false); _options.addOption(_option); final CommandLineParser _parser = new GnuParser(); try { final CommandLine _cl = _parser.parse(_options, args); if (_cl.hasOption("h")) { final String _cmdLineSyn = "java " + EscapeAndReadWriteCLI.class.getName() + " <options> <classnames>"; (new HelpFormatter()).printHelp(_cmdLineSyn, _options); System.exit(1); } if (_cl.getArgList().isEmpty()) { throw new MissingArgumentException("Please specify atleast one class."); } final EscapeAndReadWriteCLI _cli = new EscapeAndReadWriteCLI(); if (_cl.hasOption('p')) { _cli.addToSootClassPath(_cl.getOptionValue('p')); } if (_cl.hasOption('S')) { _cli.setScopeSpecFile(_cl.getOptionValue('S')); } _cli.setClassNames(_cl.getArgList()); _cli.<ITokens>execute(); } catch (final ParseException _e) { LOGGER.error("Error while parsing command line.", _e); System.out.println("Error while parsing command line." + _e); final String _cmdLineSyn = "java " + EscapeAndReadWriteCLI.class.getName() + " <options> <classnames>"; (new HelpFormatter()).printHelp(_cmdLineSyn, "Options are:", _options, ""); } catch (final Throwable _e) { LOGGER.error("Beyond our control. May day! May day!", _e); throw new RuntimeException(_e); } }
From source file:edu.ksu.cis.indus.staticanalyses.flow.instances.ofa.OFAXMLizerCLI.java
/** * The entry point to the program via command line. * //from ww w .j a v a 2 s . c o m * @param args is the command line arguments. * @throws RuntimeException when object flow analysis fails. */ public static void main(final String[] args) { final Options _options = new Options(); Option _option = new Option("c", "cumulative", false, "Consider all root methods in the same execution."); _options.addOption(_option); _option = new Option("o", "output", true, "Directory into which xml files will be written into."); _option.setArgs(1); _options.addOption(_option); _option = new Option("j", "jimple", false, "Dump xmlized jimple."); _options.addOption(_option); _option = new Option("h", "help", false, "Display message."); _options.addOption(_option); _option = new Option("p", "soot-classpath", false, "Prepend this to soot class path."); _option.setArgs(1); _option.setArgName("classpath"); _option.setOptionalArg(false); _options.addOption(_option); _option = new Option("t", "ofa-type", false, "Type of analysis : fioi, fsoi, fios, fsos, fioirt, fsoirt."); _option.setArgs(1); _option.setArgName("type"); _option.setOptionalArg(false); _option.setRequired(true); _options.addOption(_option); _option = new Option("S", "scope", true, "The scope that should be analyzed."); _option.setArgs(1); _option.setArgName("scope"); _option.setRequired(false); _options.addOption(_option); final PosixParser _parser = new PosixParser(); try { final CommandLine _cl = _parser.parse(_options, args); if (_cl.hasOption("h")) { printUsage(_options); System.exit(1); } String _outputDir = _cl.getOptionValue('o'); if (_outputDir == null) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Defaulting to current directory for output."); } _outputDir = "."; } if (_cl.getArgList().isEmpty()) { throw new MissingArgumentException("Please specify atleast one class."); } final OFAXMLizerCLI _cli = new OFAXMLizerCLI(); _cli.xmlizer.setXmlOutputDir(_outputDir); _cli.xmlizer.setGenerator(new UniqueJimpleIDGenerator()); _cli.setCumulative(_cl.hasOption('c')); _cli.setClassNames(_cl.getArgList()); _cli.type = _cl.getOptionValue('t'); if (_cl.hasOption('p')) { _cli.addToSootClassPath(_cl.getOptionValue('p')); } if (_cl.hasOption('S')) { _cli.setScopeSpecFile(_cl.getOptionValue('S')); } _cli.initialize(); _cli.<ITokens>execute(_cl.hasOption('j')); } catch (final ParseException _e) { LOGGER.error("Error while parsing command line.", _e); System.out.println("Error while parsing command line. \n" + _e); printUsage(_options); } catch (final Throwable _e) { LOGGER.error("Beyond our control. May day! May day!", _e); throw new RuntimeException(_e); } }
From source file:com.example.dlp.Inspect.java
/** * Command line application to inspect data using the Data Loss Prevention API. * Supported data formats: string, file, text file on GCS, BigQuery table, and Datastore entity *//* www. j ava 2 s .c om*/ public static void main(String[] args) throws Exception { OptionGroup optionsGroup = new OptionGroup(); optionsGroup.setRequired(true); Option stringOption = new Option("s", "string", true, "inspect string"); optionsGroup.addOption(stringOption); Option fileOption = new Option("f", "file path", true, "inspect input file path"); optionsGroup.addOption(fileOption); Option gcsOption = new Option("gcs", "Google Cloud Storage", false, "inspect GCS file"); optionsGroup.addOption(gcsOption); Option datastoreOption = new Option("ds", "Google Datastore", false, "inspect Datastore kind"); optionsGroup.addOption(datastoreOption); Option bigqueryOption = new Option("bq", "Google BigQuery", false, "inspect BigQuery table"); optionsGroup.addOption(bigqueryOption); Options commandLineOptions = new Options(); commandLineOptions.addOptionGroup(optionsGroup); Option minLikelihoodOption = Option.builder("minLikelihood").hasArg(true).required(false).build(); commandLineOptions.addOption(minLikelihoodOption); Option maxFindingsOption = Option.builder("maxFindings").hasArg(true).required(false).build(); commandLineOptions.addOption(maxFindingsOption); Option infoTypesOption = Option.builder("infoTypes").hasArg(true).required(false).build(); infoTypesOption.setArgs(Option.UNLIMITED_VALUES); commandLineOptions.addOption(infoTypesOption); Option includeQuoteOption = Option.builder("includeQuote").hasArg(true).required(false).build(); commandLineOptions.addOption(includeQuoteOption); Option bucketNameOption = Option.builder("bucketName").hasArg(true).required(false).build(); commandLineOptions.addOption(bucketNameOption); Option gcsFileNameOption = Option.builder("fileName").hasArg(true).required(false).build(); commandLineOptions.addOption(gcsFileNameOption); Option datasetIdOption = Option.builder("datasetId").hasArg(true).required(false).build(); commandLineOptions.addOption(datasetIdOption); Option tableIdOption = Option.builder("tableId").hasArg(true).required(false).build(); commandLineOptions.addOption(tableIdOption); Option projectIdOption = Option.builder("projectId").hasArg(true).required(false).build(); commandLineOptions.addOption(projectIdOption); Option datastoreNamespaceOption = Option.builder("namespace").hasArg(true).required(false).build(); commandLineOptions.addOption(datastoreNamespaceOption); Option datastoreKindOption = Option.builder("kind").hasArg(true).required(false).build(); commandLineOptions.addOption(datastoreKindOption); CommandLineParser parser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); CommandLine cmd; try { cmd = parser.parse(commandLineOptions, args); } catch (ParseException e) { System.out.println(e.getMessage()); formatter.printHelp(Inspect.class.getName(), commandLineOptions); System.exit(1); return; } Likelihood minLikelihood = Likelihood.valueOf( cmd.getOptionValue(minLikelihoodOption.getOpt(), Likelihood.LIKELIHOOD_UNSPECIFIED.name())); int maxFindings = Integer.parseInt(cmd.getOptionValue(maxFindingsOption.getOpt(), "0")); boolean includeQuote = Boolean.parseBoolean(cmd.getOptionValue(includeQuoteOption.getOpt(), "true")); List<InfoType> infoTypesList = Collections.emptyList(); if (cmd.hasOption(infoTypesOption.getOpt())) { infoTypesList = new ArrayList<>(); String[] infoTypes = cmd.getOptionValues(infoTypesOption.getOpt()); for (String infoType : infoTypes) { infoTypesList.add(InfoType.newBuilder().setName(infoType).build()); } } // string inspection if (cmd.hasOption("s")) { String val = cmd.getOptionValue(stringOption.getOpt()); inspectString(val, minLikelihood, maxFindings, infoTypesList, includeQuote); } else if (cmd.hasOption("f")) { String filePath = cmd.getOptionValue(fileOption.getOpt()); inspectFile(filePath, minLikelihood, maxFindings, infoTypesList, includeQuote); // gcs file inspection } else if (cmd.hasOption("gcs")) { String bucketName = cmd.getOptionValue(bucketNameOption.getOpt()); String fileName = cmd.getOptionValue(gcsFileNameOption.getOpt()); inspectGcsFile(bucketName, fileName, minLikelihood, infoTypesList); // datastore kind inspection } else if (cmd.hasOption("ds")) { String namespaceId = cmd.getOptionValue(datastoreNamespaceOption.getOpt(), ""); String kind = cmd.getOptionValue(datastoreKindOption.getOpt()); // use default project id when project id is not specified String projectId = cmd.getOptionValue(projectIdOption.getOpt(), ServiceOptions.getDefaultProjectId()); inspectDatastore(projectId, namespaceId, kind, minLikelihood, infoTypesList); } else if (cmd.hasOption("bq")) { String datasetId = cmd.getOptionValue(datasetIdOption.getOpt()); String tableId = cmd.getOptionValue(tableIdOption.getOpt()); // use default project id when project id is not specified String projectId = cmd.getOptionValue(projectIdOption.getOpt(), ServiceOptions.getDefaultProjectId()); inspectBigquery(projectId, datasetId, tableId, minLikelihood, infoTypesList); } }
From source file:fr.tpt.s3.mcdag.bench.MainBench.java
public static void main(String[] args) throws IOException, InterruptedException { // Command line options Options options = new Options(); Option input = new Option("i", "input", true, "MC-DAG XML models"); input.setRequired(true);//from ww w . j av a2s . co m input.setArgs(Option.UNLIMITED_VALUES); options.addOption(input); Option output = new Option("o", "output", true, "Folder where results have to be written."); output.setRequired(true); options.addOption(output); Option uUti = new Option("u", "utilization", true, "Utilization."); uUti.setRequired(true); options.addOption(uUti); Option output2 = new Option("ot", "output-total", true, "File where total results are being written"); output2.setRequired(true); options.addOption(output2); Option oCores = new Option("c", "cores", true, "Cores given to the test"); oCores.setRequired(true); options.addOption(oCores); Option oLvls = new Option("l", "levels", true, "Levels tested for the system"); oLvls.setRequired(true); options.addOption(oLvls); Option jobs = new Option("j", "jobs", true, "Number of threads to be launched."); jobs.setRequired(false); options.addOption(jobs); Option debug = new Option("d", "debug", false, "Debug logs."); debug.setRequired(false); options.addOption(debug); /* * Parsing of the command line */ CommandLineParser parser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println(e.getMessage()); formatter.printHelp("Benchmarks MultiDAG", options); System.exit(1); return; } String inputFilePath[] = cmd.getOptionValues("input"); String outputFilePath = cmd.getOptionValue("output"); String outputFilePathTotal = cmd.getOptionValue("output-total"); double utilization = Double.parseDouble(cmd.getOptionValue("utilization")); boolean boolDebug = cmd.hasOption("debug"); int nbLvls = Integer.parseInt(cmd.getOptionValue("levels")); int nbJobs = 1; int nbFiles = inputFilePath.length; if (cmd.hasOption("jobs")) nbJobs = Integer.parseInt(cmd.getOptionValue("jobs")); int nbCores = Integer.parseInt(cmd.getOptionValue("cores")); /* * While files need to be allocated * run the tests in the pool of threads */ // For dual-criticality systems we call a specific thread if (nbLvls == 2) { System.out.println(">>>>>>>>>>>>>>>>>>>>> NB levels " + nbLvls); int i_files2 = 0; String outFile = outputFilePath.substring(0, outputFilePath.lastIndexOf('.')) .concat("-schedulability.csv"); PrintWriter writer = new PrintWriter(outFile, "UTF-8"); writer.println( "Thread; File; FSched (%); FPreempts; FAct; LSched (%); LPreempts; LAct; ESched (%); EPreempts; EAct; HSched(%); HPreempts; HAct; Utilization"); writer.close(); ExecutorService executor2 = Executors.newFixedThreadPool(nbJobs); while (i_files2 != nbFiles) { BenchThreadDualCriticality bt2 = new BenchThreadDualCriticality(inputFilePath[i_files2], outFile, nbCores, boolDebug); executor2.execute(bt2); i_files2++; } executor2.shutdown(); executor2.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); int fedTotal = 0; int laxTotal = 0; int edfTotal = 0; int hybridTotal = 0; int fedPreempts = 0; int laxPreempts = 0; int edfPreempts = 0; int hybridPreempts = 0; int fedActiv = 0; int laxActiv = 0; int edfActiv = 0; int hybridActiv = 0; // Read lines in file and do average int i = 0; File f = new File(outFile); @SuppressWarnings("resource") Scanner line = new Scanner(f); while (line.hasNextLine()) { String s = line.nextLine(); if (i > 0) { // To skip the first line try (Scanner inLine = new Scanner(s).useDelimiter("; ")) { int j = 0; while (inLine.hasNext()) { String val = inLine.next(); if (j == 2) { fedTotal += Integer.parseInt(val); } else if (j == 3) { fedPreempts += Integer.parseInt(val); } else if (j == 4) { fedActiv += Integer.parseInt(val); } else if (j == 5) { laxTotal += Integer.parseInt(val); } else if (j == 6) { laxPreempts += Integer.parseInt(val); } else if (j == 7) { laxActiv += Integer.parseInt(val); } else if (j == 8) { edfTotal += Integer.parseInt(val); } else if (j == 9) { edfPreempts += Integer.parseInt(val); } else if (j == 10) { edfActiv += Integer.parseInt(val); } else if (j == 11) { hybridTotal += Integer.parseInt(val); } else if (j == 12) { hybridPreempts += Integer.parseInt(val); } else if (j == 13) { hybridActiv += Integer.parseInt(val); } j++; } } } i++; } // Write percentage double fedPerc = (double) fedTotal / nbFiles; double laxPerc = (double) laxTotal / nbFiles; double edfPerc = (double) edfTotal / nbFiles; double hybridPerc = (double) hybridTotal / nbFiles; double fedPercPreempts = (double) fedPreempts / fedActiv; double laxPercPreempts = (double) laxPreempts / laxActiv; double edfPercPreempts = (double) edfPreempts / edfActiv; double hybridPercPreempts = (double) hybridPreempts / hybridActiv; Writer wOutput = new BufferedWriter(new FileWriter(outputFilePathTotal, true)); wOutput.write(Thread.currentThread().getName() + "; " + utilization + "; " + fedPerc + "; " + fedPreempts + "; " + fedActiv + "; " + fedPercPreempts + "; " + laxPerc + "; " + laxPreempts + "; " + laxActiv + "; " + laxPercPreempts + "; " + edfPerc + "; " + edfPreempts + "; " + edfActiv + "; " + edfPercPreempts + "; " + hybridPerc + "; " + hybridPreempts + "; " + hybridActiv + "; " + hybridPercPreempts + "\n"); wOutput.close(); } else if (nbLvls > 2) { int i_files2 = 0; String outFile = outputFilePath.substring(0, outputFilePath.lastIndexOf('.')) .concat("-schedulability.csv"); PrintWriter writer = new PrintWriter(outFile, "UTF-8"); writer.println( "Thread; File; LSched (%); LPreempts; LAct; ESched (%); EPreempts; EAct; HSched(%); HPreempts; HAct; Utilization"); writer.close(); ExecutorService executor2 = Executors.newFixedThreadPool(nbJobs); while (i_files2 != nbFiles) { BenchThreadNLevels bt2 = new BenchThreadNLevels(inputFilePath[i_files2], outFile, nbCores, boolDebug); executor2.execute(bt2); i_files2++; } executor2.shutdown(); executor2.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); int laxTotal = 0; int edfTotal = 0; int hybridTotal = 0; int laxPreempts = 0; int edfPreempts = 0; int hybridPreempts = 0; int laxActiv = 0; int edfActiv = 0; int hybridActiv = 0; // Read lines in file and do average int i = 0; File f = new File(outFile); @SuppressWarnings("resource") Scanner line = new Scanner(f); while (line.hasNextLine()) { String s = line.nextLine(); if (i > 0) { // To skip the first line try (Scanner inLine = new Scanner(s).useDelimiter("; ")) { int j = 0; while (inLine.hasNext()) { String val = inLine.next(); if (j == 2) { laxTotal += Integer.parseInt(val); } else if (j == 3) { laxPreempts += Integer.parseInt(val); } else if (j == 4) { laxActiv += Integer.parseInt(val); } else if (j == 5) { edfTotal += Integer.parseInt(val); } else if (j == 6) { edfPreempts += Integer.parseInt(val); } else if (j == 7) { edfActiv += Integer.parseInt(val); } else if (j == 8) { hybridTotal += Integer.parseInt(val); } else if (j == 9) { hybridPreempts += Integer.parseInt(val); } else if (j == 10) { hybridActiv += Integer.parseInt(val); } j++; } } } i++; } // Write percentage double laxPerc = (double) laxTotal / nbFiles; double edfPerc = (double) edfTotal / nbFiles; double hybridPerc = (double) hybridTotal / nbFiles; double laxPercPreempts = (double) laxPreempts / laxActiv; double edfPercPreempts = (double) edfPreempts / edfActiv; double hybridPercPreempts = (double) hybridPreempts / hybridActiv; Writer wOutput = new BufferedWriter(new FileWriter(outputFilePathTotal, true)); wOutput.write(Thread.currentThread().getName() + "; " + utilization + "; " + laxPerc + "; " + laxPreempts + "; " + laxActiv + "; " + laxPercPreempts + "; " + edfPerc + "; " + edfPreempts + "; " + edfActiv + "; " + edfPercPreempts + "; " + hybridPerc + "; " + hybridPreempts + "; " + hybridActiv + "; " + hybridPercPreempts + "\n"); wOutput.close(); } else { System.err.println("Wrong number of levels"); System.exit(-1); } System.out.println("[BENCH Main] Done benchmarking U = " + utilization + " Levels " + nbLvls); }