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

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

Introduction

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

Prototype

GroovyInternalPosixParser

Source Link

Usage

From source file:groovy.ui.GroovyMain.java

/**
 * Parse the command line.//from  www.  j a  va  2s.  co m
 *
 * @param options the options parser.
 * @param args    the command line args.
 * @return parsed command line.
 * @throws ParseException if there was a problem.
 */
private static CommandLine parseCommandLine(Options options, String[] args) throws ParseException {
    CommandLineParser parser = new GroovyInternalPosixParser();
    return parser.parse(options, args, true);
}

From source file:org.codehaus.groovy.ant.Groovyc.java

private void runCompiler(String[] commandLine) {
    // hand crank it so we can add our own compiler configuration
    try {/*  w  w  w.java 2s.  c  om*/
        Options options = FileSystemCompiler.createCompilationOptions();

        CommandLineParser cliParser = new GroovyInternalPosixParser();

        CommandLine cli;
        cli = cliParser.parse(options, commandLine);

        configuration = FileSystemCompiler.generateCompilerConfigurationFromOptions(cli);
        configuration.setScriptExtensions(getScriptExtensions());
        String tmpExtension = getScriptExtension();
        if (tmpExtension.startsWith("*."))
            tmpExtension = tmpExtension.substring(1);
        configuration.setDefaultScriptExtension(tmpExtension);

        // Load the file name list
        String[] filenames = FileSystemCompiler.generateFileNamesFromOptions(cli);
        boolean fileNameErrors = filenames == null;

        fileNameErrors = fileNameErrors && !FileSystemCompiler.validateFiles(filenames);

        if (targetBytecode != null) {
            configuration.setTargetBytecode(targetBytecode);
        }

        if (!fileNameErrors) {
            FileSystemCompiler.doCompilation(configuration, makeCompileUnit(), filenames,
                    forceLookupUnnamedFiles);
        }

    } catch (Exception re) {
        Throwable t = re;
        if ((re.getClass() == RuntimeException.class) && (re.getCause() != null)) {
            // unwrap to the real exception
            t = re.getCause();
        }
        StringWriter writer = new StringWriter();
        new ErrorReporter(t, false).write(new PrintWriter(writer));
        String message = writer.toString();

        taskSuccess = false;
        if (errorProperty != null) {
            getProject().setNewProperty(errorProperty, "true");
        }

        if (failOnError) {
            log.error(message);
            throw new BuildException("Compilation Failed", t, getLocation());
        } else {
            log.error(message);
        }
    }
}

From source file:org.codehaus.groovy.antlr.java.Java2GroovyMain.java

public static void main(String[] args) {
    try {//  w  w w.  j av a2  s  .  co  m
        Options options = new Options();
        CommandLineParser cliParser = new GroovyInternalPosixParser();
        CommandLine cli = cliParser.parse(options, args);
        String[] filenames = cli.getArgs();
        if (filenames.length == 0) {
            System.err.println("Needs at least one filename");
        }
        Java2GroovyProcessor.processFiles(Arrays.asList(filenames));
    } catch (Throwable t) {
        t.printStackTrace();
    }
}

From source file:org.codehaus.groovy.tools.FileSystemCompiler.java

/**
 * Same as main(args) except that exceptions are thrown out instead of causing
 * the VM to exit and the lookup for .groovy files can be controlled
 *//*from  w w  w.  ja v  a2 s .c  om*/
public static void commandLineCompile(String[] args, boolean lookupUnnamedFiles) throws Exception {
    Options options = createCompilationOptions();

    CommandLineParser cliParser = new GroovyInternalPosixParser();

    CommandLine cli;
    cli = cliParser.parse(options, args);

    if (cli.hasOption('h')) {
        displayHelp(options);
        return;
    }

    if (cli.hasOption('v')) {
        displayVersion();
        return;
    }

    displayStackTraceOnError = cli.hasOption('e');

    CompilerConfiguration configuration = generateCompilerConfigurationFromOptions(cli);

    //
    // Load the file name list
    String[] filenames = generateFileNamesFromOptions(cli);
    boolean fileNameErrors = filenames == null;
    if (!fileNameErrors && (filenames.length == 0)) {
        displayHelp(options);
        return;
    }

    fileNameErrors = fileNameErrors && !validateFiles(filenames);

    if (!fileNameErrors) {
        doCompilation(configuration, null, filenames, lookupUnnamedFiles);
    }
}