/**
  * Show the dialog if needed
  *
  * @param project the project
  * @param root the vcs root
  * @return true if showing is not needed or operation completed successfully
  */
 public static boolean showIfNeeded(final Project project, final VirtualFile root) {
   final ArrayList<String> files = new ArrayList<String>();
   try {
     scanFiles(project, root, files);
     final AtomicBoolean rc = new AtomicBoolean(true);
     if (!files.isEmpty()) {
       UIUtil.invokeAndWaitIfNeeded(
           new Runnable() {
             public void run() {
               GitUpdateLocallyModifiedDialog d =
                   new GitUpdateLocallyModifiedDialog(project, root, files);
               d.show();
               rc.set(d.isOK());
             }
           });
       if (rc.get()) {
         if (!files.isEmpty()) {
           revertFiles(project, root, files);
         }
       }
     }
     return rc.get();
   } catch (final VcsException e) {
     UIUtil.invokeAndWaitIfNeeded(
         new Runnable() {
           public void run() {
             GitUIUtil.showOperationError(project, e, "Checking for locally modified files");
           }
         });
     return false;
   }
 }
 @Override
 protected JPanel processSplitter(
     @NotNull Element splitterElement,
     Element firstChild,
     Element secondChild,
     final JPanel context) {
   if (context == null) {
     final boolean orientation =
         "vertical".equals(splitterElement.getAttributeValue("split-orientation"));
     final float proportion =
         Float.valueOf(splitterElement.getAttributeValue("split-proportion")).floatValue();
     final JPanel firstComponent = process(firstChild, null);
     final JPanel secondComponent = process(secondChild, null);
     final Ref<JPanel> panelRef = new Ref<JPanel>();
     UIUtil.invokeAndWaitIfNeeded(
         new Runnable() {
           @Override
           public void run() {
             JPanel panel = new JPanel(new BorderLayout());
             panel.setOpaque(false);
             Splitter splitter = new OnePixelSplitter(orientation, proportion, 0.1f, 0.9f);
             panel.add(splitter, BorderLayout.CENTER);
             splitter.setFirstComponent(firstComponent);
             splitter.setSecondComponent(secondComponent);
             panelRef.set(panel);
           }
         });
     return panelRef.get();
   }
   final Ref<JPanel> firstComponent = new Ref<JPanel>();
   final Ref<JPanel> secondComponent = new Ref<JPanel>();
   UIUtil.invokeAndWaitIfNeeded(
       new Runnable() {
         @Override
         public void run() {
           if (context.getComponent(0) instanceof Splitter) {
             Splitter splitter = (Splitter) context.getComponent(0);
             firstComponent.set((JPanel) splitter.getFirstComponent());
             secondComponent.set((JPanel) splitter.getSecondComponent());
           } else {
             firstComponent.set(context);
             secondComponent.set(context);
           }
         }
       });
   process(firstChild, firstComponent.get());
   process(secondChild, secondComponent.get());
   return context;
 }
  @Before
  public void setUp() throws Exception {
    UIUtil.invokeAndWaitIfNeeded(
        new Runnable() {
          @Override
          public void run() {
            try {
              final IdeaTestFixtureFactory fixtureFactory =
                  IdeaTestFixtureFactory.getFixtureFactory();
              myTempDirTestFixture = fixtureFactory.createTempDirTestFixture();
              myTempDirTestFixture.setUp();

              myClientRoot = new File(myTempDirTestFixture.getTempDirPath(), "clientroot");
              myClientRoot.mkdir();

              initProject(myClientRoot, ExternalChangesDetectionVcsTest.this.getTestName());

              myVcs = new MockAbstractVcs(myProject);
              myVcs.setChangeProvider(new MyMockChangeProvider());
              myVcsManager =
                  (ProjectLevelVcsManagerImpl) ProjectLevelVcsManager.getInstance(myProject);
              myVcsManager.registerVcs(myVcs);
              myVcsManager.setDirectoryMapping("", myVcs.getName());

              myLFS = LocalFileSystem.getInstance();
              myChangeListManager = ChangeListManager.getInstance(myProject);
              myVcsDirtyScopeManager = VcsDirtyScopeManager.getInstance(myProject);
            } catch (Exception e) {
              throw new RuntimeException(e);
            }
          }
        });
  }
  @Override
  protected void tearDown() throws Exception {
    UIUtil.invokeAndWaitIfNeeded(
        new Runnable() {
          @Override
          public void run() {
            try {
              if (useJps()) {
                CompilerWorkspaceConfiguration.getInstance(getProject()).USE_COMPILE_SERVER = false;
                ApplicationManagerEx.getApplicationEx().doNotSave(true);
                new WriteCommandAction(getProject()) {
                  @Override
                  protected void run(Result result) throws Throwable {
                    final JavaAwareProjectJdkTableImpl jdkTable =
                        JavaAwareProjectJdkTableImpl.getInstanceEx();
                    jdkTable.removeJdk(jdkTable.getInternalJdk());
                  }
                }.execute();
              }

              myMainOutput.tearDown();
              myMainOutput = null;
              GroovyCompilerTestCase.super.tearDown();
            } catch (Exception e) {
              throw new RuntimeException(e);
            }
          }
        });
  }
Exemplo n.º 5
0
  @BeforeMethod
  protected void setUp(final Method testMethod) throws Exception {
    // setting hg executable
    String exec = System.getenv(HG_EXECUTABLE_PATH);
    if (exec != null) {
      myClientBinaryPath = new File(exec);
    }
    if (exec == null || !myClientBinaryPath.exists()) {
      final File pluginRoot = new File(PluginPathManager.getPluginHomePath(HgVcs.VCS_NAME));
      myClientBinaryPath = new File(pluginRoot, "testData/bin");
    }
    HgVcs.setTestHgExecutablePath(myClientBinaryPath.getPath());

    myMainRepo = initRepositories();
    myProjectDir = new File(myMainRepo.getDirFixture().getTempDirPath());

    UIUtil.invokeAndWaitIfNeeded(
        new Runnable() {
          @Override
          public void run() {
            try {
              initProject(myProjectDir, testMethod.getName());
              activateVCS(HgVcs.VCS_NAME);
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        });

    myChangeListManager = new HgTestChangeListManager(myProject);
    myTraceClient = true;
    doActionSilently(VcsConfiguration.StandardConfirmation.ADD);
    doActionSilently(VcsConfiguration.StandardConfirmation.REMOVE);
  }
  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();
  }
  private void taskFinished(@NotNull final DumbModeTask prevTask) {
    UIUtil.invokeAndWaitIfNeeded(
        new Runnable() {
          @Override
          public void run() {
            if (myProject.isDisposed()) return;
            Disposer.dispose(prevTask);

            while (true) {
              if (myUpdatesQueue.isEmpty()) {
                updateFinished();
                return;
              }

              DumbModeTask queuedTask = myUpdatesQueue.pullFirst();
              ProgressIndicatorEx indicator = myProgresses.get(queuedTask);
              if (indicator.isCanceled()) {
                Disposer.dispose(queuedTask);
                continue;
              }

              startBackgroundProcess(queuedTask, indicator);
              return;
            }
          }
        });
  }
 public void openFiles() {
   if (mySplittersElement != null) {
     initializeProgress();
     final JPanel comp = myUIBuilder.process(mySplittersElement, getTopPanel());
     UIUtil.invokeAndWaitIfNeeded(
         new Runnable() {
           @Override
           public void run() {
             if (comp != null) {
               removeAll();
               add(comp, BorderLayout.CENTER);
               mySplittersElement = null;
             }
             // clear empty splitters
             for (EditorWindow window : getWindows()) {
               if (window.getEditors().length == 0) {
                 for (EditorWindow sibling : window.findSiblings()) {
                   sibling.unsplit(false);
                 }
               }
             }
           }
         });
   }
 }
Exemplo n.º 9
0
 private void setDumbMode(final boolean dumb) {
   UIUtil.invokeAndWaitIfNeeded(
       new Runnable() {
         public void run() {
           DumbServiceImpl.getInstance(_project).setDumb(dumb);
         }
       });
 }
Exemplo n.º 10
0
 static int alert(final String msg) {
   UIUtil.invokeAndWaitIfNeeded(
       new Runnable() {
         public void run() {
           Messages.showMessageDialog(msg, "Injection Plugin", Messages.getInformationIcon());
         }
       });
   return 0;
 }
Exemplo n.º 11
0
 private static VirtualFile refreshAndFindFile(final File file) {
   return UIUtil.invokeAndWaitIfNeeded(
       new Computable<VirtualFile>() {
         @Override
         public VirtualFile compute() {
           return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
         }
       });
 }
 private void notifyLoaded() {
   UIUtil.invokeAndWaitIfNeeded(
       (Runnable)
           () -> {
             for (Runnable loadingFinishedListener : myLoadingFinishedListeners) {
               loadingFinishedListener.run();
             }
           });
 }
 protected void disposeSession(final DebuggerSession debuggerSession)
     throws InterruptedException, InvocationTargetException {
   UIUtil.invokeAndWaitIfNeeded(
       new Runnable() {
         @Override
         public void run() {
           debuggerSession.dispose();
         }
       });
 }
 private static void testMemory(final String msg) {
   if (!TEST_MEMORY_USAGE) return;
   UIUtil.invokeAndWaitIfNeeded(
       new Runnable() {
         @Override
         public void run() {
           MessageDialogBuilder.yesNo(msg, msg).show();
         }
       });
 }
Exemplo n.º 15
0
 public void addTextToEditor(final String text) {
   UIUtil.invokeAndWaitIfNeeded(
       new Runnable() {
         @Override
         public void run() {
           getConsoleView().setInputText(text);
           PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
         }
       });
 }
  protected void clearAllBreakpoints() {

    UIUtil.invokeAndWaitIfNeeded(
        new Runnable() {
          @Override
          public void run() {
            XDebuggerTestUtil.removeAllBreakpoints(getProject());
          }
        });
  }
 public void drainQueuedUsageNodes() {
   assert !ApplicationManager.getApplication().isDispatchThread() : Thread.currentThread();
   UIUtil.invokeAndWaitIfNeeded(
       new Runnable() {
         @Override
         public void run() {
           myTransferToEDTQueue.drain();
         }
       });
 }
 public void saveInCache(@NotNull TIntObjectHashMap<T> details) {
   UIUtil.invokeAndWaitIfNeeded(
       (Runnable)
           () ->
               details.forEachEntry(
                   (key, value) -> {
                     myCache.put(key, value);
                     return true;
                   }));
 }
Exemplo n.º 19
0
 protected void resolveDependenciesAndImport() {
   UIUtil.invokeAndWaitIfNeeded(
       new Runnable() {
         @Override
         public void run() {
           myProjectsManager.waitForResolvingCompletion();
           myProjectsManager.performScheduledImportInTests();
         }
       });
 }
 public static void executeOnEdt(boolean synchronous, @NotNull Runnable task) {
   if (synchronous) {
     if (ApplicationManager.getApplication().isDispatchThread()) {
       task.run();
     } else {
       UIUtil.invokeAndWaitIfNeeded(task);
     }
   } else {
     UIUtil.invokeLaterIfNeeded(task);
   }
 }
Exemplo n.º 21
0
 protected void exec(final String command) throws InterruptedException {
   waitForReady();
   myCommandSemaphore.acquire(1);
   UIUtil.invokeAndWaitIfNeeded(
       new Runnable() {
         @Override
         public void run() {
           myConsoleView.executeInConsole(command);
         }
       });
 }
  /**
   * Toggles breakpoint
   *
   * @param file getScriptPath() or path to script
   * @param line starting with 0
   */
  protected void toggleBreakpoint(final String file, final int line) {
    UIUtil.invokeAndWaitIfNeeded(
        new Runnable() {
          @Override
          public void run() {
            doToggleBreakpoint(file, line);
          }
        });

    addOrRemoveBreakpoint(file, line);
  }
 /**
  * Check and process locally modified files
  *
  * @param root the project root
  * @param ex the exception holder
  */
 protected boolean checkLocallyModified(final VirtualFile root) throws VcsException {
   final Ref<Boolean> cancelled = new Ref<Boolean>(false);
   UIUtil.invokeAndWaitIfNeeded(
       new Runnable() {
         public void run() {
           if (!GitUpdateLocallyModifiedDialog.showIfNeeded(myProject, root)) {
             cancelled.set(true);
           }
         }
       });
   return !cancelled.get();
 }
 protected static void setFileText(final PsiFile file, final String barText) throws IOException {
   UIUtil.invokeAndWaitIfNeeded(
       new Runnable() {
         @Override
         public void run() {
           try {
             VfsUtil.saveText(ObjectUtils.assertNotNull(file.getVirtualFile()), barText);
           } catch (IOException e) {
             throw new RuntimeException(e);
           }
         }
       });
 }
Exemplo n.º 25
0
 protected void waitForReadingCompletion() {
   UIUtil.invokeAndWaitIfNeeded(
       new Runnable() {
         @Override
         public void run() {
           try {
             myProjectsManager.waitForReadingCompletion();
           } catch (Exception e) {
             throw new RuntimeException(e);
           }
         }
       });
 }
 private void setPromptInner(final String prompt) {
   UIUtil.invokeAndWaitIfNeeded(
       new Runnable() {
         @Override
         public void run() {
           myConsoleEditor.setPrefixTextAndAttributes(
               prompt, ConsoleViewContentType.USER_INPUT.getAttributes());
           if (myPanel.isVisible()) {
             queueUiUpdate(false);
           }
         }
       });
 }
Exemplo n.º 27
0
  private void disposeConsole() throws InterruptedException {
    if (myCommunication != null) {
      UIUtil.invokeAndWaitIfNeeded(
          new Runnable() {
            @Override
            public void run() {
              try {
                myCommunication.close();
              } catch (Exception e) {
                e.printStackTrace();
              }
              myCommunication = null;
            }
          });
    }

    disposeConsoleProcess();

    if (!myContentDescriptorRef.isNull()) {
      UIUtil.invokeAndWaitIfNeeded(
          new Runnable() {
            @Override
            public void run() {
              Disposer.dispose(myContentDescriptorRef.get());
            }
          });
    }

    if (myConsoleView != null) {
      new WriteAction() {
        @Override
        protected void run(@NotNull Result result) throws Throwable {
          Disposer.dispose(myConsoleView);
          myConsoleView = null;
        }
      }.execute();
    }
  }
 protected void undo() {
   UIUtil.invokeAndWaitIfNeeded(
       new Runnable() {
         @Override
         public void run() {
           final TestDialog oldTestDialog = Messages.setTestDialog(TestDialog.OK);
           try {
             UndoManager.getInstance(myProject).undo(null);
           } finally {
             Messages.setTestDialog(oldTestDialog);
           }
         }
       });
 }
Exemplo n.º 29
0
 @Override
 protected void tearDown() throws Exception {
   UIUtil.invokeAndWaitIfNeeded(
       new Runnable() {
         @Override
         public void run() {
           try {
             VfsUtilTest.super.tearDown();
           } catch (Exception e) {
             throw new RuntimeException(e);
           }
         }
       });
 }
  private CompilationLog compile(final ParameterizedRunnable<CompileStatusNotification> action) {
    final Ref<CompilationLog> result = Ref.create(null);
    final Semaphore semaphore = new Semaphore();
    UIUtil.invokeAndWaitIfNeeded(
        new Runnable() {
          @Override
          public void run() {
            semaphore.down();

            CompilerManagerImpl.testSetup();
            final CompileStatusNotification callback =
                new CompileStatusNotification() {
                  @Override
                  public void finished(
                      boolean aborted, int errors, int warnings, CompileContext compileContext) {
                    try {
                      if (aborted) {
                        Assert.fail("compilation aborted");
                      }
                      result.set(
                          new CompilationLog(
                              CompilerManagerImpl.getPathsToRecompile(),
                              CompilerManagerImpl.getPathsToDelete(),
                              compileContext.getMessages(CompilerMessageCategory.ERROR),
                              compileContext.getMessages(CompilerMessageCategory.WARNING)));
                    } finally {
                      semaphore.up();
                    }
                  }
                };
            if (useExternalCompiler()) {
              myProject.save();
              CompilerTestUtil.saveSdkTable();
              CompilerTestUtil.scanSourceRootsToRecompile(myProject);
            }
            action.run(callback);
          }
        });

    long start = System.currentTimeMillis();
    while (!semaphore.waitFor(10)) {
      if (System.currentTimeMillis() - start > 60 * 1000) {
        throw new RuntimeException("timeout");
      }
      UIUtil.dispatchAllInvocationEvents();
    }
    UIUtil.dispatchAllInvocationEvents();

    return result.get();
  }