IDEA-117904 Ant integration: running: with an error (javac) the result is reported as "successful": perform all status calculations after all messages are processed

This commit is contained in:
Eugene Zhuravlev
2013-12-11 17:23:40 +01:00
parent 9e5ae50c39
commit b74c9499fa
2 changed files with 57 additions and 82 deletions
@@ -52,6 +52,7 @@ import com.intellij.problems.WolfTheProblemSolver;
import com.intellij.ui.content.*;
import com.intellij.util.Alarm;
import com.intellij.util.text.DateFormatUtil;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -102,8 +103,6 @@ public final class AntBuildMessageView extends JPanel implements DataProvider, O
private final java.util.List<LogCommand> myLog = Collections.synchronizedList(new ArrayList<LogCommand>(1024));
private volatile int myCommandsProcessedCount = 0;
private JPanel myProgressPanel;
private final AntMessageCustomizer[] myMessageCustomizers = AntMessageCustomizer.EP_NAME.getExtensions();
private final Alarm myAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD);
@@ -119,7 +118,7 @@ public final class AntBuildMessageView extends JPanel implements DataProvider, O
}
};
private boolean myIsAborted;
private volatile boolean myIsAborted;
private ActionToolbar myLeftToolbar;
private ActionToolbar myRightToolbar;
private final TreeExpander myTreeExpander = new TreeExpander() {
@@ -166,19 +165,6 @@ public final class AntBuildMessageView extends JPanel implements DataProvider, O
showAntView(AntBuildFileImpl.TREE_VIEW.value(buildFile.getAllOptions()));
}
public boolean hasMessagesOfType(MessageType type) {
synchronized (myLog) {
for (LogCommand cmd : myLog) {
if (cmd instanceof MessageCommand) {
if (((MessageCommand)cmd).getMessage().getType() == type) {
return true;
}
}
}
}
return false;
}
public void changeView() {
showAntView(!isTreeView());
if (myBuildFile != null) {
@@ -316,19 +302,6 @@ public final class AntBuildMessageView extends JPanel implements DataProvider, O
return messageView;
}
public void removeProgressPanel() {
if (myProgressPanel != null) {
myMessagePanel.remove(myProgressPanel);
// fix of 9377
SwingUtilities.invokeLater(new Runnable() {
public void run() {
myMessagePanel.validate();
}
});
myProgressPanel = null;
}
}
public void setParsingThread(OutputParser parsingThread) {
myParsingThread = parsingThread;
myIsAborted = false;
@@ -797,19 +770,63 @@ public final class AntBuildMessageView extends JPanel implements DataProvider, O
return myWarningCount;
}
void buildFinished(boolean isProgressAborted, long buildTimeInMilliseconds, @NotNull final AntBuildListener antBuildListener, OutputPacketProcessor dispatcher) {
void buildFinished(boolean isProgressAborted, final long buildTimeInMilliseconds, @NotNull final AntBuildListener antBuildListener, OutputPacketProcessor dispatcher) {
final boolean aborted = isProgressAborted || myIsAborted;
final String message = getFinishStatusText(aborted, buildTimeInMilliseconds);
dispatcher.processOutput(new Printable() {
@Override
public void printOn(Printer printer) {
if (!myProject.isDisposed()) { // if not disposed
final String message = getFinishStatusText(aborted, buildTimeInMilliseconds);
addCommand(new FinishBuildCommand(message));
final StatusBar statusBar = WindowManager.getInstance().getStatusBar(myProject);
if (statusBar != null) {
statusBar.setInfo(message);
}
final AntBuildFileBase buildFile = myBuildFile;
final boolean isBackground = buildFile != null && buildFile.isRunInBackground();
final boolean shouldActivate = !isBackground || getErrorCount() > 0;
UIUtil.invokeLaterIfNeeded(new Runnable() {
public void run() {
final Runnable finishRunnable = new Runnable() {
public void run() {
final int errorCount = getErrorCount();
final AntBuildFileBase buildFile = myBuildFile;
if (buildFile != null) {
if (errorCount == 0 && buildFile.isViewClosedWhenNoErrors()) {
close();
}
else if (errorCount > 0) {
myTreeView.scrollToFirstError();
}
else {
myTreeView.scrollToStatus();
}
}
else {
myTreeView.scrollToLastMessage();
}
VirtualFileManager.getInstance().asyncRefresh(new Runnable() {
public void run() {
antBuildListener.buildFinished(aborted ? AntBuildListener.ABORTED : AntBuildListener.FINISHED_SUCCESSFULLY, errorCount);
}
});
}
};
if (shouldActivate) {
final ToolWindow toolWindow = !myProject.isDisposed() ? ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.MESSAGES_WINDOW) : null;
if (toolWindow != null) { // can be null if project is closed
toolWindow.activate(finishRunnable, false);
}
else {
finishRunnable.run();
}
}
else {
finishRunnable.run();
}
}
});
}
}
});
@@ -819,50 +836,25 @@ public final class AntBuildMessageView extends JPanel implements DataProvider, O
if (!myIsOutputPaused) {
new OutputFlusher().doFlush();
}
final AntBuildFileBase buildFile = myBuildFile;
if (buildFile != null) {
if (getErrorCount() == 0 && buildFile.isViewClosedWhenNoErrors()) {
close();
}
else if (getErrorCount() > 0) {
myTreeView.scrollToFirstError();
}
else {
myTreeView.scrollToStatus();
}
}
else {
myTreeView.scrollToLastMessage();
}
VirtualFileManager.getInstance().asyncRefresh(new Runnable() {
public void run() {
antBuildListener.buildFinished(aborted ? AntBuildListener.ABORTED : AntBuildListener.FINISHED_SUCCESSFULLY, getErrorCount());
}
});
}
});
}
public String getFinishStatusText(boolean isAborted, long buildTimeInMilliseconds) {
int errors = getErrorCount();
int warnings = getWarningCount();
private String getFinishStatusText(boolean isAborted, long buildTimeInMilliseconds) {
final String theDateAsString = DateFormatUtil.formatDateTime(Clock.getTime());
String formattedBuildTime = formatBuildTime(buildTimeInMilliseconds / 1000);
final String formattedBuildTime = formatBuildTime(buildTimeInMilliseconds / 1000);
if (isAborted) {
return AntBundle.message("build.finished.status.ant.build.aborted", formattedBuildTime, theDateAsString);
}
else if (errors == 0 && warnings == 0) {
final int errors = getErrorCount();
final int warnings = getWarningCount();
if (errors == 0 && warnings == 0) {
return AntBundle.message("build.finished.status.ant.build.completed.successfully", formattedBuildTime, theDateAsString);
}
else if (errors == 0) {
if (errors == 0) {
return AntBundle.message("build.finished.status.ant.build.completed.with.warnings", warnings, formattedBuildTime, theDateAsString);
}
else {
return AntBundle
.message("build.finished.status.ant.build.completed.with.errors.warnings", errors, warnings, formattedBuildTime, theDateAsString);
}
return AntBundle.message("build.finished.status.ant.build.completed.with.errors.warnings", errors, warnings, formattedBuildTime, theDateAsString);
}
private static String formatBuildTime(long seconds) {
@@ -34,7 +34,6 @@ import com.intellij.lang.ant.config.AntBuildListener;
import com.intellij.lang.ant.config.impl.BuildFileProperty;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.progress.ProcessCanceledException;
@@ -43,7 +42,8 @@ import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.encoding.EncodingProjectManager;
import com.intellij.openapi.wm.*;
import com.intellij.openapi.wm.StatusBar;
import com.intellij.openapi.wm.WindowManager;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -168,8 +168,6 @@ public final class ExecutionHandler {
final OutputParser parser = OutputParser2.attachParser(project, handler, errorView, progress, buildFile);
final boolean isBackground = buildFile.isRunInBackground();
handler.addProcessListener(new ProcessAdapter() {
public void processTerminated(ProcessEvent event) {
final long buildTime = System.currentTimeMillis() - startTime;
@@ -177,21 +175,6 @@ public final class ExecutionHandler {
parser.setStopped(true);
final OutputPacketProcessor dispatcher = handler.getErr().getEventsDispatcher();
errorView.buildFinished(progress != null && progress.isCanceled(), buildTime, antBuildListener, dispatcher);
ApplicationManager.getApplication().invokeLater(new Runnable() {
public void run() {
if (project.isDisposed()) {
return;
}
errorView.removeProgressPanel();
final boolean shouldActivate = !isBackground || errorView.hasMessagesOfType(AntBuildMessageView.MessageType.ERROR);
if (shouldActivate) {
ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.MESSAGES_WINDOW);
if (toolWindow != null) { // can be null if project is closed
toolWindow.activate(null, false);
}
}
}
}, ModalityState.NON_MODAL);
}
});
handler.startNotify();