mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
remove EnsureUpToDateFromNonAWTThread
This commit is contained in:
-61
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.vcs.changes;
|
||||
|
||||
import com.intellij.diagnostic.ThreadDumper;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.util.concurrency.Semaphore;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
/**
|
||||
* for non-AWT threads, synchronously waits for completion of ChanegListManager update
|
||||
*/
|
||||
@TestOnly
|
||||
public class EnsureUpToDateFromNonAWTThread {
|
||||
private final Project myProject;
|
||||
private volatile boolean myDone;
|
||||
|
||||
public EnsureUpToDateFromNonAWTThread(final Project project) {
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
public void execute() {
|
||||
assert !ApplicationManager.getApplication().isDispatchThread();
|
||||
final Semaphore lock = new Semaphore();
|
||||
|
||||
lock.down();
|
||||
|
||||
ChangeListManager.getInstance(myProject).invokeAfterUpdate(new Runnable() {
|
||||
public void run() {
|
||||
myDone = true;
|
||||
lock.up();
|
||||
}
|
||||
}, InvokeAfterUpdateMode.SILENT, null, null);
|
||||
|
||||
if (myProject.isDisposed()) return;
|
||||
|
||||
if (!lock.waitFor(100 * 1000) && !myProject.isDisposed()) {
|
||||
//noinspection UseOfSystemOutOrSystemErr
|
||||
System.out.println(ThreadDumper.dumpThreadsToString());
|
||||
throw new AssertionError("Couldn't wait for changes update");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDone() {
|
||||
return myDone;
|
||||
}
|
||||
}
|
||||
@@ -1722,11 +1722,9 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
|
||||
return true;
|
||||
}
|
||||
myVfsListener.flushDirt();
|
||||
final EnsureUpToDateFromNonAWTThread worker = new EnsureUpToDateFromNonAWTThread(myProject);
|
||||
worker.execute();
|
||||
myUpdater.waitUntilRefreshed();
|
||||
waitUpdateAlarm();
|
||||
return worker.isDone();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.idea.svn;
|
||||
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.vcs.VcsConfiguration;
|
||||
import com.intellij.openapi.vcs.changes.EnsureUpToDateFromNonAWTThread;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class VcsWaitForUpdateForTest extends Svn17TestCase {
|
||||
@Test
|
||||
public void testRefreshes() throws Exception {
|
||||
enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
|
||||
final VirtualFile file = createFileInCommand("a.txt", "old content");
|
||||
final Object lock = new Object();
|
||||
|
||||
final Ref<Boolean> done = new Ref<Boolean>();
|
||||
final Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new EnsureUpToDateFromNonAWTThread(myProject).execute();
|
||||
done.set(Boolean.TRUE);
|
||||
synchronized (lock) {
|
||||
lock.notifyAll();
|
||||
}
|
||||
}
|
||||
},"vcs refresh");
|
||||
|
||||
thread.start();
|
||||
synchronized (lock) {
|
||||
final long start = System.currentTimeMillis();
|
||||
final int timeout = 3000;
|
||||
|
||||
while ((System.currentTimeMillis() - start < timeout) && (! Boolean.TRUE.equals(done.get()))) {
|
||||
try {
|
||||
lock.wait(timeout);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert Boolean.TRUE.equals(done.get());
|
||||
thread.join();
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.idea.svn16;
|
||||
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.vcs.VcsConfiguration;
|
||||
import com.intellij.openapi.vcs.changes.EnsureUpToDateFromNonAWTThread;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class VcsWaitForUpdateForTest extends Svn16TestCase {
|
||||
@Test
|
||||
public void testRefreshes() throws Exception {
|
||||
enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD);
|
||||
final VirtualFile file = createFileInCommand("a.txt", "old content");
|
||||
final Object lock = new Object();
|
||||
|
||||
final Ref<Boolean> done = new Ref<Boolean>();
|
||||
final Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new EnsureUpToDateFromNonAWTThread(myProject).execute();
|
||||
done.set(Boolean.TRUE);
|
||||
synchronized (lock) {
|
||||
lock.notifyAll();
|
||||
}
|
||||
}
|
||||
},"svn6 refresh");
|
||||
|
||||
thread.start();
|
||||
synchronized (lock) {
|
||||
final long start = System.currentTimeMillis();
|
||||
final int timeout = 3000;
|
||||
|
||||
while ((System.currentTimeMillis() - start < timeout) && (! Boolean.TRUE.equals(done.get()))) {
|
||||
try {
|
||||
lock.wait(timeout);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert Boolean.TRUE.equals(done.get());
|
||||
thread.join();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user