use of java.io.PrintWriter in project groovy by apache.
the class MultipleCompilationErrorsException method getMessage.
public String getMessage() {
StringWriter data = new StringWriter();
PrintWriter writer = new PrintWriter(data);
Janitor janitor = new Janitor();
writer.write(super.getMessage());
writer.println(":");
try {
collector.write(writer, janitor);
} finally {
janitor.cleanup();
}
return data.toString();
}
use of java.io.PrintWriter in project groovy by apache.
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 DefaultParser();
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 java.io.PrintWriter in project groovy by apache.
the class Groovy method processError.
private void processError(Exception e) {
StringWriter writer = new StringWriter();
new ErrorReporter(e, false).write(new PrintWriter(writer));
String message = writer.toString();
throw new BuildException("Script Failed: " + message, e, getLocation());
}
use of java.io.PrintWriter in project hadoop by apache.
the class TestFileUtil method createFile.
/**
* Creates a new file in the specified directory, with the specified name and
* the specified file contents. This method will add a newline terminator to
* the end of the contents string in the destination file.
* @param directory File non-null destination directory.
* @param name String non-null file name.
* @param contents String non-null file contents.
* @throws IOException if an I/O error occurs.
*/
private File createFile(File directory, String name, String contents) throws IOException {
File newFile = new File(directory, name);
PrintWriter pw = new PrintWriter(newFile);
try {
pw.println(contents);
} finally {
pw.close();
}
return newFile;
}
use of java.io.PrintWriter in project flink by apache.
the class CommonTestUtils method printLog4jDebugConfig.
public static void printLog4jDebugConfig(File file) throws IOException {
try (PrintWriter writer = new PrintWriter(new FileWriter(file))) {
writer.println("log4j.rootLogger=DEBUG, console");
writer.println("log4j.appender.console=org.apache.log4j.ConsoleAppender");
writer.println("log4j.appender.console.target = System.err");
writer.println("log4j.appender.console.layout=org.apache.log4j.PatternLayout");
writer.println("log4j.appender.console.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n");
writer.println("log4j.logger.org.eclipse.jetty.util.log=OFF");
writer.println("log4j.logger.org.apache.zookeeper=OFF");
writer.flush();
}
}
Aggregations