use of org.eclipse.ui.console.IOConsole in project sts4 by spring-projects.
the class ConsoleUtil method getConsole.
public Console getConsole(String title) {
final IOConsole console = new IOConsole(title, null);
final IOConsoleInputStream in = console.getInputStream();
final IOConsoleOutputStream out = console.newOutputStream();
final IOConsoleOutputStream err = console.newOutputStream();
in.setColor(getInputColor());
out.setColor(getOutputColor());
err.setColor(getErrorColor());
add(console);
return new Console(in, out, err);
}
use of org.eclipse.ui.console.IOConsole in project ow by vtst.
the class SoyCompilerLaunchConfigurationDelegate method addProcessListeners.
@Override
protected void addProcessListeners(final ILaunchConfiguration config, final Fixture fixture, IProcessListenerAcceptor acceptor) {
acceptor.acceptTerminationListener(new IProcessTerminationListener() {
public void terminated(IProcess process, int exitValue) {
IConsole console = DebugUITools.getConsole(process);
if (console instanceof IOConsole) {
IOConsole ioConsole = (IOConsole) console;
IOConsoleOutputStream stream = ioConsole.newOutputStream();
if (exitValue == 0) {
try {
stream.write(messages.getString("soy_compiler_success"));
stream.write("\n");
stream.flush();
for (IFile file : configHelper.getOutputFiles(config)) {
try {
file.refreshLocal(0, null);
} catch (CoreException e) {
}
}
} catch (IOException e) {
e.printStackTrace();
}
} else {
try {
stream.write(messages.getString("soy_compiler_error"));
stream.write("\n");
stream.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}
// try { fixture.outputFile.refreshLocal(0, null); } catch (CoreException e) {}
}
});
acceptor.acceptPatternMatchListener(new EasyPatternMatchListener() {
private Pattern pattern = Pattern.compile("Exception [^:]*com.google.template.soy.base.SoySyntaxException: " + "(In file ([^:]*)(:([0-9]+))?(, template [^:]*)?: )?(.*)");
@Override
public void connect(TextConsole console) {
super.connect(console);
try {
for (IMarker marker : fixture.inputFile.findMarkers(MARKER_TYPE, true, IResource.DEPTH_ZERO)) {
if (MARKER_SOURCE_ID.equals(marker.getAttribute(IMarker.SOURCE_ID))) {
marker.delete();
}
}
} catch (CoreException e) {
}
}
private void processLine(int offset, int length) throws BadLocationException {
String line = document.get(offset, length);
Matcher matcher = pattern.matcher(line);
if (matcher.matches()) {
String lineNumberAsString = matcher.group(4);
int lineNumber = (lineNumberAsString == null ? 1 : Integer.parseInt(lineNumberAsString));
String errorMessage = matcher.group(6);
IMarker marker;
try {
marker = fixture.inputFile.createMarker(MARKER_TYPE);
marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
marker.setAttribute(IMarker.MESSAGE, errorMessage);
marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_NORMAL);
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
marker.setAttribute(IMarker.SOURCE_ID, MARKER_SOURCE_ID);
} catch (CoreException e) {
e.printStackTrace();
}
}
}
@Override
public void matchFound(PatternMatchEvent matchEvent) {
try {
processLine(matchEvent.getOffset(), matchEvent.getLength());
} catch (BadLocationException e) {
// This should never arise if the code is correct
}
}
@Override
public String getPattern() {
return ".+";
}
});
}
use of org.eclipse.ui.console.IOConsole in project ow by vtst.
the class LessCompilerLaunchConfigurationDelegate method addProcessListeners.
protected void addProcessListeners(ILaunchConfiguration config, final Fixture fixture, IProcessListenerAcceptor acceptor) {
acceptor.acceptTerminationListener(new IProcessTerminationListener() {
public void terminated(IProcess process, int exitValue) {
IConsole console = DebugUITools.getConsole(process);
if (console instanceof IOConsole) {
IOConsole ioConsole = (IOConsole) console;
IOConsoleOutputStream stream = ioConsole.newOutputStream();
if (exitValue == 0) {
try {
stream.write(messages.getString("less_compiler_success"));
stream.write("\n");
stream.flush();
} catch (IOException e) {
e.printStackTrace();
}
/*
FileLink link = new FileLink(destinationFile, null, -1, -1, -1);
console.defaultStream.hyperlink(link, messages.getString("less_link_to_output"));
console.defaultStream.println();
*/
} else {
try {
stream.write(messages.getString("less_compiler_error"));
stream.write("\n");
stream.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}
try {
fixture.outputFile.refreshLocal(0, null);
} catch (CoreException e) {
}
}
});
acceptor.acceptPatternMatchListener(new EasyPatternMatchListener() {
private Pattern pattern = Pattern.compile("([0-9]+)( .*)");
private int numberOfLines = 0;
private int errorLineNumber = 0;
private String errorMessage = null;
@Override
public void connect(TextConsole console) {
super.connect(console);
try {
for (IMarker marker : fixture.inputFile.findMarkers(MARKER_TYPE, true, IResource.DEPTH_ZERO)) {
if (MARKER_SOURCE_ID.equals(marker.getAttribute(IMarker.SOURCE_ID))) {
marker.delete();
}
}
} catch (CoreException e) {
}
}
@Override
public void disconnect() {
if (errorLineNumber != 0 && errorMessage != null) {
try {
IMarker marker = fixture.inputFile.createMarker(MARKER_TYPE);
marker.setAttribute(IMarker.LINE_NUMBER, this.errorLineNumber);
marker.setAttribute(IMarker.MESSAGE, this.errorMessage);
marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_NORMAL);
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
marker.setAttribute(IMarker.SOURCE_ID, MARKER_SOURCE_ID);
} catch (CoreException e) {
e.printStackTrace();
}
}
}
private void processLine(int offset, int length) throws BadLocationException {
String line = document.get(offset, length);
Matcher matcher = pattern.matcher(line);
if (matcher.matches()) {
this.numberOfLines++;
int lineNumber = Integer.parseInt(matcher.group(1));
if (this.numberOfLines <= 2)
errorLineNumber = lineNumber;
FileLink link = new FileLink(fixture.inputFile, null, -1, -1, lineNumber);
console.addHyperlink(link, offset, matcher.group(1).length());
} else {
if (this.numberOfLines == 0)
errorMessage = line;
}
}
@Override
public void matchFound(PatternMatchEvent matchEvent) {
try {
processLine(matchEvent.getOffset(), matchEvent.getLength());
} catch (BadLocationException e) {
// This should never arise if the code is correct
}
}
@Override
public String getPattern() {
return ".+";
}
});
}
Aggregations