Search in sources :

Example 26 with Getopt

use of gnu.getopt.Getopt in project jbossws-cxf by jbossws.

the class Runner method parseArguments.

private static BenchmarkTest parseArguments(String[] args) throws Exception {
    String shortOpts = "t:r:s:i:a:vh";
    LongOpt[] longOpts = { new LongOpt("deployment", LongOpt.REQUIRED_ARGUMENT, null, 'd'), new LongOpt("threads", LongOpt.REQUIRED_ARGUMENT, null, 't'), new LongOpt("runs", LongOpt.REQUIRED_ARGUMENT, null, 'r'), new LongOpt("sleep", LongOpt.REQUIRED_ARGUMENT, null, 's'), new LongOpt("iterations", LongOpt.REQUIRED_ARGUMENT, null, 'i'), new LongOpt("address", LongOpt.REQUIRED_ARGUMENT, null, 'a'), new LongOpt("verbose", LongOpt.NO_ARGUMENT, null, 'v'), new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h') };
    Getopt getopt = new Getopt("Benchmark-runner", args, shortOpts, longOpts);
    int c;
    while ((c = getopt.getopt()) != -1) {
        switch(c) {
            case 't':
                threadCount = Integer.parseInt(getopt.getOptarg());
                break;
            case 'r':
                runs = Integer.parseInt(getopt.getOptarg());
                break;
            case 's':
                sleep = Long.parseLong(getopt.getOptarg());
                break;
            case 'i':
                iterations = Integer.parseInt(getopt.getOptarg());
                break;
            case 'a':
                address = getopt.getOptarg();
                break;
            case 'v':
                verbose = true;
                break;
            case 'h':
                printHelp();
                System.exit(0);
            case '?':
                System.exit(1);
        }
    }
    int classPos = getopt.getOptind();
    if (classPos >= args.length) {
        System.err.println("Error: test-class was not specified!");
        printHelp();
        System.exit(1);
    }
    try {
        Class<?> clazz = Class.forName(args[classPos]);
        System.out.println(BenchmarkTest.class.isAssignableFrom(clazz));
        System.out.println(clazz.isAssignableFrom(BenchmarkTest.class));
        return (BenchmarkTest) clazz.newInstance();
    } catch (Exception e) {
        System.out.println("Cannot instanciate " + args[classPos]);
        throw e;
    }
}
Also used : Getopt(gnu.getopt.Getopt) LongOpt(gnu.getopt.LongOpt)

Aggregations

Getopt (gnu.getopt.Getopt)26 File (java.io.File)11 IOException (java.io.IOException)10 LongOpt (gnu.getopt.LongOpt)9 I2PAppContext (net.i2p.I2PAppContext)5 BufferedReader (java.io.BufferedReader)4 InputStream (java.io.InputStream)4 InputStreamReader (java.io.InputStreamReader)4 ArrayList (java.util.ArrayList)4 FileInputStream (java.io.FileInputStream)3 RandomAccessFile (java.io.RandomAccessFile)3 Properties (java.util.Properties)3 FileOutputStream (java.io.FileOutputStream)2 FileWriter (java.io.FileWriter)2 SocketException (java.net.SocketException)2 UnknownHostException (java.net.UnknownHostException)2 HashMap (java.util.HashMap)2 OrderedProperties (net.i2p.util.OrderedProperties)2 KeyCode_FileBased (automenta.rdp.keymapping.KeyCode_FileBased)1 KeyCode_FileBased_Localised (automenta.rdp.rdp.KeyCode_FileBased_Localised)1