Ejemplo n.º 1
1
    @Override
    public void onTextAvailable(ProcessEvent event, Key outputType) {
      String text = event.getText();
      if (outputType == ProcessOutputTypes.STDERR) {
        output.append(text);

        // We loop until the state stabilizes
        State lastState;
        do {
          lastState = state;
          switch (state) {
            case WAITING:
              {
                Matcher matcher = matcher(DIAGNOSTIC_PATTERN);
                if (find(matcher)) {
                  currentCompilerMessage = new CompilerMessage();
                  currentCompilerMessage.setMessageCategoryFromString(matcher.group(1));
                  state = State.ATTRIBUTES;
                }
                break;
              }
            case ATTRIBUTES:
              {
                Matcher matcher = matcher(ATTRIBUTE_PATTERN);
                int indexDelta = 0;
                while (matcher.find()) {
                  handleSkippedOutput(
                      output.subSequence(
                          firstUnprocessedIndex + indexDelta,
                          firstUnprocessedIndex + matcher.start()));
                  currentCompilerMessage.setAttributeFromStrings(
                      matcher.group(1), matcher.group(2));
                  indexDelta = matcher.end();
                }
                firstUnprocessedIndex += indexDelta;

                Matcher endMatcher = matcher(OPEN_TAG_END_PATTERN);
                if (find(endMatcher)) {
                  state = State.MESSAGE;
                }
                break;
              }
            case MESSAGE:
              {
                Matcher matcher = matcher(MESSAGE_PATTERN);
                if (find(matcher)) {
                  currentCompilerMessage.setMessage(matcher.group(1));
                  currentCompilerMessage.reportTo(compileContext);
                  state = State.WAITING;
                }
                break;
              }
          }
        } while (state != lastState);

      } else {
        compileContext.addMessage(INFORMATION, text, "", -1, -1);
      }
    }
    @Override
    public void onTextAvailable(ProcessEvent event, Key outputType) {
      if (outputType == ProcessOutputTypes.STDERR) {
        LOG.warn(event.getText().trim());
      }
      if (outputType != ProcessOutputTypes.STDOUT) {
        return;
      }

      final String line = event.getText().trim();
      if (LOG.isDebugEnabled()) {
        LOG.debug(">> " + line);
      }

      if (myLastOp == null) {
        final WatcherOp watcherOp;
        try {
          watcherOp = WatcherOp.valueOf(line);
        } catch (IllegalArgumentException e) {
          LOG.error("Illegal watcher command: " + line);
          return;
        }

        if (watcherOp == WatcherOp.GIVEUP) {
          notifyOnFailure(ApplicationBundle.message("watcher.gave.up"), null);
          myIsShuttingDown = true;
        } else if (watcherOp == WatcherOp.RESET) {
          reset();
        } else {
          myLastOp = watcherOp;
        }
      } else if (myLastOp == WatcherOp.MESSAGE) {
        notifyOnFailure(line, NotificationListener.URL_OPENING_LISTENER);
        myLastOp = null;
      } else if (myLastOp == WatcherOp.REMAP || myLastOp == WatcherOp.UNWATCHEABLE) {
        if ("#".equals(line)) {
          if (myLastOp == WatcherOp.REMAP) {
            processRemap();
          } else {
            mySettingRoots.decrementAndGet();
            processUnwatchable();
          }
          myLines.clear();
          myLastOp = null;
        } else {
          myLines.add(line);
        }
      } else {
        String path = line.replace('\0', '\n'); // unescape
        processChange(path, myLastOp);
        myLastOp = null;
      }
    }
    @Override
    public void processTerminated(ProcessEvent event) {
      if (myProject.isDisposed()) return;
      if (!myTerminateNotified.compareAndSet(false, true)) return;

      ApplicationManager.getApplication()
          .invokeLater(
              () -> {
                RunnerLayoutUi ui = myDescriptor.getRunnerLayoutUi();
                if (ui != null && !ui.isDisposed()) {
                  ui.updateActionsNow();
                }
              },
              ModalityState.any());

      myProject
          .getMessageBus()
          .syncPublisher(EXECUTION_TOPIC)
          .processTerminated(myExecutorId, myEnvironment, myProcessHandler, event.getExitCode());

      SaveAndSyncHandler saveAndSyncHandler = SaveAndSyncHandler.getInstance();
      if (saveAndSyncHandler != null) {
        saveAndSyncHandler.scheduleRefresh();
      }
    }
Ejemplo n.º 4
0
 @Override
 public void processTerminated(ProcessEvent event) {
   if (firstUnprocessedIndex < output.length()) {
     handleSkippedOutput(output.substring(firstUnprocessedIndex).trim());
   }
   int exitCode = event.getExitCode();
   // 0 is normal, 1 is "errors found" — handled by the messages above
   if (exitCode != 0 && exitCode != 1) {
     compileContext.addMessage(
         ERROR, "Compiler terminated with exit code: " + exitCode, "", -1, -1);
   }
 }
    @Override
    public void processTerminated(ProcessEvent event) {
      LOG.warn("Watcher terminated with exit code " + event.getExitCode());

      myProcessHandler = null;

      try {
        startupProcess(true);
      } catch (IOException e) {
        shutdownProcess();
        LOG.warn(
            "Watcher terminated and attempt to restart has failed. Exiting watching thread.", e);
      }
    }
 @Override
 public void startNotified(@NotNull final ProcessEvent event) {
   super.startNotified(event);
   switchToProcessMode(event.getProcessHandler());
 }