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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user