mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
call projectOpened()/projectClosed() for project components in tests to allow to
- avoid memleaks when something happens in projectOpened/Closed - make tests environment closer to production - simplify to setup test environment (no more manual projectOpened() calls) - simplify ProjectManager (no more myTestProjects)
This commit is contained in:
@@ -318,6 +318,8 @@ binding.setVariable("wireBuildDate", { String buildNumber, String appInfoFile ->
|
||||
binding.setVariable("commonJvmArgsForTests", {
|
||||
def jdwp = "-Xrunjdwp:transport=dt_socket,server=y,suspend=$debugSuspend"
|
||||
if (debugPort != null) jdwp += ",address=$debugPort"
|
||||
else jdwp += ",address=5555"
|
||||
|
||||
return [
|
||||
"-ea",
|
||||
"-Dio.netty.leakDetectionLevel=PARANOID",
|
||||
|
||||
@@ -232,21 +232,23 @@ public class BuildManager implements ApplicationComponent{
|
||||
return pathname.isDirectory() && !TEMP_DIR_NAME.equals(pathname.getName());
|
||||
}
|
||||
});
|
||||
final Date now = new Date();
|
||||
for (File buildDataProjectDir : dirs) {
|
||||
final File usageFile = getUsageFile(buildDataProjectDir);
|
||||
if (usageFile.exists()) {
|
||||
final Pair<Date, File> usageData = readUsageFile(usageFile);
|
||||
if (usageData != null) {
|
||||
final File projectFile = usageData.second;
|
||||
if ((projectFile != null && !projectFile.exists()) || DateFormatUtil.getDifferenceInDays(usageData.first, now) > unusedThresholdDays) {
|
||||
LOG.info("Clearing project build data because the project does not exist or was not opened for more than " + unusedThresholdDays + " days: " + buildDataProjectDir.getPath());
|
||||
FileUtil.delete(buildDataProjectDir);
|
||||
if (dirs != null) {
|
||||
final Date now = new Date();
|
||||
for (File buildDataProjectDir : dirs) {
|
||||
final File usageFile = getUsageFile(buildDataProjectDir);
|
||||
if (usageFile.exists()) {
|
||||
final Pair<Date, File> usageData = readUsageFile(usageFile);
|
||||
if (usageData != null) {
|
||||
final File projectFile = usageData.second;
|
||||
if ((projectFile != null && !projectFile.exists()) || DateFormatUtil.getDifferenceInDays(usageData.first, now) > unusedThresholdDays) {
|
||||
LOG.info("Clearing project build data because the project does not exist or was not opened for more than " + unusedThresholdDays + " days: " + buildDataProjectDir.getPath());
|
||||
FileUtil.delete(buildDataProjectDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
updateUsageFile(null, buildDataProjectDir); // set usage stamp to start countdown
|
||||
else {
|
||||
updateUsageFile(null, buildDataProjectDir); // set usage stamp to start countdown
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1443,6 +1445,7 @@ public class BuildManager implements ApplicationComponent{
|
||||
|
||||
@Override
|
||||
public void projectOpened(final Project project) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) return;
|
||||
final MessageBusConnection conn = project.getMessageBus().connect();
|
||||
myConnections.put(project, conn);
|
||||
conn.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootAdapter() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -21,7 +21,6 @@ import com.intellij.codeInsight.navigation.ClassImplementationsSearch;
|
||||
import com.intellij.codeInsight.navigation.MethodImplementationsSearch;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.module.impl.ModuleManagerImpl;
|
||||
import com.intellij.openapi.project.ex.ProjectManagerEx;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
@@ -58,19 +57,11 @@ public class GotoImplementationTest extends CodeInsightTestCase {
|
||||
VirtualFile projectFile = vfsRoot.findChild("test.ipr");
|
||||
myProject = ProjectManagerEx.getInstanceEx().loadProject(projectFile.getPath());
|
||||
|
||||
simulateProjectOpen();
|
||||
ProjectManagerEx.getInstanceEx().openTestProject(myProject);
|
||||
UIUtil.dispatchAllInvocationEvents(); // startup activities
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
((ModuleManagerImpl)ModuleManager.getInstance(myProject)).projectClosed();
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void test() throws Exception {
|
||||
|
||||
ModuleManager moduleManager = ModuleManager.getInstance(getProject());
|
||||
Module[] modules = moduleManager.getModules();
|
||||
assertEquals(3, modules.length);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.roots;
|
||||
|
||||
import com.intellij.ProjectTopics;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ex.PathManagerEx;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
@@ -33,6 +34,7 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.ModuleTestCase;
|
||||
import com.intellij.util.messages.MessageBusConnection;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -41,21 +43,19 @@ import java.io.IOException;
|
||||
* @author dsl
|
||||
*/
|
||||
public class RootsChangedTest extends ModuleTestCase {
|
||||
private MessageBusConnection myConnection;
|
||||
private MyModuleRootListener myModuleRootListener;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myConnection = myProject.getMessageBus().connect();
|
||||
MessageBusConnection connection = myProject.getMessageBus().connect(myTestRootDisposable);
|
||||
myModuleRootListener = new MyModuleRootListener();
|
||||
myConnection.subscribe(ProjectTopics.PROJECT_ROOTS, myModuleRootListener);
|
||||
connection.subscribe(ProjectTopics.PROJECT_ROOTS, myModuleRootListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
myConnection.disconnect();
|
||||
super.tearDown();
|
||||
protected boolean isRunInWriteAction() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void testEventsAfterFileModifications() throws Exception {
|
||||
@@ -70,11 +70,12 @@ public class RootsChangedTest extends ModuleTestCase {
|
||||
myModuleRootListener.reset();
|
||||
|
||||
ModuleRootModificationUtil.addContentRoot(moduleA, vDir1.getPath());
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
|
||||
assertEventsCount(1);
|
||||
assertSameElements(ModuleRootManager.getInstance(moduleA).getContentRoots(), vDir1);
|
||||
|
||||
vDir1.delete(null);
|
||||
delete(vDir1);
|
||||
assertEventsCount(1);
|
||||
assertEmpty(ModuleRootManager.getInstance(moduleA).getContentRoots());
|
||||
|
||||
@@ -83,12 +84,12 @@ public class RootsChangedTest extends ModuleTestCase {
|
||||
VirtualFile vDir2 = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(dir2);
|
||||
assertNotNull(vDir2);
|
||||
|
||||
vDir2.rename(null, "dir1");
|
||||
rename(vDir2, "dir1");
|
||||
assertEventsCount(1);
|
||||
assertSameElements(ModuleRootManager.getInstance(moduleA).getContentRoots(), vDir2);
|
||||
|
||||
// when the existing root is renamed, it remains a root
|
||||
vDir2.rename(null, "dir2");
|
||||
rename(vDir2, "dir2");
|
||||
assertEventsCount(0);
|
||||
assertSameElements(ModuleRootManager.getInstance(moduleA).getContentRoots(), vDir2);
|
||||
|
||||
@@ -98,7 +99,7 @@ public class RootsChangedTest extends ModuleTestCase {
|
||||
VirtualFile vSubdir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(subdir);
|
||||
assertNotNull(vSubdir);
|
||||
|
||||
vDir2.move(null, vSubdir);
|
||||
move(vDir2, vSubdir);
|
||||
assertEventsCount(0);
|
||||
assertSameElements(ModuleRootManager.getInstance(moduleA).getContentRoots(), vDir2);
|
||||
}
|
||||
@@ -124,85 +125,105 @@ public class RootsChangedTest extends ModuleTestCase {
|
||||
}
|
||||
|
||||
public void testEditLibraryForModuleLoadFromXml() throws IOException {
|
||||
File moduleFile = PathManagerEx.findFileUnderProjectHome("java/java-tests/testData/moduleRootManager/rootsChanged/emptyModule/a.iml", getClass());
|
||||
Module a = loadModule(moduleFile, true);
|
||||
assertEventsCount(1);
|
||||
final File tempDirectory = createTempDirectory();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
File moduleFile =
|
||||
PathManagerEx.findFileUnderProjectHome("java/java-tests/testData/moduleRootManager/rootsChanged/emptyModule/a.iml", RootsChangedTest.this.getClass());
|
||||
Module a = loadModule(moduleFile, true);
|
||||
assertEventsCount(1);
|
||||
|
||||
final Sdk jdk = IdeaTestUtil.getMockJdk17();
|
||||
ProjectJdkTable.getInstance().addJdk(jdk);
|
||||
assertEventsCount(0);
|
||||
final Sdk jdk = IdeaTestUtil.getMockJdk17();
|
||||
ProjectJdkTable.getInstance().addJdk(jdk);
|
||||
assertEventsCount(0);
|
||||
|
||||
ModuleRootModificationUtil.setModuleSdk(a, jdk);
|
||||
assertEventsCount(1);
|
||||
ModuleRootModificationUtil.setModuleSdk(a, jdk);
|
||||
assertEventsCount(1);
|
||||
|
||||
final SdkModificator sdkModificator = jdk.getSdkModificator();
|
||||
sdkModificator.addRoot(getVirtualFile(tempDirectory), OrderRootType.CLASSES);
|
||||
sdkModificator.commitChanges();
|
||||
}
|
||||
});
|
||||
|
||||
final SdkModificator sdkModificator = jdk.getSdkModificator();
|
||||
sdkModificator.addRoot(getVirtualFile(createTempDirectory()), OrderRootType.CLASSES);
|
||||
sdkModificator.commitChanges();
|
||||
assertEventsCount(1);
|
||||
}
|
||||
|
||||
public void testModuleJdkEditing() throws Exception {
|
||||
final Module moduleA = createModule("a.iml");
|
||||
final Module moduleB = createModule("b.iml");
|
||||
assertEventsCount(2);
|
||||
final File tempDirectory = createTempDirectory();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Module moduleA = createModule("a.iml");
|
||||
final Module moduleB = createModule("b.iml");
|
||||
assertEventsCount(2);
|
||||
|
||||
final Sdk jdk = IdeaTestUtil.getMockJdk17();
|
||||
ProjectJdkTable.getInstance().addJdk(jdk);
|
||||
assertEventsCount(0);
|
||||
final Sdk jdk = IdeaTestUtil.getMockJdk17();
|
||||
ProjectJdkTable.getInstance().addJdk(jdk);
|
||||
assertEventsCount(0);
|
||||
|
||||
final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
|
||||
final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
|
||||
rootModelA.setSdk(jdk);
|
||||
rootModelB.setSdk(jdk);
|
||||
ModifiableRootModel[] rootModels = new ModifiableRootModel[]{rootModelA, rootModelB};
|
||||
ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel());
|
||||
assertEventsCount(1);
|
||||
final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
|
||||
final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
|
||||
rootModelA.setSdk(jdk);
|
||||
rootModelB.setSdk(jdk);
|
||||
ModifiableRootModel[] rootModels = new ModifiableRootModel[]{rootModelA, rootModelB};
|
||||
ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel());
|
||||
assertEventsCount(1);
|
||||
|
||||
final SdkModificator sdkModificator = jdk.getSdkModificator();
|
||||
sdkModificator.addRoot(getVirtualFile(createTempDirectory()), OrderRootType.CLASSES);
|
||||
sdkModificator.commitChanges();
|
||||
assertEventsCount(1);
|
||||
final SdkModificator sdkModificator = jdk.getSdkModificator();
|
||||
sdkModificator.addRoot(getVirtualFile(tempDirectory), OrderRootType.CLASSES);
|
||||
sdkModificator.commitChanges();
|
||||
assertEventsCount(1);
|
||||
|
||||
ProjectJdkTable.getInstance().removeJdk(jdk);
|
||||
assertEventsCount(1);
|
||||
ProjectJdkTable.getInstance().removeJdk(jdk);
|
||||
assertEventsCount(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testInheritedJdkEditing() throws Exception {
|
||||
final Module moduleA = createModule("a.iml");
|
||||
final Module moduleB = createModule("b.iml");
|
||||
assertEventsCount(2);
|
||||
final File tempDirectory = createTempDirectory();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Module moduleA = createModule("a.iml");
|
||||
final Module moduleB = createModule("b.iml");
|
||||
assertEventsCount(2);
|
||||
|
||||
final Sdk jdk = IdeaTestUtil.getMockJdk17("AAA");
|
||||
ProjectJdkTable.getInstance().addJdk(jdk);
|
||||
assertEventsCount(0);
|
||||
final Sdk jdk = IdeaTestUtil.getMockJdk17("AAA");
|
||||
ProjectJdkTable.getInstance().addJdk(jdk);
|
||||
assertEventsCount(0);
|
||||
|
||||
final Sdk jdkBBB = IdeaTestUtil.getMockJdk17("BBB");
|
||||
ProjectJdkTable.getInstance().addJdk(jdk);
|
||||
assertEventsCount(0);
|
||||
final Sdk jdkBBB = IdeaTestUtil.getMockJdk17("BBB");
|
||||
ProjectJdkTable.getInstance().addJdk(jdk);
|
||||
assertEventsCount(0);
|
||||
|
||||
ProjectRootManager.getInstance(myProject).setProjectSdk(jdkBBB);
|
||||
assertEventsCount(0);
|
||||
ProjectRootManager.getInstance(myProject).setProjectSdk(jdkBBB);
|
||||
assertEventsCount(0);
|
||||
|
||||
final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
|
||||
final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
|
||||
rootModelA.inheritSdk();
|
||||
rootModelB.inheritSdk();
|
||||
ModifiableRootModel[] rootModels = new ModifiableRootModel[]{rootModelA, rootModelB};
|
||||
if (rootModels.length > 0) {
|
||||
ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel());
|
||||
}
|
||||
assertEventsCount(1);
|
||||
final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
|
||||
final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
|
||||
rootModelA.inheritSdk();
|
||||
rootModelB.inheritSdk();
|
||||
ModifiableRootModel[] rootModels = new ModifiableRootModel[]{rootModelA, rootModelB};
|
||||
if (rootModels.length > 0) {
|
||||
ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel());
|
||||
}
|
||||
assertEventsCount(1);
|
||||
|
||||
ProjectRootManager.getInstance(myProject).setProjectSdk(jdk);
|
||||
assertEventsCount(1);
|
||||
ProjectRootManager.getInstance(myProject).setProjectSdk(jdk);
|
||||
assertEventsCount(1);
|
||||
|
||||
final SdkModificator sdkModificator = jdk.getSdkModificator();
|
||||
sdkModificator.addRoot(getVirtualFile(createTempDirectory()), OrderRootType.CLASSES);
|
||||
sdkModificator.commitChanges();
|
||||
assertEventsCount(1);
|
||||
final SdkModificator sdkModificator = jdk.getSdkModificator();
|
||||
sdkModificator.addRoot(getVirtualFile(tempDirectory), OrderRootType.CLASSES);
|
||||
sdkModificator.commitChanges();
|
||||
assertEventsCount(1);
|
||||
|
||||
ProjectJdkTable.getInstance().removeJdk(jdk);
|
||||
assertEventsCount(1);
|
||||
ProjectJdkTable.getInstance().removeJdk(jdk);
|
||||
assertEventsCount(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void verifyLibraryTableEditing(final LibraryTable libraryTable) throws IOException {
|
||||
@@ -210,86 +231,103 @@ public class RootsChangedTest extends ModuleTestCase {
|
||||
final Module moduleB = createModule("b.iml");
|
||||
assertEventsCount(2);
|
||||
|
||||
final Library libraryA = libraryTable.createLibrary("A");
|
||||
final Library.ModifiableModel libraryModifiableModel = libraryA.getModifiableModel();
|
||||
libraryModifiableModel.addRoot("file:///a", OrderRootType.CLASSES);
|
||||
libraryModifiableModel.commit();
|
||||
assertEventsCount(0);
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Library libraryA = libraryTable.createLibrary("A");
|
||||
final Library.ModifiableModel libraryModifiableModel = libraryA.getModifiableModel();
|
||||
libraryModifiableModel.addRoot("file:///a", OrderRootType.CLASSES);
|
||||
libraryModifiableModel.commit();
|
||||
assertEventsCount(0);
|
||||
|
||||
final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
|
||||
final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
|
||||
rootModelA.addLibraryEntry(libraryA);
|
||||
rootModelB.addLibraryEntry(libraryA);
|
||||
rootModelA.addInvalidLibrary("Q", libraryTable.getTableLevel());
|
||||
rootModelB.addInvalidLibrary("Q", libraryTable.getTableLevel());
|
||||
ModifiableRootModel[] rootModels = new ModifiableRootModel[]{rootModelA, rootModelB};
|
||||
if (rootModels.length > 0) {
|
||||
ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel());
|
||||
}
|
||||
assertEventsCount(1);
|
||||
final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
|
||||
final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
|
||||
rootModelA.addLibraryEntry(libraryA);
|
||||
rootModelB.addLibraryEntry(libraryA);
|
||||
rootModelA.addInvalidLibrary("Q", libraryTable.getTableLevel());
|
||||
rootModelB.addInvalidLibrary("Q", libraryTable.getTableLevel());
|
||||
ModifiableRootModel[] rootModels = new ModifiableRootModel[]{rootModelA, rootModelB};
|
||||
if (rootModels.length > 0) {
|
||||
ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel());
|
||||
}
|
||||
assertEventsCount(1);
|
||||
|
||||
final Library.ModifiableModel libraryModifiableModel2 = libraryA.getModifiableModel();
|
||||
final File tmpDir = FileUtil.createTempDirectory(getTestName(true), "");
|
||||
try {
|
||||
final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tmpDir);
|
||||
assertNotNull(file);
|
||||
|
||||
libraryModifiableModel2.addRoot(file.getUrl(), OrderRootType.CLASSES);
|
||||
libraryModifiableModel2.commit();
|
||||
assertEventsCount(1);
|
||||
}
|
||||
finally {
|
||||
FileUtil.delete(tmpDir);
|
||||
}
|
||||
final Library.ModifiableModel libraryModifiableModel2 = libraryA.getModifiableModel();
|
||||
final File tmpDir;
|
||||
try {
|
||||
tmpDir = FileUtil.createTempDirectory(getTestName(true), "");
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
libraryTable.removeLibrary(libraryA);
|
||||
assertEventsCount(1);
|
||||
try {
|
||||
final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tmpDir);
|
||||
assertNotNull(file);
|
||||
|
||||
final Library libraryQ = libraryTable.createLibrary("Q");
|
||||
assertEventsCount(1);
|
||||
libraryModifiableModel2.addRoot(file.getUrl(), OrderRootType.CLASSES);
|
||||
libraryModifiableModel2.commit();
|
||||
assertEventsCount(1);
|
||||
}
|
||||
finally {
|
||||
FileUtil.delete(tmpDir);
|
||||
}
|
||||
|
||||
libraryTable.removeLibrary(libraryQ);
|
||||
assertEventsCount(1);
|
||||
libraryTable.removeLibrary(libraryA);
|
||||
assertEventsCount(1);
|
||||
|
||||
final Library libraryQ = libraryTable.createLibrary("Q");
|
||||
assertEventsCount(1);
|
||||
|
||||
libraryTable.removeLibrary(libraryQ);
|
||||
assertEventsCount(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void verifyLibraryTableEditingInUncommittedModel(final LibraryTable libraryTable) {
|
||||
final Module moduleA = createModule("a.iml");
|
||||
final Module moduleB = createModule("b.iml");
|
||||
assertEventsCount(2);
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Module moduleA = createModule("a.iml");
|
||||
final Module moduleB = createModule("b.iml");
|
||||
assertEventsCount(2);
|
||||
|
||||
final Library libraryA = libraryTable.createLibrary("A");
|
||||
final Library.ModifiableModel libraryModifiableModel = libraryA.getModifiableModel();
|
||||
libraryModifiableModel.addRoot("file:///a", OrderRootType.CLASSES);
|
||||
libraryModifiableModel.commit();
|
||||
assertEventsCount(0);
|
||||
final Library libraryA = libraryTable.createLibrary("A");
|
||||
final Library.ModifiableModel libraryModifiableModel = libraryA.getModifiableModel();
|
||||
libraryModifiableModel.addRoot("file:///a", OrderRootType.CLASSES);
|
||||
libraryModifiableModel.commit();
|
||||
assertEventsCount(0);
|
||||
|
||||
final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
|
||||
final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
|
||||
rootModelA.addLibraryEntry(libraryA);
|
||||
rootModelB.addLibraryEntry(libraryA);
|
||||
final Library.ModifiableModel libraryModifiableModel2 = libraryA.getModifiableModel();
|
||||
libraryModifiableModel2.addRoot("file:///b", OrderRootType.CLASSES);
|
||||
libraryModifiableModel2.commit();
|
||||
assertEventsCount(0);
|
||||
final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
|
||||
final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
|
||||
rootModelA.addLibraryEntry(libraryA);
|
||||
rootModelB.addLibraryEntry(libraryA);
|
||||
final Library.ModifiableModel libraryModifiableModel2 = libraryA.getModifiableModel();
|
||||
libraryModifiableModel2.addRoot("file:///b", OrderRootType.CLASSES);
|
||||
libraryModifiableModel2.commit();
|
||||
assertEventsCount(0);
|
||||
|
||||
libraryTable.removeLibrary(libraryA);
|
||||
assertEventsCount(0);
|
||||
libraryTable.removeLibrary(libraryA);
|
||||
assertEventsCount(0);
|
||||
|
||||
rootModelA.addInvalidLibrary("Q", libraryTable.getTableLevel());
|
||||
rootModelB.addInvalidLibrary("Q", libraryTable.getTableLevel());
|
||||
assertEventsCount(0);
|
||||
rootModelA.addInvalidLibrary("Q", libraryTable.getTableLevel());
|
||||
rootModelB.addInvalidLibrary("Q", libraryTable.getTableLevel());
|
||||
assertEventsCount(0);
|
||||
|
||||
final Library libraryQ = libraryTable.createLibrary("Q");
|
||||
assertEventsCount(0);
|
||||
final Library libraryQ = libraryTable.createLibrary("Q");
|
||||
assertEventsCount(0);
|
||||
|
||||
ModifiableRootModel[] rootModels = new ModifiableRootModel[]{rootModelA, rootModelB};
|
||||
if (rootModels.length > 0) {
|
||||
ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel());
|
||||
}
|
||||
assertEventsCount(1);
|
||||
ModifiableRootModel[] rootModels = new ModifiableRootModel[]{rootModelA, rootModelB};
|
||||
if (rootModels.length > 0) {
|
||||
ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel());
|
||||
}
|
||||
assertEventsCount(1);
|
||||
|
||||
libraryTable.removeLibrary(libraryQ);
|
||||
assertEventsCount(1);
|
||||
libraryTable.removeLibrary(libraryQ);
|
||||
assertEventsCount(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void assertEventsCount(int count) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -29,45 +29,52 @@ import java.io.File;
|
||||
* Date: 4/9/12
|
||||
*/
|
||||
public class UnscrambleDialogTest extends JavaCodeInsightFixtureTestCase {
|
||||
private RunContentDescriptor myContent;
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
Disposer.dispose(myContent);
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testStacktrace() throws Exception {
|
||||
RunContentDescriptor content = showText("");
|
||||
Icon icon = content.getIcon();
|
||||
String name = content.getDisplayName();
|
||||
showText("");
|
||||
Icon icon = myContent.getIcon();
|
||||
String name = myContent.getDisplayName();
|
||||
assertEquals(null, icon);
|
||||
assertEquals("<Stacktrace>", name);
|
||||
}
|
||||
|
||||
public void testException() throws Exception {
|
||||
RunContentDescriptor content = showText("java.lang.NullPointerException\n" +
|
||||
showText("java.lang.NullPointerException\n" +
|
||||
"\tat com.intellij.psi.css.resolve.impl.XhtmlFileInfo.findOneStyleSheet(XhtmlFileInfo.java:291)\n" +
|
||||
"\tat com.intellij.psi.css.resolve.impl.XhtmlFileInfo.getStylesheets(XhtmlFileInfo.java:174)\n" +
|
||||
"\tat com.intellij.psi.css.resolve.impl.XhtmlFileInfo.initStylesheets(XhtmlFileInfo.java:119)");
|
||||
assertIcon("exception.png", content.getIcon());
|
||||
assertEquals("NPE", content.getDisplayName());
|
||||
assertIcon("exception.png", myContent.getIcon());
|
||||
assertEquals("NPE", myContent.getDisplayName());
|
||||
}
|
||||
|
||||
public void testThreadDump() throws Exception {
|
||||
File file = new File(getTestDataPath() + "threaddump.txt");
|
||||
String s = FileUtil.loadFile(file);
|
||||
RunContentDescriptor content = showText(s);
|
||||
assertIcon("threaddump.png", content.getIcon());
|
||||
assertEquals("<Threads>", content.getDisplayName());
|
||||
showText(s);
|
||||
assertIcon("threaddump.png", myContent.getIcon());
|
||||
assertEquals("<Threads>", myContent.getDisplayName());
|
||||
}
|
||||
|
||||
public void testDeadlock() throws Exception {
|
||||
File file = new File(getTestDataPath() + "deadlock.txt");
|
||||
String s = FileUtil.loadFile(file);
|
||||
RunContentDescriptor content = showText(s);
|
||||
assertIcon("killProcess.png", content.getIcon());
|
||||
assertEquals("<Deadlock>", content.getDisplayName());
|
||||
showText(s);
|
||||
assertIcon("killProcess.png", myContent.getIcon());
|
||||
assertEquals("<Deadlock>", myContent.getDisplayName());
|
||||
}
|
||||
|
||||
private RunContentDescriptor showText(String unscramble) {
|
||||
private void showText(String unscramble) {
|
||||
RunContentDescriptor descriptor = UnscrambleDialog.showUnscrambledText(null, "foo", getProject(), unscramble);
|
||||
assertNotNull(descriptor);
|
||||
Disposer.register(myModule, descriptor);
|
||||
return descriptor;
|
||||
Disposer.register(getTestRootDisposable(), descriptor);
|
||||
myContent = descriptor;
|
||||
}
|
||||
|
||||
private static void assertIcon(String s, Icon icon) {
|
||||
|
||||
+61
-53
@@ -22,6 +22,7 @@ import com.intellij.ide.AppLifecycleListener;
|
||||
import com.intellij.ide.RecentProjectsManager;
|
||||
import com.intellij.ide.impl.ProjectUtil;
|
||||
import com.intellij.ide.plugins.PluginManager;
|
||||
import com.intellij.ide.startup.StartupManagerEx;
|
||||
import com.intellij.ide.startup.impl.StartupManagerImpl;
|
||||
import com.intellij.notification.Notification;
|
||||
import com.intellij.notification.NotificationListener;
|
||||
@@ -91,12 +92,10 @@ public class ProjectManagerImpl extends ProjectManagerEx implements PersistentSt
|
||||
private Element myDefaultProjectRootElement; // Only used asynchronously in save and dispose, which itself are synchronized.
|
||||
private boolean myDefaultProjectConfigurationChanged;
|
||||
|
||||
private final List<Project> myOpenProjects = new ArrayList<Project>();
|
||||
private Project[] myOpenProjectsArrayCache = {};
|
||||
private Project[] myOpenProjects = {}; // guarded by lock
|
||||
private final Object lock = new Object();
|
||||
private final List<ProjectManagerListener> myListeners = ContainerUtil.createLockFreeCopyOnWriteList();
|
||||
|
||||
private final Set<Project> myTestProjects = new THashSet<Project>();
|
||||
|
||||
private final MultiMap<Project, Pair<VirtualFile, StateStorage>> myChangedProjectFiles = MultiMap.createWeakSet(); //guarded by myChangedProjectFiles
|
||||
private final SingleAlarm myChangedFilesAlarm;
|
||||
private final List<Pair<VirtualFile, StateStorage>> myChangedApplicationFiles = new SmartList<Pair<VirtualFile, StateStorage>>();
|
||||
@@ -413,35 +412,28 @@ public class ProjectManagerImpl extends ProjectManagerEx implements PersistentSt
|
||||
@Override
|
||||
@NotNull
|
||||
public Project[] getOpenProjects() {
|
||||
synchronized (myOpenProjects) {
|
||||
if (myOpenProjectsArrayCache.length != myOpenProjects.size()) {
|
||||
LOG.error("Open projects: " + myOpenProjects + "; cache: " + Arrays.asList(myOpenProjectsArrayCache));
|
||||
}
|
||||
if (myOpenProjectsArrayCache.length > 0 && myOpenProjectsArrayCache[0] != myOpenProjects.get(0)) {
|
||||
LOG.error("Open projects cache corrupted. Open projects: " + myOpenProjects + "; cache: " + Arrays.asList(myOpenProjectsArrayCache));
|
||||
}
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
Project[] testProjects = myTestProjects.toArray(new Project[myTestProjects.size()]);
|
||||
for (Project testProject : testProjects) {
|
||||
assert !testProject.isDisposed() : testProject;
|
||||
}
|
||||
return ArrayUtil.mergeArrays(myOpenProjectsArrayCache, testProjects);
|
||||
}
|
||||
return myOpenProjectsArrayCache;
|
||||
synchronized (lock) {
|
||||
return myOpenProjects;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProjectOpened(Project project) {
|
||||
synchronized (myOpenProjects) {
|
||||
return ApplicationManager.getApplication().isUnitTestMode() && myTestProjects.contains(project) || myOpenProjects.contains(project);
|
||||
synchronized (lock) {
|
||||
return ArrayUtil.contains(project, myOpenProjects);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean openProject(@NotNull final Project project) {
|
||||
if (isLight(project)) {
|
||||
throw new AssertionError("must not open light project");
|
||||
((ProjectImpl)project).setTemporarilyDisposed(false);
|
||||
boolean isInitialized = StartupManagerEx.getInstanceEx(project).startupActivityPassed();
|
||||
if (isInitialized) {
|
||||
addToOpened(project);
|
||||
// events already fired
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
final Application application = ApplicationManager.getApplication();
|
||||
@@ -449,13 +441,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements PersistentSt
|
||||
return false;
|
||||
}
|
||||
|
||||
synchronized (myOpenProjects) {
|
||||
if (myOpenProjects.contains(project)) {
|
||||
return false;
|
||||
}
|
||||
myOpenProjects.add(project);
|
||||
cacheOpenProjects();
|
||||
}
|
||||
if (!addToOpened(project)) return false;
|
||||
|
||||
fireProjectOpened(project);
|
||||
DumbService.getInstance(project).queueTask(new DumbModeTask() {
|
||||
@@ -521,15 +507,30 @@ public class ProjectManagerImpl extends ProjectManagerEx implements PersistentSt
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean addToOpened(@NotNull Project project) {
|
||||
assert !project.isDisposed() : "Must not open already disposed project";
|
||||
synchronized (lock) {
|
||||
if (isProjectOpened(project)) {
|
||||
return false;
|
||||
}
|
||||
myOpenProjects = ArrayUtil.append(myOpenProjects, project);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<Project> removeFromOpened(@NotNull Project project) {
|
||||
synchronized (lock) {
|
||||
myOpenProjects = ArrayUtil.remove(myOpenProjects, project);
|
||||
return Arrays.asList(myOpenProjects);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean canCancelProjectLoading() {
|
||||
ProgressIndicator indicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
|
||||
return !(indicator instanceof NonCancelableSection);
|
||||
}
|
||||
|
||||
private void cacheOpenProjects() {
|
||||
myOpenProjectsArrayCache = myOpenProjects.toArray(new Project[myOpenProjects.size()]);
|
||||
}
|
||||
|
||||
private static void waitForFileWatcher(@NotNull ProgressIndicator indicator) {
|
||||
LocalFileSystem fs = LocalFileSystem.getInstance();
|
||||
if (!(fs instanceof LocalFileSystemImpl)) return;
|
||||
@@ -727,22 +728,20 @@ public class ProjectManagerImpl extends ProjectManagerEx implements PersistentSt
|
||||
}
|
||||
|
||||
@Override
|
||||
@TestOnly
|
||||
public void openTestProject(@NotNull final Project project) {
|
||||
synchronized (myOpenProjects) {
|
||||
assert ApplicationManager.getApplication().isUnitTestMode();
|
||||
assert !project.isDisposed() : "Must not open already disposed project";
|
||||
myTestProjects.add(project);
|
||||
}
|
||||
assert ApplicationManager.getApplication().isUnitTestMode();
|
||||
openProject(project);
|
||||
UIUtil.dispatchAllInvocationEvents(); // post init activities are invokeLatered
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<Project> closeTestProject(@NotNull Project project) {
|
||||
synchronized (myOpenProjects) {
|
||||
assert ApplicationManager.getApplication().isUnitTestMode();
|
||||
myTestProjects.remove(project);
|
||||
return myTestProjects;
|
||||
}
|
||||
@TestOnly
|
||||
public Collection<Project> closeTestProject(@NotNull final Project project) {
|
||||
assert ApplicationManager.getApplication().isUnitTestMode();
|
||||
closeProject(project);
|
||||
return Arrays.asList(getOpenProjects());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -821,16 +820,29 @@ public class ProjectManagerImpl extends ProjectManagerEx implements PersistentSt
|
||||
|
||||
public boolean closeProject(@NotNull final Project project, final boolean save, final boolean dispose, boolean checkCanClose) {
|
||||
if (isLight(project)) {
|
||||
throw new AssertionError("must not close light project");
|
||||
// if we close project at the end of the test, just mark it closed; if we are shutting down the entire test framework, proceed to full dispose
|
||||
if (!((ProjectImpl)project).isTemporarilyDisposed()) {
|
||||
((ProjectImpl)project).setTemporarilyDisposed(true);
|
||||
removeFromOpened(project);
|
||||
return true;
|
||||
}
|
||||
((ProjectImpl)project).setTemporarilyDisposed(false);
|
||||
}
|
||||
else {
|
||||
if (!isProjectOpened(project)) return true;
|
||||
}
|
||||
if (!isProjectOpened(project)) return true;
|
||||
if (checkCanClose && !canClose(project)) return false;
|
||||
final ShutDownTracker shutDownTracker = ShutDownTracker.getInstance();
|
||||
shutDownTracker.registerStopperThread(Thread.currentThread());
|
||||
try {
|
||||
if (save) {
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
project.save();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
project.save();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (checkCanClose && !ensureCouldCloseIfUnableToSave(project)) {
|
||||
@@ -842,11 +854,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements PersistentSt
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (myOpenProjects) {
|
||||
myOpenProjects.remove(project);
|
||||
cacheOpenProjects();
|
||||
myTestProjects.remove(project);
|
||||
}
|
||||
removeFromOpened(project);
|
||||
|
||||
synchronized (myChangedProjectFiles) {
|
||||
myChangedProjectFiles.remove(project);
|
||||
|
||||
+3
-5
@@ -30,6 +30,7 @@ import com.intellij.openapi.module.EmptyModuleType;
|
||||
import com.intellij.openapi.module.ModifiableModuleModel;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.project.ex.ProjectManagerEx;
|
||||
import com.intellij.openapi.roots.ContentEntry;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||
@@ -55,6 +56,7 @@ public class NonProjectFileAccessTest extends HeavyFileEditorManagerTestCase {
|
||||
EditorNotifications notifications = new EditorNotificationsImpl(getProject());
|
||||
((ComponentManagerImpl)getProject()).registerComponentInstance(EditorNotifications.class, notifications);
|
||||
NonProjectFileWritingAccessProvider.enableChecksInTests(getProject(), true);
|
||||
ProjectManagerEx.getInstanceEx().blockReloadingProjectOnExternalChanges();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,11 +64,7 @@ public class NonProjectFileAccessTest extends HeavyFileEditorManagerTestCase {
|
||||
NonProjectFileWritingAccessProvider.setCustomUnlocker(null);
|
||||
NonProjectFileWritingAccessProvider.enableChecksInTests(getProject(), false);
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean runInDispatchThread() {
|
||||
return true;
|
||||
ProjectManagerEx.getInstanceEx().unblockReloadingProjectOnExternalChanges(); // unblock only after project is disposed
|
||||
}
|
||||
|
||||
public void testBasicAccessCheck() throws Exception {
|
||||
|
||||
@@ -18,7 +18,6 @@ package com.intellij.testFramework;
|
||||
import com.intellij.ProjectTopics;
|
||||
import com.intellij.codeInsight.completion.CompletionProgressIndicator;
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInsight.daemon.impl.EditorTracker;
|
||||
import com.intellij.codeInsight.hint.HintManager;
|
||||
import com.intellij.codeInsight.hint.HintManagerImpl;
|
||||
import com.intellij.codeInsight.lookup.LookupManager;
|
||||
@@ -61,7 +60,6 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.project.ex.ProjectEx;
|
||||
import com.intellij.openapi.project.ex.ProjectManagerEx;
|
||||
import com.intellij.openapi.project.impl.ProjectImpl;
|
||||
import com.intellij.openapi.project.impl.ProjectManagerImpl;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.*;
|
||||
@@ -309,18 +307,6 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
|
||||
descriptor.configureModule(ourModule, model, contentEntry);
|
||||
}
|
||||
});
|
||||
|
||||
MessageBusConnection connection = ourProject.getMessageBus().connect();
|
||||
connection.subscribe(ProjectTopics.MODULES, new ModuleAdapter() {
|
||||
@Override
|
||||
public void moduleAdded(@NotNull Project project, @NotNull Module module) {
|
||||
fail("Adding modules is not permitted in LightIdeaTestCase.");
|
||||
}
|
||||
});
|
||||
|
||||
StartupManagerImpl startupManager = (StartupManagerImpl)StartupManager.getInstance(ourProject);
|
||||
startupManager.runStartupActivities();
|
||||
startupManager.startCacheUpdate();
|
||||
}
|
||||
|
||||
private void cleanSourceRoot() throws IOException {
|
||||
@@ -394,13 +380,19 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
|
||||
ApplicationManager.getApplication().assertIsDispatchThread();
|
||||
if (ourProject == null || ourProjectDescriptor == null || !ourProjectDescriptor.equals(descriptor)) {
|
||||
initProject(descriptor);
|
||||
ourProject.getComponent(EditorTracker.class).projectOpened();
|
||||
}
|
||||
((ProjectImpl)ourProject).setTemporarilyDisposed(false);
|
||||
|
||||
ProjectManagerEx projectManagerEx = ProjectManagerEx.getInstanceEx();
|
||||
projectManagerEx.openTestProject(ourProject);
|
||||
|
||||
MessageBusConnection connection = ourProject.getMessageBus().connect(parentDisposable);
|
||||
connection.subscribe(ProjectTopics.MODULES, new ModuleAdapter() {
|
||||
@Override
|
||||
public void moduleAdded(@NotNull Project project, @NotNull Module module) {
|
||||
fail("Adding modules is not permitted in LightIdeaTestCase.");
|
||||
}
|
||||
});
|
||||
|
||||
clearUncommittedDocuments(getProject());
|
||||
|
||||
CodeInsightTestFixtureImpl.configureInspections(localInspectionTools, getProject(),
|
||||
@@ -596,11 +588,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
|
||||
if (checkForEditors) {
|
||||
checkEditorsReleased();
|
||||
}
|
||||
if (isLight(project)) {
|
||||
// mark temporarily as disposed so that rogue component trying to access it will fail
|
||||
((ProjectImpl)project).setTemporarilyDisposed(true);
|
||||
documentManager.clearUncommittedDocuments();
|
||||
}
|
||||
documentManager.clearUncommittedDocuments();
|
||||
}
|
||||
|
||||
public static PsiDocumentManagerImpl clearUncommittedDocuments(@NotNull Project project) {
|
||||
@@ -781,7 +769,6 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
|
||||
if (ourProject != null) {
|
||||
ApplicationManager.getApplication().assertWriteAccessAllowed();
|
||||
|
||||
((ProjectImpl)ourProject).setTemporarilyDisposed(false);
|
||||
if (!ourProject.isDisposed()) {
|
||||
VirtualFile projectFile = ((ProjectEx)ourProject).getStateStore().getProjectFile();
|
||||
File ioFile = projectFile == null ? null : VfsUtilCore.virtualToIoFile(projectFile);
|
||||
@@ -797,8 +784,8 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
|
||||
}
|
||||
}
|
||||
|
||||
ProjectManagerEx.getInstanceEx().closeAndDispose(ourProject);
|
||||
|
||||
ProjectManagerEx.getInstanceEx().closeTestProject(ourProject);
|
||||
ourProject = null;
|
||||
ourPathToKeep = null;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.intellij.testFramework;
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.EditorTracker;
|
||||
import com.intellij.ide.highlighter.ModuleFileType;
|
||||
import com.intellij.ide.highlighter.ProjectFileType;
|
||||
import com.intellij.ide.startup.impl.StartupManagerImpl;
|
||||
@@ -40,7 +39,6 @@ import com.intellij.openapi.module.EmptyModuleType;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.module.ModuleType;
|
||||
import com.intellij.openapi.module.impl.ModuleManagerImpl;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.project.ex.ProjectManagerEx;
|
||||
@@ -238,9 +236,9 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
|
||||
|
||||
myProject = doCreateProject(projectFile);
|
||||
myProjectManager.openTestProject(myProject);
|
||||
myProject.getComponent(EditorTracker.class).projectOpened();
|
||||
LocalFileSystem.getInstance().refreshIoFiles(myFilesToDelete);
|
||||
|
||||
myProjectManager.openTestProject(myProject);
|
||||
setUpModule();
|
||||
|
||||
setUpJdk();
|
||||
@@ -518,7 +516,6 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Disposer.dispose(myProject);
|
||||
ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx();
|
||||
if (projectManager instanceof ProjectManagerImpl) {
|
||||
Collection<Project> projectsStillOpen = projectManager.closeTestProject(myProject);
|
||||
@@ -526,15 +523,15 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
|
||||
Project project = projectsStillOpen.iterator().next();
|
||||
String message = "Test project is not disposed: " + project + ";\n created in: " + getCreationPlace(project);
|
||||
try {
|
||||
projectManager.closeTestProject(project);
|
||||
Disposer.dispose(project);
|
||||
projectManager.closeAndDispose(project);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// ignore, we already have somthing to throw
|
||||
// ignore, we already have something to throw
|
||||
}
|
||||
throw new AssertionError(message);
|
||||
}
|
||||
}
|
||||
Disposer.dispose(myProject);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -591,18 +588,6 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
|
||||
}
|
||||
}
|
||||
|
||||
protected void simulateProjectOpen() {
|
||||
ModuleManagerImpl mm = (ModuleManagerImpl)ModuleManager.getInstance(myProject);
|
||||
StartupManagerImpl sm = (StartupManagerImpl)StartupManager.getInstance(myProject);
|
||||
|
||||
mm.projectOpened();
|
||||
setUpJdk();
|
||||
sm.runStartupActivities();
|
||||
sm.startCacheUpdate();
|
||||
// extra init for libraries
|
||||
sm.runPostStartupActivities();
|
||||
}
|
||||
|
||||
protected void setUpJdk() {
|
||||
//final ProjectJdkEx jdk = ProjectJdkUtil.getDefaultJdk("java 1.4");
|
||||
final Sdk jdk = getTestProjectJdk();
|
||||
|
||||
+1
@@ -1228,6 +1228,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
public void run() {
|
||||
DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true); // return default value to avoid unnecessary save
|
||||
FileEditorManager editorManager = FileEditorManager.getInstance(getProject());
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
VirtualFile[] openFiles = editorManager.getOpenFiles();
|
||||
for (VirtualFile openFile : openFiles) {
|
||||
editorManager.closeFile(openFile);
|
||||
|
||||
+23
-25
@@ -18,7 +18,6 @@ package com.intellij.testFramework.fixtures.impl;
|
||||
|
||||
import com.intellij.ide.IdeView;
|
||||
import com.intellij.ide.highlighter.ProjectFileType;
|
||||
import com.intellij.ide.startup.impl.StartupManagerImpl;
|
||||
import com.intellij.idea.IdeaTestApplication;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.DataProvider;
|
||||
@@ -36,7 +35,6 @@ import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ex.ProjectManagerEx;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.startup.StartupManager;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
@@ -55,10 +53,10 @@ import com.intellij.testFramework.builders.ModuleFixtureBuilder;
|
||||
import com.intellij.testFramework.fixtures.HeavyIdeaTestFixture;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.junit.Assert;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
@@ -143,34 +141,34 @@ class HeavyIdeaTestFixtureImpl extends BaseFixture implements HeavyIdeaTestFixtu
|
||||
|
||||
|
||||
private void setUpProject() throws Exception {
|
||||
new WriteCommandAction.Simple(null) {
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
File tempDirectory = FileUtil.createTempDirectory(myName, "");
|
||||
PlatformTestCase.synchronizeTempDirVfs(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDirectory));
|
||||
myFilesToDelete.add(tempDirectory);
|
||||
public void run() {
|
||||
try {
|
||||
File tempDirectory = FileUtil.createTempDirectory(myName, "");
|
||||
PlatformTestCase.synchronizeTempDirVfs(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDirectory));
|
||||
myFilesToDelete.add(tempDirectory);
|
||||
|
||||
File projectFile = new File(tempDirectory, myName + PROJECT_FILE_SUFFIX);
|
||||
File projectFile = new File(tempDirectory, myName + PROJECT_FILE_SUFFIX);
|
||||
|
||||
LocalFileSystem.getInstance().refreshAndFindFileByIoFile(projectFile);
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
new Throwable(projectFile.getPath()).printStackTrace(new PrintStream(buffer));
|
||||
myProject = PlatformTestCase.createProject(projectFile, buffer.toString());
|
||||
LocalFileSystem.getInstance().refreshAndFindFileByIoFile(projectFile);
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
new Throwable(projectFile.getPath()).printStackTrace(new PrintStream(buffer));
|
||||
myProject = PlatformTestCase.createProject(projectFile, buffer.toString());
|
||||
ProjectManagerEx.getInstanceEx().openTestProject(myProject);
|
||||
|
||||
for (ModuleFixtureBuilder moduleFixtureBuilder: myModuleFixtureBuilders) {
|
||||
moduleFixtureBuilder.getFixture().setUp();
|
||||
for (ModuleFixtureBuilder moduleFixtureBuilder: myModuleFixtureBuilders) {
|
||||
moduleFixtureBuilder.getFixture().setUp();
|
||||
}
|
||||
|
||||
LightPlatformTestCase.clearUncommittedDocuments(myProject);
|
||||
((FileTypeManagerImpl)FileTypeManager.getInstance()).drainReDetectQueue();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
StartupManagerImpl sm = (StartupManagerImpl)StartupManager.getInstance(myProject);
|
||||
sm.runStartupActivities();
|
||||
sm.startCacheUpdate();
|
||||
sm.runPostStartupActivities();
|
||||
|
||||
ProjectManagerEx.getInstanceEx().openTestProject(myProject);
|
||||
LightPlatformTestCase.clearUncommittedDocuments(myProject);
|
||||
((FileTypeManagerImpl)FileTypeManager.getInstance()).drainReDetectQueue();
|
||||
}
|
||||
}.execute().throwException();
|
||||
});
|
||||
}
|
||||
|
||||
private void initApplication() throws Exception {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -304,9 +304,9 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
|
||||
setDefaultChangeList(list);
|
||||
|
||||
if (myIgnoredIdeaLevel.isEmpty()) {
|
||||
final String name = myProject.getName();
|
||||
myIgnoredIdeaLevel.add(IgnoredBeanFactory.ignoreFile(name + WorkspaceFileType.DOT_DEFAULT_EXTENSION, myProject));
|
||||
myIgnoredIdeaLevel.add(IgnoredBeanFactory.ignoreFile(Project.DIRECTORY_STORE_FOLDER + "/workspace.xml", myProject));
|
||||
for (String path : predefinedIgnorePaths()) {
|
||||
myIgnoredIdeaLevel.add(IgnoredBeanFactory.ignoreFile(path, myProject));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!Registry.is("ide.hide.excluded.files") && !myExcludedConvertedToIgnored) {
|
||||
@@ -318,6 +318,15 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
List<String> predefinedIgnorePaths() {
|
||||
List<String> myIgnoredIdeaLevel = new ArrayList<String>();
|
||||
myIgnoredIdeaLevel.add(myProject.getName() + WorkspaceFileType.DOT_DEFAULT_EXTENSION);
|
||||
myIgnoredIdeaLevel.add(Project.DIRECTORY_STORE_FOLDER + "/workspace.xml");
|
||||
|
||||
return myIgnoredIdeaLevel;
|
||||
}
|
||||
|
||||
void convertExcludedToIgnored() {
|
||||
for (DirectoryIndexExcludePolicy policy : DirectoryIndexExcludePolicy.EP_NAME.getExtensions(myProject)) {
|
||||
for (VirtualFile file : policy.getExcludeRootsForProject()) {
|
||||
|
||||
+31
-10
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* 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 com.intellij.openapi.vcs.changes;
|
||||
|
||||
import com.intellij.openapi.module.ModuleType;
|
||||
@@ -6,6 +21,9 @@ import com.intellij.openapi.roots.CompilerProjectExtension;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.testFramework.PlatformTestCase;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -80,21 +98,24 @@ public class ConvertExcludedToIgnoredTest extends PlatformTestCase {
|
||||
assertFalse(getChangeListManager().isIgnoredFile(inner));
|
||||
}
|
||||
|
||||
private void assertIgnored(VirtualFile... ignoredDirs) {
|
||||
private void assertIgnored(@NotNull VirtualFile... ignoredDirs) {
|
||||
assertIgnoredDirectories(getProject(), ignoredDirs);
|
||||
}
|
||||
|
||||
public static void assertIgnoredDirectories(final Project project, VirtualFile... ignoredDirs) {
|
||||
public static void assertIgnoredDirectories(@NotNull Project project, @NotNull VirtualFile... expectedIgnoredDirs) {
|
||||
List<String> expectedIgnoredPaths = new ArrayList<String>();
|
||||
for (VirtualFile dir : ignoredDirs) {
|
||||
expectedIgnoredPaths.add(dir.getPath() + "/");
|
||||
for (VirtualFile dir : expectedIgnoredDirs) {
|
||||
expectedIgnoredPaths.add(dir.getPath()+"/");
|
||||
}
|
||||
List<String> actualIgnoredPaths = new ArrayList<String>();
|
||||
for (IgnoredFileBean fileBean : ChangeListManagerImpl.getInstanceImpl(project).getFilesToIgnore()) {
|
||||
assertEquals("Unexpected ignore: " + fileBean, IgnoreSettingsType.UNDER_DIR, fileBean.getType());
|
||||
actualIgnoredPaths.add(fileBean.getPath());
|
||||
}
|
||||
assertSameElements(expectedIgnoredPaths, actualIgnoredPaths);
|
||||
ChangeListManagerImpl changeListManager = ChangeListManagerImpl.getInstanceImpl(project);
|
||||
expectedIgnoredPaths.addAll(changeListManager.predefinedIgnorePaths());
|
||||
List<String> actualIgnoredPaths = ContainerUtil.map2List(changeListManager.getFilesToIgnore(), new Function<IgnoredFileBean, String>() {
|
||||
@Override
|
||||
public String fun(IgnoredFileBean bean) {
|
||||
return bean.getPath();
|
||||
}
|
||||
});
|
||||
assertSameElements(actualIgnoredPaths, expectedIgnoredPaths);
|
||||
}
|
||||
|
||||
private ChangeListManagerImpl getChangeListManager() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -15,10 +15,12 @@
|
||||
*/
|
||||
package com.intellij.util.xml;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.xml.XmlFile;
|
||||
import com.intellij.util.xml.impl.DomFileElementImpl;
|
||||
@@ -35,45 +37,36 @@ import java.util.Set;
|
||||
public class DomFileDescriptionTest extends DomHardCoreTestCase {
|
||||
private XmlFile myFooElementFile;
|
||||
private XmlFile myBarElementFile;
|
||||
private Disposable myDisposable = Disposer.newDisposable();
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
myFooElementFile = new WriteCommandAction<XmlFile>(getProject()) {
|
||||
@Override
|
||||
protected void run(@NotNull Result<XmlFile> result) throws Throwable {
|
||||
result.setResult((XmlFile)createFile("a.xml", "<a/>"));
|
||||
}
|
||||
}.execute().getResultObject();
|
||||
myFooElementFile = (XmlFile)createFile("a.xml", "<a/>");
|
||||
|
||||
getDomManager().registerFileDescription(new MockDomFileDescription<FooElement>(FooElement.class, "a", myFooElementFile), getTestRootDisposable());
|
||||
getDomManager().registerFileDescription(new MockDomFileDescription<FooElement>(FooElement.class, "a", myFooElementFile), myDisposable);
|
||||
|
||||
myBarElementFile = new WriteCommandAction<XmlFile>(getProject()) {
|
||||
@Override
|
||||
protected void run(@NotNull Result<XmlFile> result) throws Throwable {
|
||||
result.setResult((XmlFile)createFile("b.xml", "<b/>"));
|
||||
}
|
||||
}.execute().getResultObject();
|
||||
myBarElementFile = (XmlFile)createFile("b.xml", "<b/>");
|
||||
|
||||
getDomManager().registerFileDescription(new DomFileDescription<BarElement>(BarElement.class, "b") {
|
||||
|
||||
@Override
|
||||
public boolean isMyFile(@NotNull final XmlFile file, final Module module) {
|
||||
return myFooElementFile.getText().contains("239");
|
||||
String text = myFooElementFile.getText();
|
||||
return text.contains("239");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAutomaticHighlightingEnabled() {
|
||||
return false;
|
||||
}
|
||||
}, getTestRootDisposable());
|
||||
}, myDisposable);
|
||||
|
||||
assertResultsAndClear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
Disposer.dispose(myDisposable);
|
||||
myFooElementFile = null;
|
||||
myBarElementFile = null;
|
||||
|
||||
@@ -93,7 +86,7 @@ public class DomFileDescriptionTest extends DomHardCoreTestCase {
|
||||
public boolean isMyFile(@NotNull final XmlFile file, final Module module) {
|
||||
return /*super.isMyFile(file, module) && */file.getText().contains("239");
|
||||
}
|
||||
}, getTestRootDisposable());
|
||||
}, myDisposable);
|
||||
|
||||
|
||||
assertFalse(getDomManager().isDomFile(file));
|
||||
@@ -127,7 +120,7 @@ public class DomFileDescriptionTest extends DomHardCoreTestCase {
|
||||
public void testCopyFileDescriptionFromOriginalFile() throws Throwable {
|
||||
final XmlFile file = (XmlFile)createFile("a.xml", "<b>42</b>");
|
||||
|
||||
getDomManager().registerFileDescription(new MockDomFileDescription<MyElement>(MyElement.class, "b", file), getTestRootDisposable());
|
||||
getDomManager().registerFileDescription(new MockDomFileDescription<MyElement>(MyElement.class, "b", file), myDisposable);
|
||||
file.setName("b.xml");
|
||||
assertTrue(getDomManager().isDomFile(file));
|
||||
final XmlFile copy = (XmlFile)file.copy();
|
||||
@@ -138,7 +131,7 @@ public class DomFileDescriptionTest extends DomHardCoreTestCase {
|
||||
public void testDependantFileDescriptionCauseStackOverflow() throws Throwable {
|
||||
final XmlFile interestingFile = (XmlFile)createFile("a.xml", "<b>42</b>");
|
||||
|
||||
getDomManager().registerFileDescription(new MockDomFileDescription<MyElement>(MyElement.class, "b", (XmlFile)null), getTestRootDisposable());
|
||||
getDomManager().registerFileDescription(new MockDomFileDescription<MyElement>(MyElement.class, "b", (XmlFile)null), myDisposable);
|
||||
for (int i = 0; i < 239; i++) {
|
||||
getDomManager().registerFileDescription(new MockDomFileDescription<AbstractElement>(AbstractElement.class, "b", (XmlFile)null) {
|
||||
@Override
|
||||
@@ -147,7 +140,7 @@ public class DomFileDescriptionTest extends DomHardCoreTestCase {
|
||||
getDomManager().isDomFile(interestingFile);
|
||||
return super.getDependencyItems(file);
|
||||
}
|
||||
}, getTestRootDisposable());
|
||||
}, myDisposable);
|
||||
}
|
||||
|
||||
getDomManager().isDomFile(interestingFile);
|
||||
@@ -160,7 +153,7 @@ public class DomFileDescriptionTest extends DomHardCoreTestCase {
|
||||
protected void initializeFileDescription() {
|
||||
registerNamespacePolicy("foo", "bar");
|
||||
}
|
||||
}, getTestRootDisposable());
|
||||
}, myDisposable);
|
||||
|
||||
final PsiFile file = createFile("xxx.xml", "<xxx/>");
|
||||
assertFalse(getDomManager().isDomFile(file));
|
||||
@@ -182,7 +175,7 @@ public class DomFileDescriptionTest extends DomHardCoreTestCase {
|
||||
protected void initializeFileDescription() {
|
||||
registerNamespacePolicy("foo", "bar");
|
||||
}
|
||||
}, getTestRootDisposable());
|
||||
}, myDisposable);
|
||||
|
||||
final PsiFile file = createFile("xxx.xml", "<xxx/>");
|
||||
assertFalse(getDomManager().isDomFile(file));
|
||||
@@ -205,7 +198,7 @@ public class DomFileDescriptionTest extends DomHardCoreTestCase {
|
||||
public boolean isMyFile(@NotNull final XmlFile file, @Nullable final Module module) {
|
||||
return file.getText().contains("foo");
|
||||
}
|
||||
}, getTestRootDisposable());
|
||||
}, myDisposable);
|
||||
final XmlFile file = (XmlFile)createFile("xxx.xml", "<xxx zzz=\"foo\"><boy/><boy/><xxx/>");
|
||||
final MyElement boy = getDomManager().getFileElement(file, MyElement.class).getRootElement().getBoys().get(0);
|
||||
new WriteCommandAction(getProject()) {
|
||||
|
||||
Reference in New Issue
Block a user