<commit_before>/*****************************************************************************
 * Copyright (C) NanoContainer Organization. All rights reserved.            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *                                                                           *
 *****************************************************************************/

package org.nanocontainer;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.nanocontainer.script.ScriptedContainerBuilderFactory;
import org.picocontainer.defaults.ObjectReference;
import org.picocontainer.defaults.SimpleReference;

import java.io.File;
import java.io.IOException;
import java.net.URL;

public class Standalone {

    private static final char HELP_OPT = 'h';
    private static final char VERSION_OPT = 'v';
    private static final char COMPOSITION_OPT = 'c';
    private static final char RESOURCE_OPT = 'r';
    private static final char QUIET_OPT = 'q';
    private static final char NOWAIT_OPT = 'n';

    static final Options createOptions() {
        Options options = new Options();
        options.addOption(String.valueOf(HELP_OPT), "help", false,
                "print this message and exit");
        options.addOption(String.valueOf(VERSION_OPT), "version", false,
                "print the version information and exit");
        options.addOption(String.valueOf(COMPOSITION_OPT), "composition", true,
                "specify the composition file");
        options.addOption(String.valueOf(RESOURCE_OPT), "resource", true,
                "specify the composition file (as a resource read from classpath - like inside a jar)");
        options.addOption(String.valueOf(QUIET_OPT), "quiet", false,
                "forces ScriptedContainerBuilderFactory to be quiet");
        options.addOption(String.valueOf(NOWAIT_OPT), "nowait", false,
                "forces ScriptedContainerBuilderFactory to exit after start");
        return options;
    }

    public static void main(String[] args) throws IOException, ClassNotFoundException {
        CommandLine cl = null;
        Options options = createOptions();
        try {
            cl = getCommandLine(args, options);
        } catch (ParseException e) {
            System.out.println("Error in parsing arguments: ");
            e.printStackTrace();
            System.exit(-1);
        }

        if (cl.hasOption(HELP_OPT)) {
            printUsage(options);
            System.exit(0);
        }
        if (cl.hasOption(VERSION_OPT)) {
            printVersion();
            System.exit(0);
        }

        boolean quiet = cl.hasOption(QUIET_OPT);
        boolean nowait = cl.hasOption(NOWAIT_OPT);
        try {
            String compositionFile = cl.getOptionValue(COMPOSITION_OPT);
            String compositionResource = cl.getOptionValue(RESOURCE_OPT);
            if (compositionFile != null) {
                File composition = new File(compositionFile);
                buildAndStartContainer(composition, quiet, nowait);
            } else if (compositionResource != null) {
                URL composition = Standalone.class.getResource(compositionResource);
                buildAndStartContainer(composition, quiet, nowait);
            } else {
                printUsage(options);
                System.exit(0);
            }
        } catch (RuntimeException e) {
            System.err.println("Failed to start application. Cause : " + e.getMessage());
            e.printStackTrace();
            throw e;
        } catch (ClassNotFoundException e) {
            System.err.println("Failed to start application. A Class was not found. Exception message : " + e.getMessage());
            e.printStackTrace();
            throw e;
        }
        if (!quiet) {
            System.out.println("Exiting ScriptedContainerBuilderFactory's standalone main method.");
        }
    }<commit_msg>supporting the 'boot' module<commit_after>/*****************************************************************************
 * Copyright (C) NanoContainer Organization. All rights reserved.            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *                                                                           *
 *****************************************************************************/

package org.nanocontainer;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.nanocontainer.script.ScriptedContainerBuilderFactory;
import org.picocontainer.defaults.ObjectReference;
import org.picocontainer.defaults.SimpleReference;

import java.io.File;
import java.io.IOException;
import java.net.URL;

public class Standalone {

    private static final char HELP_OPT = 'h';
    private static final char VERSION_OPT = 'v';
    private static final char COMPOSITION_OPT = 'c';
    private static final char RESOURCE_OPT = 'r';
    private static final char QUIET_OPT = 'q';
    private static final char NOWAIT_OPT = 'n';

    static final Options createOptions() {
        Options options = new Options();
        options.addOption(String.valueOf(HELP_OPT), "help", false,
                "print this message and exit");
        options.addOption(String.valueOf(VERSION_OPT), "version", false,
                "print the version information and exit");
        options.addOption(String.valueOf(COMPOSITION_OPT), "composition", true,
                "specify the composition file");
        options.addOption(String.valueOf(RESOURCE_OPT), "resource", true,
                "specify the composition file (as a resource read from classpath - like inside a jar)");
        options.addOption(String.valueOf(QUIET_OPT), "quiet", false,
                "forces ScriptedContainerBuilderFactory to be quiet");
        options.addOption(String.valueOf(NOWAIT_OPT), "nowait", false,
                "forces ScriptedContainerBuilderFactory to exit after start");
        return options;
    }

    public static void main(String[] args) throws IOException, ClassNotFoundException {
		new Standalone(args);
    }

    public Standalone(String[] args) throws IOException, ClassNotFoundException {
        CommandLine cl = null;
        Options options = createOptions();
        try {
            cl = getCommandLine(args, options);
        } catch (ParseException e) {
            System.out.println("Error in parsing arguments: ");
            e.printStackTrace();
            System.exit(-1);
        }

        if (cl.hasOption(HELP_OPT)) {
            printUsage(options);
            System.exit(0);
        }
        if (cl.hasOption(VERSION_OPT)) {
            printVersion();
            System.exit(0);
        }

        boolean quiet = cl.hasOption(QUIET_OPT);
        boolean nowait = cl.hasOption(NOWAIT_OPT);
        try {
            String compositionFile = cl.getOptionValue(COMPOSITION_OPT);
            String compositionResource = cl.getOptionValue(RESOURCE_OPT);
			Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
            if (compositionFile != null) {
                File composition = new File(compositionFile);
                buildAndStartContainer(composition, quiet, nowait);
            } else if (compositionResource != null) {
                URL composition = Standalone.class.getResource(compositionResource);
                buildAndStartContainer(composition, quiet, nowait);
            } else {
                printUsage(options);
                System.exit(0);
            }
        } catch (RuntimeException e) {
            System.err.println("Failed to start application. Cause : " + e.getMessage());
            e.printStackTrace();
            throw e;
        } catch (ClassNotFoundException e) {
            System.err.println("Failed to start application. A Class was not found. Exception message : " + e.getMessage());
            e.printStackTrace();
            throw e;
        }
        if (!quiet) {
            System.out.println("Exiting ScriptedContainerBuilderFactory's standalone main method.");
        }
    }
{'fraction_non_alphanumeric': 0.1399033599280818, 'fraction_numerical': 0.0008989774131924936, 'mean_word_length': 2.2756716967243285, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7654759', 'n_tokens_mistral': 2148, 'n_tokens_neox': 2072, 'n_words': 564}