@Override public int run(String[] args) throws Exception { try { jc.parse(args); } catch (ParameterException pe) { System.err.println(pe.getMessage()); return 1; } if ("help".equals(jc.getParsedCommand())) { return help.usage(jc, COMMANDS); } Command cmd = COMMANDS.get(jc.getParsedCommand()); if (cmd == null) { return help.usage(jc, COMMANDS); } try { return cmd.execute(getConf()); } catch (CommandException ce) { System.err.println("Command Error: " + ce.getMessage()); return 1; } catch (IllegalArgumentException e) { System.err.println("Argument Error: " + e.getMessage()); return 1; } catch (IllegalStateException e) { System.err.println("State Error: " + e.getMessage()); return 1; } }
private boolean parse(String[] args) { try { new JCommander(this, args); return true; } catch (ParameterException e) { System.err.println("Arguments parse error: " + e.getMessage()); printUsage(); return false; } }
private static UserArguments parseUserArguments(String[] args) { UserArguments userArguments = new UserArguments(); try { new JCommander(userArguments, args); } catch (ParameterException e) { e.printStackTrace(System.err); new JCommander(userArguments, new String[] {"-help"}).usage(); } return userArguments; }
public static void main(String[] args) { /* Parse and validate command line parameters */ CommandLineParameters params = new CommandLineParameters(); try { JCommander jc = new JCommander(params, args); if (params.help) { jc.setProgramName("java -Xmx[several]G -jar otp.jar"); jc.usage(); System.exit(0); } params.infer(); } catch (ParameterException pex) { LOG.error("Parameter error: {}", pex.getMessage()); System.exit(1); } OTPConfigurator configurator = new OTPConfigurator(params); // start graph builder, if asked for GraphBuilderTask graphBuilder = configurator.builderFromParameters(); if (graphBuilder != null) { graphBuilder.run(); // Inform configurator which graph is to be used for in-memory handoff. if (params.inMemory) configurator.makeGraphService(graphBuilder.getGraph()); } // start visualizer, if asked for GraphVisualizer graphVisualizer = configurator.visualizerFromParameters(); if (graphVisualizer != null) { graphVisualizer.run(); } // start web server, if asked for GrizzlyServer grizzlyServer = configurator.serverFromParameters(); if (grizzlyServer != null) { while (true) { // Loop to restart server on uncaught fatal exceptions. try { grizzlyServer.run(); return; } catch (Throwable throwable) { throwable.printStackTrace(); LOG.error( "An uncaught {} occurred inside OTP. Restarting server.", throwable.getClass().getSimpleName()); } } } if (graphBuilder == null && graphVisualizer == null && grizzlyServer == null) { LOG.info("Nothing to do. Use --help to see available tasks."); ; } }
public static void main(String[] args) { class Arguments { @Parameter( names = {"-m", "--matrix"}, description = "Matrix definition path.", required = true) private String matrix; @Parameter( names = {"-r", "--repo"}, description = "Repository path.", required = true) private String repository; @Parameter( names = {"-f", "--factor"}, description = "Scaling factor.") private int factor = 10; @Parameter( names = {"-n", "--name"}, description = "User name.") private String name = ""; @Parameter( names = {"-e", "--email"}, description = "Email address.") private String email = ""; } try { Arguments arguments = new Arguments(); new JCommander(arguments, args); try (Repository repository = new Repository(Paths.get(arguments.repository), arguments.name, arguments.email)) { repository.illustrate(new Matrix(Paths.get(arguments.matrix)), arguments.factor); } } catch (ParameterException error) { System.err.println(error.getMessage()); } catch (IOException | Matrix.FileFormatException | Repository.GitException error) { LOGGER.severe(error.toString()); } }
/** * Parses command line arguments and populates this command line instance. * * <p>If the command line arguments include the "help" argument, or if the arguments have * incorrect values or order, then usage information is printed to {@link System#out} and the * program terminates. * * @param args the command line arguments * @return an instance of the parsed arguments object */ public Arguments parse(String[] args) { JCommander jCommander = new JCommander(this); jCommander.setProgramName("jsonschema2pojo"); try { jCommander.parse(args); if (this.showHelp) { jCommander.usage(); exit(EXIT_OKAY); } } catch (ParameterException e) { System.err.println(e.getMessage()); jCommander.usage(); exit(EXIT_ERROR); } return this; }
public static void main(String[] args) { final Options options = new Options(); JCommander jCommander = new JCommander(options); jCommander.setProgramName("java -jar ColorBleeding.jar"); try { String inPath = "/tmp/images"; String[] argv = { /* "-overwrite", */ "-dir", inPath, "-debug", "-maxiterations", "2", "-outdir", "/tmp/result", "-numthreads", "8" }; if (System.getProperty("overrideArgs", "false").equals("true")) { args = argv; } jCommander.parse(args); execute(options); } catch (ParameterException e) { logger.error(e.getMessage()); if (jCommander != null) { jCommander.usage(); } } catch (IOException e) { logger.error("Error while processing images", e); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public static void main(String... args) { CommandLineArgs parsedArgs = new CommandLineArgs(); JCommander jc = new JCommander(parsedArgs); try { jc.parse(args); } catch (ParameterException e) { StringBuilder out = new StringBuilder(e.getLocalizedMessage()).append("\n\n"); jc.usage(out); System.err.println(out.toString()); System.exit(1); return; } if (parsedArgs.help) { jc.usage(); return; } SpoonRunner spoonRunner = new SpoonRunner.Builder() // .setTitle(parsedArgs.title) .setApplicationApk(parsedArgs.apk) .setInstrumentationApk(parsedArgs.testApk) .setOutputDirectory(parsedArgs.output) .setDebug(parsedArgs.debug) .setAndroidSdk(parsedArgs.sdk) .setNoAnimations(parsedArgs.noAnimations) .setTestSize(parsedArgs.size) .setAdbTimeout(parsedArgs.adbTimeoutSeconds * 1000) .setClassName(parsedArgs.className) .setMethodName(parsedArgs.methodName) .useAllAttachedDevices() .build(); if (!spoonRunner.run() && parsedArgs.failOnFailure) { System.exit(1); } }
@Override public int run(String[] args) throws Exception { // Validate params etc JCommander jComm = new JCommander(this); jComm.setProgramName("Splout Page Counts example"); try { jComm.parse(args); } catch (ParameterException e) { System.err.println(e.getMessage()); jComm.usage(); System.exit(-1); } boolean generate = !noGenerate; // just for clarifying if (generateTupleFiles && deploy) { System.err.println("Can't run a 'dry' TupleFile generation and deploy it."); jComm.usage(); System.exit(-1); } Path outPath = new Path(outputPath); FileSystem outFs = outPath.getFileSystem(getConf()); if (!FileSystem.getLocal(conf).equals(FileSystem.get(conf))) { File nativeLibs = new File("native"); if (nativeLibs.exists()) { SploutHadoopConfiguration.addSQLite4JavaNativeLibsToDC(conf); } } if (generate) { Path inputPath = new Path(this.inputPath); FileSystem inputFileSystem = inputPath.getFileSystem(conf); FileStatus[] fileStatuses = inputFileSystem.listStatus(inputPath); // define the schema that the resultant table will have: date, hour, pagename, pageviews final Schema tableSchema = new Schema( "pagecounts", Fields.parse("date:string, hour:string, pagename:string, pageviews:int")); // define the schema of the input files: projectcode, pagename, pageviews, bytes Schema fileSchema = new Schema( "pagecountsfile", Fields.parse("projectcode:string, pagename:string, pageviews:int, bytes:long")); // instantiate a TableBuilder TableBuilder tableBuilder = new TableBuilder(tableSchema); // for every input file... for (FileStatus fileStatus : fileStatuses) { String fileName = fileStatus.getPath().getName().toString(); // strip the date and the hour from the file name String fileDate = fileName.split("-")[1]; String fileHour = fileName.split("-")[2].substring(0, 2); // instantiate a custom RecordProcessor to process the records of this file PageCountsRecordProcessor recordProcessor = new PageCountsRecordProcessor(tableSchema, fileDate, fileHour); // use the tableBuilder method for adding each of the files to the mix tableBuilder.addCSVTextFile( fileStatus.getPath(), ' ', TupleTextInputFormat.NO_QUOTE_CHARACTER, TupleTextInputFormat.NO_ESCAPE_CHARACTER, false, false, TupleTextInputFormat.NO_NULL_STRING, fileSchema, recordProcessor); } // partition the dataset by pagename - which should give a fair even distribution. tableBuilder.partitionBy("pagename"); // create a compound index on pagename, date so that typical queries for the dataset will be // fast tableBuilder.createIndex("pagename", "date"); long nonExactPageSize = memoryForIndexing / 32000; // number of pages int pageSize = (int) Math.pow(2, (int) Math.round(Math.log(nonExactPageSize) / Math.log(2))); Log.info( "Pagesize = " + pageSize + " as memory for indexing was [" + memoryForIndexing + "] and there are 32000 pages."); tableBuilder.initialSQL("pragma page_size=" + pageSize); // insertion order is very important for optimizing query speed because it makes data be // co-located in disk tableBuilder.insertionSortOrder(OrderBy.parse("pagename:asc, date:asc")); // instantiate a TablespaceBuilder TablespaceBuilder tablespaceBuilder = new TablespaceBuilder(); // we will partition this dataset in as many partitions as: tablespaceBuilder.setNPartitions(nPartitions); tablespaceBuilder.add(tableBuilder.build()); // we turn a specific SQLite pragma on for making autocomplete queries fast tablespaceBuilder.initStatements("pragma case_sensitive_like=true;"); HadoopUtils.deleteIfExists(outFs, outPath); // finally, instantiate a TablespaceGenerator and execute it TablespaceGenerator tablespaceViewBuilder; if (generateTupleFiles) { // we subclass TablespaceGenerator to be able to run the generation without outputting the // SQLite stores, for // benchmark comparisons. // In the future this feature may be useful in general for debugging store creation. tablespaceViewBuilder = new TablespaceGenerator(tablespaceBuilder.build(), outPath) { @Override public void generateView( Configuration conf, SamplingType samplingType, SamplingOptions samplingOptions) throws Exception { prepareOutput(conf); final int nPartitions = tablespace.getnPartitions(); if (nPartitions > 1) { partitionMap = sample(nPartitions, conf, samplingType, samplingOptions); } else { partitionMap = PartitionMap.oneShardOpenedMap(); } writeOutputMetadata(conf); TupleMRBuilder builder = createMRBuilder(nPartitions, conf); // Set a TupleOutput here instead of SQLiteOutput builder.setOutput( new Path(outputPath, OUT_STORE), new TupleOutputFormat(tableSchema), ITuple.class, NullWritable.class); Job job = builder.createJob(); executeViewGeneration(job); } }; } else { // ... otherwise a standard TablespaceGenerator is used. tablespaceViewBuilder = new TablespaceGenerator(tablespaceBuilder.build(), outPath); } tablespaceViewBuilder.generateView( getConf(), SamplingType.RESERVOIR, new TupleSampler.DefaultSamplingOptions()); } if (deploy) { // use StoreDeployerTool for deploying the already generated dataset StoreDeployerTool deployer = new StoreDeployerTool(qnode, getConf()); ArrayList<TablespaceDepSpec> deployments = new ArrayList<TablespaceDepSpec>(); deployments.add(new TablespaceDepSpec("pagecounts", outPath.toString(), repFactor, null)); deployer.deploy(deployments); } return 1; }
/** * @param args * @throws IOException * @throws MarshallingException */ public static void main(final String[] args) throws Exception { final Arguments arguments = new Arguments(); final JCommander commander = new JCommander(arguments); try { commander.parse(args); } catch (final ParameterException e) { System.err.println(e.getMessage()); final StringBuilder builder = new StringBuilder(); commander.usage(builder); System.err.println(builder); return; } final KeyStore keystore = KeyStore.getInstance("jks"); InputStream keystoreStream = null; try { keystoreStream = new FileInputStream(arguments.getKeystore()); keystore.load(keystoreStream, arguments.getKeystorePassword().toCharArray()); } finally { if (keystoreStream != null) keystoreStream.close(); } final Map<String, String> keyPasswords = new HashMap<>(); if (arguments.getEncryptionKey() != null) keyPasswords.put(arguments.getEncryptionKey(), arguments.getEncryptionKeyPassword()); if (arguments.getSigningKey() != null) keyPasswords.put(arguments.getSigningKey(), arguments.getSigningKeyPassword()); if (arguments.getTlsKey() != null) keyPasswords.put(arguments.getTlsKey(), arguments.getTlsKeyPassword()); bootstrap(); final JKSKeyManager keyManager = new JKSKeyManager(keystore, keyPasswords, null); final MetadataGenerator generator = new MetadataGenerator(); generator.setKeyManager(keyManager); generator.setEntityId(arguments.getEntityId()); generator.setEntityAlias(arguments.getAlias()); generator.setEntityBaseURL(arguments.getBaseURL()); generator.setSignMetadata(arguments.isSignMetadata()); generator.setRequestSigned(arguments.isRequestSigned()); generator.setWantAssertionSigned(arguments.isWantAssertionSigned()); generator.setSigningKey(arguments.getSigningKey()); generator.setEncryptionKey(arguments.getEncryptionKey()); if (arguments.getTlsKey() != null && arguments.getTlsKey().length() > 0) { generator.setTlsKey(arguments.getTlsKey()); } final Collection<String> bindingsSSO = new LinkedList<String>(); final Collection<String> bindingsHoKSSO = new LinkedList<String>(); final AllowedSSOBindings defaultBinding = arguments.getSsoDefaultBinding(); int assertionConsumerIndex = 0; for (final AllowedSSOBindings binding : arguments.getSsoBindings()) { // Set default binding if (binding.equals(defaultBinding)) { assertionConsumerIndex = bindingsSSO.size() + bindingsHoKSSO.size(); } // Set included bindings if (AllowedSSOBindings.SSO_POST.equals(binding)) { bindingsSSO.add(SAMLConstants.SAML2_POST_BINDING_URI); } else if (AllowedSSOBindings.SSO_ARTIFACT.equals(binding)) { bindingsSSO.add(SAMLConstants.SAML2_ARTIFACT_BINDING_URI); } else if (AllowedSSOBindings.SSO_PAOS.equals(binding)) { bindingsSSO.add(SAMLConstants.SAML2_PAOS_BINDING_URI); } else if (AllowedSSOBindings.HOKSSO_POST.equals(binding)) { bindingsHoKSSO.add(SAMLConstants.SAML2_POST_BINDING_URI); } else if (AllowedSSOBindings.HOKSSO_ARTIFACT.equals(binding)) { bindingsHoKSSO.add(SAMLConstants.SAML2_ARTIFACT_BINDING_URI); } } // Set bindings generator.setBindingsSSO(bindingsSSO); generator.setBindingsHoKSSO(bindingsHoKSSO); generator.setAssertionConsumerIndex(assertionConsumerIndex); // Discovery if (arguments.isIncludeDiscovery()) { generator.setIncludeDiscovery(true); if (arguments.getCustomDiscoveryURL() != null && arguments.getCustomDiscoveryURL().length() > 0) { generator.setCustomDiscoveryURL(arguments.getCustomDiscoveryURL()); } } else { generator.setIncludeDiscovery(false); } generator.setNameID(arguments.getNameID()); final EntityDescriptor descriptor = generator.generateMetadata(); final ExtendedMetadata extendedMetadata = generator.generateExtendedMetadata(); extendedMetadata.setSecurityProfile(arguments.getSecurityProfile()); extendedMetadata.setSslSecurityProfile(arguments.getSslSecurityProfile()); extendedMetadata.setRequireLogoutRequestSigned(arguments.isRequireLogoutRequestSigned()); extendedMetadata.setRequireLogoutResponseSigned(arguments.isRequireLogoutResponseSigned()); extendedMetadata.setRequireArtifactResolveSigned(arguments.isRequireArtifactResolveSigned()); Writer metadataWriter = null; try { metadataWriter = new FileWriter(arguments.getMetadataOutput()); metadataWriter.write(getMetadataAsString(descriptor)); } finally { if (metadataWriter != null) { metadataWriter.flush(); metadataWriter.close(); } } if (arguments.getExtendedMetadataOutput() != null) { Writer extendedMetadataWriter = null; try { extendedMetadataWriter = new FileWriter(arguments.getExtendedMetadataOutput()); extendedMetadataWriter.write( getConfiguration(arguments.getExtendedMetadataOutput().getName(), extendedMetadata)); } finally { if (extendedMetadataWriter != null) { extendedMetadataWriter.flush(); extendedMetadataWriter.close(); } } } }
@Override public int run(String[] args) throws Exception { if (getConf() != null) { DefaultConfiguration.set(getConf()); } try { jc.parse(args); } catch (MissingCommandException e) { console.error(e.getMessage()); return 1; } catch (ParameterException e) { console.error(e.getMessage()); return 1; } // configure log4j if (debug) { org.apache.log4j.Logger console = org.apache.log4j.Logger.getLogger(Main.class); console.setLevel(Level.DEBUG); } String parsed = jc.getParsedCommand(); if (parsed == null) { console.error("Unable to parse command."); return 1; } Command command = (Command) jc.getCommands().get(parsed).getObjects().get(0); if (command == null) { console.error("Unable to find command."); return 1; } try { if (command instanceof Configurable) { ((Configurable) command).setConf(getConf()); } return command.run(); } catch (IllegalArgumentException e) { if (debug) { console.error("Argument error", e); } else { console.error("Argument error: {}", e.getMessage()); } return 1; } catch (IllegalStateException e) { if (debug) { console.error("State error", e); } else { console.error("State error: {}", e.getMessage()); } return 1; } catch (ValidationException e) { if (debug) { console.error("Validation error", e); } else { console.error("Validation error: {}", e.getMessage()); } return 1; } catch (DatasetNotFoundException e) { if (debug) { console.error("Cannot find dataset", e); } else { // the error message already contains "No such dataset: <name>" console.error(e.getMessage()); } return 1; } catch (DatasetIOException e) { if (debug) { console.error("IO error", e); } else { console.error("IO error: {}", e.getMessage()); } return 1; } catch (Exception e) { if (debug) { console.error("Unknown error", e); } else { console.error("Unknown error: {}", e.getMessage()); } return 1; } }