Example usage for org.apache.commons.cli Option Option

List of usage examples for org.apache.commons.cli Option Option

Introduction

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

Prototype

public Option(String opt, String longOpt, boolean hasArg, String description) throws IllegalArgumentException 

Source Link

Document

Creates an Option using the specified parameters.

Usage

From source file:com.rabbitmq.examples.FileConsumer.java

public static void main(String[] args) {
    Options options = new Options();
    options.addOption(new Option("h", "uri", true, "AMQP URI"));
    options.addOption(new Option("q", "queue", true, "queue name"));
    options.addOption(new Option("t", "type", true, "exchange type"));
    options.addOption(new Option("e", "exchange", true, "exchange name"));
    options.addOption(new Option("k", "routing-key", true, "routing key"));
    options.addOption(new Option("d", "directory", true, "output directory"));

    CommandLineParser parser = new GnuParser();

    try {//from ww w  .j a  v a  2s.c  o m
        CommandLine cmd = parser.parse(options, args);

        String uri = strArg(cmd, 'h', "amqp://localhost");
        String requestedQueueName = strArg(cmd, 'q', "");
        String exchangeType = strArg(cmd, 't', "direct");
        String exchange = strArg(cmd, 'e', null);
        String routingKey = strArg(cmd, 'k', null);
        String outputDirName = strArg(cmd, 'd', ".");

        File outputDir = new File(outputDirName);
        if (!outputDir.exists() || !outputDir.isDirectory()) {
            System.err.println("Output directory must exist, and must be a directory.");
            System.exit(2);
        }

        ConnectionFactory connFactory = new ConnectionFactory();
        connFactory.setUri(uri);
        Connection conn = connFactory.newConnection();

        final Channel ch = conn.createChannel();

        String queueName = (requestedQueueName.equals("") ? ch.queueDeclare()
                : ch.queueDeclare(requestedQueueName, false, false, false, null)).getQueue();

        if (exchange != null || routingKey != null) {
            if (exchange == null) {
                System.err.println("Please supply exchange name to bind to (-e)");
                System.exit(2);
            }
            if (routingKey == null) {
                System.err.println("Please supply routing key pattern to bind to (-k)");
                System.exit(2);
            }
            ch.exchangeDeclare(exchange, exchangeType);
            ch.queueBind(queueName, exchange, routingKey);
        }

        QueueingConsumer consumer = new QueueingConsumer(ch);
        ch.basicConsume(queueName, consumer);
        while (true) {
            QueueingConsumer.Delivery delivery = consumer.nextDelivery();
            Map<String, Object> headers = delivery.getProperties().getHeaders();
            byte[] body = delivery.getBody();
            Object headerFilenameO = headers.get("filename");
            String headerFilename = (headerFilenameO == null) ? UUID.randomUUID().toString()
                    : headerFilenameO.toString();
            File givenName = new File(headerFilename);
            if (givenName.getName().equals("")) {
                System.out.println("Skipping file with empty name: " + givenName);
            } else {
                File f = new File(outputDir, givenName.getName());
                System.out.print("Writing " + f + " ...");
                FileOutputStream o = new FileOutputStream(f);
                o.write(body);
                o.close();
                System.out.println(" done.");
            }
            ch.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
        }
    } catch (Exception ex) {
        System.err.println("Main thread caught exception: " + ex);
        ex.printStackTrace();
        System.exit(1);
    }
}

From source file:com.xafero.vee.cmd.MainApp.java

public static void main(String[] args) {
    // Define options
    Option help = new Option("?", "help", false, "print this message");
    Option version = new Option("v", "version", false, "print the version information and exit");
    Option eval = Option.builder("e").desc("evaluate script").argName("file").longOpt("eval").hasArg().build();
    Option list = new Option("l", "list", false, "print all available languages");
    // Collect them
    Options options = new Options();
    options.addOption(help);// w w w .ja v a  2  s.co  m
    options.addOption(version);
    options.addOption(eval);
    options.addOption(list);
    // If nothing given, nothing will happen
    if (args == null || args.length < 1) {
        printHelp(options);
        return;
    }
    // Parse command line
    try {
        CommandLineParser parser = new DefaultParser();
        CommandLine line = parser.parse(options, args);
        // Work on it
        process(line, options);
    } catch (Throwable e) {
        System.err.printf("Error occurred: %n " + e.getMessage());
    }
}

From source file:net.robyf.dbpatcher.Launcher.java

public static void main(final String[] args) throws DBPatcherException { //NOSONAR
    Options options = new Options();

    Option usernameOption = new Option("u", "username", true, "Database username");
    usernameOption.setRequired(true);/*from  www. jav a 2 s  . c o m*/
    options.addOption(usernameOption);
    Option passwordOption = new Option("p", "password", true, "Database password");
    passwordOption.setRequired(true);
    options.addOption(passwordOption);
    Option databaseOption = new Option("d", "databaseName", true, "Database name");
    databaseOption.setRequired(true);
    options.addOption(databaseOption);
    options.addOption("r", "rollback-if-error", false, "Rolls back the entire operation in case of errors");
    options.addOption("v", "to-version", true, "Target version number");
    options.addOption("s", "simulation", false, "Simulate the operation without touching the current database");
    options.addOption("c", "character-set", true, "Character set (default value: ISO-8859-1)");

    Parameters parameters = new Parameters();
    boolean showHelp = false;
    try {
        CommandLine commandLine = new PosixParser().parse(options, args);

        parameters.setUsername(commandLine.getOptionValue("u"));
        parameters.setPassword(commandLine.getOptionValue("p"));
        parameters.setDatabaseName(commandLine.getOptionValue("d"));

        parameters.setRollbackIfError(commandLine.hasOption("r"));
        parameters.setSimulationMode(commandLine.hasOption("s"));
        if (commandLine.hasOption("v")) {
            parameters.setTargetVersion(new Long(commandLine.getOptionValue("v")));
        }
        if (commandLine.hasOption("c")) {
            parameters.setCharset(Charset.forName(commandLine.getOptionValue("c")));
        }

        if (commandLine.getArgs().length == 1) {
            parameters.setSchemaPath(commandLine.getArgs()[0]);
        } else {
            showHelp = true;
        }
    } catch (ParseException pe) {
        showHelp = true;
    }

    if (showHelp) {
        new HelpFormatter().printHelp("java -jar dbpatcher.jar" + " -u username -p password -d database_name"
                + " [options] schema_root", "Available options:", options, "");
    } else {
        DBPatcherFactory.getDBPatcher().patch(parameters);
    }
}

From source file:com.commonsware.android.gcm.cmd.GCM.java

@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);//from w  w  w  .ja v a2 s .  co m
    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();
    }
}

From source file:fr.tpt.s3.mcdag.generator.MainGenerator.java

/**
 * Main method for the generator: it launches a given number of threads with the parameters
 * given//from   w  ww.  j  a  v a2s .c  o  m
 * @param args
 */
public static void main(String[] args) {

    /* ============================ Command line ================= */
    Options options = new Options();

    Option o_hi = new Option("mu", "max_utilization", true, "Upper bound utilization");
    o_hi.setRequired(true);
    options.addOption(o_hi);

    Option o_tasks = new Option("nt", "nb_tasks", true, "Number of tasks for the system");
    o_tasks.setRequired(true);
    options.addOption(o_tasks);

    Option o_eprob = new Option("e", "eprobability", true, "Probability of edges");
    o_eprob.setRequired(true);
    options.addOption(o_eprob);

    Option o_levels = new Option("l", "levels", true, "Number of criticality levels");
    o_levels.setRequired(true);
    options.addOption(o_levels);

    Option o_para = new Option("p", "parallelism", true, "Max parallelism for the DAGs");
    o_para.setRequired(true);
    options.addOption(o_para);

    Option o_nbdags = new Option("nd", "num_dags", true, "Number of DAGs");
    o_nbdags.setRequired(true);
    options.addOption(o_nbdags);

    Option o_nbfiles = new Option("nf", "num_files", true, "Number of files");
    o_nbfiles.setRequired(true);
    options.addOption(o_nbfiles);

    Option o_rfactor = new Option("rf", "reduc_factor", true, "Reduction factor for criticality modes");
    o_rfactor.setRequired(false);
    options.addOption(o_rfactor);

    Option o_out = new Option("o", "output", true, "Output file for the DAG");
    o_out.setRequired(true);
    options.addOption(o_out);

    Option graphOpt = new Option("g", "graphviz", false, "Generate a graphviz DOT file");
    graphOpt.setRequired(false);
    options.addOption(graphOpt);

    Option debugOpt = new Option("d", "debug", false, "Enabling debug");
    debugOpt.setRequired(false);
    options.addOption(debugOpt);

    Option jobsOpt = new Option("j", "jobs", true, "Number of jobs");
    jobsOpt.setRequired(false);
    options.addOption(jobsOpt);

    CommandLineParser parser = new DefaultParser();
    HelpFormatter formatter = new HelpFormatter();
    CommandLine cmd;

    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        formatter.printHelp("DAG Generator", options);

        System.exit(1);
        return;
    }

    double maxU = Double.parseDouble(cmd.getOptionValue("max_utilization"));
    int edgeProb = Integer.parseInt(cmd.getOptionValue("eprobability"));
    int levels = Integer.parseInt(cmd.getOptionValue("levels"));
    int nbDags = Integer.parseInt(cmd.getOptionValue("num_dags"));
    int nbFiles = Integer.parseInt(cmd.getOptionValue("num_files"));
    int para = Integer.parseInt(cmd.getOptionValue("parallelism"));
    int nbTasks = Integer.parseInt(cmd.getOptionValue("nb_tasks"));
    boolean graph = cmd.hasOption("graphviz");
    boolean debug = cmd.hasOption("debug");
    String output = cmd.getOptionValue("output");
    int nbJobs = 1;
    if (cmd.hasOption("jobs"))
        nbJobs = Integer.parseInt(cmd.getOptionValue("jobs"));
    double rfactor = 2.0;
    if (cmd.hasOption("reduc_factor"))
        rfactor = Double.parseDouble(cmd.getOptionValue("reduc_factor"));
    /* ============================= Generator parameters ============================= */

    if (nbFiles < 0 || nbDags < 0 || nbJobs < 0) {
        System.err.println("[ERROR] Generator: Number of files & DAGs need to be positive.");
        formatter.printHelp("DAG Generator", options);
        System.exit(1);
        return;
    }

    Thread threads[] = new Thread[nbJobs];

    int nbFilesCreated = 0;
    int count = 0;

    while (nbFilesCreated != nbFiles) {
        int launched = 0;

        for (int i = 0; i < nbJobs && count < nbFiles; i++) {
            String outFile = output.substring(0, output.lastIndexOf('.')).concat("-" + count + ".xml");
            GeneratorThread gt = new GeneratorThread(maxU, nbTasks, edgeProb, levels, para, nbDags, rfactor,
                    outFile, graph, debug);
            threads[i] = new Thread(gt);
            threads[i].setName("GeneratorThread-" + i);
            launched++;
            count++;
            threads[i].start();
        }

        for (int i = 0; i < launched; i++) {
            try {
                threads[i].join();
                nbFilesCreated++;
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:fr.cnrs.sharp.Main.java

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

    Option versionOpt = new Option("v", "version", false, "print the version information and exit");
    Option helpOpt = new Option("h", "help", false, "print the help");

    Option inProvFileOpt = OptionBuilder.withArgName("input_PROV_file_1> ... <input_PROV_file_n")
            .withLongOpt("input_PROV_files").withDescription("The list of PROV input files, in RDF Turtle.")
            .hasArgs().create("i");

    Option inRawFileOpt = OptionBuilder.withArgName("input_raw_file_1> ... <input_raw_file_n")
            .withLongOpt("input_raw_files")
            .withDescription(/*from   w ww . j  av  a2 s. co  m*/
                    "The list of raw files to be fingerprinted and possibly interlinked with owl:sameAs.")
            .hasArgs().create("ri");

    Option summaryOpt = OptionBuilder.withArgName("summary").withLongOpt("summary")
            .withDescription("Materialization of wasInfluencedBy relations.").create("s");

    options.addOption(inProvFileOpt);
    options.addOption(inRawFileOpt);
    options.addOption(versionOpt);
    options.addOption(helpOpt);
    options.addOption(summaryOpt);

    String header = "SharpTB is a tool to maturate provenance based on PROV inferences";
    String footer = "\nPlease report any issue to alban.gaignard@univ-nantes.fr";

    try {
        CommandLineParser parser = new BasicParser();
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption("h")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("SharpTB", header, options, footer, true);
            System.exit(0);
        }

        if (cmd.hasOption("v")) {
            logger.info("SharpTB version 0.1.0");
            System.exit(0);
        }

        if (cmd.hasOption("ri")) {
            String[] inFiles = cmd.getOptionValues("ri");
            Model model = ModelFactory.createDefaultModel();
            for (String inFile : inFiles) {
                Path p = Paths.get(inFile);
                if (!p.toFile().isFile()) {
                    logger.error("Cannot find file " + inFile);
                    System.exit(1);
                } else {
                    //1. fingerprint
                    try {
                        model.add(Interlinking.fingerprint(p));
                    } catch (IOException e) {
                        logger.error("Cannot fingerprint file " + inFile);
                    }
                }
            }
            //2. genSameAs
            Model sameAs = Interlinking.generateSameAs(model);
            sameAs.write(System.out, "TTL");
        }

        if (cmd.hasOption("i")) {
            String[] inFiles = cmd.getOptionValues("i");
            Model data = ModelFactory.createDefaultModel();
            for (String inFile : inFiles) {
                Path p = Paths.get(inFile);
                if (!p.toFile().isFile()) {
                    logger.error("Cannot find file " + inFile);
                    System.exit(1);
                } else {
                    RDFDataMgr.read(data, inFile, Lang.TTL);
                }
            }
            Model res = Harmonization.harmonizeProv(data);

            try {
                Path pathInfProv = Files.createTempFile("PROV-inf-tgd-egd-", ".ttl");
                res.write(new FileWriter(pathInfProv.toFile()), "TTL");
                System.out.println("Harmonized PROV written to file " + pathInfProv.toString());

                //if the summary option is activated, then save the subgraph and generate a visualization
                if (cmd.hasOption("s")) {

                    String queryInfluence = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
                            + "PREFIX prov: <http://www.w3.org/ns/prov#> \n" + "CONSTRUCT { \n"
                            + "    ?x ?p ?y .\n" + "    ?x rdfs:label ?lx .\n" + "    ?y rdfs:label ?ly .\n"
                            + "} WHERE {\n" + "    ?x ?p ?y .\n"
                            + "    FILTER (?p IN (prov:wasInfluencedBy)) .\n" + "    ?x rdfs:label ?lx .\n"
                            + "    ?y rdfs:label ?ly .\n" + "}";

                    Query query = QueryFactory.create(queryInfluence);
                    QueryExecution queryExec = QueryExecutionFactory.create(query, res);
                    Model summary = queryExec.execConstruct();
                    queryExec.close();
                    Util.writeHtmlViz(summary);
                }

            } catch (IOException ex) {
                logger.error("Impossible to write the harmonized provenance file.");
                System.exit(1);
            }
        } else {
            //                logger.info("Please fill the -i input parameter.");
            //                HelpFormatter formatter = new HelpFormatter();
            //                formatter.printHelp("SharpTB", header, options, footer, true);
            //                System.exit(0);
        }

    } catch (ParseException ex) {
        logger.error("Error while parsing command line arguments. Please check the following help:");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("SharpToolBox", header, options, footer, true);
        System.exit(1);
    }
}

From source file:net.sf.brunneng.iqdb.db.DBWorker.java

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

    Option actionOpt = new Option("a", "action", true, "The action on db, which should be executed." + BR_LINE
            + " Possible actions: " + BR_LINE + createActionsDescription());
    actionOpt.setRequired(true);//from w w  w.  jav a2s.  c  om
    options.addOption(actionOpt);

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

        String actionStr = commandLine.getOptionValue("action");
        DBAction action = null;
        try {
            action = DBAction.valueOf(actionStr);
        } catch (IllegalStateException exc) {
            System.out.println("Unknown action: " + actionStr);
            System.out.println("Possible actions: " + createActionsDescription());
            System.exit(-1);
        }

        DBWorker worker = new DBWorker(action, null, null, null);
        worker.execute();
    } catch (ParseException exc) {
        System.out.println("Unable to parse command line arguments. Error: " + exc.getMessage());
        printUsageAndExit(options);
    }
}

From source file:fr.tpt.s3.mcdag.scheduling.Main.java

public static void main(String[] args) throws IOException, InterruptedException {

    /* Command line options */
    Options options = new Options();

    Option input = new Option("i", "input", true, "MC-DAG XML Models");
    input.setRequired(true);/*from  www .j  a  v  a  2 s .  c o m*/
    input.setArgs(Option.UNLIMITED_VALUES); // Sets maximum number of threads to be launched
    options.addOption(input);

    Option outSched = new Option("os", "out-scheduler", false, "Write the scheduling tables into a file.");
    outSched.setRequired(false);
    options.addOption(outSched);

    Option outPrism = new Option("op", "out-prism", false, "Write PRISM model into a file.");
    outPrism.setRequired(false);
    options.addOption(outPrism);

    Option jobs = new Option("j", "jobs", true, "Number of threads to be launched.");
    jobs.setRequired(false);
    options.addOption(jobs);

    Option debugOpt = new Option("d", "debug", false, "Enabling debug.");
    debugOpt.setRequired(false);
    options.addOption(debugOpt);

    Option preemptOpt = new Option("p", "preempt", false, "Count for preemptions.");
    preemptOpt.setRequired(false);
    options.addOption(preemptOpt);

    CommandLineParser parser = new DefaultParser();
    HelpFormatter formatter = new HelpFormatter();
    CommandLine cmd;

    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.err.println(e.getMessage());
        formatter.printHelp("MC-DAG framework", options);

        System.exit(1);
        return;
    }

    String inputFilePath[] = cmd.getOptionValues("input");
    boolean bOutSched = cmd.hasOption("out-scheduler");
    boolean bOutPrism = cmd.hasOption("out-prism");
    boolean debug = cmd.hasOption("debug");
    boolean preempt = cmd.hasOption("preempt");
    boolean levels = cmd.hasOption("n-levels");
    int nbFiles = inputFilePath.length;

    int nbJobs = 1;
    if (cmd.hasOption("jobs"))
        nbJobs = Integer.parseInt(cmd.getOptionValue("jobs"));

    if (debug)
        System.out.println("[DEBUG] Launching " + inputFilePath.length + " thread(s).");

    int i_files = 0;
    ExecutorService executor = Executors.newFixedThreadPool(nbJobs);

    /* Launch threads to solve allocation */
    while (i_files != nbFiles) {
        SchedulingThread ft = new SchedulingThread(inputFilePath[i_files], bOutSched, bOutPrism, debug,
                preempt);

        ft.setLevels(levels);
        executor.execute(ft);
        i_files++;
    }

    executor.shutdown();
    executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
    System.out.println("[FRAMEWORK Main] DONE");
}

From source file:com.github.braully.graph.UtilResultMerge.java

public static void main(String... args) throws Exception {
    Options options = new Options();

    Option input = new Option("i", "input", true, "input file path");
    input.setRequired(false);/*from   w  w w.j a v a  2 s .co  m*/
    options.addOption(input);

    Option output = new Option("o", "output", true, "output file");
    output.setRequired(false);
    options.addOption(output);

    Option verb = new Option("v", "verbose", false, "verbose");
    output.setRequired(false);
    options.addOption(verb);

    Option exluces = new Option("x", "exclude", true, "exclude operations");
    exluces.setRequired(false);
    options.addOption(exluces);

    CommandLineParser parser = new DefaultParser();
    HelpFormatter formatter = new HelpFormatter();
    CommandLine cmd;

    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.out.println(e.getMessage());
        formatter.printHelp("UtilResult", options);

        System.exit(1);
        return;
    }

    String[] excludes = cmd.getOptionValues("exclude");
    String[] inputs = cmd.getOptionValues("input");
    if (inputs == null) {
        inputs = new String[] {
                "/home/strike/Dropbox/workspace/graph-caratheodory-np3/grafos-processamento/Almost_hypohamiltonian"
                //                "/media/dados/documentos/grafos-processamento/Almost_hypohamiltonian",
                //                "/home/strike/Documentos/grafos-processamento/Cubic",
                //                "/home/strike/Documentos/grafos-processamento/Critical_H-free",
                //                "/home/strike/Documentos/grafos-processamento/Highly_irregular",
                //                "/home/strike/Documentos/grafos-processamento/Hypohamiltonian_graphs",
                //                "/home/strike/Documentos/grafos-processamento/Maximal_triangle-free",
                //                "/home/strike/Documentos/grafos-processamento/Minimal_Ramsey",
                //                "/home/strike/Documentos/grafos-processamento/Strongly_regular",
                //                "/home/strike/Documentos/grafos-processamento/Vertex-transitive",
                //                "/home/strike/Documentos/grafos-processamento/Trees"
        };
        excludes = new String[] { "carathe" };
        verbose = true;
    }

    if (cmd.hasOption(verb.getOpt())) {
        verbose = true;
    }

    if (inputs != null) {
        processInputs(inputs, excludes);
    }
}

From source file:fr.inria.edelweiss.kgdqp.core.FedQueryingCLI.java

@SuppressWarnings("unchecked")
public static void main(String args[]) throws ParseException, EngineException {

    List<String> endpoints = new ArrayList<String>();
    String queryPath = null;/*w w w .j av  a 2s  .  c o  m*/
    int slice = -1;

    Options options = new Options();
    Option helpOpt = new Option("h", "help", false, "print this message");
    Option queryOpt = new Option("q", "query", true, "specify the sparql query file");
    Option endpointOpt = new Option("e", "endpoints", true, "the list of federated sparql endpoint URLs");
    Option groupingOpt = new Option("g", "grouping", true, "triple pattern optimisation");
    Option slicingOpt = new Option("s", "slicing", true, "size of the slicing parameter");
    Option versionOpt = new Option("v", "version", false, "print the version information and exit");
    options.addOption(queryOpt);
    options.addOption(endpointOpt);
    options.addOption(helpOpt);
    options.addOption(versionOpt);
    options.addOption(groupingOpt);
    options.addOption(slicingOpt);

    String header = "Corese/KGRAM DQP command line interface";
    String footer = "\nPlease report any issue to alban.gaignard@cnrs.fr";

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = parser.parse(options, args);
    if (cmd.hasOption("h")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("kgdqp", header, options, footer, true);
        System.exit(0);
    }
    if (!cmd.hasOption("e")) {
        logger.info("You must specify at least the URL of one sparql endpoint !");
        System.exit(0);
    } else {
        endpoints = new ArrayList<String>(Arrays.asList(cmd.getOptionValues("e")));
    }
    if (!cmd.hasOption("q")) {
        logger.info("You must specify a path for a sparql query !");
        System.exit(0);
    } else {
        queryPath = cmd.getOptionValue("q");
    }
    if (cmd.hasOption("s")) {
        try {
            slice = Integer.parseInt(cmd.getOptionValue("s"));
        } catch (NumberFormatException ex) {
            logger.warn(cmd.getOptionValue("s") + " is not formatted as number for the slicing parameter");
            logger.warn("Slicing disabled");
        }
    }
    if (cmd.hasOption("v")) {
        logger.info("version 3.0.4-SNAPSHOT");
        System.exit(0);
    }

    /////////////////
    Graph graph = Graph.create();
    QueryProcessDQP exec = QueryProcessDQP.create(graph);
    exec.setGroupingEnabled(cmd.hasOption("g"));
    if (slice > 0) {
        exec.setSlice(slice);
    }
    Provider sProv = ProviderImplCostMonitoring.create();
    exec.set(sProv);

    for (String url : endpoints) {
        try {
            exec.addRemote(new URL(url), WSImplem.REST);
        } catch (MalformedURLException ex) {
            logger.error(url + " is not a well-formed URL");
            System.exit(1);
        }
    }

    StringBuffer fileData = new StringBuffer(1000);
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new FileReader(queryPath));
    } catch (FileNotFoundException ex) {
        logger.error("Query file " + queryPath + " not found !");
        System.exit(1);
    }
    char[] buf = new char[1024];
    int numRead = 0;
    try {
        while ((numRead = reader.read(buf)) != -1) {
            String readData = String.valueOf(buf, 0, numRead);
            fileData.append(readData);
            buf = new char[1024];
        }
        reader.close();
    } catch (IOException ex) {
        logger.error("Error while reading query file " + queryPath);
        System.exit(1);
    }

    String sparqlQuery = fileData.toString();

    //        Query q = exec.compile(sparqlQuery, null);
    //        System.out.println(q);

    StopWatch sw = new StopWatch();
    sw.start();
    Mappings map = exec.query(sparqlQuery);
    int dqpSize = map.size();
    System.out.println("--------");
    long time = sw.getTime();
    System.out.println(time + " " + dqpSize);
}