Search in sources :

Example 1 with GroovyInternalPosixParser

use of org.apache.commons.cli.GroovyInternalPosixParser in project groovy-core by groovy.

the class Groovyc method runCompiler.

private void runCompiler(String[] commandLine) {
    // hand crank it so we can add our own compiler configuration
    try {
        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);
        }
    }
}
Also used : Options(org.apache.commons.cli.Options) GroovyInternalPosixParser(org.apache.commons.cli.GroovyInternalPosixParser) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) CommandLine(org.apache.commons.cli.CommandLine) ErrorReporter(org.codehaus.groovy.tools.ErrorReporter) StringWriter(java.io.StringWriter) CommandLineParser(org.apache.commons.cli.CommandLineParser) BuildException(org.apache.tools.ant.BuildException) PrintWriter(java.io.PrintWriter)

Example 2 with GroovyInternalPosixParser

use of org.apache.commons.cli.GroovyInternalPosixParser in project groovy-core by groovy.

the class Java2GroovyMain method main.

public static void main(String[] args) {
    try {
        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();
    }
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) CommandLineParser(org.apache.commons.cli.CommandLineParser) GroovyInternalPosixParser(org.apache.commons.cli.GroovyInternalPosixParser)

Aggregations

CommandLine (org.apache.commons.cli.CommandLine)2 CommandLineParser (org.apache.commons.cli.CommandLineParser)2 GroovyInternalPosixParser (org.apache.commons.cli.GroovyInternalPosixParser)2 Options (org.apache.commons.cli.Options)2 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 MalformedURLException (java.net.MalformedURLException)1 BuildException (org.apache.tools.ant.BuildException)1 ErrorReporter (org.codehaus.groovy.tools.ErrorReporter)1