Java Code Examples for org.apache.commons.cli.PosixParser

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project anarchyape, under directory /src/main/java/ape/.

Source file: Main.java

  21 
vote

/** 
 * This method would parse the array that store all arguments read from StdIn  and return a CommandLine object
 */
public static CommandLine getCommand(String[] args) throws ParseException {
  if (args == null || args.length < 1 || args[0] == null) {
    printHelp();
    return null;
  }
  CommandLineParser parser=new PosixParser();
  return parser.parse(opts,args);
}
 

Example 2

From project android-rindirect, under directory /rindirect/src/main/java/de/akquinet/android/rindirect/.

Source file: Main.java

  21 
vote

/** 
 * Main method. This methods defines the arguments, parse them and launch the R indirection generation.
 * @param args the arguments.
 * @throws ParseException
 * @throws IOException
 */
public static void main(String[] args) throws ParseException, Exception {
  LOGGER.setLevel(Level.WARNING);
  Options options=new Options();
  options.addOption("P","package",true,"destination package (mandatory)").addOption("R","classname",true,"generated java file [R]").addOption("D","destination",true,"the root of the destination [src]").addOption("I","input",true,"R file [searched in the 'gen' folder]").addOption("V","verbose",false,"Enable verbose mode");
  CommandLineParser parser=new PosixParser();
  CommandLine cmd=parser.parse(options,args);
  RIndirect rindirect=configure(cmd);
  rindirect.generate();
}
 

Example 3

From project Chess_1, under directory /src/main/java/com/es/.

Source file: CmdConfiguration.java

  21 
vote

public boolean parse(String[] args){
  final CommandLineParser parser=new PosixParser();
  try {
    commandLine=parser.parse(options,args);
  }
 catch (  final ParseException e) {
    LOG.error("Error parsing the command line",e);
    return false;
  }
  return true;
}
 

Example 4

From project Flume-Hive, under directory /src/java/com/cloudera/flume/core/.

Source file: EventUtil.java

  21 
vote

public static CommandLine defaultSinkParser(String[] argv) throws ParseException {
  Options options=new Options();
  options.addOption("d",false,"Directly send to collector");
  options.addOption("c",false,"Directly output to console");
  CommandLineParser parser=new PosixParser();
  CommandLine cmd=parser.parse(options,argv);
  return cmd;
}
 

Example 5

From project flume_1, under directory /flume-core/src/main/java/com/cloudera/flume/core/.

Source file: EventUtil.java

  21 
vote

public static CommandLine defaultSinkParser(String[] argv) throws ParseException {
  Options options=new Options();
  options.addOption("d",false,"Directly send to collector");
  options.addOption("c",false,"Directly output to console");
  CommandLineParser parser=new PosixParser();
  CommandLine cmd=parser.parse(options,argv);
  return cmd;
}
 

Example 6

From project harmony, under directory /harmony.ui.reservationcli/src/main/java/org/opennaas/extensions/idb/shell/.

Source file: CommandlineReservationClient.java

  21 
vote

/** 
 * Main function.
 * @param args The parameter.
 */
public static void main(final String[] args){
  cli=new CommandlineReservationClient();
  parser=new PosixParser();
  options=new Options();
  System.out.println(shortLicense);
  generateParameter();
  analyzeArguments(args);
  if ("help".equals(action)) {
    new HelpFormatter().printHelp("java " + CommandlineReservationClient.class.getSimpleName(),options);
  }
 else {
    runArguments(args);
  }
}
 

Example 7

From project heritrix3, under directory /commons/src/main/java/org/archive/io/.

Source file: Arc2Warc.java

  21 
vote

/** 
 * Command-line interface to Arc2Warc.
 * @param args Command-line arguments.
 * @throws ParseException Failed parse of the command line.
 * @throws IOException
 * @throws java.text.ParseException
 */
@SuppressWarnings("unchecked") public static void main(String[] args) throws ParseException, IOException, java.text.ParseException {
  Options options=new Options();
  options.addOption(new Option("h","help",false,"Prints this message and exits."));
  options.addOption(new Option("f","force",false,"Force overwrite of target file."));
  PosixParser parser=new PosixParser();
  CommandLine cmdline=parser.parse(options,args,false);
  List<String> cmdlineArgs=cmdline.getArgList();
  Option[] cmdlineOptions=cmdline.getOptions();
  HelpFormatter formatter=new HelpFormatter();
  if (cmdlineArgs.size() <= 0) {
    usage(formatter,options,0);
  }
  boolean force=false;
  for (int i=0; i < cmdlineOptions.length; i++) {
switch (cmdlineOptions[i].getId()) {
case 'h':
      usage(formatter,options,0);
    break;
case 'f':
  force=true;
break;
default :
throw new RuntimeException("Unexpected option: " + +cmdlineOptions[i].getId());
}
}
if (cmdlineArgs.size() != 2) {
usage(formatter,options,0);
}
(new Arc2Warc()).transform(new File(cmdlineArgs.get(0)),new File(cmdlineArgs.get(1)),force);
}
 

Example 8

From project jmxsh, under directory /src/jmxsh/.

Source file: CloseCmd.java

  21 
vote

private CommandLine parseCommandLine(TclObject argv[]) throws ParseException {
  String[] args=new String[argv.length - 1];
  for (int i=0; i < argv.length - 1; i++)   args[i]=argv[i + 1].toString();
  CommandLine cl=(new PosixParser()).parse(this.opts,args);
  return cl;
}
 

Example 9

From project jnrpe-lib, under directory /jnrpe-lib/src/main/java/it/jnrpe/plugins/.

Source file: PluginProxy.java

  21 
vote

/** 
 * Executes the proxied plugin passing the received arguments as parameters.
 * @param args The parameters to be passed to the plugin
 * @return The return value of the plugin.
 */
public ReturnValue execute(final String[] args){
  CommandLineParser clp=new PosixParser();
  try {
    CommandLine cl=clp.parse(m_Options,args);
    if (getListeners() != null && m_plugin instanceof IPluginInterfaceEx) {
      ((IPluginInterfaceEx)m_plugin).addListeners(getListeners());
    }
    return m_plugin.execute(new PluginCommandLine(cl));
  }
 catch (  ParseException e) {
    return new ReturnValue(Status.UNKNOWN,e.getMessage());
  }
}
 

Example 10

From project jreversepro, under directory /src/main/java/org/jreversepro/cmd/.

Source file: CommandLineInterface.java

  21 
vote

public CommandLineInterface(){
  options=new Options();
  options.addOption(OPTION_INPUT,true,"input stream (file/URL)");
  options.addOption(OPTION_DISASSEMBLE,false,"disassemble class files");
  options.addOption(OPTION_DECOMPILE,false,"decompile class files");
  options.addOption(OPTION_GUI,false,"launch Swing UI");
  options.addOption(OPTION_VIEW_CONSTANT_POOL,false,"view constant pool");
  parser=new PosixParser();
  cmd=null;
  outputType=OutputType.NONE;
  guiEnabled=false;
}
 

Example 11

From project Metamorphosis, under directory /metamorphosis-server-wrapper/src/main/java/com/taobao/metamorphosis/.

Source file: ServerStartup.java

  21 
vote

public static void main(final String[] args){
  final CommandLine line=StartupHelp.parseCmdLine(args,new PosixParser());
  final Map<String,Properties> pluginsInfo=getPluginsInfo(line);
  final EnhancedBroker broker=new EnhancedBroker(getMetaConfig(line),pluginsInfo);
  broker.start();
}
 

Example 12

From project onebusaway-uk, under directory /onebusaway-uk-atco-cif-to-gtfs-converter/src/main/java/org/onebusaway/uk/atco_cif_to_gtfs_converter/.

Source file: AtcoCifToGtfsConverterMain.java

  21 
vote

public void run(String[] args) throws ParseException, IOException {
  Options options=new Options();
  buildOptions(options);
  Parser parser=new PosixParser();
  CommandLine cli=parser.parse(options,args);
  args=cli.getArgs();
  if (args.length != 2) {
    usage();
    System.exit(-1);
  }
  AtcoCifToGtfsConverter converter=new AtcoCifToGtfsConverter();
  configureConverter(args,cli,converter);
  converter.run();
}
 

Example 13

From project scape, under directory /pc-as/toolwrapper/core/src/main/java/eu/scape_project/tool/toolwrapper/.

Source file: ToolWrapperCommandline.java

  21 
vote

/** 
 * Method that parses the program arguments and return an object that represents that same arguments ( {@link CommandLine})
 */
private CommandLine parseArguments(String[] args){
  CommandLineParser parser=new PosixParser();
  CommandLine commandLine=null;
  try {
    commandLine=parser.parse(options,args);
  }
 catch (  org.apache.commons.cli.ParseException e) {
    System.err.println(e);
  }
  return commandLine;
}
 

Example 14

From project zookeeper, under directory /src/java/main/org/apache/zookeeper/cli/.

Source file: AddAuthCommand.java

  21 
vote

@Override public CliCommand parse(String[] cmdArgs) throws ParseException {
  Parser parser=new PosixParser();
  CommandLine cl=parser.parse(options,cmdArgs);
  args=cl.getArgs();
  if (args.length < 2) {
    throw new ParseException(getUsageStr());
  }
  return this;
}
 

Example 15

From project bonecp, under directory /bonecp-benchmark/src/main/java/com/jolbox/benchmark/.

Source file: BenchmarkMain.java

  20 
vote

/** 
 * @param args
 * @throws ClassNotFoundException 
 * @throws PropertyVetoException 
 * @throws SQLException 
 * @throws NoSuchMethodException 
 * @throws InvocationTargetException 
 * @throws IllegalAccessException 
 * @throws InterruptedException 
 * @throws SecurityException 
 * @throws IllegalArgumentException 
 * @throws NamingException 
 * @throws ParseException 
 */
public static void main(String[] args) throws ClassNotFoundException, SQLException, PropertyVetoException, IllegalArgumentException, SecurityException, InterruptedException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, NamingException, ParseException {
  Options options=new Options();
  options.addOption("t","threads",true,"Max number of threads");
  options.addOption("s","stepping",true,"Stepping of threads");
  options.addOption("p","poolsize",true,"Pool size");
  options.addOption("h","help",false,"Help");
  CommandLineParser parser=new PosixParser();
  CommandLine cmd=parser.parse(options,args);
  if (cmd.hasOption("h")) {
    HelpFormatter formatter=new HelpFormatter();
    formatter.printHelp("benchmark.jar",options);
    System.exit(1);
  }
  Class.forName("com.jolbox.bonecp.MockJDBCDriver");
  new MockJDBCDriver();
  BenchmarkTests tests=new BenchmarkTests();
  BenchmarkTests.threads=200;
  BenchmarkTests.stepping=20;
  BenchmarkTests.pool_size=200;
  System.out.println("JIT warm up");
  tests.testMultiThreadedConstantDelay(0);
  BenchmarkTests.threads=200;
  BenchmarkTests.stepping=5;
  BenchmarkTests.pool_size=100;
  if (cmd.hasOption("t")) {
    BenchmarkTests.threads=Integer.parseInt(cmd.getOptionValue("t","400"));
  }
  if (cmd.hasOption("s")) {
    BenchmarkTests.stepping=Integer.parseInt(cmd.getOptionValue("s","20"));
  }
  if (cmd.hasOption("p")) {
    BenchmarkTests.pool_size=Integer.parseInt(cmd.getOptionValue("p","200"));
  }
  System.out.println("Starting benchmark tests with " + BenchmarkTests.threads + " threads (stepping "+ BenchmarkTests.stepping+ ") using pool size of "+ BenchmarkTests.pool_size+ " connections");
  System.out.println("Starting tests");
  plotLineGraph(tests.testMultiThreadedConstantDelay(0),0,false);
  plotBarGraph("Single Thread","bonecp-singlethread-poolsize-" + BenchmarkTests.pool_size + "-threads-"+ BenchmarkTests.threads+ ".png",tests.testSingleThread());
  plotBarGraph("Prepared Statement\nSingle Threaded","bonecp-preparedstatement-single-poolsize-" + BenchmarkTests.pool_size + "-threads-"+ BenchmarkTests.threads+ ".png",tests.testPreparedStatementSingleThread());
}
 

Example 16

From project bpelunit, under directory /net.bpelunit.framework.client.command/src/main/java/net/bpelunit/framework/ui/command/.

Source file: BPELUnitCommandLineRunner.java

  20 
vote

@SuppressWarnings("unchecked") private final void parseOptionsFromCommandLine(String[] args){
  saveCoverageDetails=false;
  CommandLineParser parser=new PosixParser();
  try {
    CommandLine cmd=parser.parse(options,args);
    verifyCommandLineArguments(cmd);
    verbose=cmd.hasOption(PARAMETER_VERBOSE);
    xmlFileName=trimEqualsSignFromStart(cmd.getOptionValue(PARAMETER_XMLFILE));
    logFileName=trimEqualsSignFromStart(cmd.getOptionValue(PARAMETER_LOGFILE));
    if (cmd.hasOption(PARAMETER_COVERAGEFILE)) {
      covFileName=trimEqualsSignFromStart(cmd.getOptionValue(PARAMETER_COVERAGEFILE));
    }
    if (cmd.hasOption(PARAMETER_DETAILEDCOVERAGEFILE)) {
      covFileName=trimEqualsSignFromStart(cmd.getOptionValue(PARAMETER_DETAILEDCOVERAGEFILE));
      saveCoverageDetails=true;
    }
    ArrayList<String> remainingOptions=new ArrayList<String>(cmd.getArgList());
    setAndValidateTestSuiteFileName(remainingOptions.remove(0));
    testCaseNames=remainingOptions;
  }
 catch (  ParseException e) {
    showHelpAndExit();
  }
}
 

Example 17

From project cidb, under directory /obo2solr/src/main/java/edu/toronto/cs/cidb/obo2solr/.

Source file: Main.java

  20 
vote

public static void main(String args[]){
  Options options=generateOptions();
  try {
    CommandLineParser parser=new PosixParser();
    CommandLine cmd=parser.parse(options,args);
    if (!cmd.hasOption(OBO_DB_LOCATION_OPTION) || cmd.hasOption(HELP_OPTION)) {
      showUsage(options);
      System.exit(cmd.hasOption(HELP_OPTION) ? 0 : 1);
    }
    ParameterPreparer paramPrep=new ParameterPreparer();
    SolrUpdateGenerator generator=new SolrUpdateGenerator();
    File input=paramPrep.getInputFileHandler(cmd.getOptionValue(OBO_DB_LOCATION_OPTION));
    File output=paramPrep.getOutputFileHandler(cmd.getOptionValue(OUTPUT_XML_LOCATION_OPTION,DEFAULT_OUTPUT_XML_LOCATION));
    Map<String,Double> fieldSelection=paramPrep.getFieldSelection(cmd.getOptionValue(INDEX_FILEDS_OPTION,""));
    generator.transform(input,output,fieldSelection);
  }
 catch (  Exception ex) {
    ex.printStackTrace();
  }
}
 

Example 18

From project cw-omnibus, under directory /Push/GCMCommand/src/com/commonsware/android/gcm/cmd/.

Source file: GCM.java

  20 
vote

@SuppressWarnings("static-access") public static void main(String[] args){
  Option helpOpt=new Option("h","help",false,"print this message");
  Option apiKeyOpt=OptionBuilder.withArgName("key").hasArg().isRequired().withDescription("GCM API key").withLongOpt("apiKey").create('a');
  Option deviceOpt=OptionBuilder.withArgName("regId").hasArg().isRequired().withDescription("device to send to").withLongOpt("device").create('d');
  Option dataOpt=OptionBuilder.withArgName("key=value").hasArgs(2).withDescription("datum to send").withValueSeparator().withLongOpt("data").create('D');
  Options options=new Options();
  options.addOption(apiKeyOpt);
  options.addOption(deviceOpt);
  options.addOption(dataOpt);
  options.addOption(helpOpt);
  CommandLineParser parser=new PosixParser();
  try {
    CommandLine line=parser.parse(options,args);
    if (line.hasOption('h') || !line.hasOption('a') || !line.hasOption('d')) {
      HelpFormatter formatter=new HelpFormatter();
      formatter.printHelp("gcm",options,true);
    }
 else {
      sendMessage(line.getOptionValue('a'),Arrays.asList(line.getOptionValues('d')),line.getOptionProperties("data"));
    }
  }
 catch (  org.apache.commons.cli.MissingOptionException moe) {
    System.err.println("Invalid command syntax");
    HelpFormatter formatter=new HelpFormatter();
    formatter.printHelp("gcm",options,true);
  }
catch (  Exception e) {
    e.printStackTrace();
  }
}
 

Example 19

From project dcm4che, under directory /dcm4che-tool/dcm4che-tool-common/src/main/java/org/dcm4che/tool/common/.

Source file: CLIUtils.java

  20 
vote

public static CommandLine parseComandLine(String[] args,Options opts,ResourceBundle rb2,Class<?> clazz) throws ParseException {
  CommandLineParser parser=new PosixParser();
  CommandLine cl=parser.parse(opts,args);
  if (cl.hasOption("h")) {
    HelpFormatter formatter=new HelpFormatter();
    formatter.printHelp(rb2.getString("usage"),rb2.getString("description"),opts,rb2.getString("example"));
    System.exit(0);
  }
  if (cl.hasOption("V")) {
    Package p=clazz.getPackage();
    String s=p.getName();
    System.out.println(s.substring(s.lastIndexOf('.') + 1) + ": " + p.getImplementationVersion());
    System.exit(0);
  }
  return cl;
}
 

Example 20

From project httpcore, under directory /httpcore-ab/src/main/java/org/apache/http/benchmark/.

Source file: HttpBenchmark.java

  20 
vote

public static void main(String[] args) throws Exception {
  Options options=CommandLineUtils.getOptions();
  CommandLineParser parser=new PosixParser();
  CommandLine cmd=parser.parse(options,args);
  if (args.length == 0 || cmd.hasOption('h') || cmd.getArgs().length != 1) {
    CommandLineUtils.showUsage(options);
    System.exit(1);
  }
  Config config=new Config();
  CommandLineUtils.parseCommandLine(cmd,config);
  if (config.getUrl() == null) {
    CommandLineUtils.showUsage(options);
    System.exit(1);
  }
  HttpBenchmark httpBenchmark=new HttpBenchmark(config);
  httpBenchmark.execute();
}
 

Example 21

From project indextank-engine, under directory /src/main/java/com/flaptor/indextank/storage/.

Source file: IndexesLogServer.java

  20 
vote

public static void main(String[] args) throws IOException, InterruptedException {
  CommandLineParser parser=new PosixParser();
  int readerPort, managerPort;
  try {
    CommandLine line=parser.parse(getOptions(),args);
    if (line.hasOption("help")) {
      printHelp(getOptions(),null);
      System.exit(1);
      return;
    }
    String val=null;
    val=line.getOptionValue("reader_port",null);
    if (null != val) {
      readerPort=Integer.valueOf(val);
    }
 else {
      printHelp(getOptions(),"Must specify a server port");
      System.exit(1);
      return;
    }
    val=null;
    val=line.getOptionValue("manager_port",null);
    if (null != val) {
      managerPort=Integer.valueOf(val);
    }
 else {
      printHelp(getOptions(),"Must specify a server port");
      System.exit(1);
      return;
    }
  }
 catch (  ParseException exp) {
    printHelp(getOptions(),exp.getMessage());
    System.exit(1);
    return;
  }
  new IndexesLogServer(readerPort,managerPort).start();
}
 

Example 22

From project jnrpe-server, under directory /jnrpe-server/src/main/java/it/jnrpe/server/.

Source file: JNRPEServer.java

  20 
vote

private static CommandLine parseCommandLine(String[] vsArgs){
  Digester d=DigesterLoader.createDigester(new InputSource(JNRPEServer.class.getResourceAsStream("command-line-digester.xml")));
  try {
    XMLOptions opts=(XMLOptions)d.parse(JNRPEServer.class.getResourceAsStream("jnrpe-command-line.xml"));
    m_Options=opts.toOptions();
    CommandLineParser clp=new PosixParser();
    return clp.parse(m_Options,vsArgs);
  }
 catch (  IOException e) {
  }
catch (  SAXException e) {
    e.printStackTrace();
  }
catch (  ParseException e) {
    printUsage(e);
  }
  return null;
}
 

Example 23

From project ManalithBot, under directory /ManalithBotConsole/src/main/java/org/manalith/ircbot/console/.

Source file: Launcher.java

  20 
vote

public static void main(String[] args) throws Exception {
  Options options=new Options();
  options.addOption("c",true,"config file");
  CommandLineParser parser=new PosixParser();
  CommandLine cmd=parser.parse(options,args);
  String configFile="config.xml";
  String configFileOptionArg=cmd.getOptionValue("c");
  if (StringUtils.isNotBlank(configFileOptionArg)) {
    configFile=configFileOptionArg;
  }
  ApplicationContext context=new FileSystemXmlApplicationContext(configFile);
  UsernamePasswordAuthenticationToken userToken=new UsernamePasswordAuthenticationToken("admin","admin");
  SecurityContextHolder.getContext().setAuthentication(userToken);
  Launcher launcher=context.getBean(Launcher.class);
  ConsoleReader reader=new ConsoleReader();
  String line;
  while (!StringUtils.equals((line=reader.readLine("prompt> ")),"exit")) {
    String[] strs=StringUtils.split(line," ");
    launcher.sendMessage(strs[0],strs[1]);
  }
}
 

Example 24

From project mwe, under directory /plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/core/.

Source file: WorkflowRunner.java

  20 
vote

@SuppressWarnings("static-access") protected static CommandLine getCommandLine(String[] args) throws ParseException {
  final Options options=new Options();
  options.addOption(OptionBuilder.hasArgs().withArgName("className,moreArgs").withDescription("the name of a class that implements ProgressMonitor. More arguments can be appended that will be injected to the monitor," + " if it has a init(String[] args) method.").withLongOpt("monitorClass").withValueSeparator(',').create(MONITOR));
  options.addOption(OptionBuilder.withLongOpt("ant").withDescription("must be set when using in Ant context").create(ANT));
  final Option paramOption=OptionBuilder.withArgName("key=value").withDescription("external property that is handled as workflow property").hasArgs().create(PARAM);
  paramOption.setLongOpt("param");
  options.addOption(paramOption);
  options.addOption(OptionBuilder.hasArgs().withArgName("className").withDescription("the name of a class that implements a public method 'public void processCmdLine(String[] cmdLineArgs, Map paramsToUseInWorkflow, WorkflowContext ctx)'.").withLongOpt("cmdLineProcessor").create(CMDL));
  final Option runnerOption=OptionBuilder.withArgName("className").withDescription("WorkflowRunnerEngine class").hasArgs().create(ENGINE);
  runnerOption.setLongOpt("engine");
  options.addOption(runnerOption);
  final CommandLineParser parser=new PosixParser();
  CommandLine line=parser.parse(options,args);
  return line;
}
 

Example 25

From project nuxeo-distribution, under directory /nuxeo-launcher/src/main/java/org/nuxeo/launcher/.

Source file: NuxeoLauncher.java

  20 
vote

/** 
 * @since 5.6
 */
protected static CommandLine parseOptions(String[] args) throws ParseException {
  initParserOptions();
  CommandLineParser parser=new PosixParser();
  CommandLine cmdLine=null;
  Boolean stopAfterParsing=true;
  try {
    cmdLine=parser.parse(launcherOptions,args);
    if (cmdLine.hasOption(OPTION_HELP) || cmdLine.getArgList().contains(OPTION_HELP)) {
      printLongHelp();
    }
 else     if (cmdLine.getArgList().isEmpty()) {
      printShortHelp();
    }
 else {
      stopAfterParsing=false;
    }
  }
 catch (  UnrecognizedOptionException e) {
    log.error(e.getMessage());
    printShortHelp();
  }
catch (  MissingArgumentException e) {
    log.error(e.getMessage());
    printShortHelp();
  }
catch (  ParseException e) {
    log.error("Error while parsing command line: " + e.getMessage());
    printShortHelp();
  }
 finally {
    if (stopAfterParsing) {
      throw new ParseException("Invalid command line");
    }
  }
  return cmdLine;
}
 

Example 26

From project pluto, under directory /pluto-util/src/main/java/org/apache/pluto/util/cli/.

Source file: AssemblerCLI.java

  20 
vote

public void run() throws ParseException, IOException, UtilityException {
  CommandLineParser parser=new PosixParser();
  CommandLine line=parser.parse(options,args);
  String[] args=line.getArgs();
  if (args.length != 1) {
    abort();
    return;
  }
  String dest=line.getOptionValue("file");
  if (dest == null) {
    dest=args[0];
  }
  File source=new File(args[0]);
  File result=new File(dest);
  result.getParentFile().mkdirs();
  if (!source.exists()) {
    System.out.println("File does not exist: " + source.getCanonicalPath());
  }
  System.out.println("-----------------------------------------------");
  System.out.println("Assembling: " + source.getCanonicalPath());
  System.out.println("        to: " + result.getCanonicalPath());
  File webXml=new File(args[0],Assembler.SERVLET_XML);
  File portletXml=new File(args[0],Assembler.PORTLET_XML);
  AssemblerConfig config=new AssemblerConfig();
  config.setWebappDescriptor(webXml);
  config.setPortletDescriptor(portletXml);
  config.setDestination(webXml);
  Assembler assembler=AssemblerFactory.getFactory().createAssembler(config);
  config.setPortletDescriptor(portletXml);
  config.setWebappDescriptor(webXml);
  assembler.assemble(config);
  System.out.println("Complete!");
}
 

Example 27

From project RecordBreaker, under directory /test/com/cloudera/recordbreaker/learnstructure/test/.

Source file: GenerateTestAvro.java

  20 
vote

/** 
 */
public static void main(String argv[]) throws IOException, InstantiationException {
  CommandLine cmd=null;
  Options options=new Options();
  options.addOption("?",false,"Help for command-line");
  options.addOption("n",true,"# tuples to emit per file");
  try {
    CommandLineParser parser=new PosixParser();
    cmd=parser.parse(options,argv);
  }
 catch (  ParseException pe) {
    HelpFormatter fmt=new HelpFormatter();
    fmt.printHelp("GenerateTestAvro",options,true);
    System.exit(-1);
  }
  if (cmd.hasOption("?")) {
    HelpFormatter fmt=new HelpFormatter();
    fmt.printHelp("GenerateTestAvro",options,true);
    System.exit(0);
  }
  int numToEmit=100;
  if (cmd.hasOption("n")) {
    try {
      numToEmit=Integer.parseInt(cmd.getOptionValue("n"));
    }
 catch (    NumberFormatException nfe) {
      nfe.printStackTrace();
    }
  }
  String[] argArray=cmd.getArgs();
  if (argArray.length == 0) {
    HelpFormatter fmt=new HelpFormatter();
    fmt.printHelp("GenerateTestAvro",options,true);
    System.exit(0);
  }
  File outputDir=new File(argArray[0]).getCanonicalFile();
  GenerateTestAvro gta=new GenerateTestAvro();
  gta.generateData(outputDir,numToEmit);
}
 

Example 28

From project seismichadoop, under directory /src/main/java/com/cloudera/seismic/segy/.

Source file: SegyUnloader.java

  20 
vote

@Override public int run(String[] args) throws Exception {
  Options options=new Options();
  options.addOption("input",true,"SU sequence files to export from Hadoop");
  options.addOption("output",true,"The local SU file to write");
  CommandLine cmdLine=new PosixParser().parse(options,args,false);
  if (!cmdLine.hasOption("input") || !cmdLine.hasOption("output")) {
    System.out.println("Mising required input/output arguments");
    new HelpFormatter().printHelp("SegyUnloader",options);
    System.exit(1);
  }
  Configuration conf=getConf();
  FileSystem hdfs=FileSystem.get(conf);
  Path inputPath=new Path(cmdLine.getOptionValue("input"));
  if (!hdfs.exists(inputPath)) {
    System.out.println("Input path does not exist");
    System.exit(1);
  }
  PathFilter pf=new PathFilter(){
    @Override public boolean accept(    Path path){
      return !path.getName().startsWith("_");
    }
  }
;
  DataOutputStream os=new DataOutputStream(new FileOutputStream(cmdLine.getOptionValue("output")));
  for (  FileStatus fs : hdfs.listStatus(inputPath,pf)) {
    write(fs.getPath(),os,conf);
  }
  os.close();
  return 0;
}
 

Example 29

From project spring-migration-analyzer, under directory /command-line/src/main/java/org/springframework/migrationanalyzer/commandline/.

Source file: AbstractMigrationAnalysis.java

  20 
vote

final void run(String[] args){
  CommandLine commandLine=null;
  try {
    commandLine=new PosixParser().parse(OPTIONS,args);
    String inputPath=commandLine.getOptionValue(OptionsFactory.OPTION_KEY_INPUT_PATH);
    String outputType=commandLine.getOptionValue(OptionsFactory.OPTION_KEY_OUTPUT_TYPE);
    String outputPath=commandLine.getOptionValue(OptionsFactory.OPTION_KEY_OUTPUT_PATH);
    String[] excludes=commandLine.getOptionValues(OptionsFactory.OPTION_KEY_EXCLUDE);
    getExecutor(inputPath,outputType,outputPath,excludes).execute();
  }
 catch (  ParseException e) {
    new HelpFormatter().printHelp("migration-analysis.[sh | bat] [OPTION]...",OPTIONS);
    exit(-1);
  }
}
 

Example 30

From project syncany, under directory /syncany/src/org/syncany/.

Source file: Syncany.java

  20 
vote

public static void start(){
  try {
    Options options=new Options();
    options.addOption("c","config",true,"Alternative config file (Default: ~/.syncany/config.xml)");
    options.addOption("h","help",false,"Print this message.");
    CommandLineParser parser=new PosixParser();
    CommandLine line=parser.parse(options,args);
    if (line.hasOption("help")) {
      new HelpFormatter().printHelp("syncany",options);
      System.exit(0);
    }
    if (line.hasOption("config")) {
      config.load(new File(line.getOptionValue("config")));
    }
 else {
      config.load();
    }
  }
 catch (  ConfigException e) {
    System.err.println("ERROR: Configuration exception: " + e.getMessage());
    System.err.println(StringUtil.getStackTrace(e));
    System.exit(1);
  }
catch (  ParseException e) {
    System.err.println("ERROR: Command line arguments invalid: " + e.getMessage());
    System.err.println(StringUtil.getStackTrace(e));
    System.exit(1);
  }
  try {
    new Application().start();
  }
 catch (  final Exception e) {
    ErrorDialog.showDialog(e);
  }
}
 

Example 31

From project texnlp, under directory /src/main/java/texnlp/apps/.

Source file: FormatConverter.java

  20 
vote

public static void main(String[] args){
  CommandLineParser optparse=new PosixParser();
  Options options=new Options();
  options.addOption("o","output",true,"the output format");
  options.addOption("h","help",false,"help");
  try {
    CommandLine cline=optparse.parse(options,args);
    if (cline.hasOption('h')) {
      HelpFormatter formatter=new HelpFormatter();
      formatter.printHelp("java texnlp.apps.FormatConverter options filename",options);
      System.exit(0);
    }
    String outputFormat="candc";
    if (cline.hasOption('o'))     outputFormat=cline.getOptionValue('o');
    if (outputFormat.equals("conll"))     convertToConll(cline.getArgs()[0]);
 else     convertToCandc(cline.getArgs()[0]);
  }
 catch (  ParseException exp) {
    System.out.println("Unexpected exception parsing command line options:" + exp.getMessage());
  }
}