List of usage examples for org.apache.commons.cli ParseException getLocalizedMessage
public String getLocalizedMessage()
From source file:cloudproject.test.GetContainerInfo.java
/** * Takes a media container (file) as the first argument, opens it, * and tells you what's inside the container. * /*from w w w . j a va2 s.co m*/ * @param args Must contain one string which represents a filename. If no arguments, then prints help. * @throws IOException if file cannot be opened. * @throws InterruptedException if process is interrupted while querying. */ public static void main(String[] args) throws InterruptedException, IOException { //Print out everything in the console into the file printOutputFile pof = new printOutputFile(); pof.printOutToFile("BigBuckBunny_320x180_v7"); final Options options = new Options(); options.addOption("h", "help", false, "displays help"); options.addOption("v", "version", false, "version of this library"); //OPen a file from local // String filename = "/Users/lxb200709/Documents/TransCloud/videosource/big_buck_bunny_1080p_h264.mov"; // String filename = "/Users/lxb200709/Documents/TransCloud/videosource/sample.flv"; // String filename = "/Users/lxb200709/Documents/TransCloud/videosource/bbb_sunflower_1080p_60fps_normal.mp4"; String filename = "/Users/lxb200709/Documents/TransCloud/videosource/inputvideo/big_buck_bunny_720p_VP8_VORBIS_25fps_3900K.WebM"; // String filename = "/Users/lxb200709/Documents/TransCloud/videosource/big_buck_bunny_480p_h264.mov"; // String filename = "/Users/lxb200709/Documents/TransCloud/videosource/akiyo_cif.y4m"; getInfo(filename); final CommandLineParser parser = new org.apache.commons.cli.BasicParser(); try { final CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("version")) { // let's find what version of the library we're running final String version = io.humble.video_native.Version.getVersionInfo(); System.out.println("Humble Version: " + version); } else if (cmd.hasOption("help") || args.length == 0) { final HelpFormatter formatter = new HelpFormatter(); // formatter.printHelp(GetContainerInfo.class.getCanonicalName() + " [<filename> ...]", options); } else { final String[] parsedArgs = cmd.getArgs(); for (String arg : parsedArgs) getInfo(arg); } } catch (ParseException e) { System.err.println("Exception parsing command line: " + e.getLocalizedMessage()); } }
From source file:io.s4.client.Adapter.java
@SuppressWarnings("static-access") public static void main(String args[]) throws IOException, InterruptedException { Options options = new Options(); options.addOption(OptionBuilder.withArgName("corehome").hasArg().withDescription("core home").create("c")); options.addOption(//from w w w . ja v a 2 s . c o m OptionBuilder.withArgName("instanceid").hasArg().withDescription("instance id").create("i")); options.addOption( OptionBuilder.withArgName("configtype").hasArg().withDescription("configuration type").create("t")); options.addOption(OptionBuilder.withArgName("userconfig").hasArg() .withDescription("user-defined legacy data adapter configuration file").create("d")); CommandLineParser parser = new GnuParser(); CommandLine commandLine = null; try { commandLine = parser.parse(options, args); } catch (ParseException pe) { System.err.println(pe.getLocalizedMessage()); System.exit(1); } int instanceId = -1; if (commandLine.hasOption("i")) { String instanceIdStr = commandLine.getOptionValue("i"); try { instanceId = Integer.parseInt(instanceIdStr); } catch (NumberFormatException nfe) { System.err.println("Bad instance id: %s" + instanceIdStr); System.exit(1); } } if (commandLine.hasOption("c")) { coreHome = commandLine.getOptionValue("c"); } String configType = "typical"; if (commandLine.hasOption("t")) { configType = commandLine.getOptionValue("t"); } String userConfigFilename = null; if (commandLine.hasOption("d")) { userConfigFilename = commandLine.getOptionValue("d"); } File userConfigFile = new File(userConfigFilename); if (!userConfigFile.isFile()) { System.err.println("Bad user configuration file: " + userConfigFilename); System.exit(1); } File coreHomeFile = new File(coreHome); if (!coreHomeFile.isDirectory()) { System.err.println("Bad core home: " + coreHome); System.exit(1); } if (instanceId > -1) { System.setProperty("instanceId", "" + instanceId); } else { System.setProperty("instanceId", "" + S4Util.getPID()); } String configBase = coreHome + File.separatorChar + "conf" + File.separatorChar + configType; String configPath = configBase + File.separatorChar + "client-adapter-conf.xml"; File configFile = new File(configPath); if (!configFile.exists()) { System.err.printf("adapter config file %s does not exist\n", configPath); System.exit(1); } // load adapter config xml ApplicationContext coreContext; coreContext = new FileSystemXmlApplicationContext("file:" + configPath); ApplicationContext context = coreContext; Adapter adapter = (Adapter) context.getBean("client_adapter"); ApplicationContext appContext = new FileSystemXmlApplicationContext( new String[] { "file:" + userConfigFilename }, context); Map<?, ?> inputStubBeanMap = appContext.getBeansOfType(InputStub.class); Map<?, ?> outputStubBeanMap = appContext.getBeansOfType(OutputStub.class); if (inputStubBeanMap.size() == 0 && outputStubBeanMap.size() == 0) { System.err.println("No user-defined input/output stub beans"); System.exit(1); } ArrayList<InputStub> inputStubs = new ArrayList<InputStub>(inputStubBeanMap.size()); ArrayList<OutputStub> outputStubs = new ArrayList<OutputStub>(outputStubBeanMap.size()); // add all input stubs for (Map.Entry<?, ?> e : inputStubBeanMap.entrySet()) { String beanName = (String) e.getKey(); System.out.println("Adding InputStub " + beanName); inputStubs.add((InputStub) e.getValue()); } // add all output stubs for (Map.Entry<?, ?> e : outputStubBeanMap.entrySet()) { String beanName = (String) e.getKey(); System.out.println("Adding OutputStub " + beanName); outputStubs.add((OutputStub) e.getValue()); } adapter.setInputStubs(inputStubs); adapter.setOutputStubs(outputStubs); }
From source file:fr.inria.atlanmod.instantiator.neoEMF.Launcher.java
public static void main(String[] args) throws GenerationException, IOException { ResourceSetImpl resourceSet = new ResourceSetImpl(); { // initializing the registry resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(EcorePackage.eNS_PREFIX, new EcoreResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap() .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put(NeoEMFURI.NEOEMF_HBASE_SCHEME, NeoEMFResourceFactory.eINSTANCE); }/* w ww. j a v a2 s. co m*/ Options options = new Options(); configureOptions(options); CommandLineParser parser = new GnuParser(); try { CommandLine commandLine = parser.parse(options, args); String epackage_class = commandLine.getOptionValue(E_PACKAGE_CLASS); LOGGER.info("Start loading the package"); Class<?> inClazz = Launcher.class.getClassLoader().loadClass(epackage_class); EPackage _package = (EPackage) inClazz.getMethod("init").invoke(null); Resource metamodelResource = new XMIResourceImpl(URI.createFileURI("dummy")); metamodelResource.getContents().add(_package); LOGGER.info("Finish loading the package"); int size = Launcher.DEFAULT_AVERAGE_MODEL_SIZE; if (commandLine.hasOption(SIZE)) { Number number = (Number) commandLine.getParsedOptionValue(SIZE); size = (int) Math.min(Integer.MAX_VALUE, number.longValue()); } float variation = Launcher.DEFAULT_DEVIATION; if (commandLine.hasOption(VARIATION)) { Number number = (Number) commandLine.getParsedOptionValue(VARIATION); if (number.floatValue() < 0.0f || number.floatValue() > 1.0f) { throw new ParseException(MessageFormat.format("Invalid value for option -{0}: {1}", VARIATION, number.floatValue())); } variation = number.floatValue(); } float propVariation = Launcher.DEFAULT_DEVIATION; if (commandLine.hasOption(PROP_VARIATION)) { Number number = (Number) commandLine.getParsedOptionValue(PROP_VARIATION); if (number.floatValue() < 0.0f || number.floatValue() > 1.0f) { throw new ParseException(MessageFormat.format("Invalid value for option -{0}: {1}", PROP_VARIATION, number.floatValue())); } propVariation = number.floatValue(); } long seed = System.currentTimeMillis(); if (commandLine.hasOption(SEED)) { seed = ((Number) commandLine.getParsedOptionValue(SEED)).longValue(); } Range<Integer> range = Range.between(Math.round(size * (1 - variation)), Math.round(size * (1 + variation))); GenericMetamodelConfig config = new GenericMetamodelConfig(metamodelResource, range, seed); GenericMetamodelGenerator modelGen = new GenericMetamodelGenerator(config); if (commandLine.hasOption(OUTPUT_PATH)) { String outDir = commandLine.getOptionValue(OUTPUT_PATH); //java.net.URI intermediateURI = java.net.URI.create(outDir); modelGen.setSamplesPath(outDir); } int numberOfModels = 1; if (commandLine.hasOption(N_MODELS)) { numberOfModels = ((Number) commandLine.getParsedOptionValue(N_MODELS)).intValue(); } int valuesSize = GenericMetamodelConfig.DEFAULT_AVERAGE_VALUES_LENGTH; if (commandLine.hasOption(VALUES_SIZE)) { Number number = (Number) commandLine.getParsedOptionValue(VALUES_SIZE); valuesSize = (int) Math.min(Integer.MAX_VALUE, number.longValue()); } int referencesSize = GenericMetamodelConfig.DEFAULT_AVERAGE_REFERENCES_SIZE; if (commandLine.hasOption(VALUES_SIZE)) { Number number = (Number) commandLine.getParsedOptionValue(DEGREE); referencesSize = (int) Math.min(Integer.MAX_VALUE, number.longValue()); } config.setValuesRange(Math.round(valuesSize * (1 - propVariation)), Math.round(valuesSize * (1 + propVariation))); config.setReferencesRange(Math.round(referencesSize * (1 - propVariation)), Math.round(referencesSize * (1 + propVariation))); config.setPropertiesRange(Math.round(referencesSize * (1 - propVariation)), Math.round(referencesSize * (1 + propVariation))); long start = System.currentTimeMillis(); modelGen.runGeneration(resourceSet, numberOfModels, size, variation); long end = System.currentTimeMillis(); LOGGER.info( MessageFormat.format("Generation finished after {0} s", Long.toString((end - start) / 1000))); if (commandLine.hasOption(DIAGNOSE)) { for (Resource resource : resourceSet.getResources()) { LOGGER.info( MessageFormat.format("Requested validation for resource ''{0}''", resource.getURI())); BasicDiagnostic diagnosticChain = diagnoseResource(resource); if (!isFailed(diagnosticChain)) { LOGGER.info(MessageFormat.format("Result of the diagnosis of resurce ''{0}'' is ''OK''", resource.getURI())); } else { LOGGER.severe(MessageFormat.format("Found ''{0}'' error(s) in the resource ''{1}''", diagnosticChain.getChildren().size(), resource.getURI())); for (Diagnostic diagnostic : diagnosticChain.getChildren()) { LOGGER.fine(diagnostic.getMessage()); } } } LOGGER.info("Validation finished"); } } catch (ParseException e) { System.err.println(e.getLocalizedMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.setOptionComparator(new OptionComarator<Option>()); try { formatter.setWidth(Math.max(Terminal.getTerminal().getTerminalWidth(), 80)); } catch (Throwable t) { LOGGER.warning("Unable to get console information"); } ; formatter.printHelp("java -jar <this-file.jar>", options, true); System.exit(ERROR); } catch (ClassNotFoundException t) { System.err.println("ERROR: Unable to load class" + t.getLocalizedMessage()); StringWriter stringWriter = new StringWriter(); t.printStackTrace(new PrintWriter(stringWriter)); System.err.println(stringWriter.toString()); } catch (Throwable t) { System.err.println("ERROR: " + t.getLocalizedMessage()); StringWriter stringWriter = new StringWriter(); t.printStackTrace(new PrintWriter(stringWriter)); System.err.println(t); LOGGER.severe(stringWriter.toString()); System.exit(ERROR); } }
From source file:fr.inria.atlanmod.dag.instantiator.Launcher.java
public static void main(String[] args) throws GenerationException, IOException { ResourceSetImpl resourceSet = new ResourceSetImpl(); { // initializing the registry resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(EcorePackage.eNS_PREFIX, new EcoreResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap() .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put(NeoEMFURI.NEOEMF_HBASE_SCHEME, NeoEMFResourceFactory.eINSTANCE); }/*www . j a v a 2 s . co m*/ Options options = new Options(); configureOptions(options); CommandLineParser parser = new GnuParser(); try { CommandLine commandLine = parser.parse(options, args); // String epackage_class = commandLine.getOptionValue(E_PACKAGE_CLASS); // // LOGGER.info("Start loading the package"); // Class<?> inClazz = Launcher.class.getClassLoader().loadClass(epackage_class); // EPackage _package = (EPackage) inClazz.getMethod("init").invoke(null); // // Resource metamodelResource = new XMIResourceImpl(URI.createFileURI("dummy")); // metamodelResource.getContents().add(_package); // LOGGER.info("Finish loading the package"); int size = Launcher.DEFAULT_AVERAGE_MODEL_SIZE; if (commandLine.hasOption(SIZE)) { Number number = (Number) commandLine.getParsedOptionValue(SIZE); size = (int) Math.min(Integer.MAX_VALUE, number.longValue()); } float variation = Launcher.DEFAULT_DEVIATION; if (commandLine.hasOption(VARIATION)) { Number number = (Number) commandLine.getParsedOptionValue(VARIATION); if (number.floatValue() < 0.0f || number.floatValue() > 1.0f) { throw new ParseException(MessageFormat.format("Invalid value for option -{0}: {1}", VARIATION, number.floatValue())); } variation = number.floatValue(); } float propVariation = Launcher.DEFAULT_DEVIATION; if (commandLine.hasOption(PROP_VARIATION)) { Number number = (Number) commandLine.getParsedOptionValue(PROP_VARIATION); if (number.floatValue() < 0.0f || number.floatValue() > 1.0f) { throw new ParseException(MessageFormat.format("Invalid value for option -{0}: {1}", PROP_VARIATION, number.floatValue())); } propVariation = number.floatValue(); } long seed = System.currentTimeMillis(); if (commandLine.hasOption(SEED)) { seed = ((Number) commandLine.getParsedOptionValue(SEED)).longValue(); } Range<Integer> range = Range.between(Math.round(size * (1 - variation)), Math.round(size * (1 + variation))); ISpecimenConfiguration config = new DagMetamodelConfig(range, seed); IGenerator generator = new DagGenerator(config, config.getSeed()); GenericMetamodelGenerator modelGen = new GenericMetamodelGenerator(generator); if (commandLine.hasOption(OUTPUT_PATH)) { String outDir = commandLine.getOptionValue(OUTPUT_PATH); //java.net.URI intermediateURI = java.net.URI.create(outDir); modelGen.setSamplesPath(outDir); } int numberOfModels = 1; if (commandLine.hasOption(N_MODELS)) { numberOfModels = ((Number) commandLine.getParsedOptionValue(N_MODELS)).intValue(); } int valuesSize = GenericMetamodelConfig.DEFAULT_AVERAGE_VALUES_LENGTH; if (commandLine.hasOption(VALUES_SIZE)) { Number number = (Number) commandLine.getParsedOptionValue(VALUES_SIZE); valuesSize = (int) Math.min(Integer.MAX_VALUE, number.longValue()); } int referencesSize = GenericMetamodelConfig.DEFAULT_AVERAGE_REFERENCES_SIZE; if (commandLine.hasOption(DEGREE)) { Number number = (Number) commandLine.getParsedOptionValue(DEGREE); referencesSize = (int) Math.min(Integer.MAX_VALUE, number.longValue()); } config.setValuesRange(Math.round(valuesSize * (1 - propVariation)), Math.round(valuesSize * (1 + propVariation))); config.setReferencesRange(Math.round(referencesSize * (1 - propVariation)), Math.round(referencesSize * (1 + propVariation))); config.setPropertiesRange(Math.round(referencesSize * (1 - propVariation)), Math.round(referencesSize * (1 + propVariation))); long start = System.currentTimeMillis(); modelGen.runGeneration(resourceSet, numberOfModels, size, variation); long end = System.currentTimeMillis(); LOGGER.info( MessageFormat.format("Generation finished after {0} s", Long.toString((end - start) / 1000))); // for (Resource rsc : resourceSet.getResources()) { // if (rsc.getContents().get(0) instanceof DAG) { // // } // // } if (commandLine.hasOption(DIAGNOSE)) { for (Resource resource : resourceSet.getResources()) { LOGGER.info( MessageFormat.format("Requested validation for resource ''{0}''", resource.getURI())); BasicDiagnostic diagnosticChain = diagnoseResource(resource); if (!isFailed(diagnosticChain)) { LOGGER.info(MessageFormat.format("Result of the diagnosis of resurce ''{0}'' is ''OK''", resource.getURI())); } else { LOGGER.severe(MessageFormat.format("Found ''{0}'' error(s) in the resource ''{1}''", diagnosticChain.getChildren().size(), resource.getURI())); for (Diagnostic diagnostic : diagnosticChain.getChildren()) { LOGGER.fine(diagnostic.getMessage()); } } } LOGGER.info("Validation finished"); } } catch (ParseException e) { System.err.println(e.getLocalizedMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.setOptionComparator(new OptionComarator<Option>()); try { formatter.setWidth(Math.max(Terminal.getTerminal().getTerminalWidth(), 80)); } catch (Throwable t) { LOGGER.warning("Unable to get console information"); } ; formatter.printHelp("java -jar <this-file.jar>", options, true); System.exit(ERROR); } catch (Throwable t) { System.err.println("ERROR: " + t.getLocalizedMessage()); StringWriter stringWriter = new StringWriter(); t.printStackTrace(new PrintWriter(stringWriter)); System.err.println(t); LOGGER.severe(stringWriter.toString()); System.exit(ERROR); } }
From source file:com.smartmarmot.dbforbix.DBforBix.java
public static void main(final String[] args) { Config config = Config.getInstance(); String action = ""; options = new Options(); options.addOption("v", false, "display version and exit"); options.addOption("t", false, "test configuration"); options.addOption("h", false, "display help"); options.addOption("b", true, "base directory"); options.addOption("c", true, "config file location"); // options.addOption("d", false, "enable debugging"); options.addOption("C", false, "enable console output"); options.addOption("a", true, "action (start/stop/status)"); // handle command line parameters try {/*from w ww .j a v a2 s . co m*/ CommandLineParser cmdparser = new DefaultParser(); CommandLine cmd = cmdparser.parse(options, args); if (cmd.hasOption("v")) { System.out.println(Constants.BANNER); System.exit(0); } if (cmd.hasOption("t")) { System.out.println("not implemented"); System.exit(0); } if (args.length == 0 || cmd.hasOption("h")) { displayUsage(); System.exit(0); } // if (cmd.hasOption("d")) { // debug = true; // Logger.getRootLogger().setLevel(Level.ALL); // } if (cmd.hasOption("C")) Logger.getRootLogger().addAppender(new ConsoleAppender(new SimpleLayout())); action = cmd.getOptionValue("a", "help"); /** * set config file path */ config.setBasedir(cmd.getOptionValue("b", ".")); config.setConfigFile(cmd.getOptionValue("c", config.getBasedir() + File.separator + "conf" + File.separator + "config.properties")); } catch (ParseException e) { System.err.println("Error in parameters: " + e.getLocalizedMessage()); System.exit(-1); } //autoupdate cycle while (true) { try { switch (action.toLowerCase()) { case "start": { reinit(); LOG.info("Starting " + Constants.BANNER); // writePid(_pid, _pidfile); _zabbixSender = new ZabbixSender(ZabbixSender.PROTOCOL.V32); _zabbixSender.updateServerList(config.getZabbixServers().toArray(new ZabbixServer[0])); _zabbixSender.start(); //persSender = new PersistentDBSender(PersistentDBSender.PROTOCOL.V18); //persSender.updateServerList(config.getZabbixServers().toArray(new ZServer[0])); //persSender.start(); config.startChecks(); action = "update"; } break; case "update": { LOG.info("Sleeping before configuration update..."); Thread.sleep(config.getUpdateConfigTimeout() * 1000); LOG.info("Updating DBforBix configuration..."); if (config.checkConfigChanges()) action = "stop"; } break; case "stop": { LOG.info("Stopping DBforBix..."); config = config.reset(); if (_zabbixSender != null) { _zabbixSender.terminate(); while (_zabbixSender.isAlive()) Thread.yield(); } //workTimers=new HashMap<String, Timer>(); _zabbixSender = null; if (persSender != null) { persSender.terminate(); while (persSender.isAlive()) Thread.yield(); } DBManager dbman = DBManager.getInstance(); dbman = dbman.cleanAll(); action = "start"; } break; default: { LOG.error("Unknown action " + action); System.exit(-5); } break; } } catch (Throwable th) { LOG.fatal("DBforBix crashed!", th); } } }
From source file:com.blackboard.WebdavBulkDeleterClient.java
public static void main(String[] args) { if (System.getProperty("log4j.configuration") != null) { PropertyConfigurator.configure(System.getProperty("log4j.configuration")); } else {//from w w w .j a v a2 s . c o m BasicConfigurator.configure(); } // Perform command line parsing in an as friendly was as possible. // Could be improved CommandLineParser parser = new PosixParser(); Options options = new Options(); // Use a map to store our options and loop over it to check and parse options via // addAllOptions() and verifyOptions() below Map<String, String> optionsAvailable = new HashMap<String, String>(); optionsAvailable.put("deletion-list", "The file containing the list of courses to delete"); optionsAvailable.put("user", "User with deletion privileges, usually bbsupport"); optionsAvailable.put("password", "Password - ensure you escape any shell characters"); optionsAvailable.put("url", "The Learn URL - usually https://example.com/bbcswebdav/courses"); options = addAllOptions(options, optionsAvailable); options.addOption(OptionBuilder.withLongOpt("no-verify-ssl").withDescription("Don't verify SSL") .hasArg(false).create()); CommandLine line = null; try { line = parser.parse(options, args); verifyOptions(line, optionsAvailable); } catch (ParseException e) { // Detailed reason will be printed by verifyOptions above logger.fatal("Incorrect options specified, exiting..."); System.exit(1); } Scanner scanner = null; try { scanner = new Scanner(new File(line.getOptionValue("deletion-list"))); } catch (FileNotFoundException e) { logger.fatal("Cannot open file : " + e.getLocalizedMessage()); System.exit(1); } // By default we verify SSL certs boolean verifyCertStatus = true; if (line.hasOption("no-verify-ssl")) { verifyCertStatus = false; } // Loop through deletion list and delete courses if they exist. LearnServer instance; try { logger.debug("Attempting to open connection"); instance = new LearnServer(line.getOptionValue("user"), line.getOptionValue("password"), line.getOptionValue("url"), verifyCertStatus); String currentCourse = null; logger.debug("Connection open"); while (scanner.hasNextLine()) { currentCourse = scanner.nextLine(); if (instance.exists(currentCourse)) { try { instance.deleteCourse(currentCourse); logger.info("Processing " + currentCourse + " : Result - Deletion Successful"); } catch (IOException ioe) { logger.error("Processing " + currentCourse + " : Result - Could not Delete (" + ioe.getLocalizedMessage() + ")"); } } else { logger.info("Processing " + currentCourse + " : Result - Course does not exist"); } } } catch (IllegalArgumentException e) { logger.fatal(e.getLocalizedMessage()); System.exit(1); } catch (IOException ioe) { logger.debug(ioe); logger.fatal(ioe.getMessage()); } }
From source file:fr.inria.atlanmod.instantiator.SpecimenGenerator.java
public static void main(String[] args) throws GenerationException, IOException { Options options = new Options(); configureOptions(options);/*from www .jav a2 s . c o m*/ CommandLineParser parser = new GnuParser(); try { CommandLine commandLine = parser.parse(options, args); String metamodel = commandLine.getOptionValue(METAMODEL); DefaultModelGenerator modelGen = new DefaultModelGenerator(URI.createFileURI(metamodel)); if (commandLine.hasOption(ADDITIONAL_METAMODEL)) { for (String additionalMetamodel : commandLine.getOptionValues(ADDITIONAL_METAMODEL)) { URI additionalMetamodelUri = URI.createFileURI(additionalMetamodel); Resource resource = new XMIResourceImpl(additionalMetamodelUri); resource.load(Collections.emptyMap()); registerPackages(resource); } } if (commandLine.hasOption(OUTPUT_DIR)) { String outDir = commandLine.getOptionValue(OUTPUT_DIR); modelGen.setSamplesPath(Paths.get(outDir)); } else { modelGen.setSamplesPath(Paths.get(".")); } if (commandLine.hasOption(N_MODELS)) { int models = ((Number) commandLine.getParsedOptionValue(N_MODELS)).intValue(); modelGen.setSetSize(new int[] { models }); } else { modelGen.setSetSize(new int[] { 1 }); } if (commandLine.hasOption(SIZE)) { long size = ((Number) commandLine.getParsedOptionValue(SIZE)).longValue(); modelGen.setModelsSize(new long[] { size }); } else { modelGen.setModelsSize(new long[] { 1000 }); } if (commandLine.hasOption(SEED)) { long seed = ((Number) commandLine.getParsedOptionValue(SEED)).longValue(); modelGen.setSeed(seed); } else { modelGen.setSeed(System.currentTimeMillis()); } modelGen.runGeneration(); } catch (ParseException e) { System.err.println(e.getLocalizedMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.setOptionComparator(new OptionComarator<Option>()); try { formatter.setWidth(Math.max(TerminalFactory.get().getWidth(), 80)); } catch (Throwable t) { // Nothing to do... } ; formatter.printHelp("java -jar <this-file.jar>", options, true); } }
From source file:com.tvh.gmaildrafter.Drafter.java
/** * @param args the command line arguments */// w w w . jav a 2 s . c o m public static void main(String[] args) { Options options = getCMDLineOptions(); CommandLineParser parser = new PosixParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("help")) { printHelpMessage(options); System.exit(0); } String emailBody = null; String emailSubject = null; if (cmd.hasOption("body")) { String bodyFile = cmd.getOptionValue("body"); File body = new File(bodyFile); emailBody = FileUtils.readFileToString(body); if (cmd.hasOption("deletebody")) { body.delete(); } } else if (cmd.hasOption("stdin")) { emailBody = Util.readEntireStdin(); } if (cmd.hasOption("subject")) emailSubject = cmd.getOptionValue("subject"); else if (cmd.hasOption("subjectfile")) { String subjectFile = cmd.getOptionValue("subjectfile"); File subject = new File(subjectFile); emailSubject = FileUtils.readFileToString(subject); if (cmd.hasOption("deletesubjectfile")) subject.delete(); } String username = null; if (cmd.hasOption("username")) username = cmd.getOptionValue("username"); String password = null; if (cmd.hasOption("password")) password = cmd.getOptionValue("password"); String[] bcc = cmd.getOptionValues("bcc"); String[] cc = cmd.getOptionValues("cc"); Boolean sendImmediately = cmd.hasOption("immediate"); String[] attachments = cmd.getOptionValues("attachments"); String[] attachmentnames = cmd.getOptionValues("attachmentnames"); String[] destinations = cmd.getOptionValues("to"); Credentials credentials = Authenticater.getValidCredentials(username, password); if (credentials != null) { boolean success = false; while (!success) { try { composeMail(credentials, emailSubject, emailBody, attachments, attachmentnames, destinations, cc, bcc, sendImmediately); success = true; } catch (AuthenticationFailedException e) { JOptionPane.showMessageDialog(null, "Invalid login, please try again!"); credentials = Authenticater.getValidCredentials(username, null); success = false; } } } } catch (ParseException ex) { javax.swing.JOptionPane.showMessageDialog(null, ex.getMessage()); printHelpMessage(options); System.exit(7); } catch (IOException ex) { System.out.println("IO Exception " + ex.getLocalizedMessage()); printHelpMessage(options); System.exit(2); } catch (LoginException ex) { System.out.println(ex.getMessage()); System.exit(3); } System.exit(0); }
From source file:it.uniud.ailab.dcore.launchers.Launcher.java
/** * Starts the Distiller using the specified configuration, analyzing the * specified file, writing the output in the specified folder. * * @param args the command-line parameters. *//*from w ww . j a v a 2 s .c o m*/ public static void main(String[] args) { CommandLineParser parser = new DefaultParser(); createOptions(); CommandLine cmd; try { // parse the command line arguments cmd = parser.parse(options, args); } catch (ParseException exp) { // oops, something went wrong printError("Error while parsing command line options: " + exp.getLocalizedMessage()); return; } // if no options has been selected, just return. if (cmd.getOptions().length == 0) { printHelp(); return; } // read the options. if (readOptions(cmd)) { // everything's good! proceed doWork(); } else { printError("Unexpected error while parsing command line options\n" + "Please contact the developers of the framwork to get " + "additional help."); return; } }
From source file:com.toy.TOYConfig.java
public static final TOYConfig parse(String[] args) { CommandLineParser parser = new BasicParser(); CommandLine commandLine = null;/*from ww w. j ava 2 s.c o m*/ Command command = null; try { commandLine = parser.parse(get(), args); } catch (ParseException e) { LOG.error("\n{}", e.getLocalizedMessage()); LOG.debug("Can't parse cmd line", e); } if (commandLine == null) { printHelp(); System.exit(-1); } // start, stop or status ? boolean start = commandLine.hasOption("start"); boolean stop = commandLine.hasOption("stop"); boolean status = commandLine.hasOption("status"); boolean add = commandLine.hasOption("add"); if (start && stop || stop && status) { printHelp(); System.exit(-1); } if (add) command = Command.ADD; if (start) command = Command.START; if (stop) command = Command.STOP; if (status) command = Command.STATUS; if (command == Command.ADD || command == Command.START) Preconditions.checkNotNull(commandLine.getOptionValue("war"), "Please specify application with -war"); return new TOYConfig(commandLine.getOptionValue("zookeeper"), commandLine.getOptionValue("tomcat"), commandLine.getOptionValue("war"), commandLine.getOptionValue("queue", "default"), commandLine.getOptionValue("memory", "64"), commandLine.getOptionValue("ns", "default"), command); }