perforce tests fixed

This commit is contained in:
Alexey Kudravtsev
2014-04-23 12:48:35 +04:00
parent 46fea0f5d6
commit 60f2a36569
5 changed files with 71 additions and 36 deletions
@@ -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<PsiFile>() {
@Override
public PsiFile compute() {
return PsiManager.getInstance(getProject()).findFile(virtualFile[0]);
}
@@ -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<IdeaProjectTestFixture> 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() {
@@ -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();
}
}
@@ -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<Pair<VcsInitObject, Runnable>> myList;
private final List<Pair<VcsInitObject, Runnable>> myList = new ArrayList<Pair<VcsInitObject, Runnable>>();
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<Pair<VcsInitObject, Runnable>>();
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<Pair<VcsInitObject, Runnable>>() {
@Override
public int compare(Pair<VcsInitObject, Runnable> o1, Pair<VcsInitObject, Runnable> o2) {
return new Integer(o1.getFirst().getOrder()).compareTo(new Integer(o2.getFirst().getOrder()));
return o1.getFirst().getOrder() - o2.getFirst().getOrder();
}
});
for (Pair<VcsInitObject, Runnable> pair : list) {
pair.getSecond().run();
}
}
@TestOnly
public void waitForInitialized() {
try {
myFuture.get();
myFuture = null;
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
}
@@ -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<VirtualFile> result = new Ref<VirtualFile>();
new WriteCommandAction.Simple(project) {
public static VirtualFile createDir(@NotNull final Project project, @NotNull final VirtualFile parent, @NotNull final String name) {
return new WriteCommandAction<VirtualFile>(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<VirtualFile> 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) {