public void testStatusDoesNotLockForWrite() throws Exception {
    final File ioFile = new File(myWorkingCopyRoot, filename);
    ioFile.getParentFile().mkdirs();

    /*SVNWCClient client11 = new SVNWCClient((ISVNRepositoryPool)null, new DefaultSVNOptions());
    client11.doAdd(ioFile.getParentFile(), true, false, true, true);*/

    ioFile.createNewFile();
    try {
      final SVNStatusClient readClient =
          new SVNStatusClient((ISVNRepositoryPool) null, new DefaultSVNOptions());
      final Semaphore semaphore = new Semaphore();
      final Semaphore semaphoreMain = new Semaphore();
      final Semaphore semaphoreWokeUp = new Semaphore();

      final AtomicReference<Boolean> wasUp = new AtomicReference<Boolean>(false);
      final ISVNStatusHandler handler =
          status -> {
            semaphore.waitFor();
            wasUp.set(true);
          };

      semaphore.down();
      semaphoreMain.down();
      semaphoreWokeUp.down();

      final SVNException[] exception = new SVNException[1];
      Thread thread =
          new Thread(
              () -> {
                try {
                  semaphoreMain.up();
                  readClient.doStatus(myWorkingCopyRoot, true, false, true, false, handler);
                  semaphoreWokeUp.up();
                } catch (SVNException e) {
                  exception[0] = e;
                }
              },
              "svn test");
      thread.start();

      semaphoreMain.waitFor();
      TimeoutUtil.sleep(5);
      SVNWCClient client = new SVNWCClient((ISVNRepositoryPool) null, new DefaultSVNOptions());
      client.doAdd(ioFile.getParentFile(), true, false, true, true);
      semaphore.up();
      semaphoreWokeUp.waitFor();

      Assert.assertEquals(true, wasUp.get().booleanValue());
      if (exception[0] != null) {
        throw exception[0];
      }
      thread.join();
    } finally {
      ioFile.delete();
    }
  }
Пример #2
0
  public synchronized void stop() {
    if (myOriginal.isRunning()) {
      myOriginal.stop();
    } else {
      myStartupAlarm.cancelAllRequests();
    }

    // needed only for correct assertion of !progress.isRunning() in
    // ApplicationImpl.runProcessWithProgressSynchroniously
    final Semaphore semaphore = new Semaphore();
    semaphore.down();

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            semaphore.waitFor();
            if (myDialog != null) {
              // System.out.println("myDialog.destroyProcess()");
              myDialog.close(DialogWrapper.OK_EXIT_CODE);
              myDialog = null;
            }
          }
        });

    super.stop(); // should be last to not leaveModal before closing the dialog
    semaphore.up();
  }
  public void stop() {
    super.stop();

    myQueue.cancelAllUpdates();
    myFreezeSemaphore.up();

    ApplicationManager.getApplication()
        .invokeLater(
            new Runnable() {
              public void run() {
                final CompletionPhase phase = CompletionServiceImpl.getCompletionPhase();
                if (!(phase instanceof CompletionPhase.BgCalculation)
                    || phase.indicator != CompletionProgressIndicator.this) return;

                LOG.assertTrue(!getProject().isDisposed(), "project disposed");

                if (myEditor.isDisposed()) {
                  LookupManager.getInstance(getProject()).hideActiveLookup();
                  CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
                  return;
                }

                if (myEditor instanceof EditorWindow) {
                  LOG.assertTrue(
                      ((EditorWindow) myEditor).getInjectedFile().isValid(),
                      "injected file !valid");
                  LOG.assertTrue(
                      ((DocumentWindow) myEditor.getDocument()).isValid(), "docWindow !valid");
                }
                PsiFile file = myLookup.getPsiFile();
                LOG.assertTrue(file == null || file.isValid(), "file !valid");

                myLookup.setCalculating(false);

                if (hideAutopopupIfMeaningless()) {
                  return;
                }

                if (myCount == 0) {
                  if (!isAutopopupCompletion()) {
                    LookupManager.getInstance(getProject()).hideActiveLookup();

                    final CompletionProgressIndicator current =
                        CompletionServiceImpl.getCompletionService().getCurrentCompletion();
                    LOG.assertTrue(
                        current == null, current + "!=" + CompletionProgressIndicator.this);

                    handleEmptyLookup(!((CompletionPhase.BgCalculation) phase).modifiersChanged);
                  }
                } else {
                  CompletionServiceImpl.setCompletionPhase(
                      new CompletionPhase.ItemsCalculated(CompletionProgressIndicator.this));
                  updateLookup();
                }
              }
            },
            myQueue.getModalityState());
  }
  public synchronized void close() throws IOException {
    if (myWaitForThreadFuture != null) {
      myWaitForThreadFuture.cancel(true);
    }
    if (myWaitSemaphore != null) {
      myWaitSemaphore.up();
    }

    try {
      if (myInputStream != null && !myContainsError) {
        myInputStream.close();
        try {
          Thread.sleep(10);
        } catch (InterruptedException e) {
          // ignore
        }
      }
    } finally {
      try {
        if (myOutputStream != null && !myContainsError) {
          myOutputStream.close();
          try {
            Thread.sleep(10);
          } catch (InterruptedException e) {
            // ignore
          }
        }
        try {
          if (myErrThread != null) {
            myErrThread.setProcessTerminated(true);
          }
          if (myStdErrFuture != null) {
            myStdErrFuture.get();
          }
        } catch (InterruptedException e) {
          //
        } catch (ExecutionException e) {
          LOG.error(e);
        }
      } finally {
        try {
          if (myProcess != null) {
            myProcess.destroy();
          }
        } finally {
          myInputStream = null;
          myOutputStream = null;
          myProcess = null;
        }
      }
    }
  }
 private void waitForProcess(Application application) {
   myWaitSemaphore = new Semaphore();
   myWaitSemaphore.down();
   myWaitForThreadFuture =
       application.executeOnPooledThread(
           () -> {
             try {
               myProcess.waitFor();
             } catch (InterruptedException ignored) {
             } finally {
               myWaitSemaphore.up();
             }
           });
 }
  public void fireEvents(boolean hasWriteAction) {
    try {
      if (!iHaveEventsToFire) return;

      if (hasWriteAction) {
        fireEventsInWriteAction();
      } else {
        ApplicationManager.getApplication()
            .runWriteAction(
                new Runnable() {
                  @Override
                  public void run() {
                    fireEventsInWriteAction();
                  }
                });
      }
    } finally {
      mySemaphore.up();
    }
  }
Пример #7
0
 @Override
 protected void processCommand(int command) throws IOException {
   boolean result = true;
   try {
     super.processCommand(command);
   } catch (Throwable e) {
     //noinspection InstanceofCatchParameter
     if (!(e instanceof SocketException)) {
       result = false;
       fail.set(true);
       try {
         LOG.error(e);
       } catch (AssertionError ignored) {
       }
     }
   } finally {
     if (!result) {
       semaphore.up();
     }
   }
 }
  @Override
  public synchronized void stop() {
    if (myOriginal.isRunning()) {
      myOriginal.stop();
    } else {
      myStartupAlarm.cancelAllRequests();

      if (!myOriginalStarted && myOriginal instanceof Disposable) {
        // dispose original because start & stop were not called so original progress might not have
        // released its resources
        Disposer.dispose(((Disposable) myOriginal));
      }
    }

    // needed only for correct assertion of !progress.isRunning() in
    // ApplicationImpl.runProcessWithProgressSynchroniously
    final Semaphore semaphore = new Semaphore();
    semaphore.down();

    SwingUtilities.invokeLater(
        new Runnable() {
          @Override
          public void run() {
            semaphore.waitFor();
            if (myDialog != null) {
              // System.out.println("myDialog.destroyProcess()");
              myDialog.close(DialogWrapper.OK_EXIT_CODE);
              myDialog = null;
            }
          }
        });

    try {
      super.stop(); // should be last to not leaveModal before closing the dialog
    } finally {
      semaphore.up();
    }
  }
 @Override
 public void finished(
     boolean aborted, int errors, int warnings, final CompileContext compileContext) {
   try {
     for (CompilerMessageCategory category : CompilerMessageCategory.values()) {
       for (CompilerMessage message : compileContext.getMessages(category)) {
         final String msg = message.getMessage();
         if (category != CompilerMessageCategory.INFORMATION
             || !msg.startsWith("Compilation completed successfully")) {
           myMessages.add(category + ": " + msg);
         }
       }
     }
     if (errors > 0) {
       fail("Compiler errors occurred! " + StringUtil.join(myMessages, "\n"));
     }
     assertFalse("Code did not compile!", aborted);
   } catch (Throwable t) {
     myError = t;
   } finally {
     mySemaphore.up();
   }
 }
Пример #10
0
 public void done() {
   mySemaphore.up();
 }
Пример #11
0
 @Override
 public void end() {
   super.end();
   mySemaphore.up();
 }
 public void finished() {
   done.up();
 }
  public void reloadClasses(final Map<String, HotSwapFile> modifiedClasses) {
    DebuggerManagerThreadImpl.assertIsManagerThread();

    if (modifiedClasses == null || modifiedClasses.size() == 0) {
      myProgress.addMessage(
          myDebuggerSession,
          MessageCategory.INFORMATION,
          DebuggerBundle.message("status.hotswap.loaded.classes.up.to.date"));
      return;
    }

    final DebugProcessImpl debugProcess = getDebugProcess();
    final VirtualMachineProxyImpl virtualMachineProxy = debugProcess.getVirtualMachineProxy();

    final Project project = debugProcess.getProject();
    final BreakpointManager breakpointManager =
        (DebuggerManagerEx.getInstanceEx(project)).getBreakpointManager();
    breakpointManager.disableBreakpoints(debugProcess);

    // virtualMachineProxy.suspend();

    try {
      RedefineProcessor redefineProcessor = new RedefineProcessor(virtualMachineProxy);

      int processedEntriesCount = 0;
      for (final Map.Entry<String, HotSwapFile> entry : modifiedClasses.entrySet()) {
        // stop if process is finished already
        if (debugProcess.isDetached() || debugProcess.isDetaching()) {
          break;
        }
        if (redefineProcessor.getProcessedClassesCount() == 0 && myProgress.isCancelled()) {
          // once at least one class has been actually reloaded, do not interrupt the whole process
          break;
        }
        processedEntriesCount++;
        final String qualifiedName = entry.getKey();
        if (qualifiedName != null) {
          myProgress.setText(qualifiedName);
          myProgress.setFraction(processedEntriesCount / (double) modifiedClasses.size());
        }
        try {
          redefineProcessor.processClass(qualifiedName, entry.getValue().file);
        } catch (IOException e) {
          reportProblem(qualifiedName, e);
        }
      }

      if (redefineProcessor.getProcessedClassesCount() == 0 && myProgress.isCancelled()) {
        // once at least one class has been actually reloaded, do not interrupt the whole process
        return;
      }

      redefineProcessor.processPending();
      myProgress.setFraction(1);

      final int partiallyRedefinedClassesCount =
          redefineProcessor.getPartiallyRedefinedClassesCount();
      if (partiallyRedefinedClassesCount == 0) {
        myProgress.addMessage(
            myDebuggerSession,
            MessageCategory.INFORMATION,
            DebuggerBundle.message(
                "status.classes.reloaded", redefineProcessor.getProcessedClassesCount()));
      } else {
        final String message =
            DebuggerBundle.message(
                "status.classes.not.all.versions.reloaded",
                partiallyRedefinedClassesCount,
                redefineProcessor.getProcessedClassesCount());
        myProgress.addMessage(myDebuggerSession, MessageCategory.WARNING, message);
      }

      LOG.debug("classes reloaded");
    } catch (Throwable e) {
      processException(e);
    }

    debugProcess.getPositionManager().clearCache();

    DebuggerContextImpl context = myDebuggerSession.getContextManager().getContext();
    SuspendContextImpl suspendContext = context.getSuspendContext();
    if (suspendContext != null) {
      XExecutionStack stack = suspendContext.getActiveExecutionStack();
      if (stack != null) {
        ((JavaExecutionStack) stack).initTopFrame();
      }
    }

    final Semaphore waitSemaphore = new Semaphore();
    waitSemaphore.down();
    //noinspection SSBasedInspection
    SwingUtilities.invokeLater(
        () -> {
          try {
            if (!project.isDisposed()) {
              breakpointManager.reloadBreakpoints();
              debugProcess.getRequestsManager().clearWarnings();
              if (LOG.isDebugEnabled()) {
                LOG.debug("requests updated");
                LOG.debug("time stamp set");
              }
              myDebuggerSession.refresh(false);

              XDebugSession session = myDebuggerSession.getXDebugSession();
              if (session != null) {
                session.rebuildViews();
              }
            }
          } catch (Throwable e) {
            LOG.error(e);
          } finally {
            waitSemaphore.up();
          }
        });

    waitSemaphore.waitFor();

    if (!project.isDisposed()) {
      try {
        breakpointManager.enableBreakpoints(debugProcess);
      } catch (Exception e) {
        processException(e);
      }
    }
  }