From aa1041893a2710f7170343a2b33ea2198a6ac2d3 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Thu, 26 Jan 2017 10:59:17 +0100 Subject: [PATCH 1/6] cleanup (unused import) --- .../src/com/intellij/openapi/components/service.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/platform/projectModel-impl/src/com/intellij/openapi/components/service.kt b/platform/projectModel-impl/src/com/intellij/openapi/components/service.kt index 4b2f8791fbc7..c30a15c3b38e 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/components/service.kt +++ b/platform/projectModel-impl/src/com/intellij/openapi/components/service.kt @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 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,7 +15,6 @@ */ package com.intellij.openapi.components -import com.intellij.openapi.application.Application import com.intellij.openapi.components.impl.ComponentManagerImpl import com.intellij.openapi.components.impl.stores.IComponentStore import com.intellij.openapi.project.Project From e9189e60a3cbc73799385f01986f75c9ea9a0a91 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Thu, 26 Jan 2017 15:00:11 +0100 Subject: [PATCH 2/6] explicitly set module file based storage (prepare to fix IDEA-147530 ModifiableModuleModel#newModule should always create a new module from scratch) add EmptyModuleManager to not break MPS core plugin in the future --- .../src/ModuleStateStorageManager.kt | 3 +- .../src/ModuleStoreImpl.kt | 9 ++++ .../openapi/module/impl/ModuleImpl.java | 6 +-- .../module/impl/ModuleManagerComponent.java | 5 +- .../openapi/project/impl/ProjectImpl.java | 12 +++-- .../src/com/intellij/core/CoreModule.java | 4 +- .../com/intellij/core/CoreModuleManager.java | 11 ++-- .../impl/stores/IComponentStore.java | 5 ++ .../openapi/module/EmptyModuleManager.kt | 51 +++++++++++++++++++ .../openapi/module/impl/ModuleEx.java | 5 +- .../module/impl/ModuleManagerImpl.java | 12 ++--- 11 files changed, 96 insertions(+), 27 deletions(-) create mode 100644 platform/projectModel-impl/src/com/intellij/openapi/module/EmptyModuleManager.kt diff --git a/platform/configuration-store-impl/src/ModuleStateStorageManager.kt b/platform/configuration-store-impl/src/ModuleStateStorageManager.kt index d8bcf43530e1..9a00e4154d71 100644 --- a/platform/configuration-store-impl/src/ModuleStateStorageManager.kt +++ b/platform/configuration-store-impl/src/ModuleStateStorageManager.kt @@ -20,6 +20,7 @@ import com.intellij.openapi.components.StateStorageOperation import com.intellij.openapi.components.StoragePathMacros import com.intellij.openapi.components.TrackingPathMacroSubstitutor import com.intellij.openapi.module.Module +import com.intellij.openapi.module.ModuleManager import com.intellij.openapi.module.impl.ModuleEx import com.intellij.openapi.module.impl.ModuleManagerImpl import com.intellij.openapi.module.impl.getModuleNameByFilePath @@ -39,7 +40,7 @@ class ModuleStateStorageManager(macroSubstitutor: TrackingPathMacroSubstitutor, val module = componentManager as ModuleEx val oldName = module.name module.rename(getModuleNameByFilePath(newPath), false) - ModuleManagerImpl.getInstanceImpl(module.project).fireModuleRenamedByVfsEvent(module, oldName) + (ModuleManager.getInstance(module.project) as? ModuleManagerImpl)?.fireModuleRenamedByVfsEvent(module, oldName) } } } diff --git a/platform/configuration-store-impl/src/ModuleStoreImpl.kt b/platform/configuration-store-impl/src/ModuleStoreImpl.kt index 551b7f7881f7..2c910763e6f7 100644 --- a/platform/configuration-store-impl/src/ModuleStoreImpl.kt +++ b/platform/configuration-store-impl/src/ModuleStoreImpl.kt @@ -17,6 +17,7 @@ package com.intellij.configurationStore import com.intellij.openapi.components.* import com.intellij.openapi.module.Module +import com.intellij.openapi.vfs.VirtualFile import com.intellij.util.io.exists import java.nio.file.Paths @@ -64,4 +65,12 @@ abstract class ModuleStoreBase : ComponentStoreImpl() { storageManager.getCachedFileStorages(listOf(StoragePathMacros.MODULE_FILE)).firstOrNull()?.setFile(null, Paths.get(path)) } } + + override fun setPath(path: String, file: VirtualFile?) { + if (!storageManager.addMacro(StoragePathMacros.MODULE_FILE, path)) { + return + } + + (storageManager.getOrCreateStorage(StoragePathMacros.MODULE_FILE) as FileBasedStorage).setFile(file, null) + } } \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleImpl.java b/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleImpl.java index 4ae09f433f2c..482b6e3b47cf 100644 --- a/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 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. @@ -79,11 +79,11 @@ public class ModuleImpl extends PlatformComponentManagerImpl implements ModuleEx } @Override - public void init(@NotNull final String path, @Nullable final Runnable beforeComponentCreation) { + public void init(@NotNull final String path, @Nullable VirtualFile file, @Nullable final Runnable beforeComponentCreation) { init((ProgressIndicator)null, () -> { // create ServiceManagerImpl at first to force extension classes registration getPicoContainer().getComponentInstance(ModuleServiceManagerImpl.class); - ServiceKt.getStateStore(this).setPath(path); + ServiceKt.getStateStore(this).setPath(path, file); if (beforeComponentCreation != null) { beforeComponentCreation.run(); diff --git a/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerComponent.java b/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerComponent.java index a99a274a601b..19d831d83376 100644 --- a/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerComponent.java +++ b/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerComponent.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 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. @@ -30,6 +30,7 @@ import com.intellij.openapi.module.UnknownModuleType; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.project.impl.ProjectLifecycleListener; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.util.messages.MessageHandler; import org.jetbrains.annotations.NotNull; @@ -113,7 +114,7 @@ public class ModuleManagerComponent extends ModuleManagerImpl { @NotNull @Override - protected ModuleEx createAndLoadModule(@NotNull String filePath) { + protected ModuleEx createAndLoadModule(@NotNull String filePath, @NotNull VirtualFile file) { return new ModuleImpl(filePath, myProject); } diff --git a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectImpl.java b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectImpl.java index 075a1a7f0fb9..b99f3dc1552f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 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. @@ -313,9 +313,13 @@ public class ProjectImpl extends PlatformComponentManagerImpl implements Project ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); if (indicator == null) return; + ModuleManager moduleManager = ModuleManager.getInstance(this); + if (!(moduleManager instanceof ModuleManagerImpl)) { + return; + } + double toDistribute = 1 - indicator.getFraction(); - ModuleManagerImpl moduleManager = (ModuleManagerImpl)ModuleManager.getInstance(this); - int modulesCount = moduleManager.getModulePathsCount(); + int modulesCount = ((ModuleManagerImpl)moduleManager).getModulePathsCount(); EditorsSplitters splitters = ((FileEditorManagerImpl)FileEditorManager.getInstance(this)).getMainSplitters(); int editors = splitters.getEditorsCount(); @@ -323,7 +327,7 @@ public class ProjectImpl extends PlatformComponentManagerImpl implements Project if (modulesCount != 0) { double step = modulesPart / modulesCount; - moduleManager.setProgressStep(step); + ((ModuleManagerImpl)moduleManager).setProgressStep(step); } if (editors != 0) { diff --git a/platform/projectModel-impl/src/com/intellij/core/CoreModule.java b/platform/projectModel-impl/src/com/intellij/core/CoreModule.java index c187ce626968..ea43d70a7096 100644 --- a/platform/projectModel-impl/src/com/intellij/core/CoreModule.java +++ b/platform/projectModel-impl/src/com/intellij/core/CoreModule.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 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. @@ -111,7 +111,7 @@ public class CoreModule extends MockComponentManager implements ModuleEx { } @Override - public void init(@NotNull String path, @Nullable final Runnable beforeComponentCreation) { + public void init(@NotNull String path, @Nullable VirtualFile file, @Nullable Runnable beforeComponentCreation) { } @Override diff --git a/platform/projectModel-impl/src/com/intellij/core/CoreModuleManager.java b/platform/projectModel-impl/src/com/intellij/core/CoreModuleManager.java index 2b1f1c82b291..2f8473059c0d 100644 --- a/platform/projectModel-impl/src/com/intellij/core/CoreModuleManager.java +++ b/platform/projectModel-impl/src/com/intellij/core/CoreModuleManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 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.openapi.module.impl.ModuleManagerImpl; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.roots.impl.ModuleRootManagerImpl; -import com.intellij.openapi.vfs.StandardFileSystems; import com.intellij.openapi.vfs.VirtualFile; import org.jdom.JDOMException; import org.jetbrains.annotations.NotNull; @@ -48,14 +47,12 @@ public class CoreModuleManager extends ModuleManagerImpl { @NotNull @Override - protected ModuleEx createAndLoadModule(@NotNull String filePath) throws IOException { + protected ModuleEx createAndLoadModule(@NotNull String filePath, @NotNull VirtualFile file) throws IOException { final ModuleEx module = createModule(filePath); - VirtualFile vFile = StandardFileSystems.local().findFileByPath(filePath); try { - assert vFile != null; ModuleRootManagerImpl.ModuleRootManagerState state = new ModuleRootManagerImpl.ModuleRootManagerState(); - state.readExternal(CoreProjectLoader.loadStorageFile(module, vFile).get("NewModuleRootManager")); - ((ModuleRootManagerImpl) ModuleRootManager.getInstance(module)).loadState(state); + state.readExternal(CoreProjectLoader.loadStorageFile(module, file).get("NewModuleRootManager")); + ((ModuleRootManagerImpl)ModuleRootManager.getInstance(module)).loadState(state); } catch (JDOMException e) { throw new IOException(e); diff --git a/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/IComponentStore.java b/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/IComponentStore.java index 325471647e6a..41aa4561e660 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/IComponentStore.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/components/impl/stores/IComponentStore.java @@ -22,6 +22,7 @@ import com.intellij.openapi.util.Pair; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.messages.MessageBus; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; import java.util.List; @@ -33,6 +34,10 @@ public interface IComponentStore { */ void setPath(@NotNull String path); + default void setPath(@NotNull String path, @Nullable VirtualFile file) { + setPath(path); + } + void initComponent(@NotNull Object component, boolean service); void reloadStates(@NotNull Set componentNames, @NotNull MessageBus messageBus); diff --git a/platform/projectModel-impl/src/com/intellij/openapi/module/EmptyModuleManager.kt b/platform/projectModel-impl/src/com/intellij/openapi/module/EmptyModuleManager.kt new file mode 100644 index 000000000000..07f679f812ff --- /dev/null +++ b/platform/projectModel-impl/src/com/intellij/openapi/module/EmptyModuleManager.kt @@ -0,0 +1,51 @@ +/* + * Copyright 2000-2017 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.module + +import com.intellij.openapi.project.Project +import com.intellij.util.messages.MessageBus +import org.jetbrains.annotations.NotNull + +class EmptyModuleManager(project: Project, messageBus: MessageBus) : ModuleManager() { + override fun hasModuleGroups() = false + + override fun newModule(filePath: String, moduleTypeId: String) = throw UnsupportedOperationException() + + override fun loadModule(filePath: String) = throw UnsupportedOperationException() + + override fun disposeModule(module: Module) { + } + + override fun getModules() = emptyArray() + + override fun findModuleByName(name: String) = null + + override fun getSortedModules() = emptyArray() + + override fun moduleDependencyComparator() = throw UnsupportedOperationException() + + override fun getModuleDependentModules(module: Module) = emptyList() + + override fun isModuleDependent(@NotNull module: Module, @NotNull onModule: Module) = false + + override fun moduleGraph() = moduleGraph(true) + + override fun moduleGraph(includeTests: Boolean) = throw UnsupportedOperationException() + + override fun getModifiableModel() = throw UnsupportedOperationException() + + override fun getModuleGroupPath(module: Module) = emptyArray() +} \ No newline at end of file diff --git a/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleEx.java b/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleEx.java index 55ae3730143f..cde78370de6d 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleEx.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleEx.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 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. @@ -16,6 +16,7 @@ package com.intellij.openapi.module.impl; import com.intellij.openapi.module.Module; +import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -26,7 +27,7 @@ public interface ModuleEx extends Module { /** * @param path System-independent path. */ - void init(@NotNull String path, @Nullable Runnable beforeComponentCreation); + void init(@NotNull String path, @Nullable VirtualFile file, @Nullable Runnable beforeComponentCreation); default void moduleAdded() { } diff --git a/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java index 056f6c47b63a..ad1cf573af89 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java @@ -586,7 +586,7 @@ public abstract class ModuleManagerImpl extends ModuleManager implements Disposa protected abstract ModuleEx createModule(@NotNull String filePath); @NotNull - protected abstract ModuleEx createAndLoadModule(@NotNull String filePath) throws IOException; + protected abstract ModuleEx createAndLoadModule(@NotNull String filePath, @NotNull VirtualFile file) throws IOException; static class ModuleModelImpl implements ModifiableModuleModel { final Map myModules = Collections.synchronizedMap(new LinkedHashMap<>()); @@ -690,7 +690,7 @@ public abstract class ModuleManagerImpl extends ModuleManager implements Disposa if (module == null) { module = myManager.createModule(filePath); final ModuleEx newModule = module; - initModule(module, filePath, () -> { + initModule(module, filePath, null, () -> { newModule.setOption(Module.ELEMENT_TYPE, moduleTypeId); if (options != null) { for (Map.Entry option : options.entrySet()) { @@ -753,14 +753,14 @@ public abstract class ModuleManagerImpl extends ModuleManager implements Disposa ApplicationManager.getApplication().invokeAndWait(() -> moduleFile.refresh(false, false)); return () -> ReadAction.compute(() -> { if (myManager.myProject.isDisposed()) return null; - ModuleEx result = myManager.createAndLoadModule(path); - initModule(result, path, null); + ModuleEx result = myManager.createAndLoadModule(path, moduleFile); + initModule(result, path, moduleFile, null); return result; }); } - private void initModule(@NotNull ModuleEx module, @NotNull String path, @Nullable Runnable beforeComponentCreation) { - module.init(path, beforeComponentCreation); + private void initModule(@NotNull ModuleEx module, @NotNull String path, @Nullable VirtualFile file, @Nullable Runnable beforeComponentCreation) { + module.init(path, file, beforeComponentCreation); myModulesCache = null; myModules.put(module.getName(), module); } From 576787ccae3a612983c8982a16ac6b17a3048fad Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Thu, 26 Jan 2017 15:59:09 +0100 Subject: [PATCH 3/6] IDEA-147530 ModifiableModuleModel#newModule should always create a new module from scratch --- .../configuration-store-impl/src/FileBasedStorage.kt | 4 +++- .../configuration-store-impl/src/ModuleStoreImpl.kt | 7 ++++++- .../src/StateStorageManagerImpl.kt | 10 ++++++++-- .../testSrc/ModuleStoreTest.kt | 10 ++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/platform/configuration-store-impl/src/FileBasedStorage.kt b/platform/configuration-store-impl/src/FileBasedStorage.kt index 58b3176b25c5..74db699aa40d 100644 --- a/platform/configuration-store-impl/src/FileBasedStorage.kt +++ b/platform/configuration-store-impl/src/FileBasedStorage.kt @@ -58,6 +58,8 @@ open class FileBasedStorage(file: Path, private var lineSeparator: LineSeparator? = null private var blockSavingTheContent = false + var resolveVirtualFileOnlyOnWrite = false + @Volatile var file = file private set @@ -120,7 +122,7 @@ open class FileBasedStorage(file: Path, return loadLocalDataUsingIo() } - val file = virtualFile + val file = if (resolveVirtualFileOnlyOnWrite) cachedVirtualFile else virtualFile if (file == null || file.isDirectory || !file.isValid) { LOG.debug { "Document was not loaded for $fileSpec, not a file" } } diff --git a/platform/configuration-store-impl/src/ModuleStoreImpl.kt b/platform/configuration-store-impl/src/ModuleStoreImpl.kt index 2c910763e6f7..31a17383f389 100644 --- a/platform/configuration-store-impl/src/ModuleStoreImpl.kt +++ b/platform/configuration-store-impl/src/ModuleStoreImpl.kt @@ -71,6 +71,11 @@ abstract class ModuleStoreBase : ComponentStoreImpl() { return } - (storageManager.getOrCreateStorage(StoragePathMacros.MODULE_FILE) as FileBasedStorage).setFile(file, null) + storageManager.getOrCreateStorage(StoragePathMacros.MODULE_FILE, storageCustomizer = { + (this as FileBasedStorage).setFile(file, null) + // ModifiableModuleModel#newModule should always create a new module from scratch + // https://youtrack.jetbrains.com/issue/IDEA-147530 + resolveVirtualFileOnlyOnWrite = true + }) } } \ No newline at end of file diff --git a/platform/configuration-store-impl/src/StateStorageManagerImpl.kt b/platform/configuration-store-impl/src/StateStorageManagerImpl.kt index bdf5546e0eda..3a46e6d9458f 100644 --- a/platform/configuration-store-impl/src/StateStorageManagerImpl.kt +++ b/platform/configuration-store-impl/src/StateStorageManagerImpl.kt @@ -148,11 +148,13 @@ open class StateStorageManagerImpl(private val rootTagName: String, return if (path.endsWith('/')) path.substring(0, path.length - 1) else path } + // storageCustomizer - to ensure that other threads will use fully constructed and configured storage (invoked under the same lock as created) fun getOrCreateStorage(collapsedPath: String, roamingType: RoamingType = RoamingType.DEFAULT, storageClass: Class = StateStorage::class.java, @Suppress("DEPRECATION") stateSplitter: Class = StateSplitterEx::class.java, - exclusive: Boolean = false): StateStorage { + exclusive: Boolean = false, + storageCustomizer: (StateStorage.() -> Unit)? = null): StateStorage { val normalizedCollapsedPath = normalizeFileSpec(collapsedPath) val key: String if (storageClass == StateStorage::class.java) { @@ -166,7 +168,11 @@ open class StateStorageManagerImpl(private val rootTagName: String, } return storageLock.read { storages.get(key) } ?: storageLock.write { - storages.getOrPut(key, { createStateStorage(storageClass, normalizedCollapsedPath, roamingType, stateSplitter, exclusive) }) + storages.getOrPut(key) { + val storage = createStateStorage(storageClass, normalizedCollapsedPath, roamingType, stateSplitter, exclusive) + storageCustomizer?.let { storage.it() } + storage + } } } diff --git a/platform/configuration-store-impl/testSrc/ModuleStoreTest.kt b/platform/configuration-store-impl/testSrc/ModuleStoreTest.kt index 964c03838bb5..2e78e7e76ad2 100644 --- a/platform/configuration-store-impl/testSrc/ModuleStoreTest.kt +++ b/platform/configuration-store-impl/testSrc/ModuleStoreTest.kt @@ -77,6 +77,16 @@ class ModuleStoreTest { } } + @Test fun `newModule should always create a new module from scratch`() { + val moduleFile = runWriteAction { + VfsTestUtil.createFile(tempDirManager.newVirtualDirectory("module"), "test.iml", "") + } + + Paths.get(moduleFile.path).createModule().useAndDispose { + assertThat(getOptionValue("foo")).isNull() + } + } + @Test fun `must be empty if classpath storage`() { // we must not use VFS here, file must not be created val moduleFile = tempDirManager.newPath("module", refreshVfs = true).resolve("test.iml") From c93a1a4a4b634de55f0b6622646bc364eae4be60 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 27 Jan 2017 11:50:36 +0100 Subject: [PATCH 4/6] createJ2EEModule throws error if cannot create module, add notnull annotations --- .../intellij/compiler/BaseCompilerTestCase.java | 3 ++- ...IntroduceFieldWitSetUpInitializationTest.java | 16 +++++++++++++++- .../intellij/testFramework/PlatformTestCase.java | 10 +++++++--- .../idea/eclipse/Eclipse2ModulesTest.java | 3 ++- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/java/compiler/impl/testSrc/com/intellij/compiler/BaseCompilerTestCase.java b/java/compiler/impl/testSrc/com/intellij/compiler/BaseCompilerTestCase.java index 0609009dbf81..4305c37547e5 100644 --- a/java/compiler/impl/testSrc/com/intellij/compiler/BaseCompilerTestCase.java +++ b/java/compiler/impl/testSrc/com/intellij/compiler/BaseCompilerTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 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. @@ -335,6 +335,7 @@ public abstract class BaseCompilerTestCase extends ModuleTestCase { return iprFile; } + @NotNull @Override protected Module doCreateRealModule(String moduleName) { //todo[nik] reuse code from PlatformTestCase diff --git a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceFieldWitSetUpInitializationTest.java b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceFieldWitSetUpInitializationTest.java index f2b71328a349..f35843479b31 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceFieldWitSetUpInitializationTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceFieldWitSetUpInitializationTest.java @@ -1,5 +1,17 @@ /* - * Copyright (c) 2000-2007 JetBrains s.r.o. All Rights Reserved. + * Copyright 2000-2017 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. */ /* @@ -21,6 +33,7 @@ import com.intellij.psi.util.PsiTreeUtil; import com.intellij.refactoring.introduceField.BaseExpressionToFieldHandler; import com.intellij.refactoring.introduceField.LocalToFieldHandler; import com.intellij.util.PathUtil; +import org.jetbrains.annotations.NotNull; import org.junit.Before; import java.io.File; @@ -31,6 +44,7 @@ public class IntroduceFieldWitSetUpInitializationTest extends CodeInsightTestCas return JavaTestUtil.getJavaTestDataPath(); } + @NotNull @Override protected Module createModule(final String name) { final Module module = super.createModule(name); diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java index 057fa9cbc951..756a9593decd 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 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. @@ -325,25 +325,29 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro }.execute().throwException(); } + @NotNull protected Module createMainModule() throws IOException { return createModule(myProject.getName()); } + @NotNull protected Module createModule(@NonNls final String moduleName) { return doCreateRealModule(moduleName); } + @NotNull protected Module doCreateRealModule(final String moduleName) { return doCreateRealModuleIn(moduleName, myProject, getModuleType()); } + @NotNull protected static Module doCreateRealModuleIn(String moduleName, final Project project, final ModuleType moduleType) { final VirtualFile baseDir = project.getBaseDir(); assertNotNull(baseDir); - String path = baseDir.getPath(); - return createModuleAt(moduleName, project, moduleType, path); + return createModuleAt(moduleName, project, moduleType, baseDir.getPath()); } + @NotNull protected static Module createModuleAt(String moduleName, Project project, ModuleType moduleType, String path) { File moduleFile = new File(FileUtil.toSystemDependentName(path), moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION); FileUtil.createIfDoesntExist(moduleFile); diff --git a/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/Eclipse2ModulesTest.java b/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/Eclipse2ModulesTest.java index f2b6ca4904d9..bd6dce66a6ca 100644 --- a/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/Eclipse2ModulesTest.java +++ b/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/Eclipse2ModulesTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2017 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. @@ -55,6 +55,7 @@ public abstract class Eclipse2ModulesTest extends IdeaTestCase { copyDirContentsTo(vTestRoot, getProject().getBaseDir()); } + @NotNull @Override protected Module createMainModule() { return createModule(DEPEND_MODULE_NAME); From 5ea80f2e3fe28a9a16a6e5ad576c1230e721cfb6 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 27 Jan 2017 12:39:58 +0100 Subject: [PATCH 5/6] use THashSet, notnull --- .../src/com/intellij/testFramework/PlatformTestCase.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java index 756a9593decd..401bc0b4b17e 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java @@ -74,6 +74,7 @@ import com.intellij.util.indexing.FileBasedIndex; import com.intellij.util.indexing.FileBasedIndexImpl; import com.intellij.util.indexing.IndexableSetContributor; import com.intellij.util.ui.UIUtil; +import gnu.trove.THashSet; import junit.framework.TestCase; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -104,7 +105,7 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro protected ProjectManagerEx myProjectManager; protected Project myProject; protected Module myModule; - protected static final Collection myFilesToDelete = new HashSet<>(); + protected static final Collection myFilesToDelete = new THashSet<>(); protected boolean myAssertionsInTestDetected; protected static final Logger LOG = Logger.getInstance("#com.intellij.testFramework.PlatformTestCase"); public static Thread ourTestThread; From ec31fa83fc4be1543e9e8ecfa5e226c023a71b5a Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 27 Jan 2017 15:17:36 +0100 Subject: [PATCH 6/6] notnull --- .../intellij/testFramework/ModuleTestCase.java | 16 +++++++++------- .../intellij/openapi/module/ModuleManager.java | 5 ++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/java/testFramework/src/com/intellij/testFramework/ModuleTestCase.java b/java/testFramework/src/com/intellij/testFramework/ModuleTestCase.java index bc00a96b8a3f..cf23fce616db 100644 --- a/java/testFramework/src/com/intellij/testFramework/ModuleTestCase.java +++ b/java/testFramework/src/com/intellij/testFramework/ModuleTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 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. @@ -81,7 +81,7 @@ public abstract class ModuleTestCase extends IdeaTestCase { } } - protected Module createModule(final File moduleFile) { + protected Module createModule(@NotNull File moduleFile) { return createModule(moduleFile, StdModuleTypes.JAVA); } @@ -99,14 +99,16 @@ public abstract class ModuleTestCase extends IdeaTestCase { return module; } - protected Module loadModule(@NotNull String modulePath) { - final String normalizedPath = FileUtil.toSystemIndependentName(modulePath); - LocalFileSystem.getInstance().refreshAndFindFileByPath(normalizedPath); + protected Module loadModule(@NotNull VirtualFile file) { + return loadModule(file.getPath()); + } + protected Module loadModule(@NotNull String modulePath) { final ModuleManager moduleManager = ModuleManager.getInstance(myProject); Module module; try { - module = ApplicationManager.getApplication().runWriteAction((ThrowableComputable)() -> moduleManager.loadModule(normalizedPath)); + module = ApplicationManager.getApplication().runWriteAction((ThrowableComputable)() -> moduleManager.loadModule( + FileUtil.toSystemIndependentName(modulePath))); } catch (Exception e) { LOG.error(e); @@ -130,7 +132,7 @@ public abstract class ModuleTestCase extends IdeaTestCase { @Override public boolean visitFile(@NotNull VirtualFile file) { if (!file.isDirectory() && file.getName().endsWith(ModuleFileType.DOT_DEFAULT_EXTENSION)) { - ModuleImpl module = (ModuleImpl)loadModule(file.getPath()); + ModuleImpl module = (ModuleImpl)loadModule(file); if (moduleConsumer != null) { moduleConsumer.consume(module); } diff --git a/platform/projectModel-api/src/com/intellij/openapi/module/ModuleManager.java b/platform/projectModel-api/src/com/intellij/openapi/module/ModuleManager.java index 7ef52032a98a..0e25a83c0d61 100644 --- a/platform/projectModel-api/src/com/intellij/openapi/module/ModuleManager.java +++ b/platform/projectModel-api/src/com/intellij/openapi/module/ModuleManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2017 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. @@ -64,8 +64,7 @@ public abstract class ModuleManager extends SimpleModificationTracker { * @throws ModuleWithNameAlreadyExists if a module with such a name already exists in the project. */ @NotNull - public abstract Module loadModule(@NotNull String filePath) - throws InvalidDataException, IOException, JDOMException, ModuleWithNameAlreadyExists; + public abstract Module loadModule(@NotNull String filePath) throws IOException, JDOMException, ModuleWithNameAlreadyExists; /** * Disposes of the specified module and removes it from the project.