Search in sources :

Example 36 with TestOnly

use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.

the class UpdateRequestsQueue method waitUntilRefreshed.

@TestOnly
public void waitUntilRefreshed() {
    while (true) {
        final Semaphore semaphore = new Semaphore();
        synchronized (myLock) {
            if (!myRequestSubmitted && !myRequestRunning) {
                return;
            }
            if (!myRequestRunning) {
                myFuture.set(myExecutor.submit(new MyRunnable()));
            }
            semaphore.down();
            myWaitingUpdateCompletionSemaphores.add(semaphore);
        }
        if (!semaphore.waitFor(100 * 1000)) {
            LOG.error("Too long VCS update");
            return;
        }
    }
}
Also used : Semaphore(com.intellij.util.concurrency.Semaphore) TestOnly(org.jetbrains.annotations.TestOnly)

Example 37 with TestOnly

use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.

the class VfsRootAccess method allowRootAccess.

@TestOnly
public static void allowRootAccess(@NotNull Disposable disposable, @NotNull final String... roots) {
    if (roots.length == 0)
        return;
    allowRootAccess(roots);
    Disposer.register(disposable, new Disposable() {

        @Override
        public void dispose() {
            disallowRootAccess(roots);
        }
    });
}
Also used : Disposable(com.intellij.openapi.Disposable) TestOnly(org.jetbrains.annotations.TestOnly)

Example 38 with TestOnly

use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.

the class VfsRootAccess method assertAccessInTests.

@TestOnly
static void assertAccessInTests(@NotNull VirtualFileSystemEntry child, @NotNull NewVirtualFileSystem delegate) {
    final Application application = ApplicationManager.getApplication();
    if (SHOULD_PERFORM_ACCESS_CHECK && application.isUnitTestMode() && application instanceof ApplicationImpl && ((ApplicationImpl) application).isComponentsCreated() && !ApplicationInfoImpl.isInStressTest()) {
        if (delegate != LocalFileSystem.getInstance() && delegate != JarFileSystem.getInstance()) {
            return;
        }
        // root' children are loaded always
        if (child.getParent() == null || child.getParent().getParent() == null) {
            return;
        }
        Set<String> allowed = ApplicationManager.getApplication().runReadAction(new Computable<Set<String>>() {

            @Override
            public Set<String> compute() {
                return allowedRoots();
            }
        });
        boolean isUnder = allowed == null || allowed.isEmpty();
        if (!isUnder) {
            String childPath = child.getPath();
            if (delegate == JarFileSystem.getInstance()) {
                VirtualFile local = JarFileSystem.getInstance().getVirtualFileForJar(child);
                assert local != null : child;
                childPath = local.getPath();
            }
            for (String root : allowed) {
                if (FileUtil.startsWith(childPath, root)) {
                    isUnder = true;
                    break;
                }
                if (root.startsWith(JarFileSystem.PROTOCOL_PREFIX)) {
                    String rootLocalPath = FileUtil.toSystemIndependentName(PathUtil.toPresentableUrl(root));
                    isUnder = FileUtil.startsWith(childPath, rootLocalPath);
                    if (isUnder)
                        break;
                }
            }
        }
        assert isUnder : "File accessed outside allowed roots: " + child + ";\nAllowed roots: " + new ArrayList<>(allowed);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashSet(gnu.trove.THashSet) Set(java.util.Set) ApplicationImpl(com.intellij.openapi.application.impl.ApplicationImpl) Application(com.intellij.openapi.application.Application) TestOnly(org.jetbrains.annotations.TestOnly)

Example 39 with TestOnly

use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.

the class NativeFileWatcherImpl method shutdown.

@Override
@TestOnly
public void shutdown() throws InterruptedException {
    Application app = ApplicationManager.getApplication();
    assert app != null && app.isUnitTestMode() : app;
    MyProcessHandler processHandler = myProcessHandler;
    if (processHandler != null) {
        myIsShuttingDown = true;
        shutdownProcess();
        long t = System.currentTimeMillis();
        while (!processHandler.isProcessTerminated()) {
            if ((System.currentTimeMillis() - t) > 5000) {
                throw new InterruptedException("Timed out waiting watcher process to terminate");
            }
            TimeoutUtil.sleep(100);
        }
    }
}
Also used : Application(com.intellij.openapi.application.Application) TestOnly(org.jetbrains.annotations.TestOnly)

Example 40 with TestOnly

use of org.jetbrains.annotations.TestOnly in project intellij-community by JetBrains.

the class NativeFileWatcherImpl method startup.

@Override
@TestOnly
public void startup() throws IOException {
    Application app = ApplicationManager.getApplication();
    assert app != null && app.isUnitTestMode() : app;
    myIsShuttingDown = false;
    myStartAttemptCount = 0;
    startupProcess(false);
}
Also used : Application(com.intellij.openapi.application.Application) TestOnly(org.jetbrains.annotations.TestOnly)

Aggregations

TestOnly (org.jetbrains.annotations.TestOnly)56 Disposable (com.intellij.openapi.Disposable)18 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 NotNull (org.jetbrains.annotations.NotNull)7 Project (com.intellij.openapi.project.Project)5 Application (com.intellij.openapi.application.Application)4 Document (com.intellij.openapi.editor.Document)3 Editor (com.intellij.openapi.editor.Editor)3 THashSet (gnu.trove.THashSet)3 Nullable (org.jetbrains.annotations.Nullable)3 HighlightingPass (com.intellij.codeHighlighting.HighlightingPass)2 TextEditorHighlightingPass (com.intellij.codeHighlighting.TextEditorHighlightingPass)2 ApplicationEx (com.intellij.openapi.application.ex.ApplicationEx)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 CollectionListModel (com.intellij.ui.CollectionListModel)2 THashMap (gnu.trove.THashMap)2 BackgroundEditorHighlighter (com.intellij.codeHighlighting.BackgroundEditorHighlighter)1 Pass (com.intellij.codeHighlighting.Pass)1 AutoPopupController (com.intellij.codeInsight.AutoPopupController)1 com.intellij.codeInsight.daemon (com.intellij.codeInsight.daemon)1