From 60f2a36569667a46be611a7a03aaba5f1fa7b98e Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 23 Apr 2014 12:23:09 +0400 Subject: [PATCH] perforce tests fixed --- .../impl/HeavyIdeaTestFixtureImpl.java | 12 ++++-- .../vcs/AbstractVcsTestCase.java | 9 +++-- .../vcs/impl/ProjectLevelVcsManagerImpl.java | 8 +++- .../openapi/vcs/impl/VcsInitialization.java | 40 +++++++++++++------ .../com/intellij/openapi/vcs/VcsTestUtil.java | 38 +++++++++++------- 5 files changed, 71 insertions(+), 36 deletions(-) diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/HeavyIdeaTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/HeavyIdeaTestFixtureImpl.java index 3551da7fcd34..4adc2aa57cef 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/HeavyIdeaTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/HeavyIdeaTestFixtureImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -29,6 +29,8 @@ import com.intellij.openapi.editor.Editor; import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.fileEditor.OpenFileDescriptor; import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx; +import com.intellij.openapi.fileTypes.FileTypeManager; +import com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.project.Project; @@ -146,9 +148,9 @@ class HeavyIdeaTestFixtureImpl extends BaseFixture implements HeavyIdeaTestFixtu new WriteCommandAction.Simple(null) { @Override protected void run() throws Throwable { - File projectFile = FileUtil.createTempFile(myName+"_", PROJECT_FILE_SUFFIX); - FileUtil.delete(projectFile); - myFilesToDelete.add(projectFile); + File tempDirectory = FileUtil.createTempDirectory(myName, ""); + File projectFile = new File(tempDirectory, myName + PROJECT_FILE_SUFFIX); + myFilesToDelete.add(tempDirectory); LocalFileSystem.getInstance().refreshAndFindFileByIoFile(projectFile); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); @@ -166,6 +168,7 @@ class HeavyIdeaTestFixtureImpl extends BaseFixture implements HeavyIdeaTestFixtu ProjectManagerEx.getInstanceEx().openTestProject(myProject); LightPlatformTestCase.clearUncommittedDocuments(myProject); + ((FileTypeManagerImpl)FileTypeManager.getInstance()).drainReDetectQueue(); } }.execute().throwException(); } @@ -244,6 +247,7 @@ class HeavyIdeaTestFixtureImpl extends BaseFixture implements HeavyIdeaTestFixtu } }.execute(); return ApplicationManager.getApplication().runReadAction(new Computable() { + @Override public PsiFile compute() { return PsiManager.getInstance(getProject()).findFile(virtualFile[0]); } diff --git a/platform/testFramework/testSrc/com/intellij/testFramework/vcs/AbstractVcsTestCase.java b/platform/testFramework/testSrc/com/intellij/testFramework/vcs/AbstractVcsTestCase.java index 10a6bc58d9f3..4df8f9cdeb53 100644 --- a/platform/testFramework/testSrc/com/intellij/testFramework/vcs/AbstractVcsTestCase.java +++ b/platform/testFramework/testSrc/com/intellij/testFramework/vcs/AbstractVcsTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -28,6 +28,7 @@ import com.intellij.openapi.vcs.*; import com.intellij.openapi.vcs.annotate.AnnotationProvider; import com.intellij.openapi.vcs.annotate.FileAnnotation; import com.intellij.openapi.vcs.changes.*; +import com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.testFramework.UsefulTestCase; @@ -95,7 +96,7 @@ public abstract class AbstractVcsTestCase { if (pluginName != null) { System.setProperty(key, pluginName); } - String name = getClass().getName() + "." + testName; + String name = testName; final TestFixtureBuilder testFixtureBuilder = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(name); myProjectFixture = testFixtureBuilder.getFixture(); testFixtureBuilder.addModule(EmptyModuleFixtureBuilder.class).addContentRoot(clientRoot.toString()); @@ -116,13 +117,15 @@ public abstract class AbstractVcsTestCase { assert myWorkingCopyDir != null; } }); - } finally { + } + finally { if (was != null) { System.setProperty(key, was); } else { System.clearProperty(key); } } + ((ProjectLevelVcsManagerImpl)ProjectLevelVcsManager.getInstance(myProject)).waitForInitialized(); } protected void projectCreated() { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java index 87d7faab4523..904b070d2a57 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/ProjectLevelVcsManagerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -72,6 +72,7 @@ import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.TestOnly; import javax.swing.*; import java.awt.*; @@ -896,4 +897,9 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme public ContentRevisionCache getContentRevisionCache() { return myContentRevisionCache; } + + @TestOnly + public void waitForInitialized() { + myInitialization.waitForInitialized(); + } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsInitialization.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsInitialization.java index f0987ce8d228..498f3d1a5c28 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsInitialization.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/VcsInitialization.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -21,32 +21,34 @@ import com.intellij.openapi.project.DumbAwareRunnable; import com.intellij.openapi.project.Project; import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.util.Pair; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.TestOnly; +import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; -import java.util.LinkedList; import java.util.List; +import java.util.concurrent.Future; public class VcsInitialization { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.impl.VcsInitialization"); - private final Project myProject; - private final List> myList; + private final List> myList = new ArrayList>(); private final Object myLock; private boolean myInitStarted; + private volatile Future myFuture; - public VcsInitialization(final Project project) { + public VcsInitialization(@NotNull final Project project) { myLock = new Object(); - myProject = project; - myList = new LinkedList>(); - StartupManager.getInstance(myProject).registerPostStartupActivity(new DumbAwareRunnable() { + StartupManager.getInstance(project).registerPostStartupActivity(new DumbAwareRunnable() { + @Override public void run() { - if (myProject.isDisposed()) return; - ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { + if (project.isDisposed()) return; + myFuture = ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { @Override public void run() { - if (!myProject.isDisposed()) { + if (!project.isDisposed()) { execute(); } } @@ -55,7 +57,7 @@ public class VcsInitialization { }); } - public void add(final VcsInitObject vcsInitObject, final Runnable runnable) { + public void add(@NotNull final VcsInitObject vcsInitObject, @NotNull final Runnable runnable) { synchronized (myLock) { if (myInitStarted) { if (! vcsInitObject.isCanBeLast()) { @@ -76,12 +78,24 @@ public class VcsInitialization { myInitStarted = true; // list would not be modified starting from this point } Collections.sort(list, new Comparator>() { + @Override public int compare(Pair o1, Pair o2) { - return new Integer(o1.getFirst().getOrder()).compareTo(new Integer(o2.getFirst().getOrder())); + return o1.getFirst().getOrder() - o2.getFirst().getOrder(); } }); for (Pair pair : list) { pair.getSecond().run(); } } + + @TestOnly + public void waitForInitialized() { + try { + myFuture.get(); + myFuture = null; + } + catch (Exception e) { + throw new RuntimeException(e); + } + } } diff --git a/platform/vcs-impl/testSrc/com/intellij/openapi/vcs/VcsTestUtil.java b/platform/vcs-impl/testSrc/com/intellij/openapi/vcs/VcsTestUtil.java index 51b6fdd1226e..63f54a8c15b5 100644 --- a/platform/vcs-impl/testSrc/com/intellij/openapi/vcs/VcsTestUtil.java +++ b/platform/vcs-impl/testSrc/com/intellij/openapi/vcs/VcsTestUtil.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2014 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; import com.intellij.notification.Notification; @@ -54,24 +69,17 @@ public class VcsTestUtil { * @param name Name of the directory. * @return reference to the created or already existing directory. */ - public static VirtualFile createDir(@NotNull Project project, @NotNull final VirtualFile parent, @NotNull final String name) { - final Ref result = new Ref(); - new WriteCommandAction.Simple(project) { + public static VirtualFile createDir(@NotNull final Project project, @NotNull final VirtualFile parent, @NotNull final String name) { + return new WriteCommandAction(project) { @Override - protected void run() throws Throwable { - try { - VirtualFile dir = parent.findChild(name); - if (dir == null) { - dir = parent.createChildDirectory(this, name); - } - result.set(dir); - } - catch (IOException e) { - throw new RuntimeException(e); + protected void run(@NotNull Result result) throws Throwable { + VirtualFile dir = parent.findChild(name); + if (dir == null) { + dir = parent.createChildDirectory(this, name); } + result.setResult(dir); } - }.execute(); - return result.get(); + }.execute().throwException().getResultObject(); } public static void renameFileInCommand(@NotNull Project project, @NotNull final VirtualFile file, @NotNull final String newName) {