Example usage for org.apache.commons.cli CommandLine getOptionValue

List of usage examples for org.apache.commons.cli CommandLine getOptionValue

Introduction

In this page you can find the example usage for org.apache.commons.cli CommandLine getOptionValue.

Prototype

public String getOptionValue(char opt) 

Source Link

Document

Retrieve the argument, if any, of this option.

Usage

From source file:com.norconex.collector.http.HttpCollector.java

/**
 * Invokes the HTTP Collector from the command line.  
 * @param args Invoke it once without any arguments to get a 
 *    list of command-line options./*  www  .  j  a va 2  s .  c  o m*/
 */
public static void main(String[] args) {
    CommandLine cmd = parseCommandLineArguments(args);
    String action = cmd.getOptionValue(ARG_ACTION);
    File configFile = new File(cmd.getOptionValue(ARG_CONFIG));
    File varFile = null;
    if (cmd.hasOption(ARG_VARIABLES)) {
        varFile = new File(cmd.getOptionValue(ARG_VARIABLES));
    }

    try {
        HttpCollector conn = new HttpCollector(configFile, varFile);
        if (ARG_ACTION_START.equalsIgnoreCase(action)) {
            conn.crawl(false);
        } else if (ARG_ACTION_RESUME.equalsIgnoreCase(action)) {
            conn.crawl(true);
        } else if (ARG_ACTION_STOP.equalsIgnoreCase(action)) {
            conn.stop();
        }
    } catch (Exception e) {
        File errorFile = new File("./error-" + System.currentTimeMillis() + ".log");
        System.err.println("\n\nAn ERROR occured:\n\n" + e.getLocalizedMessage());
        System.err.println(
                "\n\nDetails of the error has been stored at: " + errorFile.getAbsolutePath() + "\n\n");
        try {
            PrintWriter w = new PrintWriter(errorFile);
            e.printStackTrace(w);
            w.flush();
            w.close();
        } catch (FileNotFoundException e1) {
            throw new HttpCollectorException("Cannot write error file.", e1);
        }
    }
}

From source file:dk.statsbiblioteket.jpar2.filecompare.FileCompare.java

/**
 * Main method. /*from   www. j a va  2 s .c om*/
 * @param args
 */
public static void main(String[] args) {

    Options options = new Options();
    options.addOption("s", "slices", true, "The number of slices to use in the comparison");

    CommandLineParser parser = new PosixParser();
    try {
        CommandLine cmd = parser.parse(options, args);
        args = cmd.getArgs();
        if (!cmd.hasOption("s") || args.length != 2) {
            System.exit(2);
        }
        int slices = Integer.parseInt(cmd.getOptionValue("s").trim());

        File f1 = new File(args[0]);
        File f2 = new File(args[1]);
        if (f1.length() == f2.length()) {
            int sliceSize = (int) (f1.length() / slices);//rounding here...

            DataFile df1 = new DataFile(f1, sliceSize);
            DataFile df2 = new DataFile(f2, sliceSize);

            List<Integer> defectIndexes = df1.compareWithIndex(df2);

            for (int index : defectIndexes) {
                System.out.println("index " + index + ", from " + index * sliceSize + " to "
                        + (index + 1) * sliceSize + " is defect");
            }
            if (defectIndexes.size() == 0) {
                System.out.println("Files are identical");
            }

        } else {
            System.out.println("Files differ in length, cannot help you");
        }
    } catch (ParseException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    } catch (IOException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    }

}

From source file:fr.inria.atlanmod.atl_mr.utils.NeoEMFHBaseMigrator.java

public static void main(String[] args) {
    Options options = new Options();

    Option inputOpt = OptionBuilder.create(IN);
    inputOpt.setArgName("INPUT");
    inputOpt.setDescription("Input file, both of xmi and zxmi extensions are supported");
    inputOpt.setArgs(1);/*from w w  w.j a v  a  2 s  . c om*/
    inputOpt.setRequired(true);

    Option outputOpt = OptionBuilder.create(OUT);
    outputOpt.setArgName("OUTPUT");
    outputOpt.setDescription("Output HBase resource URI");
    outputOpt.setArgs(1);
    outputOpt.setRequired(true);

    Option inClassOpt = OptionBuilder.create(E_PACKAGE);
    inClassOpt.setArgName("METAMODEL");
    inClassOpt.setDescription("URI of the ecore Metamodel");
    inClassOpt.setArgs(1);
    inClassOpt.setRequired(true);

    options.addOption(inputOpt);
    options.addOption(outputOpt);
    options.addOption(inClassOpt);

    CommandLineParser parser = new PosixParser();

    try {
        CommandLine commandLine = parser.parse(options, args);

        URI sourceUri = URI.createFileURI(commandLine.getOptionValue(IN));
        URI targetUri = URI.createURI(commandLine.getOptionValue(OUT));
        URI metamodelUri = URI.createFileURI(commandLine.getOptionValue(E_PACKAGE));

        NeoEMFHBaseMigrator.class.getClassLoader().loadClass(commandLine.getOptionValue(E_PACKAGE))
                .getMethod("init").invoke(null);
        //org.eclipse.gmt.modisco.java.kyanos.impl.JavaPackageImpl.init();

        ResourceSet resourceSet = new ResourceSetImpl();
        resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore",
                new EcoreResourceFactoryImpl());
        resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi",
                new XMIResourceFactoryImpl());
        resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("zxmi",
                new XMIResourceFactoryImpl());
        resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put(KyanosURI.KYANOS_HBASE_SCHEME,
                KyanosResourceFactory.eINSTANCE);

        //Registering the metamodel
        //         Resource MMResource = resourceSet.createResource(metamodelUri);
        //         MMResource.load(Collections.EMPTY_MAP);
        //         ATLMRUtils.registerPackages(resourceSet, MMResource);
        //Loading the XMI resource
        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}",
                ATLMRUtils.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}",
                ATLMRUtils.byteCountToDisplaySize(finalUsedMemory)));
        LOG.log(Level.INFO, MessageFormat.format("Memory use increase: {0}",
                ATLMRUtils.byteCountToDisplaySize(finalUsedMemory - initialUsedMemory)));

        Resource targetResource = resourceSet.createResource(targetUri);

        Map<String, Object> saveOpts = new HashMap<String, Object>();
        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 KyanosHbaseResourceImpl) {
            KyanosHbaseResourceImpl.shutdownWithoutUnload((KyanosHbaseResourceImpl) targetResource);
        } else {
            targetResource.unload();
        }

    } catch (ParseException e) {
        ATLMRUtils.showError(e.toString());
        ATLMRUtils.showError("Current arguments: " + Arrays.toString(args));
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("java -jar <this-file.jar>", options, true);
    } catch (Throwable e) {
        ATLMRUtils.showError(e.toString());
        e.printStackTrace();
    }
}

From source file:gov.lanl.adore.djatoka.DjatokaCompress.java

/**
 * Uses apache commons cli to parse input args. Passes parsed
 * parameters to ICompress implementation.
 * @param args command line parameters to defined input,output,etc.
 *///from   www .ja v  a2s.com
public static void main(String[] args) {
    // create the command line parser
    CommandLineParser parser = new PosixParser();

    // create the Options
    Options options = new Options();
    options.addOption("i", "input", true, "Filepath of the input file or dir.");
    options.addOption("o", "output", true, "Filepath of the output file or dir.");
    options.addOption("r", "rate", true, "Absolute Compression Ratio");
    options.addOption("s", "slope", true,
            "Used to generate relative compression ratio based on content characteristics.");
    options.addOption("y", "Clayers", true, "Number of quality levels.");
    options.addOption("l", "Clevels", true, "Number of DWT levels (reolution levels).");
    options.addOption("v", "Creversible", true, "Use Reversible Wavelet");
    options.addOption("c", "Cprecincts", true, "Precinct dimensions");
    options.addOption("p", "props", true, "Compression Properties File");
    options.addOption("d", "Corder", true, "Progression order");
    options.addOption("g", "ORGgen_plt", true, "Enables insertion of packet length information in the header");
    options.addOption("t", "ORGtparts", true, "Division of each tile's packets into tile-parts");
    options.addOption("b", "Cblk", true, "Codeblock Size");
    options.addOption("a", "AltImpl", true, "Alternate ICompress Implemenation");

    try {
        if (args.length == 0) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("gov.lanl.adore.djatoka.DjatokaCompress", options);
            System.exit(0);
        }

        // parse the command line arguments
        CommandLine line = parser.parse(options, args);
        String input = line.getOptionValue("i");
        String output = line.getOptionValue("o");

        String propsFile = line.getOptionValue("p");
        DjatokaEncodeParam p;
        if (propsFile != null) {
            Properties props = IOUtils.loadConfigByPath(propsFile);
            p = new DjatokaEncodeParam(props);
        } else
            p = new DjatokaEncodeParam();
        String rate = line.getOptionValue("r");
        if (rate != null)
            p.setRate(rate);
        String slope = line.getOptionValue("s");
        if (slope != null)
            p.setSlope(slope);
        String Clayers = line.getOptionValue("y");
        if (Clayers != null)
            p.setLayers(Integer.parseInt(Clayers));
        String Clevels = line.getOptionValue("l");
        if (Clevels != null)
            p.setLevels(Integer.parseInt(Clevels));
        String Creversible = line.getOptionValue("v");
        if (Creversible != null)
            p.setUseReversible(Boolean.parseBoolean(Creversible));
        String Cprecincts = line.getOptionValue("c");
        if (Cprecincts != null)
            p.setPrecincts(Cprecincts);
        String Corder = line.getOptionValue("d");
        if (Corder != null)
            p.setProgressionOrder(Corder);
        String ORGgen_plt = line.getOptionValue("g");
        if (ORGgen_plt != null)
            p.setInsertPLT(Boolean.parseBoolean(ORGgen_plt));
        String Cblk = line.getOptionValue("b");
        if (Cblk != null)
            p.setCodeBlockSize(Cblk);
        String alt = line.getOptionValue("a");

        ICompress jp2 = new KduCompressExe();
        if (alt != null)
            jp2 = (ICompress) Class.forName(alt).newInstance();
        if (new File(input).isDirectory() && new File(output).isDirectory()) {
            ArrayList<File> files = IOUtils.getFileList(input, new SourceImageFileFilter(), false);
            for (File f : files) {
                long x = System.currentTimeMillis();
                File outFile = new File(output, f.getName().substring(0, f.getName().indexOf(".")) + ".jp2");
                compress(jp2, f.getAbsolutePath(), outFile.getAbsolutePath(), p);
                report(f.getAbsolutePath(), x);
            }
        } else {
            long x = System.currentTimeMillis();
            File f = new File(input);
            if (output == null)
                output = f.getName().substring(0, f.getName().indexOf(".")) + ".jp2";
            if (new File(output).isDirectory())
                output = output + f.getName().substring(0, f.getName().indexOf(".")) + ".jp2";
            compress(jp2, input, output, p);
            report(input, x);
        }
    } catch (ParseException e) {
        logger.error("Parse exception:" + e.getMessage(), e);
    } catch (DjatokaException e) {
        logger.error("djatoka Compression exception:" + e.getMessage(), e);
    } catch (InstantiationException e) {
        logger.error("Unable to initialize alternate implemenation:" + e.getMessage(), e);
    } catch (Exception e) {
        logger.error("An exception occured:" + e.getMessage(), e);
    }
}

From source file:com.continuuity.loom.runtime.DummyProvisioner.java

public static void main(final String[] args) throws Exception {
    Options options = new Options();
    options.addOption("h", "host", true, "Loom server to connect to");
    options.addOption("p", "port", true, "Loom server port to connect to");
    options.addOption("c", "concurrency", true, "default concurrent threads");
    options.addOption("f", "failurePercent", true, "% of the time a provisioner should fail its task");
    options.addOption("o", "once", false, "whether or not only one task should be taken before exiting");
    options.addOption("d", "taskDuration", true, "number of milliseconds it should take to finish a task");
    options.addOption("s", "sleepMs", true,
            "number of milliseconds a thread will sleep before taking another task");
    options.addOption("n", "numTasks", true,
            "number of tasks to try and take from the queue.  Default is infinite.");
    options.addOption("t", "tenant", true, "tenant id to use.");

    try {//from   ww  w.java2s .com
        CommandLineParser parser = new BasicParser();
        CommandLine cmd = parser.parse(options, args);
        host = cmd.hasOption('h') ? cmd.getOptionValue('h') : "localhost";
        port = cmd.hasOption('p') ? Integer.valueOf(cmd.getOptionValue('p')) : 55054;
        concurrency = cmd.hasOption('c') ? Integer.valueOf(cmd.getOptionValue('c')) : 5;
        failurePercent = cmd.hasOption('f') ? Integer.valueOf(cmd.getOptionValue('f')) : 0;
        runOnce = cmd.hasOption('o');
        taskMs = cmd.hasOption('d') ? Long.valueOf(cmd.getOptionValue('d')) : 1000;
        sleepMs = cmd.hasOption('s') ? Long.valueOf(cmd.getOptionValue('s')) : 1000;
        numTasks = cmd.hasOption('n') ? Integer.valueOf(cmd.getOptionValue('n')) : -1;
        tenant = cmd.hasOption('t') ? cmd.getOptionValue('t') : "loom";
    } catch (ParseException e) {
        LOG.error("exception parsing input arguments.", e);
        return;
    }
    if (concurrency < 1) {
        LOG.error("invalid concurrency level {}.", concurrency);
        return;
    }

    if (runOnce) {
        new Provisioner("dummy-0", tenant, host, port, failurePercent, taskMs, sleepMs, 1).runOnce();
    } else {
        LOG.info(String.format(
                "running with %d threads, connecting to %s:%d using tenant %s, with a failure rate of"
                        + "%d percent, task time of %d ms, and sleep time of %d ms between fetches",
                concurrency, host, port, tenant, failurePercent, taskMs, sleepMs));
        pool = Executors.newFixedThreadPool(concurrency);

        try {
            int tasksPerProvisioner = numTasks >= 0 ? numTasks / concurrency : -1;
            int extra = numTasks < 0 ? 0 : numTasks % concurrency;
            pool.execute(new Provisioner("dummy-0", tenant, host, port, failurePercent, taskMs, sleepMs,
                    tasksPerProvisioner + extra));
            for (int i = 1; i < concurrency; i++) {
                pool.execute(new Provisioner("dummy-" + i, tenant, host, port, failurePercent, taskMs, sleepMs,
                        tasksPerProvisioner));
            }
        } catch (Exception e) {
            LOG.error("Caught exception, shutting down now.", e);
            pool.shutdownNow();
        }
        pool.shutdown();
    }
}

From source file:edu.indiana.d2i.sloan.internal.CreateVMSimulator.java

public static void main(String[] args) {
    CreateVMSimulator simulator = new CreateVMSimulator();

    CommandLineParser parser = new PosixParser();

    try {//from   w  ww.  j  a  v a  2s  .c o m
        CommandLine line = simulator.parseCommandLine(parser, args);

        String imagePath = line.getOptionValue(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.IMAGE_PATH));
        int vcpu = Integer.parseInt(line.getOptionValue(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.VCPU)));
        int mem = Integer.parseInt(line.getOptionValue(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.MEM)));

        if (!HypervisorCmdSimulator.resourceExist(imagePath)) {
            logger.error(String.format("Cannot find requested image: %s", imagePath));
            System.exit(ERROR_CODE.get(ERROR_STATE.IMAGE_NOT_EXIST));
        }

        if (!hasEnoughCPUs(vcpu)) {
            logger.error(String.format("Don't have enough cpus, requested %d", vcpu));
            System.exit(ERROR_CODE.get(ERROR_STATE.NOT_ENOUGH_CPU));
        }

        if (!hasEnoughMem(mem)) {
            logger.error(String.format("Don't have enough memory, requested %d", mem));
            System.exit(ERROR_CODE.get(ERROR_STATE.NOT_ENOUGH_MEM));
        }

        String wdir = line.getOptionValue(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.WORKING_DIR));

        if (HypervisorCmdSimulator.resourceExist(wdir)) {
            logger.error(String.format("Working directory %s already exists ", wdir));
            System.exit(ERROR_CODE.get(ERROR_STATE.VM_ALREADY_EXIST));
        }

        // copy VM image to working directory
        File imageFile = new File(imagePath);
        FileUtils.copyFile(imageFile, new File(HypervisorCmdSimulator.cleanPath(wdir) + imageFile.getName()));

        // write state as property file so that we can query later
        Properties prop = new Properties();

        prop.put(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.IMAGE_PATH), imagePath);
        prop.put(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.VCPU), String.valueOf(vcpu));
        prop.put(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.MEM), String.valueOf(mem));
        prop.put(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.WORKING_DIR), wdir);
        prop.put(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.VNC_PORT),
                line.getOptionValue(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.VNC_PORT)));
        prop.put(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.SSH_PORT),
                line.getOptionValue(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.SSH_PORT)));
        prop.put(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.LOGIN_USERNAME),
                line.getOptionValue(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.LOGIN_USERNAME)));
        prop.put(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.LOGIN_PASSWD),
                line.getOptionValue(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.LOGIN_PASSWD)));

        // write VM state as shutdown
        prop.put(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.VM_STATE), VMState.SHUTDOWN.toString());
        // write VM mode as undefined
        prop.put(CMD_FLAG_VALUE.get(CMD_FLAG_KEY.VM_MODE), VMMode.NOT_DEFINED.toString());

        prop.store(
                new FileOutputStream(new File(
                        HypervisorCmdSimulator.cleanPath(wdir) + HypervisorCmdSimulator.VM_INFO_FILE_NAME)),
                "");

        // do other related settings
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            logger.error(e.getMessage());
        }

        // success
        System.exit(0);

    } catch (ParseException e) {
        logger.error(String.format("Cannot parse input arguments: %s%n, expected:%n%s",
                StringUtils.join(args, " "), simulator.getUsage(100, "", 5, 5, "")));

        System.exit(ERROR_CODE.get(ERROR_STATE.INVALID_INPUT_ARGS));
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
        System.exit(ERROR_CODE.get(ERROR_STATE.IO_ERR));
    }
}

From source file:com.thoughtworks.xstream.tools.benchmark.parsers.ParserBenchmark.java

public static void main(String[] args) {
    int counter = 1000;

    Options options = new Options();
    options.addOption("p", "product", true, "Class name of the product to use for benchmark");
    options.addOption("n", true, "Number of repetitions");

    Harness harness = new Harness();
    harness.addMetric(new DeserializationSpeedMetric(0, false) {
        public String toString() {
            return "Initial run deserialization";
        }//from   www  . ja  v  a  2s  .  c om
    });

    Parser parser = new PosixParser();
    try {
        CommandLine commandLine = parser.parse(options, args);
        String name = null;
        if (commandLine.hasOption('p')) {
            name = commandLine.getOptionValue('p');
        }
        if (name == null || name.equals("DOM")) {
            harness.addProduct(new XStreamDom());
        }
        if (name == null || name.equals("JDOM")) {
            harness.addProduct(new XStreamJDom());
        }
        if (name == null || name.equals("DOM4J")) {
            harness.addProduct(new XStreamDom4J());
        }
        if (name == null || name.equals("XOM")) {
            harness.addProduct(new XStreamXom());
        }
        if (name == null || name.equals("BEAStAX")) {
            harness.addProduct(new XStreamBEAStax());
        }
        if (name == null || name.equals("Woodstox")) {
            harness.addProduct(new XStreamWoodstox());
        }
        if (JVM.is16() && (name == null || name.equals("SJSXP"))) {
            harness.addProduct(new XStreamSjsxp());
        }
        if (name == null || name.equals("Xpp3")) {
            harness.addProduct(new XStreamXpp3());
        }
        if (name == null || name.equals("kXML2")) {
            harness.addProduct(new XStreamKXml2());
        }
        if (name == null || name.equals("Xpp3DOM")) {
            harness.addProduct(new XStreamXpp3DOM());
        }
        if (name == null || name.equals("kXML2DOM")) {
            harness.addProduct(new XStreamKXml2DOM());
        }
        if (commandLine.hasOption('n')) {
            counter = Integer.parseInt(commandLine.getOptionValue('n'));
        }
    } catch (ParseException e) {
        e.printStackTrace();
    }

    harness.addMetric(new DeserializationSpeedMetric(counter, false));
    harness.addTarget(new BasicTarget());
    harness.addTarget(new ExtendedTarget());
    harness.addTarget(new ReflectionTarget());
    harness.addTarget(new SerializableTarget());
    harness.addTarget(new JavaBeanTarget());
    if (false) {
        harness.addTarget(new FieldReflection());
        harness.addTarget(new HierarchyLevelReflection());
        harness.addTarget(new InnerClassesReflection());
        harness.addTarget(new StaticInnerClassesReflection());
    }
    harness.run(new TextReporter(new PrintWriter(System.out, true)));
    System.out.println("Done.");
}

From source file:de.burlov.amazon.s3.S3Utils.java

public static void main(String[] args) {
    Options opts = new Options();
    OptionGroup gr = new OptionGroup();
    gr.setRequired(true);//from   w ww . ja va  2 s  .c o  m
    gr.addOption(new Option(LIST, false, ""));
    gr.addOption(new Option(DELETE, false, ""));

    opts.addOptionGroup(gr);

    opts.addOption(new Option("k", true, "Access key for AWS account"));
    opts.addOption(new Option("s", true, "Secret key for AWS account"));
    opts.addOption(new Option("b", true, "Bucket"));
    CommandLine cmd = null;
    try {
        cmd = new PosixParser().parse(opts, args);

        String accessKey = cmd.getOptionValue("k");
        if (StringUtils.isBlank(accessKey)) {
            System.out.println("Missing amazon access key");
            return;
        }
        String secretKey = cmd.getOptionValue("s");
        if (StringUtils.isBlank(secretKey)) {
            System.out.println("Missing secret key");
            return;
        }
        String bucket = cmd.getOptionValue("b");
        if (cmd.hasOption(LIST)) {
            if (StringUtils.isBlank(bucket)) {
                printBuckets(accessKey, secretKey);
            } else {
                printBucket(accessKey, secretKey, bucket);
            }
        } else if (cmd.hasOption(DELETE)) {
            if (StringUtils.isBlank(bucket)) {
                System.out.println("Bucket name required");
                return;
            }
            int count = deleteBucket(accessKey, secretKey, bucket);
            System.out.println("Deleted objects in bucket: " + count);
        }
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        printUsage(opts);
        return;
    } catch (Exception e) {
        e.printStackTrace(System.err);
    }
}

From source file:edu.msu.cme.rdp.framebot.stat.TaxonAbundance.java

/**
 * this class group the nearest matches by phylum/class, or by match 
 * @param args//from   w w  w  . j a v a2  s.c  o  m
 * @throws Exception 
 */
public static void main(String[] args) throws Exception {
    HashMap<String, Double> coveragetMap = null;
    double identity = 0.0;
    try {
        CommandLine line = new PosixParser().parse(options, args);
        if (line.hasOption("seqCoverage")) {
            String coveragefile = line.getOptionValue("seqCoverage");
            coveragetMap = parseKmerCoverage(coveragefile);
        }
        if (line.hasOption("identity")) {
            identity = Double.parseDouble(line.getOptionValue("identity"));
            if (identity < 0 || identity > 100) {
                throw new IllegalArgumentException("identity cutoff should be in the range of 0 and 100");
            }
        }

        args = line.getArgs();
        if (args.length != 3) {
            throw new Exception("");
        }

    } catch (Exception e) {
        System.out.println("Command Error: " + e.getMessage());
        new HelpFormatter().printHelp(80, "[options] <FrameBot Alignment file or Dir> <seqLineage> <out file> ",
                "", options,
                "seqLineage: a tab-delimited file with ref seqID and lineage, or fasta of ref seq with lineage as the descrption"
                        + "\nframeBot alignment file or Dir: frameBot alignment files "
                        + "\noutfile: output with the nearest match count group by phylum/class; and by match name");
    }
    TaxonAbundance.mapAbundance(new File(args[0]), new File(args[1]), args[2], coveragetMap, identity);
}

From source file:fr.inria.atlanmod.kyanos.benchmarks.KyanosGraphQuery.java

public static void main(String[] args) {
    Options options = new Options();

    Option inputOpt = OptionBuilder.create(IN);
    inputOpt.setArgName("INPUT");
    inputOpt.setDescription("Input Kyanos resource directory");
    inputOpt.setArgs(1);/*from  w  ww . ja  v  a  2  s. com*/
    inputOpt.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(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 uri = NeoBlueprintsURI.createNeoGraphURI(new File(commandLine.getOptionValue(IN)));

        Class<?> inClazz = KyanosGraphQuery.class.getClassLoader()
                .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS));
        inClazz.getMethod("init").invoke(null);

        ResourceSet resourceSet = new ResourceSetImpl();
        resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap()
                .put(NeoBlueprintsURI.NEO_GRAPH_SCHEME, PersistentResourceFactory.eINSTANCE);

        Resource resource = resourceSet.createResource(uri);

        Map<String, Object> loadOpts = 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()) {
                loadOpts.put((String) entry.getKey(), (String) entry.getValue());
            }
        }
        resource.load(loadOpts);
        {
            LOG.log(Level.INFO, "Start query");
            long begin = System.currentTimeMillis();
            EList<MethodDeclaration> list = JavaQueries.getUnusedMethodsList(resource);
            long end = System.currentTimeMillis();
            LOG.log(Level.INFO, "End query");
            LOG.log(Level.INFO, MessageFormat.format("Query result (list) contains {0} elements", list.size()));
            LOG.log(Level.INFO, MessageFormat.format("Time spent: {0}", MessageUtil.formatMillis(end - begin)));
        }

        {
            LOG.log(Level.INFO, "Start query");
            long begin = System.currentTimeMillis();
            EList<MethodDeclaration> list = JavaQueries.getUnusedMethodsLoop(resource);
            long end = System.currentTimeMillis();
            LOG.log(Level.INFO, "End query");
            LOG.log(Level.INFO,
                    MessageFormat.format("Query result (loops) contains {0} elements", list.size()));
            LOG.log(Level.INFO, MessageFormat.format("Time spent: {0}", MessageUtil.formatMillis(end - begin)));
        }

        if (resource instanceof PersistentResourceImpl) {
            PersistentResourceImpl.shutdownWithoutUnload((PersistentResourceImpl) resource);
        } else {
            resource.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());
    }
}