Search in sources :

Example 1 with OutputPacketProcessor

use of com.intellij.lang.ant.segments.OutputPacketProcessor in project intellij-community by JetBrains.

the class ExecutionHandler method processRunningAnt.

private static void processRunningAnt(final ProgressIndicator progress, final AntProcessHandler handler, final AntBuildMessageView errorView, final AntBuildFileBase buildFile, final long startTime, final AntBuildListener antBuildListener) {
    final Project project = buildFile.getProject();
    final StatusBar statusbar = WindowManager.getInstance().getStatusBar(project);
    if (statusbar != null) {
        statusbar.setInfo(AntBundle.message("ant.build.started.status.message"));
    }
    final CheckCancelTask checkCancelTask = new CheckCancelTask(progress, handler);
    checkCancelTask.start(0);
    final OutputParser parser = OutputParser2.attachParser(project, handler, errorView, progress, buildFile);
    handler.addProcessListener(new ProcessAdapter() {

        private final StringBuilder myUnprocessedStdErr = new StringBuilder();

        public void onTextAvailable(ProcessEvent event, Key outputType) {
            if (outputType == ProcessOutputTypes.STDERR) {
                final String text = event.getText();
                synchronized (myUnprocessedStdErr) {
                    myUnprocessedStdErr.append(text);
                }
            }
        }

        public void processTerminated(ProcessEvent event) {
            final long buildTime = System.currentTimeMillis() - startTime;
            checkCancelTask.cancel();
            parser.setStopped(true);
            final OutputPacketProcessor dispatcher = handler.getErr().getEventsDispatcher();
            try {
                if (event.getExitCode() != 0) {
                    // in case process exits abnormally, provide all unprocessed stderr content
                    final String unprocessed;
                    synchronized (myUnprocessedStdErr) {
                        unprocessed = myUnprocessedStdErr.toString();
                        myUnprocessedStdErr.setLength(0);
                    }
                    if (!unprocessed.isEmpty()) {
                        dispatcher.processOutput(new Printable() {

                            public void printOn(Printer printer) {
                                errorView.outputError(unprocessed, AntBuildMessageView.PRIORITY_ERR);
                            }
                        });
                    }
                } else {
                    synchronized (myUnprocessedStdErr) {
                        myUnprocessedStdErr.setLength(0);
                    }
                }
            } finally {
                errorView.buildFinished(progress != null && progress.isCanceled(), buildTime, antBuildListener, dispatcher);
            }
        }
    });
    handler.startNotify();
}
Also used : Project(com.intellij.openapi.project.Project) Printable(com.intellij.execution.testframework.Printable) Printer(com.intellij.execution.testframework.Printer) StatusBar(com.intellij.openapi.wm.StatusBar) Key(com.intellij.openapi.util.Key) OutputPacketProcessor(com.intellij.lang.ant.segments.OutputPacketProcessor)

Aggregations

Printable (com.intellij.execution.testframework.Printable)1 Printer (com.intellij.execution.testframework.Printer)1 OutputPacketProcessor (com.intellij.lang.ant.segments.OutputPacketProcessor)1 Project (com.intellij.openapi.project.Project)1 Key (com.intellij.openapi.util.Key)1 StatusBar (com.intellij.openapi.wm.StatusBar)1