use of com.intellij.util.concurrency.Semaphore in project intellij-community by JetBrains.
the class MavenUtil method smartInvokeAndWait.
public static void smartInvokeAndWait(final Project p, final ModalityState state, final Runnable r) {
if (isNoBackgroundMode() || ApplicationManager.getApplication().isDispatchThread()) {
r.run();
} else {
final Semaphore semaphore = new Semaphore();
semaphore.down();
DumbService.getInstance(p).smartInvokeLater(() -> {
try {
r.run();
} finally {
semaphore.up();
}
}, state);
semaphore.waitFor();
}
}
use of com.intellij.util.concurrency.Semaphore in project intellij-community by JetBrains.
the class SvnBusyOnAddTest method testStatusDoesNotLockForWrite.
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<>(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();
}
}
use of com.intellij.util.concurrency.Semaphore in project intellij-community by JetBrains.
the class MavenBeforeRunTasksProvider method executeTask.
public boolean executeTask(final DataContext context, RunConfiguration configuration, ExecutionEnvironment env, final MavenBeforeRunTask task) {
final Semaphore targetDone = new Semaphore();
final boolean[] result = new boolean[] { true };
try {
ApplicationManager.getApplication().invokeAndWait(() -> {
final Project project = CommonDataKeys.PROJECT.getData(context);
final MavenProject mavenProject = getMavenProject(task);
if (project == null || project.isDisposed() || mavenProject == null)
return;
FileDocumentManager.getInstance().saveAllDocuments();
final MavenExplicitProfiles explicitProfiles = MavenProjectsManager.getInstance(project).getExplicitProfiles();
final MavenRunner mavenRunner = MavenRunner.getInstance(project);
targetDone.down();
new Task.Backgroundable(project, TasksBundle.message("maven.tasks.executing"), true) {
public void run(@NotNull ProgressIndicator indicator) {
try {
MavenRunnerParameters params = new MavenRunnerParameters(true, mavenProject.getDirectory(), ParametersListUtil.parse(task.getGoal()), explicitProfiles.getEnabledProfiles(), explicitProfiles.getDisabledProfiles());
result[0] = mavenRunner.runBatch(Collections.singletonList(params), null, null, TasksBundle.message("maven.tasks.executing"), indicator);
} finally {
targetDone.up();
}
}
@Override
public boolean shouldStartInBackground() {
return MavenRunner.getInstance(project).getSettings().isRunMavenInBackground();
}
@Override
public void processSentToBackground() {
MavenRunner.getInstance(project).getSettings().setRunMavenInBackground(true);
}
}.queue();
}, ModalityState.NON_MODAL);
} catch (Exception e) {
MavenLog.LOG.error(e);
return false;
}
targetDone.waitFor();
return result[0];
}
use of com.intellij.util.concurrency.Semaphore in project intellij-community by JetBrains.
the class MavenProjectsProcessor method waitForCompletion.
public void waitForCompletion() {
if (isStopped)
return;
if (ApplicationManager.getApplication().isUnitTestMode()) {
synchronized (myQueue) {
while (!myQueue.isEmpty()) {
startProcessing(myQueue.poll());
}
}
return;
}
final Semaphore semaphore = new Semaphore();
semaphore.down();
scheduleTask(new MavenProjectsProcessorTask() {
public void perform(Project project, MavenEmbeddersManager embeddersManager, MavenConsole console, MavenProgressIndicator indicator) throws MavenProcessCanceledException {
semaphore.up();
}
});
while (true) {
if (isStopped || semaphore.waitFor(1000))
return;
}
}
use of com.intellij.util.concurrency.Semaphore in project intellij-community by JetBrains.
the class SvnHistoryTest method testRepositoryRootHistory.
@Test
public void testRepositoryRootHistory() throws Exception {
enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
enableSilentOperation(VcsConfiguration.StandardConfirmation.REMOVE);
myCnt = 0;
final VcsHistoryProvider provider = SvnVcs.getInstance(myProject).getVcsHistoryProvider();
final SubTree tree = new SubTree(myWorkingCopyDir);
checkin();
for (int i = 0; i < 10; i++) {
VcsTestUtil.editFileInCommand(myProject, tree.myS1File, "1\n2\n3\n4\n" + i);
checkin();
}
final Semaphore semaphore = new Semaphore();
semaphore.down();
final FilePath rootPath = VcsContextFactory.SERVICE.getInstance().createFilePathOnNonLocal(myRepoUrl, true);
provider.reportAppendableHistory(rootPath, new VcsAppendableHistorySessionPartner() {
@Override
public void reportCreatedEmptySession(VcsAbstractHistorySession session) {
}
@Override
public void acceptRevision(VcsFileRevision revision) {
++myCnt;
semaphore.up();
}
@Override
public void reportException(VcsException exception) {
throw new RuntimeException(exception);
}
@Override
public void finished() {
}
@Override
public void beforeRefresh() {
}
@Override
public void forceRefresh() {
}
});
semaphore.waitFor(1000);
Assert.assertTrue(myCnt > 0);
}
Aggregations