Ejemplo n.º 1
0
  public final void runBare() throws Throwable {
    final Throwable[] throwables = new Throwable[1];

    SwingUtilities.invokeAndWait(
        new Runnable() {
          public void run() {
            try {
              ourTestThread = Thread.currentThread();
              startRunAndTear();
            } catch (Throwable throwable) {
              throwables[0] = throwable;
            } finally {
              ourTestThread = null;
              try {
                cleanupApplicationCaches();
              } catch (Throwable e) {
                e.printStackTrace();
              }
            }
          }
        });

    if (throwables[0] != null) {
      throw throwables[0];
    }

    // just to make sure all deffered Runnable's to finish
    SwingUtilities.invokeAndWait(EmptyRunnable.getInstance());

    if (IdeaLogger.ourErrorsOccurred != null) {
      throw IdeaLogger.ourErrorsOccurred;
    }
  }
  private List<String> runCompiler(final Consumer<ErrorReportingCallback> runnable) {
    final Semaphore semaphore = new Semaphore();
    semaphore.down();
    final ErrorReportingCallback callback = new ErrorReportingCallback(semaphore);
    UIUtil.invokeAndWaitIfNeeded(
        new Runnable() {
          @Override
          public void run() {
            try {
              if (useJps()) {
                getProject().save();
                CompilerTestUtil.saveSdkTable();
                File ioFile = VfsUtil.virtualToIoFile(myModule.getModuleFile());
                if (!ioFile.exists()) {
                  getProject().save();
                  assert ioFile.exists() : "File does not exist: " + ioFile.getPath();
                }
              }
              runnable.consume(callback);
            } catch (Exception e) {
              throw new RuntimeException(e);
            }
          }
        });

    // tests run in awt
    while (!semaphore.waitFor(100)) {
      if (SwingUtilities.isEventDispatchThread()) {
        UIUtil.dispatchAllInvocationEvents();
      }
    }
    callback.throwException();
    return callback.getMessages();
  }
  @Override
  public void annotateExternally(
      @NotNull final PsiModifierListOwner listOwner,
      @NotNull final String annotationFQName,
      @NotNull final PsiFile fromFile,
      final PsiNameValuePair[] value) {
    final Project project = myPsiManager.getProject();
    final PsiFile containingFile = listOwner.getContainingFile();
    if (!(containingFile instanceof PsiJavaFile)) {
      return;
    }
    final String packageName = ((PsiJavaFile) containingFile).getPackageName();
    final VirtualFile virtualFile = containingFile.getVirtualFile();
    LOG.assertTrue(virtualFile != null);
    final List<OrderEntry> entries =
        ProjectRootManager.getInstance(project).getFileIndex().getOrderEntriesForFile(virtualFile);
    if (entries.isEmpty()) {
      return;
    }
    for (final OrderEntry entry : entries) {
      if (entry instanceof ModuleOrderEntry) continue;
      VirtualFile[] virtualFiles = AnnotationOrderRootType.getFiles(entry);
      virtualFiles = filterByReadOnliness(virtualFiles);

      if (virtualFiles.length > 0) {
        chooseRootAndAnnotateExternally(
            listOwner,
            annotationFQName,
            fromFile,
            project,
            packageName,
            virtualFile,
            virtualFiles,
            value);
      } else {
        if (ApplicationManager.getApplication().isUnitTestMode()
            || ApplicationManager.getApplication().isHeadlessEnvironment()) {
          return;
        }
        SwingUtilities.invokeLater(
            new Runnable() {
              @Override
              public void run() {
                setupRootAndAnnotateExternally(
                    entry,
                    project,
                    listOwner,
                    annotationFQName,
                    fromFile,
                    packageName,
                    virtualFile,
                    value);
              }
            });
      }
      break;
    }
  }