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