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

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

Introduction

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

Prototype

Options

Source Link

Usage

From source file:com.github.zk1931.pulsefs.Main.java

public static void main(String[] args) throws Exception {
    // Options for command arguments.
    Options options = new Options();

    Option port = OptionBuilder.withArgName("port").hasArg(true).isRequired(true).withDescription("port number")
            .create("port");

    Option addr = OptionBuilder.withArgName("addr").hasArg(true).withDescription("addr (ip:port) for Zab.")
            .create("addr");

    Option join = OptionBuilder.withArgName("join").hasArg(true).withDescription("the addr of server to join.")
            .create("join");

    Option dir = OptionBuilder.withArgName("dir").hasArg(true).withDescription("the directory for logs.")
            .create("dir");

    Option help = OptionBuilder.withArgName("h").hasArg(false).withLongOpt("help")
            .withDescription("print out usages.").create("h");

    Option timeout = OptionBuilder.withArgName("timeout").hasArg(true)
            .withDescription("session timeout(seconds)").create("timeout");

    options.addOption(port).addOption(addr).addOption(join).addOption(dir).addOption(timeout).addOption(help);

    CommandLineParser parser = new BasicParser();
    CommandLine cmd;/*  w  w w  .ja  v a  2 s  .  c  om*/
    String usage = "./bin/pulsefs -port port [Options]";
    try {
        cmd = parser.parse(options, args);
        if (cmd.hasOption("h")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp(usage, options);
            return;
        }
    } catch (ParseException exp) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(usage, options);
        return;
    }

    PulseFSConfig config = new PulseFSConfig();

    if (cmd.hasOption("addr")) {
        config.setServerId(cmd.getOptionValue("addr"));
    }
    if (cmd.hasOption("join")) {
        config.setJoinPeer(cmd.getOptionValue("join"));
    }
    if (cmd.hasOption("dir")) {
        config.setLogDir(cmd.getOptionValue("dir"));
    }
    if (cmd.hasOption("timeout")) {
        String sessionTimeout = cmd.getOptionValue("timeout");
        config.setSessionTimeout(Integer.parseInt(sessionTimeout));
    }
    if (cmd.hasOption("port")) {
        config.setPort(Integer.parseInt(cmd.getOptionValue("port")));
    }

    Server server = new Server(config.getPort());
    // Suppress "Server" header in HTTP response.
    for (Connector y : server.getConnectors()) {
        for (ConnectionFactory x : y.getConnectionFactories()) {
            if (x instanceof HttpConnectionFactory) {
                ((HttpConnectionFactory) x).getHttpConfiguration().setSendServerVersion(false);
            }
        }
    }

    PulseFS fs = new PulseFS(config);
    SessionFilter sessionFilter = new SessionFilter(fs);
    FilterHolder filters = new FilterHolder(sessionFilter);

    ServletContextHandler pulsefs = new ServletContextHandler(ServletContextHandler.SESSIONS);
    pulsefs.setContextPath(PulseFSConfig.PULSEFS_ROOT);
    pulsefs.setAllowNullPathInfo(true);
    pulsefs.addServlet(new ServletHolder(new PulseFSHandler(fs)), "/*");
    pulsefs.addFilter(filters, "/*", EnumSet.of(DispatcherType.REQUEST));

    ServletContextHandler servers = new ServletContextHandler(ServletContextHandler.SESSIONS);
    servers.setContextPath(PulseFSConfig.PULSEFS_SERVERS_PATH);
    // Redirects /pulsefs/servers to /pulsefs/servers/
    servers.setAllowNullPathInfo(true);
    servers.addServlet(new ServletHolder(new PulseFSServersHandler(fs)), "/*");
    servers.addFilter(filters, "/*", EnumSet.of(DispatcherType.REQUEST));

    ServletContextHandler tree = new ServletContextHandler(ServletContextHandler.SESSIONS);
    tree.setContextPath("/");
    tree.addServlet(new ServletHolder(new TreeHandler(fs)), "/*");
    tree.addFilter(filters, "/*", EnumSet.of(DispatcherType.REQUEST));

    ServletContextHandler sessions = new ServletContextHandler(ServletContextHandler.SESSIONS);
    sessions.setContextPath(PulseFSConfig.PULSEFS_SESSIONS_PATH);
    // Redirects /pulsefs/sessions to /pulsefs/sessions/
    sessions.setAllowNullPathInfo(true);
    sessions.addServlet(new ServletHolder(new PulseFSSessionsHandler(fs)), "/*");
    sessions.addFilter(filters, "/*", EnumSet.of(DispatcherType.REQUEST));

    ContextHandlerCollection contexts = new ContextHandlerCollection();
    contexts.setHandlers(new Handler[] { sessions, servers, pulsefs, tree });
    server.setHandler(contexts);
    server.start();
    server.join();
}

From source file:com.ikanow.infinit.e.core.CoreMain.java

/**
 * @param args//from  ww w. j a  v  a  2  s.  c  o m
 * @throws ParseException 
 * @throws IOException 
 * @throws InterruptedException 
 */
public static void main(String[] args) throws ParseException, IOException, InterruptedException {

    CommandLineParser cliParser = new BasicParser();
    Options allOps = new Options();
    // Common
    allOps.addOption("c", "config", true, "Configuration path");
    allOps.addOption("g", "community", true, "Only run on one community");
    // Harvest specific
    allOps.addOption("h", "harvest", false, "Run harvester");
    allOps.addOption("l", "local", false, "(for debug: use dummy index)");
    allOps.addOption("i", "source", true, "(for debug: use a single source)");
    allOps.addOption("r", "reset", false, "Reset bad sources");
    // Sync specific
    allOps.addOption("s", "sync", false, "Run synchronization");
    allOps.addOption("f", "from", true, "String unix time (secs) from when to sync");
    // Custom specifc
    allOps.addOption("p", "custom", false, "Run custom processing server");
    allOps.addOption("d", "dummy", true, "Use to keep temp unwanted options on the command line");
    allOps.addOption("j", "jobtitle", true, "(for debug: run a single job)");

    CommandLine cliOpts = cliParser.parse(allOps, args);

    Globals.setIdentity(com.ikanow.infinit.e.data_model.Globals.Identity.IDENTITY_SERVICE);

    if (cliOpts.hasOption("config")) {
        String configOverride = (String) cliOpts.getOptionValue("config");
        Globals.overrideConfigLocation(configOverride);
    }
    //Set up logging
    java.io.File file = new java.io.File(
            com.ikanow.infinit.e.data_model.Globals.getLogPropertiesLocation() + ".xml");
    if (file.exists()) {
        DOMConfigurator.configure(com.ikanow.infinit.e.data_model.Globals.getLogPropertiesLocation() + ".xml");
    } else {
        PropertyConfigurator.configure(Globals.getLogPropertiesLocation());
    }

    if (cliOpts.hasOption("harvest")) {
        if (SourceUtils.checkDbSyncLock()) {
            Thread.sleep(10000); // (wait 10s and then try again)
            System.exit(0);
        }
        String communityOverride = null;
        String sourceDebug = null;
        if (cliOpts.hasOption("local")) {
            ElasticSearchManager.setLocalMode(true);
        }
        if (cliOpts.hasOption("reset")) {
            SourceUtils.resetBadSources();
        }
        if (cliOpts.hasOption("community")) {
            communityOverride = (String) cliOpts.getOptionValue("community");
        }
        if (cliOpts.hasOption("source")) {
            sourceDebug = (String) cliOpts.getOptionValue("source");
        }
        new HarvestThenProcessController()
                .startService(SourceUtils.getSourcesToWorkOn(communityOverride, sourceDebug, false, true));
    } //TESTED
    else if (cliOpts.hasOption("sync")) {
        if (SourceUtils.checkDbSyncLock()) {
            Thread.sleep(10000); // (wait 10s and then try again)
            System.exit(0);
        }
        // Sync command line options:
        long nTimeOfLastCleanse_secs = 0; // (default)
        if (cliOpts.hasOption("from")) {
            try {
                nTimeOfLastCleanse_secs = Long.parseLong((String) cliOpts.getOptionValue("from"));
            } catch (NumberFormatException e) {
                System.out.println("From date is incorrect");
                System.exit(-1);
            }
        }
        String communityOverride = null;
        String sourceDebug = null;
        if (cliOpts.hasOption("community")) {
            communityOverride = (String) cliOpts.getOptionValue("community");
        } else if (cliOpts.hasOption("source")) {
            sourceDebug = (String) cliOpts.getOptionValue("source");
        }
        SourceUtils.checkSourcesHaveHashes(communityOverride, sourceDebug);
        // (infrequently ie as part of sync, check all the sources have hashes, which the harvester depends on)

        new SynchronizationController().startService(nTimeOfLastCleanse_secs,
                SourceUtils.getSourcesToWorkOn(communityOverride, sourceDebug, true, true));
    } //TESTED
    else if (cliOpts.hasOption("custom")) {
        String jobOverride = null;
        if (cliOpts.hasOption("jobtitle")) {
            jobOverride = (String) cliOpts.getOptionValue("jobtitle");
        }
        CustomProcessingController customPxController = new CustomProcessingController();
        customPxController.checkScheduledJobs(jobOverride);
        customPxController.checkRunningJobs();
        customPxController.runThroughSavedQueues();
    } else {
        //Test code for distribution:
        //         boolean bSync = true;
        //         LinkedList<SourcePojo> testSources = null;
        //         LinkedList<SourcePojo> batchOfSources = null;
        //         testSources = getSourcesToWorkOn(null, null, bSync, true);
        //         System.out.println("Sources considered = " + testSources.size());
        //         // Grab a batch of sources
        //         batchOfSources = getDistributedSourceList(testSources, null, false);
        //         System.out.println("Sources left = " + testSources.size());
        //         System.out.println("Sources extracted = " + new com.google.gson.Gson().toJson(batchOfSources));

        System.out.println(
                "com.ikanow.infinit.e.core.server [--config <config-dir>] [--harvest [<other options>]|--sync [<other options>]|--custom [<other options>]]");
        System.exit(-1);
    }
    MongoApplicationLock.registerAppShutdown(); // (in case the saved queries are running, for some reason built in startup hook not running)
}

From source file:com.redhat.poc.jdg.bankofchina.performance.TestCase531RemoteMultiThreads.java

public static void main(String[] args) throws Exception {
    CommandLine commandLine;//from w  w  w.j  a  v a2s. co m
    Options options = new Options();
    options.addOption("n", true, "The read thread numbers option");
    options.addOption("t", true, "The thread read times option");
    BasicParser parser = new BasicParser();
    parser.parse(options, args);
    commandLine = parser.parse(options, args);
    if (commandLine.getOptions().length > 0) {
        if (commandLine.hasOption("n")) {
            String numbers = commandLine.getOptionValue("n");
            if (numbers != null && numbers.length() > 0) {
                readThreadNumbers = Integer.parseInt(numbers);
            }
        }
        if (commandLine.hasOption("t")) {
            String times = commandLine.getOptionValue("t");
            if (times != null && times.length() > 0) {
                threadReadTimes = Integer.parseInt(times);
            }
        }
    }

    System.out.println();
    System.out.println("%%%%%%%%%  userid.csv  %%%%%%%%%");
    LoadUserIdList();
    randomPoolSize = userIdList.size();
    System.out.println(
            "%%%%%%%%% ? userid.csv ,  " + randomPoolSize + " ?? %%%%%%%%%");
    randomPoolSizeByThread = randomPoolSize / readThreadNumbers;

    System.out.println();
    System.out.println(
            "%%%%%%%%% ?, " + readThreadNumbers + " ,, ???, "
                    + threadReadTimes + " ,?, ?(ms)," + new Date().getTime());

    for (int i = 0; i < readThreadNumbers; i++) {
        new TestCase531RemoteMultiThreads(i * randomPoolSizeByThread).start();
    }
}

From source file:com.redhat.poc.jdg.bankofchina.performance.TestCase532RemoteMultiThreads.java

public static void main(String[] args) throws Exception {
    CommandLine commandLine;//  w  ww .j a v a 2  s .c om
    Options options = new Options();
    options.addOption("n", true, "The read thread numbers option");
    options.addOption("t", true, "The thread read times option");
    BasicParser parser = new BasicParser();
    parser.parse(options, args);
    commandLine = parser.parse(options, args);
    if (commandLine.getOptions().length > 0) {
        if (commandLine.hasOption("n")) {
            String numbers = commandLine.getOptionValue("n");
            if (numbers != null && numbers.length() > 0) {
                writeThreadNumbers = Integer.parseInt(numbers);
            }
        }
        if (commandLine.hasOption("t")) {
            String times = commandLine.getOptionValue("t");
            if (times != null && times.length() > 0) {
                threadWriteTimes = Integer.parseInt(times);
            }
        }
    }
    System.out.println();
    System.out.println("%%%%%%%%%  userid.csv  %%%%%%%%%");
    LoadUserIdList();
    randomPoolSize = userIdList.size();
    System.out.println(
            "%%%%%%%%% ? userid.csv ,  " + randomPoolSize + " ?? %%%%%%%%%");
    randomPoolSizeByThread = randomPoolSize / writeThreadNumbers;

    System.out.println();
    System.out.println(
            "%%%%%%%%% ?, " + writeThreadNumbers + ", , ??, "
                    + threadWriteTimes + ", ?, ?(ms)," + new Date().getTime());

    for (int i = 0; i < writeThreadNumbers; i++) {
        new TestCase532RemoteMultiThreads(i * randomPoolSizeByThread).start();
    }
}

From source file:apps.LuceneIndexer.java

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

    options.addOption("i", null, true, "input file");
    options.addOption("o", null, true, "output directory");
    options.addOption("r", null, true, "optional output TREC-format QREL file");

    options.addOption("bm25_b", null, true, "BM25 parameter: b");
    options.addOption("bm25_k1", null, true, "BM25 parameter: k1");
    options.addOption("bm25fixed", null, false, "use the fixed BM25 similarity");

    Joiner commaJoin = Joiner.on(',');
    Joiner spaceJoin = Joiner.on(' ');

    options.addOption("source_type", null, true,
            "document source type: " + commaJoin.join(SourceFactory.getDocSourceList()));

    // If you increase this value, you may need to modify the following line in *.sh file
    // export MAVEN_OPTS="-Xms8192m -server"
    double ramBufferSizeMB = 1024 * 8; // 8 GB

    CommandLineParser parser = new org.apache.commons.cli.GnuParser();

    IndexWriter indexWriter = null;//from   w w  w  .j  a va2s. c o m
    BufferedWriter qrelWriter = null;

    int docNum = 0;

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

        String inputFileName = null, outputDirName = null, qrelFileName = null;

        if (cmd.hasOption("i")) {
            inputFileName = cmd.getOptionValue("i");
        } else {
            Usage("Specify 'input file'", options);
        }

        if (cmd.hasOption("o")) {
            outputDirName = cmd.getOptionValue("o");
        } else {
            Usage("Specify 'index directory'", options);
        }

        if (cmd.hasOption("r")) {
            qrelFileName = cmd.getOptionValue("r");
        }

        String sourceName = cmd.getOptionValue("source_type");

        if (sourceName == null)
            Usage("Specify document source type", options);

        if (qrelFileName != null)
            qrelWriter = new BufferedWriter(new FileWriter(qrelFileName));

        File outputDir = new File(outputDirName);
        if (!outputDir.exists()) {
            if (!outputDir.mkdirs()) {
                System.out.println("couldn't create " + outputDir.getAbsolutePath());
                System.exit(1);
            }
        }
        if (!outputDir.isDirectory()) {
            System.out.println(outputDir.getAbsolutePath() + " is not a directory!");
            System.exit(1);
        }
        if (!outputDir.canWrite()) {
            System.out.println("Can't write to " + outputDir.getAbsolutePath());
            System.exit(1);
        }

        boolean useFixedBM25 = cmd.hasOption("bm25fixed");

        float bm25_k1 = UtilConst.BM25_K1_DEFAULT, bm25_b = UtilConst.BM25_B_DEFAULT;

        if (cmd.hasOption("bm25_k1")) {
            try {
                bm25_k1 = Float.parseFloat(cmd.getOptionValue("bm25_k1"));
            } catch (NumberFormatException e) {
                Usage("Wrong format for 'bm25_k1'", options);
            }
        }

        if (cmd.hasOption("bm25_b")) {
            try {
                bm25_b = Float.parseFloat(cmd.getOptionValue("bm25_b"));
            } catch (NumberFormatException e) {
                Usage("Wrong format for 'bm25_b'", options);
            }
        }

        EnglishAnalyzer analyzer = new EnglishAnalyzer();
        FSDirectory indexDir = FSDirectory.open(Paths.get(outputDirName));
        IndexWriterConfig indexConf = new IndexWriterConfig(analyzer);

        /*
            OpenMode.CREATE creates a new index or overwrites an existing one.
            https://lucene.apache.org/core/6_0_0/core/org/apache/lucene/index/IndexWriterConfig.OpenMode.html#CREATE
        */
        indexConf.setOpenMode(OpenMode.CREATE);
        indexConf.setRAMBufferSizeMB(ramBufferSizeMB);

        System.out.println(String.format("BM25 parameters k1=%f b=%f ", bm25_k1, bm25_b));

        if (useFixedBM25) {
            System.out.println(String.format("Using fixed BM25Simlarity, k1=%f b=%f", bm25_k1, bm25_b));
            indexConf.setSimilarity(new BM25SimilarityFix(bm25_k1, bm25_b));
        } else {
            System.out.println(String.format("Using Lucene BM25Similarity, k1=%f b=%f", bm25_k1, bm25_b));
            indexConf.setSimilarity(new BM25Similarity(bm25_k1, bm25_b));
        }

        indexWriter = new IndexWriter(indexDir, indexConf);

        DocumentSource inpDocSource = SourceFactory.createDocumentSource(sourceName, inputFileName);
        DocumentEntry inpDoc = null;
        TextCleaner textCleaner = new TextCleaner(null);

        while ((inpDoc = inpDocSource.next()) != null) {
            ++docNum;

            Document luceneDoc = new Document();
            ArrayList<String> cleanedToks = textCleaner.cleanUp(inpDoc.mDocText);
            String cleanText = spaceJoin.join(cleanedToks);

            //        System.out.println(inpDoc.mDocId);
            //        System.out.println(cleanText);
            //        System.out.println("==============================");

            luceneDoc.add(new StringField(UtilConst.FIELD_ID, inpDoc.mDocId, Field.Store.YES));
            luceneDoc.add(new TextField(UtilConst.FIELD_TEXT, cleanText, Field.Store.YES));
            indexWriter.addDocument(luceneDoc);

            if (inpDoc.mIsRel != null && qrelWriter != null) {
                saveQrelOneEntry(qrelWriter, inpDoc.mQueryId, inpDoc.mDocId, inpDoc.mIsRel ? MAX_GRADE : 0);
            }
            if (docNum % 1000 == 0)
                System.out.println(String.format("Indexed %d documents", docNum));

        }

    } catch (ParseException e) {
        e.printStackTrace();
        Usage("Cannot parse arguments" + e, options);
    } catch (Exception e) {
        System.err.println("Terminating due to an exception: " + e);
        System.exit(1);
    } finally {
        System.out.println(String.format("Indexed %d documents", docNum));

        try {
            if (null != indexWriter)
                indexWriter.close();
            if (null != qrelWriter)
                qrelWriter.close();
        } catch (IOException e) {
            System.err.println("IO exception: " + e);
            e.printStackTrace();
        }
    }
}

From source file:microbiosima.SelectiveMicrobiosima.java

/**
 * @param args/*  w ww  . java  2  s . co m*/
 *            the command line arguments
 * @throws java.io.FileNotFoundException
 * @throws java.io.UnsupportedEncodingException
 */

public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException {
    int populationSize = 500;//Integer.parseInt(parameters[1]);
    int microSize = 1000;//Integer.parseInt(parameters[2]);
    int numberOfSpecies = 150;//Integer.parseInt(parameters[3]);
    int numberOfGeneration = 10000;
    int Ngene = 10;
    int numberOfObservation = 100;
    int numberOfReplication = 10;
    double Ngenepm = 5;
    double pctEnv = 0;
    double pctPool = 0;
    double msCoeff = 1;
    double hsCoeff = 1;
    boolean HMS_or_TMS = true;

    Options options = new Options();

    Option help = new Option("h", "help", false, "print this message");
    Option version = new Option("v", "version", false, "print the version information and exit");
    options.addOption(help);
    options.addOption(version);

    options.addOption(Option.builder("o").longOpt("obs").hasArg().argName("OBS")
            .desc("Number generation for observation [default: 100]").build());
    options.addOption(Option.builder("r").longOpt("rep").hasArg().argName("REP")
            .desc("Number of replication [default: 1]").build());

    Builder C = Option.builder("c").longOpt("config").numberOfArgs(6).argName("Pop Micro Spec Gen")
            .desc("Four Parameters in the following orders: "
                    + "(1) population size, (2) microbe size, (3) number of species, (4) number of generation, (5) number of total traits, (6)number of traits per microbe"
                    + " [default: 500 1000 150 10000 10 5]");
    options.addOption(C.build());

    HelpFormatter formatter = new HelpFormatter();
    String syntax = "microbiosima pctEnv pctPool";
    String header = "\nSimulates the evolutionary and ecological dynamics of microbiomes within a population of hosts.\n\n"
            + "required arguments:\n" + "  pctEnv             Percentage of environmental acquisition\n"
            + "  pctPool            Percentage of pooled environmental component\n"
            + "  msCoeff            Parameter related to microbe selection strength\n"
            + "  hsCoeff            Parameter related to host selection strength\n"
            + "  HMS_or_TMS         String HMS or TMS to specify host-mediated or trait-mediated microbe selection\n"
            + "\noptional arguments:\n";
    String footer = "\n";

    formatter.setWidth(80);

    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = null;

    try {
        cmd = parser.parse(options, args);
        String[] pct_config = cmd.getArgs();

        if (cmd.hasOption("h") || args.length == 0) {
            formatter.printHelp(syntax, header, options, footer, true);
            System.exit(0);
        }
        if (cmd.hasOption("v")) {
            System.out.println("Microbiosima " + VERSION);
            System.exit(0);
        }
        if (pct_config.length != 5) {
            System.out.println(
                    "ERROR! Required exactly five argumennts for pct_env, pct_pool, msCoeff, hsCoeff and HMS_or_TMS. It got "
                            + pct_config.length + ": " + Arrays.toString(pct_config));
            formatter.printHelp(syntax, header, options, footer, true);
            System.exit(3);
        } else {
            pctEnv = Double.parseDouble(pct_config[0]);
            pctPool = Double.parseDouble(pct_config[1]);
            msCoeff = Double.parseDouble(pct_config[2]);
            hsCoeff = Double.parseDouble(pct_config[3]);
            if (pct_config[4].equals("HMS"))
                HMS_or_TMS = true;
            if (pct_config[4].equals("TMS"))
                HMS_or_TMS = false;
            if (pctEnv < 0 || pctEnv > 1) {
                System.out.println(
                        "ERROR: pctEnv (Percentage of environmental acquisition) must be between 0 and 1 (pctEnv="
                                + pctEnv + ")! EXIT");
                System.exit(3);
            }
            if (pctPool < 0 || pctPool > 1) {
                System.out.println(
                        "ERROR: pctPool (Percentage of pooled environmental component must) must be between 0 and 1 (pctPool="
                                + pctPool + ")! EXIT");
                System.exit(3);
            }
            if (msCoeff < 1) {
                System.out.println(
                        "ERROR: msCoeff (parameter related to microbe selection strength) must be not less than 1 (msCoeff="
                                + msCoeff + ")! EXIT");
                System.exit(3);
            }
            if (hsCoeff < 1) {
                System.out.println(
                        "ERROR: hsCoeff (parameter related to host selection strength) must be not less than 1 (hsCoeff="
                                + hsCoeff + ")! EXIT");
                System.exit(3);
            }
            if (!(pct_config[4].equals("HMS") || pct_config[4].equals("TMS"))) {
                System.out.println(
                        "ERROR: HMS_or_TMS (parameter specifying host-mediated or trait-mediated selection) must be either 'HMS' or 'TMS' (HMS_or_TMS="
                                + pct_config[4] + ")! EXIT");
                System.exit(3);
            }

        }
        if (cmd.hasOption("config")) {
            String[] configs = cmd.getOptionValues("config");
            populationSize = Integer.parseInt(configs[0]);
            microSize = Integer.parseInt(configs[1]);
            numberOfSpecies = Integer.parseInt(configs[2]);
            numberOfGeneration = Integer.parseInt(configs[3]);
            Ngene = Integer.parseInt(configs[4]);
            Ngenepm = Double.parseDouble(configs[5]);
            if (Ngenepm > Ngene) {
                System.out.println(
                        "ERROR: number of traits per microbe must not be greater than number of total traits! EXIT");
                System.exit(3);
            }
        }
        if (cmd.hasOption("obs")) {
            numberOfObservation = Integer.parseInt(cmd.getOptionValue("obs"));
        }
        if (cmd.hasOption("rep")) {
            numberOfReplication = Integer.parseInt(cmd.getOptionValue("rep"));
        }

    } catch (ParseException e) {
        e.printStackTrace();
        System.exit(3);
    }

    StringBuilder sb = new StringBuilder();
    sb.append("Configuration Summary:").append("\n\tPopulation size: ").append(populationSize)
            .append("\n\tMicrobe size: ").append(microSize).append("\n\tNumber of species: ")
            .append(numberOfSpecies).append("\n\tNumber of generation: ").append(numberOfGeneration)
            .append("\n\tNumber generation for observation: ").append(numberOfObservation)
            .append("\n\tNumber of replication: ").append(numberOfReplication)
            .append("\n\tNumber of total traits: ").append(Ngene).append("\n\tNumber of traits per microbe: ")
            .append(Ngenepm).append("\n");
    System.out.println(sb.toString());

    double[] environment = new double[numberOfSpecies];
    for (int i = 0; i < numberOfSpecies; i++) {
        environment[i] = 1 / (double) numberOfSpecies;
    }
    int[] fitnessToHost = new int[Ngene];
    int[] fitnessToMicrobe = new int[Ngene];

    for (int rep = 0; rep < numberOfReplication; rep++) {
        String prefix = "" + (rep + 1) + "_";
        String sufix;
        if (HMS_or_TMS)
            sufix = "_E" + pctEnv + "_P" + pctPool + "_HS" + hsCoeff + "_HMS" + msCoeff + ".txt";
        else
            sufix = "_E" + pctEnv + "_P" + pctPool + "_HS" + hsCoeff + "_TMS" + msCoeff + ".txt";
        System.out.println("Output 5 result files in the format of: " + prefix + "[****]" + sufix);
        try {
            PrintWriter file1 = new PrintWriter(
                    new BufferedWriter(new FileWriter(prefix + "gamma_diversity" + sufix)));
            PrintWriter file2 = new PrintWriter(
                    new BufferedWriter(new FileWriter(prefix + "alpha_diversity" + sufix)));
            PrintWriter file3 = new PrintWriter(
                    new BufferedWriter(new FileWriter(prefix + "beta_diversity" + sufix)));
            PrintWriter file4 = new PrintWriter(new BufferedWriter(new FileWriter(prefix + "sum" + sufix)));
            PrintWriter file5 = new PrintWriter(
                    new BufferedWriter(new FileWriter(prefix + "inter_generation_distance" + sufix)));
            PrintWriter file6 = new PrintWriter(
                    new BufferedWriter(new FileWriter(prefix + "environment_population_distance" + sufix)));
            PrintWriter file7 = new PrintWriter(
                    new BufferedWriter(new FileWriter(prefix + "host_fitness" + sufix)));
            PrintWriter file8 = new PrintWriter(
                    new BufferedWriter(new FileWriter(prefix + "cos_theta" + sufix)));
            PrintWriter file9 = new PrintWriter(
                    new BufferedWriter(new FileWriter(prefix + "host_fitness_distribution" + sufix)));
            PrintWriter file10 = new PrintWriter(
                    new BufferedWriter(new FileWriter(prefix + "microbiome_fitness_distribution" + sufix)));
            PrintWriter file11 = new PrintWriter(
                    new BufferedWriter(new FileWriter(prefix + "bacteria_contents" + sufix)));
            PrintWriter file12 = new PrintWriter(
                    new BufferedWriter(new FileWriter(prefix + "individual_bacteria_contents" + sufix)));
            for (int i = 0; i < Ngene; i++) {
                fitnessToMicrobe[i] = MathUtil.getNextInt(2) - 1;
                fitnessToHost[i] = MathUtil.getNextInt(2) - 1;
            }
            MathUtil.setSeed(rep % numberOfReplication);
            SelectiveSpeciesRegistry ssr = new SelectiveSpeciesRegistry(numberOfSpecies, Ngene, Ngenepm,
                    msCoeff, fitnessToHost, fitnessToMicrobe);
            MathUtil.setSeed();
            SelectivePopulation population = new SelectivePopulation(microSize, environment, populationSize,
                    pctEnv, pctPool, 0, 0, ssr, hsCoeff, HMS_or_TMS);

            while (population.getNumberOfGeneration() < numberOfGeneration) {
                population.sumSpecies();
                if (population.getNumberOfGeneration() % numberOfObservation == 0) {
                    //file1.print(population.gammaDiversity(false));
                    //file2.print(population.alphaDiversity(false));
                    //file1.print("\t");
                    //file2.print("\t");
                    file1.println(population.gammaDiversity(true));
                    file2.println(population.alphaDiversity(true));
                    //file3.print(population.betaDiversity(true));
                    //file3.print("\t");
                    file3.println(population.BrayCurtis(true));
                    file4.println(population.printOut());
                    file5.println(population.interGenerationDistance());
                    file6.println(population.environmentPopulationDistance());
                    file7.print(population.averageHostFitness());
                    file7.print("\t");
                    file7.println(population.varianceHostFitness());
                    file8.println(population.cosOfMH());
                    file9.println(population.printOutHFitness());
                    file10.println(population.printOutMFitness());
                    file11.println(population.printBacteriaContents());
                }
                population.getNextGen();
            }
            for (SelectiveIndividual host : population.getIndividuals()) {
                file12.println(host.printBacteriaContents());
            }
            file1.close();
            file2.close();
            file3.close();
            file4.close();
            file5.close();
            file6.close();
            file7.close();
            file8.close();
            file9.close();
            file10.close();
            file11.close();
            file12.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.hortonworks.registries.storage.tool.TablesInitializer.java

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

    options.addOption(Option.builder("s").numberOfArgs(1).longOpt(OPTION_SCRIPT_ROOT_PATH)
            .desc("Root directory of script path").build());

    options.addOption(Option.builder("c").numberOfArgs(1).longOpt(OPTION_CONFIG_FILE_PATH)
            .desc("Config file path").build());

    options.addOption(Option.builder("m").numberOfArgs(1).longOpt(OPTION_MYSQL_JAR_URL_PATH)
            .desc("Mysql client jar url to download").build());

    options.addOption(Option.builder().hasArg(false).longOpt(OPTION_EXECUTE_CREATE_TABLE)
            .desc("Execute 'create table' script").build());

    options.addOption(Option.builder().hasArg(false).longOpt(OPTION_EXECUTE_DROP_TABLE)
            .desc("Execute 'drop table' script").build());

    options.addOption(Option.builder().hasArg(false).longOpt(OPTION_EXECUTE_CHECK_CONNECTION)
            .desc("Check the connection for configured data source").build());

    CommandLineParser parser = new BasicParser();
    CommandLine commandLine = parser.parse(options, args);

    if (!commandLine.hasOption(OPTION_CONFIG_FILE_PATH) || !commandLine.hasOption(OPTION_SCRIPT_ROOT_PATH)) {
        usage(options);//from w w  w  .ja  v  a  2 s  .c  om
        System.exit(1);
    }

    // either create or drop should be specified, not both
    boolean executeCreate = commandLine.hasOption(OPTION_EXECUTE_CREATE_TABLE);
    boolean executeDrop = commandLine.hasOption(OPTION_EXECUTE_DROP_TABLE);
    boolean checkConnection = commandLine.hasOption(OPTION_EXECUTE_CHECK_CONNECTION);

    boolean moreThanOneOperationIsSpecified = executeCreate == executeDrop ? executeCreate : checkConnection;
    boolean noOperationSpecified = !(executeCreate || executeDrop || checkConnection);

    if (moreThanOneOperationIsSpecified) {
        System.out.println(
                "Only one operation can be execute at once, please select 'create' or 'drop', or 'check-connection'.");
        System.exit(1);
    } else if (noOperationSpecified) {
        System.out.println(
                "One of 'create', 'drop', 'check-connection' operation should be specified to execute.");
        System.exit(1);
    }

    String confFilePath = commandLine.getOptionValue(OPTION_CONFIG_FILE_PATH);
    String scriptRootPath = commandLine.getOptionValue(OPTION_SCRIPT_ROOT_PATH);
    String mysqlJarUrl = commandLine.getOptionValue(OPTION_MYSQL_JAR_URL_PATH);

    StorageProviderConfiguration storageProperties;
    try {
        Map<String, Object> conf = Utils.readConfig(confFilePath);

        StorageProviderConfigurationReader confReader = new StorageProviderConfigurationReader();
        storageProperties = confReader.readStorageConfig(conf);
    } catch (IOException e) {
        System.err.println("Error occurred while reading config file: " + confFilePath);
        System.exit(1);
        throw new IllegalStateException("Shouldn't reach here");
    }

    String bootstrapDirPath = null;
    try {
        bootstrapDirPath = System.getProperty("bootstrap.dir");
        MySqlDriverHelper.downloadMySQLJarIfNeeded(storageProperties, bootstrapDirPath, mysqlJarUrl);
    } catch (Exception e) {
        System.err.println("Error occurred while downloading MySQL jar. bootstrap dir: " + bootstrapDirPath);
        System.exit(1);
        throw new IllegalStateException("Shouldn't reach here");
    }

    try {
        SQLScriptRunner sqlScriptRunner = new SQLScriptRunner(storageProperties);

        try {
            sqlScriptRunner.initializeDriver();
        } catch (ClassNotFoundException e) {
            System.err.println(
                    "Driver class is not found in classpath. Please ensure that driver is in classpath.");
            System.exit(1);
        }

        if (checkConnection) {
            if (!sqlScriptRunner.checkConnection()) {
                System.exit(1);
            }
        } else if (executeDrop) {
            doExecuteDrop(sqlScriptRunner, storageProperties, scriptRootPath);
        } else {
            // executeCreate
            doExecuteCreate(sqlScriptRunner, storageProperties, scriptRootPath);
        }
    } catch (IOException e) {
        System.err.println("Error occurred while reading script file. Script root path: " + scriptRootPath);
        System.exit(1);
    }
}

From source file:edu.umd.ujjwalgoel.AnalyzePMI.java

@SuppressWarnings({ "static-access" })
public static void main(String[] args) {
    Options options = new Options();

    options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT));

    CommandLine cmdline = null;//from   ww w.  j ava2 s  .co m
    CommandLineParser parser = new GnuParser();

    try {
        cmdline = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println("Error parsing command line: " + exp.getMessage());
        System.exit(-1);
    }

    if (!cmdline.hasOption(INPUT)) {
        System.out.println("args: " + Arrays.toString(args));
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(120);
        formatter.printHelp(AnalyzePMI.class.getName(), options);
        ToolRunner.printGenericCommandUsage(System.out);
        System.exit(-1);
    }

    String inputPath = cmdline.getOptionValue(INPUT);
    System.out.println("input path: " + inputPath);

    BufferedReader br = null;
    int countPairs = 0;

    List<PairOfWritables<PairOfStrings, FloatWritable>> pmis = new ArrayList<PairOfWritables<PairOfStrings, FloatWritable>>();
    List<PairOfWritables<PairOfStrings, FloatWritable>> cloudPmis = new ArrayList<PairOfWritables<PairOfStrings, FloatWritable>>();
    List<PairOfWritables<PairOfStrings, FloatWritable>> lovePmis = new ArrayList<PairOfWritables<PairOfStrings, FloatWritable>>();

    PairOfWritables<PairOfStrings, FloatWritable> highestPMI = null;
    PairOfWritables<PairOfStrings, FloatWritable> highestCloudPMI = null;
    PairOfWritables<PairOfStrings, FloatWritable> highestCloudPMI2 = null;
    PairOfWritables<PairOfStrings, FloatWritable> highestCloudPMI3 = null;

    PairOfWritables<PairOfStrings, FloatWritable> highestLovePMI = null;
    PairOfWritables<PairOfStrings, FloatWritable> highestLovePMI2 = null;
    PairOfWritables<PairOfStrings, FloatWritable> highestLovePMI3 = null;

    try {
        FileSystem fs = FileSystem.get(new Configuration());
        FileStatus[] status = fs.listStatus(new Path(inputPath));
        //PairOfStrings pair = new PairOfStrings();
        for (int i = 0; i < status.length; i++) {
            br = new BufferedReader(new InputStreamReader(fs.open(status[i].getPath())));
            String line = br.readLine();
            while (line != null) {
                String[] words = line.split("\\t");
                float value = Float.parseFloat(words[1].trim());
                String[] wordPair = words[0].replaceAll("\\(", "").replaceAll("\\)", "").split(",");
                PairOfStrings pair = new PairOfStrings();
                pair.set(wordPair[0].trim(), wordPair[1].trim());
                if (wordPair[0].trim().equals("cloud")) {
                    PairOfWritables<PairOfStrings, FloatWritable> cloudPmi = new PairOfWritables<PairOfStrings, FloatWritable>();
                    cloudPmi.set(pair, new FloatWritable(value));
                    cloudPmis.add(cloudPmi);
                    if ((highestCloudPMI == null)
                            || (highestCloudPMI.getRightElement().compareTo(cloudPmi.getRightElement()) < 0)) {
                        highestCloudPMI = cloudPmi;
                    } else if ((highestCloudPMI2 == null)
                            || (highestCloudPMI2.getRightElement().compareTo(cloudPmi.getRightElement()) < 0)) {
                        highestCloudPMI2 = cloudPmi;
                    } else if ((highestCloudPMI3 == null)
                            || (highestCloudPMI3.getRightElement().compareTo(cloudPmi.getRightElement()) < 0)) {
                        highestCloudPMI3 = cloudPmi;
                    }
                }
                if (wordPair[0].trim().equals("love")) {
                    PairOfWritables<PairOfStrings, FloatWritable> lovePmi = new PairOfWritables<PairOfStrings, FloatWritable>();
                    lovePmi.set(pair, new FloatWritable(value));
                    lovePmis.add(lovePmi);
                    if ((highestLovePMI == null)
                            || (highestLovePMI.getRightElement().compareTo(lovePmi.getRightElement()) < 0)) {
                        highestLovePMI = lovePmi;
                    } else if ((highestLovePMI2 == null)
                            || (highestLovePMI2.getRightElement().compareTo(lovePmi.getRightElement()) < 0)) {
                        highestLovePMI2 = lovePmi;
                    } else if ((highestLovePMI3 == null)
                            || (highestLovePMI3.getRightElement().compareTo(lovePmi.getRightElement()) < 0)) {
                        highestLovePMI3 = lovePmi;
                    }
                }
                PairOfWritables<PairOfStrings, FloatWritable> pmi = new PairOfWritables<PairOfStrings, FloatWritable>();
                pmi.set(pair, new FloatWritable(value));
                pmis.add(pmi);
                if (highestPMI == null) {
                    highestPMI = pmi;
                } else if (highestPMI.getRightElement().compareTo(pmi.getRightElement()) < 0) {
                    highestPMI = pmi;
                }
                countPairs++;
                line = br.readLine();
            }
        }
    } catch (Exception ex) {
        System.out.println("ERROR" + ex.getMessage());
    }

    /*Collections.sort(pmis, new Comparator<PairOfWritables<PairOfStrings, FloatWritable>>() {
      public int compare(PairOfWritables<PairOfStrings, FloatWritable> e1,
          PairOfWritables<PairOfStrings, FloatWritable> e2) {
        /*if (e2.getRightElement().compareTo(e1.getRightElement()) == 0) {
          return e1.getLeftElement().getLeftElement().compareTo(e2.getLeftElement().getLeftElement());
        }
            
        return e2.getRightElement().compareTo(e1.getRightElement());
      }
    });
            
            
    Collections.sort(cloudPmis, new Comparator<PairOfWritables<PairOfStrings, FloatWritable>>() {
      public int compare(PairOfWritables<PairOfStrings, FloatWritable> e1,
          PairOfWritables<PairOfStrings, FloatWritable> e2) {
        if (e2.getRightElement().compareTo(e1.getRightElement()) == 0) {
    return e1.getLeftElement().getLeftElement().compareTo(e2.getLeftElement().getLeftElement());
            }
            
        return e2.getRightElement().compareTo(e1.getRightElement());
      }
    });
            
            
    Collections.sort(lovePmis, new Comparator<PairOfWritables<PairOfStrings, FloatWritable>>() {
      public int compare(PairOfWritables<PairOfStrings, FloatWritable> e1,
          PairOfWritables<PairOfStrings, FloatWritable> e2) {
        if (e2.getRightElement().compareTo(e1.getRightElement()) == 0) {
    return e1.getLeftElement().getLeftElement().compareTo(e2.getLeftElement().getLeftElement());
           }
            
        return e2.getRightElement().compareTo(e1.getRightElement());
      }
    });
            
     PairOfWritables<PairOfStrings, FloatWritable> highestPMI = pmis.get(0);
     PairOfWritables<PairOfStrings, FloatWritable> highestCloudPMI = cloudPmis.get(0);      PairOfWritables<PairOfStrings, FloatWritable> highestCloudPMI2 = cloudPmis.get(1);
     PairOfWritables<PairOfStrings, FloatWritable> highestCloudPMI3 = cloudPmis.get(2);
             
     PairOfWritables<PairOfStrings, FloatWritable> highestLovePMI = lovePmis.get(0);       PairOfWritables<PairOfStrings, FloatWritable> highestLovePMI2 = lovePmis.get(1);
     PairOfWritables<PairOfStrings, FloatWritable> highestLovePMI3 = lovePmis.get(2);*/

    System.out.println("Total Distinct Pairs : " + countPairs);
    System.out.println("Pair with highest PMI : (" + highestPMI.getLeftElement().getLeftElement() + ", "
            + highestPMI.getLeftElement().getRightElement());

    System.out
            .println("Word with highest PMI with Cloud : " + highestCloudPMI.getLeftElement().getRightElement()
                    + " with value : " + highestCloudPMI.getRightElement().get());
    System.out.println(
            "Word with second highest PMI with Cloud : " + highestCloudPMI2.getLeftElement().getRightElement()
                    + " with value : " + highestCloudPMI2.getRightElement().get());
    System.out.println(
            "Word with third highest PMI with Cloud : " + highestCloudPMI3.getLeftElement().getRightElement()
                    + " with value : " + highestCloudPMI3.getRightElement().get());

    System.out.println("Word with highest PMI with Love : " + highestLovePMI.getLeftElement().getRightElement()
            + " with value : " + highestLovePMI.getRightElement().get());
    System.out.println(
            "Word with second highest PMI with Love : " + highestLovePMI2.getLeftElement().getRightElement()
                    + " with value : " + highestLovePMI2.getRightElement().get());
    System.out.println(
            "Word with third highest PMI with Love : " + highestLovePMI3.getLeftElement().getRightElement()
                    + " with value : " + highestLovePMI3.getRightElement().get());

}

From source file:fr.inria.atlanmod.kyanos.benchmarks.MorsaTraverser.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 w w . j  a  va 2  s. c  om
    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);

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

    CommandLineParser parser = new PosixParser();

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

        URI uri = URI.createURI("morsa://" + commandLine.getOptionValue(IN));

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

        ResourceSet resourceSet = new ResourceSetImpl();
        resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put("morsa",
                new MorsaResourceFactoryImpl(new MongoDBMorsaBackendFactory()));

        Resource resource = resourceSet.createResource(uri);

        Map<String, Object> loadOpts = new HashMap<String, Object>();
        loadOpts.put(IMorsaResource.OPTION_SERVER_URI, "localhost");
        loadOpts.put(IMorsaResource.OPTION_MAX_SAVE_CACHE_SIZE, 30000);
        loadOpts.put(IMorsaResource.OPTION_DEMAND_LOAD, false);
        //         loadOpts.put(IMorsaResource.OPTION_CACHE_POLICY, FIFOEObjectCachePolicy.class.getName());
        //         loadOpts.put(IMorsaResource.OPTION_MAX_CACHE_SIZE, 30000);
        //         loadOpts.put(IMorsaResource.OPTION_CACHE_FLUSH_FACTOR, 0.3f);
        //         loadOpts.put(IMorsaResource.OPTION_DEMAND_LOAD_STRATEGY, IMorsaResource.OPTION_SINGLE_LOAD_STRATEGY);
        //         loadOpts.put(IMorsaResource.OPTION_DEMAND_LOAD, true);

        resource.load(loadOpts);

        LOG.log(Level.INFO, "Start counting");
        int count = 0;
        long begin = System.currentTimeMillis();
        for (Iterator<EObject> iterator = resource.getAllContents(); iterator.hasNext(); iterator
                .next(), count++)
            ;
        long end = System.currentTimeMillis();
        LOG.log(Level.INFO, "End counting");
        LOG.log(Level.INFO, MessageFormat.format("Resource {0} contains {1} elements", uri, count));
        LOG.log(Level.INFO, MessageFormat.format("Time spent: {0}", MessageUtil.formatMillis(end - begin)));

    } 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());
    }
}

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

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

    Option inputOpt = OptionBuilder.create(IN);
    inputOpt.setArgName("INPUT");
    inputOpt.setDescription("Input file");
    inputOpt.setArgs(1);//from  ww w .  j av  a  2  s  . c  o m
    inputOpt.setRequired(true);

    Option outputOpt = OptionBuilder.create(OUT);
    outputOpt.setArgName("OUTPUT");
    outputOpt.setDescription("Output directory");
    outputOpt.setArgs(1);
    outputOpt.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 repoOpt = OptionBuilder.create(REPO_NAME);
    repoOpt.setArgName("REPO_NAME");
    repoOpt.setDescription("CDO Repository name");
    repoOpt.setArgs(1);
    repoOpt.setRequired(true);

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

    CommandLineParser parser = new PosixParser();

    try {
        CommandLine commandLine = parser.parse(options, args);
        URI sourceUri = URI.createFileURI(commandLine.getOptionValue(IN));

        String outputDir = commandLine.getOptionValue(OUT);
        String repositoryName = commandLine.getOptionValue(REPO_NAME);

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

        ResourceSet resourceSet = new ResourceSetImpl();

        resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi",
                new XMIResourceFactoryImpl());
        resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("zxmi",
                new XMIResourceFactoryImpl());

        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}",
                MessageUtil.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}",
                MessageUtil.byteCountToDisplaySize(finalUsedMemory)));
        LOG.log(Level.INFO, MessageFormat.format("Memory use increase: {0}",
                MessageUtil.byteCountToDisplaySize(finalUsedMemory - initialUsedMemory)));

        EmbeddedCDOServer server = new EmbeddedCDOServer(outputDir, repositoryName);
        try {
            server.run();
            CDOSession session = server.openSession();
            CDOTransaction transaction = session.openTransaction();
            transaction.getRootResource().getContents().clear();
            LOG.log(Level.INFO, "Start moving elements");
            transaction.getRootResource().getContents().addAll(sourceResource.getContents());
            LOG.log(Level.INFO, "End moving elements");
            LOG.log(Level.INFO, "Commiting");
            transaction.commit();
            LOG.log(Level.INFO, "Commit done");
            transaction.close();
            session.close();
        } finally {
            server.stop();
        }
    } 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());
    }
}