List of usage examples for org.apache.commons.cli Option setArgName
public void setArgName(String argName)
From source file:de.onyxbits.raccoon.cli.Router.java
public static void main(String[] args) { Options options = new Options(); Option property = Option.builder("D").argName("property=value").numberOfArgs(2).valueSeparator() .desc(Messages.getString(DESC + "D")).build(); options.addOption(property);//from w w w . j a v a 2 s.c o m Option help = new Option("h", "help", false, Messages.getString(DESC + "h")); options.addOption(help); Option version = new Option("v", "version", false, Messages.getString(DESC + "v")); options.addOption(version); // GPA: Google Play Apps (we might add different markets later) Option playAppDetails = new Option(null, "gpa-details", true, Messages.getString(DESC + "gpa-details")); playAppDetails.setArgName("package"); options.addOption(playAppDetails); Option playAppBulkDetails = new Option(null, "gpa-bulkdetails", true, Messages.getString(DESC + "gpa-bulkdetails")); playAppBulkDetails.setArgName("file"); options.addOption(playAppBulkDetails); Option playAppBatchDetails = new Option(null, "gpa-batchdetails", true, Messages.getString(DESC + "gpa-batchdetails")); playAppBatchDetails.setArgName("file"); options.addOption(playAppBatchDetails); Option playAppSearch = new Option(null, "gpa-search", true, Messages.getString(DESC + "gpa-search")); playAppSearch.setArgName("query"); options.addOption(playAppSearch); CommandLine commandLine = null; try { commandLine = new DefaultParser().parse(options, args); } catch (ParseException e) { System.err.println(e.getMessage()); System.exit(1); } if (commandLine.hasOption(property.getOpt())) { System.getProperties().putAll(commandLine.getOptionProperties(property.getOpt())); } if (commandLine.hasOption(help.getOpt())) { new HelpFormatter().printHelp("raccoon", Messages.getString("header"), options, Messages.getString("footer"), true); System.exit(0); } if (commandLine.hasOption(version.getOpt())) { System.out.println(GlobalsProvider.getGlobals().get(Version.class)); System.exit(0); } if (commandLine.hasOption(playAppDetails.getLongOpt())) { Play.details(commandLine.getOptionValue(playAppDetails.getLongOpt())); System.exit(0); } if (commandLine.hasOption(playAppBulkDetails.getLongOpt())) { Play.bulkDetails(new File(commandLine.getOptionValue(playAppBulkDetails.getLongOpt()))); System.exit(0); } if (commandLine.hasOption(playAppBatchDetails.getLongOpt())) { Play.details(new File(commandLine.getOptionValue(playAppBatchDetails.getLongOpt()))); System.exit(0); } if (commandLine.hasOption(playAppSearch.getLongOpt())) { Play.search(commandLine.getOptionValue(playAppSearch.getLongOpt())); System.exit(0); } }
From source file:net.sf.jsignpdf.verify.SignatureCounter.java
/** * Main program.//from www. j a v a 2 s .co m * * @param args */ public static void main(String[] args) { // create the Options final Option optHelp = new Option("h", "help", false, "print this message"); final Option optDebug = new Option("d", "debug", false, "enables debug output"); final Option optNames = new Option("n", "names", false, "print comma separated signature names instead of the count"); final Option optPasswd = new Option("p", "password", true, "set password for opening PDF"); optPasswd.setArgName("password"); final Options options = new Options(); options.addOption(optHelp); options.addOption(optDebug); options.addOption(optNames); options.addOption(optPasswd); CommandLine line = null; try { // create the command line parser CommandLineParser parser = new PosixParser(); // parse the command line arguments line = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Unable to parse command line (Use -h for the help)\n" + exp.getMessage()); System.exit(Constants.EXIT_CODE_PARSE_ERR); } final String[] tmpArgs = line.getArgs(); if (line.hasOption("h") || args == null || args.length == 0) { // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(70, "java -jar SignatureCounter.jar [file1.pdf [file2.pdf ...]]", "JSignPdf SignatureCounter is a command line tool which prints count of signatures in given PDF document.", options, null, true); } else { byte[] tmpPasswd = null; if (line.hasOption("p")) { tmpPasswd = line.getOptionValue("p").getBytes(); } final boolean debug = line.hasOption("d"); final boolean names = line.hasOption("n"); for (String tmpFilePath : tmpArgs) { if (debug) { System.out.print("Counting signatures in " + tmpFilePath + ": "); } final File tmpFile = new File(tmpFilePath); if (!tmpFile.canRead()) { System.err.println("Couldn't read the file. Check the path and permissions: " + tmpFilePath); System.exit(Constants.EXIT_CODE_CANT_READ_FILE); } try { final PdfReader pdfReader = PdfUtils.getPdfReader(tmpFilePath, tmpPasswd); @SuppressWarnings("unchecked") final List<String> sigNames = pdfReader.getAcroFields().getSignatureNames(); if (names) { //print comma-separated names boolean isNotFirst = false; for (String sig : sigNames) { if (isNotFirst) { System.out.println(","); } else { isNotFirst = true; } System.out.println(sig); } } else { //normal processing print only count of signatures System.out.println(sigNames.size()); if (debug) { System.out.println("Signature names: " + sigNames); } } } catch (IOException e) { e.printStackTrace(); System.exit(Constants.EXIT_CODE_COMMON_ERROR); } } } }
From source file:fr.inria.atlanmod.kyanos.benchmarks.KyanosGraphCreator.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input file"); inputOpt.setArgs(1);/*from www. ja v a2 s .c o m*/ inputOpt.setRequired(true); Option outputOpt = OptionBuilder.create(OUT); outputOpt.setArgName("OUTPUT"); outputOpt.setDescription("Output directory"); outputOpt.setArgs(1); outputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(EPACKAGE_CLASS); inClassOpt.setArgName("CLASS"); inClassOpt.setDescription("FQN of EPackage implementation class"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); Option optFileOpt = OptionBuilder.create(OPTIONS_FILE); optFileOpt.setArgName("FILE"); optFileOpt.setDescription("Properties file holding the options to be used in the Kyanos Resource"); optFileOpt.setArgs(1); options.addOption(inputOpt); options.addOption(outputOpt); options.addOption(inClassOpt); options.addOption(optFileOpt); CommandLineParser parser = new PosixParser(); try { PersistenceBackendFactoryRegistry.getFactories().put(NeoBlueprintsURI.NEO_GRAPH_SCHEME, new BlueprintsPersistenceBackendFactory()); CommandLine commandLine = parser.parse(options, args); URI sourceUri = URI.createFileURI(commandLine.getOptionValue(IN)); URI targetUri = NeoBlueprintsURI.createNeoGraphURI(new File(commandLine.getOptionValue(OUT))); Class<?> inClazz = KyanosGraphCreator.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("zxmi", new XMIResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap() .put(NeoBlueprintsURI.NEO_GRAPH_SCHEME, PersistentResourceFactory.eINSTANCE); Resource sourceResource = resourceSet.createResource(sourceUri); Map<String, Object> loadOpts = new HashMap<String, Object>(); if ("zxmi".equals(sourceUri.fileExtension())) { loadOpts.put(XMIResource.OPTION_ZIP, Boolean.TRUE); } Runtime.getRuntime().gc(); long initialUsedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); LOG.log(Level.INFO, MessageFormat.format("Used memory before loading: {0}", MessageUtil.byteCountToDisplaySize(initialUsedMemory))); LOG.log(Level.INFO, "Loading source resource"); sourceResource.load(loadOpts); LOG.log(Level.INFO, "Source resource loaded"); Runtime.getRuntime().gc(); long finalUsedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); LOG.log(Level.INFO, MessageFormat.format("Used memory after loading: {0}", MessageUtil.byteCountToDisplaySize(finalUsedMemory))); LOG.log(Level.INFO, MessageFormat.format("Memory use increase: {0}", MessageUtil.byteCountToDisplaySize(finalUsedMemory - initialUsedMemory))); Resource targetResource = resourceSet.createResource(targetUri); Map<String, Object> saveOpts = new HashMap<String, Object>(); if (commandLine.hasOption(OPTIONS_FILE)) { Properties properties = new Properties(); properties.load(new FileInputStream(new File(commandLine.getOptionValue(OPTIONS_FILE)))); for (final Entry<Object, Object> entry : properties.entrySet()) { saveOpts.put((String) entry.getKey(), (String) entry.getValue()); } } List<StoreOption> storeOptions = new ArrayList<StoreOption>(); storeOptions.add(BlueprintsResourceOptions.EStoreGraphOption.AUTOCOMMIT); saveOpts.put(BlueprintsResourceOptions.STORE_OPTIONS, storeOptions); targetResource.save(saveOpts); LOG.log(Level.INFO, "Start moving elements"); targetResource.getContents().clear(); targetResource.getContents().addAll(sourceResource.getContents()); LOG.log(Level.INFO, "End moving elements"); LOG.log(Level.INFO, "Start saving"); targetResource.save(saveOpts); LOG.log(Level.INFO, "Saved"); if (targetResource instanceof PersistentResourceImpl) { PersistentResourceImpl.shutdownWithoutUnload((PersistentResourceImpl) targetResource); } else { targetResource.unload(); } } catch (ParseException e) { MessageUtil.showError(e.toString()); MessageUtil.showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { MessageUtil.showError(e.toString()); } }
From source file:ca.uhn.hunit.example.MllpHl7v2MessageSwapper.java
public static void main(String[] theArgs) { Options options = new Options(); Option option = new Option("R", true, "Text to substiture in the message"); option.setArgs(2);//from w w w . ja v a 2 s. co m option.setArgName("text=substitution"); option.setValueSeparator('='); option.setRequired(true); options.addOption(option); option = new Option("p", true, "Number of passes"); option.setValueSeparator('='); option.setRequired(false); options.addOption(option); CommandLine commandLine; int passes; try { commandLine = new PosixParser().parse(options, theArgs); passes = Integer.parseInt(commandLine.getOptionValue("p", "1")); } catch (ParseException e) { HelpFormatter hf = new HelpFormatter(); hf.printHelp( "java -cp hunit-[version]-jar-with-dependencies.jar ca.uhn.hunit.example.MllpHl7v2MessageSwapper {-Rtext=substitution}... [options]", options); return; } Properties substitutions = commandLine.getOptionProperties("R"); new MllpHl7v2MessageSwapper(true, substitutions, passes).run(); }
From source file:de.topobyte.livecg.ShowVisualization.java
public static void main(String[] args) { EnumNameLookup<Visualization> visualizationSwitch = new EnumNameLookup<Visualization>(Visualization.class, true);/*from ww w .j ava 2 s. c om*/ // @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:illarion.compile.Compiler.java
public static void main(final String[] args) { ByteArrayOutputStream stdOutBuffer = new ByteArrayOutputStream(); PrintStream orgStdOut = System.out; System.setOut(new PrintStream(stdOutBuffer)); SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install();//w w w .j av a 2s .c o m Options options = new Options(); final Option npcDir = new Option("n", "npc-dir", true, "The place where the compiled NPC files are stored."); npcDir.setArgs(1); npcDir.setArgName("directory"); npcDir.setRequired(false); options.addOption(npcDir); final Option questDir = new Option("q", "quest-dir", true, "The place where the compiled Quest files are stored."); questDir.setArgs(1); questDir.setArgName("directory"); questDir.setRequired(false); options.addOption(questDir); final Option type = new Option("t", "type", true, "This option is used to set what kind of parser is supposed to be used in case" + " the content of standard input is processed."); type.setArgs(1); type.setArgName("type"); type.setRequired(false); options.addOption(type); CommandLineParser parser = new GnuParser(); try { CommandLine cmd = parser.parse(options, args); String[] files = cmd.getArgs(); if (files.length > 0) { System.setOut(orgStdOut); stdOutBuffer.writeTo(orgStdOut); processFileMode(cmd); } else { System.setOut(orgStdOut); processStdIn(cmd); } } catch (final ParseException e) { final HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("java -jar compiler.jar [Options] File", options, true); System.exit(-1); } catch (final IOException e) { LOGGER.error(e.getLocalizedMessage()); System.exit(-1); } }
From source file:com.genentech.chemistry.openEye.apps.SDFCatsIndexer.java
/** * @param args/*from ww w.j a v a 2 s . com*/ */ public static void main(String... args) throws IOException { // create command line Options object Options options = new Options(); Option opt = new Option(OPT_INFILE, true, "input file oe-supported Use .sdf|.smi to specify the file type."); opt.setRequired(true); opt.setArgName("fn"); options.addOption(opt); opt = new Option(OPT_OUTFILE, true, "output file oe-supported. Use .sdf|.smi to specify the file type."); opt.setRequired(true); opt.setArgName("fn"); options.addOption(opt); opt = new Option(OPT_NORMALIZATION, true, "Normalization method: Counts|CountsPerAtom|CountsPerFeature(def) multiple allowed"); opt.setArgName("meth"); options.addOption(opt); opt = new Option(OPT_PRINTDESC, false, "Causes the descriptor for describing each linear path in a molceule to be created"); options.addOption(opt); opt = new Option(OPT_RGROUPTYPES, false, "treat RGroup attachement point ([U]) as atom type."); options.addOption(opt); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.err.println(e.getMessage()); exitWithHelp(options); } String inFile = cmd.getOptionValue(OPT_INFILE); String outFile = cmd.getOptionValue(OPT_OUTFILE); AtomTyperInterface[] myTypes = CATSIndexer.typers; String tagPrefix = ""; if (cmd.hasOption(OPT_RGROUPTYPES)) { myTypes = CATSIndexer.rgroupTypers; tagPrefix = "RG"; } if (cmd.hasOption(OPT_PRINTDESC)) { SDFCatsIndexer sdfIndexer = new SDFCatsIndexer(myTypes, tagPrefix); sdfIndexer.printDescriptors(inFile, outFile); sdfIndexer.close(); return; } EnumSet<Normalization> normMeth = EnumSet.noneOf(Normalization.class); if (cmd.hasOption(OPT_NORMALIZATION)) for (String n : cmd.getOptionValues(OPT_NORMALIZATION)) normMeth.add(Normalization.valueOf(n)); else normMeth.add(Normalization.CountsPerFeature); SDFCatsIndexer sdfIndexer = new SDFCatsIndexer(myTypes, tagPrefix); sdfIndexer.run(inFile, outFile, normMeth); sdfIndexer.close(); }
From source file:de.bruse.c2x.cli.Main.java
public static void main(String[] args) { CommandLineParser parser = new GnuParser(); Options options = new Options(); Option input = new Option("i", INPUT, HAS_ARGS, "CityGML file to be converted."); input.setArgs(ONE);/*from w w w . j ava 2 s . c om*/ input.setArgName(INPUT); input.setRequired(Boolean.TRUE); options.addOption(input); Option levelOfDetail = new Option("l", LEVEL_OF_DETAIL, HAS_ARGS, "Level of detail to be converted. Possible values are LOD1 and LOD2."); levelOfDetail.setArgs(ONE); levelOfDetail.setArgName(LEVEL_OF_DETAIL); levelOfDetail.setRequired(Boolean.TRUE); options.addOption(levelOfDetail); Option geometryType = new Option("t", GEOMETRY_TYPE, HAS_ARGS, "Geometry type to be converted. Possible values are SOLID and MULTI_SURFACE."); geometryType.setArgs(ONE); geometryType.setArgName(GEOMETRY_TYPE); geometryType.setRequired(Boolean.TRUE); options.addOption(geometryType); Option output = new Option("o", OUTPUT, HAS_ARGS, "File path of the output file."); output.setArgs(ONE); output.setArgName(OUTPUT); output.setRequired(Boolean.FALSE); options.addOption(output); Option targetFormat = new Option("f", FORMAT, HAS_ARGS, "Format of the output file. Possible values are X3D and COLLADA."); targetFormat.setArgs(ONE); targetFormat.setArgName(FORMAT); targetFormat.setRequired(Boolean.TRUE); options.addOption(targetFormat); Option split = new Option("s", SPLIT, NO_ARGS, "Generate one scene node for each building (X3D only)."); split.setArgName(SPLIT); split.setRequired(Boolean.FALSE); options.addOption(split); Option validate = new Option("v", VALIDATE, NO_ARGS, "Validate the CityGML file."); validate.setArgName(VALIDATE); validate.setRequired(Boolean.FALSE); options.addOption(validate); try { CommandLine line = parser.parse(options, args); if (line.hasOption(INPUT) && line.hasOption(LEVEL_OF_DETAIL) && line.hasOption(GEOMETRY_TYPE) && line.hasOption(FORMAT)) { String inputValue = line.getOptionValue(INPUT); String levelOfDetailValue = line.getOptionValue(LEVEL_OF_DETAIL); String geometryTypeValue = line.getOptionValue(GEOMETRY_TYPE); String targetFormatValue = line.getOptionValue(FORMAT); String outputValue = line.getOptionValue(OUTPUT); LevelOfDetail lod = LevelOfDetail.valueOf(levelOfDetailValue); GeometryType type = GeometryType.valueOf(geometryTypeValue); if (Objects.isNull(lod) || Objects.isNull(type) || (!targetFormatValue.equals(X3D) && !targetFormatValue.equals(COLLADA))) { printHelp(options); } else { if (line.hasOption(VALIDATE)) { triggerValidation(inputValue); } if (targetFormatValue.equals(X3D)) { boolean splitValue = false; if (line.hasOption(SPLIT)) { splitValue = true; } if (Objects.isNull(outputValue) || outputValue.isEmpty()) { outputValue = inputValue + X3D_FILE_EXT; } triggerX3DConversion(inputValue, lod, type, outputValue, splitValue); } else if (targetFormatValue.equals(COLLADA)) { if (Objects.isNull(outputValue) || outputValue.isEmpty()) { outputValue = inputValue + COLLADA_FILE_EXT; } triggerColladaConversion(inputValue, lod, type, outputValue); } System.out.println("Conversion succeeded."); } } else { printHelp(options); } } catch (ParseException | IllegalArgumentException e) { printHelp(options); } catch (ValidationException e) { System.out.println("Input file is invalid. Operation canceled.\n" + e.getMessage()); } catch (ConversionException e) { String message = "Failed to convert CityGML."; if (Objects.nonNull(e.getMessage())) { message += " " + e.getMessage(); } System.out.println(message); } catch (IOException e) { System.out.println("Failed to read from file '" + input + "'."); } }
From source file:com.genentech.chemistry.openEye.apps.SDFTopologicalIndexer.java
/** * @param args//from w w w .j a va 2 s. com */ public static void main(String... args) throws IOException { // create command line Options object Options options = new Options(); Option opt = new Option(OPT_INFILE, true, "input file oe-supported Use .sdf|.smi to specify the file type."); opt.setRequired(true); opt.setArgName("fn"); options.addOption(opt); opt = new Option(OPT_OUTFILE, true, "output file oe-supported. Use .sdf|.smi to specify the file type."); opt.setRequired(true); opt.setArgName("fn"); options.addOption(opt); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.err.println(e.getMessage()); exitWithHelp(options); } args = cmd.getArgs(); if (cmd.hasOption("d")) { System.err.println("Start debugger and press return:"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } if (args.length == 0) { System.err.println("Specify at least one index type"); exitWithHelp(options); } String inFile = cmd.getOptionValue(OPT_INFILE); String outFile = cmd.getOptionValue(OPT_OUTFILE); Set<String> selectedIndexes = new HashSet<String>(args.length); if (args.length == 1 && "all".equalsIgnoreCase(args[0])) selectedIndexes = AVAILIndexes; else selectedIndexes.addAll(Arrays.asList(args)); if (!AVAILIndexes.containsAll(selectedIndexes)) { selectedIndexes.removeAll(AVAILIndexes); StringBuilder err = new StringBuilder("Unknown Index types: "); for (String it : selectedIndexes) err.append(it).append(" "); System.err.println(err); exitWithHelp(options); } SDFTopologicalIndexer sdfIndexer = new SDFTopologicalIndexer(outFile, selectedIndexes); sdfIndexer.run(inFile); sdfIndexer.close(); }
From source file:edu.ksu.cis.indus.xmlizer.JimpleXMLizerCLI.java
/** * The entry point to execute this xmlizer from command prompt. * //from ww w.java2s.c o m * @param s is the command-line arguments. * @throws RuntimeException when jimple xmlization fails. * @pre s != null */ public static void main(final String[] s) { final Scene _scene = Scene.v(); final Options _options = new Options(); Option _o = new Option("d", "dump directory", true, "The directory in which to write the xml files. " + "If unspecified, the xml output will be directed standard out."); _o.setArgs(1); _o.setArgName("path"); _o.setOptionalArg(false); _options.addOption(_o); _o = new Option("h", "help", false, "Display message."); _options.addOption(_o); _o = new Option("p", "soot-classpath", true, "Prepend this to soot class path."); _o.setArgs(1); _o.setArgName("classpath"); _o.setOptionalArg(false); _options.addOption(_o); final HelpFormatter _help = new HelpFormatter(); try { final CommandLine _cl = (new BasicParser()).parse(_options, s); final String[] _args = _cl.getArgs(); if (_cl.hasOption('h')) { final String _cmdLineSyn = "java " + JimpleXMLizerCLI.class.getName() + "<options> <class names>"; _help.printHelp(_cmdLineSyn.length(), _cmdLineSyn, "", _options, "", true); } else { if (_args.length > 0) { if (_cl.hasOption('p')) { _scene.setSootClassPath( _cl.getOptionValue('p') + File.pathSeparator + _scene.getSootClassPath()); } final NamedTag _tag = new NamedTag("JimpleXMLizer"); for (int _i = 0; _i < _args.length; _i++) { final SootClass _sc = _scene.loadClassAndSupport(_args[_i]); _sc.addTag(_tag); } final IProcessingFilter _filter = new TagBasedProcessingFilter(_tag.getName()); writeJimpleAsXML(new Environment(_scene), _cl.getOptionValue('d'), null, new UniqueJimpleIDGenerator(), _filter); } else { System.out.println("No classes were specified."); } } } catch (final ParseException _e) { LOGGER.error("Error while parsing command line.", _e); printUsage(_options); } catch (final Throwable _e) { LOGGER.error("Beyond our control. May day! May day!", _e); throw new RuntimeException(_e); } }