Make MODULE_FILE optional
authorVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Wed, 10 Feb 2016 12:06:53 +0000 (13:06 +0100)
committerVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Wed, 10 Feb 2016 15:55:51 +0000 (16:55 +0100)
15 files changed:
platform/configuration-store-impl/src/ModuleStoreImpl.kt
platform/configuration-store-impl/src/ProjectStoreImpl.kt
platform/configuration-store-impl/src/com/intellij/configurationStore/ProjectFileStorageAnnotation.java
platform/lang-impl/src/com/intellij/execution/impl/ModuleRunConfigurationManager.java
platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java
platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleImpl.java
platform/projectModel-api/src/com/intellij/openapi/components/State.java
platform/projectModel-api/src/com/intellij/openapi/components/Storage.java
platform/projectModel-impl/src/com/intellij/openapi/roots/impl/TestModulePropertiesImpl.java
plugins/devkit/src/build/PluginBuildConfiguration.java
plugins/eclipse/src/org/jetbrains/idea/eclipse/config/EclipseModuleManagerImpl.java
python/src/com/jetbrains/python/ReSTService.java
python/src/com/jetbrains/python/documentation/PyDocumentationSettings.java
python/src/com/jetbrains/python/packaging/PyPackageRequirementsSettings.java
python/src/com/jetbrains/python/testing/TestRunnerService.java

index 941f7d69ea8fb206b33edd0157c6e24b71380158..0dea4f25406980bc0d7a34490f531d1781661288 100644 (file)
  */
 package com.intellij.configurationStore
 
-import com.intellij.openapi.components.PathMacroManager
-import com.intellij.openapi.components.StoragePathMacros
-import com.intellij.openapi.components.stateStore
+import com.intellij.openapi.components.*
 import com.intellij.openapi.module.Module
 import java.io.File
 
+private val MODULE_FILE_STORAGE_ANNOTATION = ProjectFileStorageAnnotation(StoragePathMacros.MODULE_FILE, false)
+
 private open class ModuleStoreImpl(module: Module, private val pathMacroManager: PathMacroManager) : ComponentStoreImpl() {
   override val project = module.project
 
   override val storageManager = ModuleStateStorageManager(pathMacroManager.createTrackingSubstitutor(), module)
 
+  override fun <T> getStorageSpecs(component: PersistentStateComponent<T>, stateSpec: State, operation: StateStorageOperation): Array<out Storage> {
+    val storages = stateSpec.storages
+    if (storages.isEmpty()) {
+      return arrayOf(MODULE_FILE_STORAGE_ANNOTATION)
+    }
+    else {
+      return super.getStorageSpecs(component, stateSpec, operation)
+    }
+  }
+
   override fun setPath(path: String) {
     if (!storageManager.addMacro(StoragePathMacros.MODULE_FILE, path)) {
       storageManager.getCachedFileStorages(listOf(StoragePathMacros.MODULE_FILE)).firstOrNull()?.setFile(null, File(path))
index 5e645c63a937174e776c5d50eef207eb1e1b63ad..e74abf19c7ababe3da2e99e599c14304cd53bbfe 100644 (file)
@@ -55,10 +55,8 @@ const val PROJECT_CONFIG_DIR = "\$PROJECT_CONFIG_DIR$"
 val IProjectStore.nameFile: Path
   get() = Paths.get(projectBasePath, Project.DIRECTORY_STORE_FOLDER, ProjectImpl.NAME_FILE)
 
-internal val PROJECT_FILE_STORAGE_ANNOTATION = ProjectFileStorageAnnotation()
-internal val DEPRECATED_PROJECT_FILE_STORAGE_ANNOTATION = object : ProjectFileStorageAnnotation() {
-  override fun deprecated() = true
-}
+internal val PROJECT_FILE_STORAGE_ANNOTATION = ProjectFileStorageAnnotation(PROJECT_FILE, false)
+internal val DEPRECATED_PROJECT_FILE_STORAGE_ANNOTATION = ProjectFileStorageAnnotation(PROJECT_FILE, true)
 
 abstract class ProjectStoreBase(override final val project: ProjectImpl) : ComponentStoreImpl(), IProjectStore {
   // protected setter used in upsource
index 693a1634b693e0a5658ec1adede61110f1070f0a..7c01adaec4cee8b9ef7375dd5d429facb19863ef 100644 (file)
@@ -6,10 +6,19 @@ import org.jetbrains.annotations.NotNull;
 import java.lang.annotation.Annotation;
 
 @SuppressWarnings("ClassExplicitlyAnnotation")
-public class ProjectFileStorageAnnotation implements Storage {
+final class ProjectFileStorageAnnotation implements Storage {
+  private String path;
+
+  private boolean deprecated;
+
+  ProjectFileStorageAnnotation(String path, boolean deprecated) {
+    this.path = path;
+    this.deprecated = deprecated;
+  }
+
   @Override
   public String id() {
-    return "___Default___";
+    return "default";
   }
 
   @Override
@@ -19,7 +28,7 @@ public class ProjectFileStorageAnnotation implements Storage {
 
   @Override
   public String value() {
-    return ProjectStoreImplKt.PROJECT_FILE;
+    return path;
   }
 
   @Override
@@ -29,7 +38,7 @@ public class ProjectFileStorageAnnotation implements Storage {
 
   @Override
   public boolean deprecated() {
-    return false;
+    return deprecated;
   }
 
   @Override
index fb1b8fc3285d800e2f6d59bfe684c1482aedeaed..6f6bd17f14bbb4f7ea20af160d1f4a3ffaf3e3a6 100644 (file)
@@ -21,8 +21,6 @@ import com.intellij.execution.configurations.ModuleBasedConfiguration;
 import com.intellij.execution.configurations.RunConfiguration;
 import com.intellij.openapi.components.PersistentStateComponent;
 import com.intellij.openapi.components.State;
-import com.intellij.openapi.components.Storage;
-import com.intellij.openapi.components.StoragePathMacros;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.module.ModuleComponent;
@@ -44,7 +42,7 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Set;
 
-@State(name = ModuleRunConfigurationManager.COMPONENT_NAME, storages = @Storage(StoragePathMacros.MODULE_FILE))
+@State(name = ModuleRunConfigurationManager.COMPONENT_NAME)
 public final class ModuleRunConfigurationManager extends ModuleAdapter implements ModuleComponent, PersistentStateComponent<Element> {
   private static final Logger LOG = Logger.getInstance(ModuleRunConfigurationManager.class);
   @NonNls static final String COMPONENT_NAME = "ModuleRunConfigurationManager";
index d0659cab55d3c626e8fa1ec8a6d0275b44c1fcb0..2bf042e9629c96ec018ee662262f121f2d81c10a 100644 (file)
@@ -27,8 +27,6 @@ import com.intellij.facet.impl.invalid.InvalidFacetType;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.components.PersistentStateComponent;
 import com.intellij.openapi.components.State;
-import com.intellij.openapi.components.Storage;
-import com.intellij.openapi.components.StoragePathMacros;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.module.ModuleComponent;
@@ -51,10 +49,7 @@ import java.util.*;
 /**
  * @author nik
  */
-@State(
-  name = FacetManagerImpl.COMPONENT_NAME,
-  storages = @Storage(StoragePathMacros.MODULE_FILE)
-)
+@State(name = FacetManagerImpl.COMPONENT_NAME)
 public class FacetManagerImpl extends FacetManager implements ModuleComponent, PersistentStateComponent<FacetManagerState> {
   private static final Logger LOG = Logger.getInstance("#com.intellij.facet.FacetManagerImpl");
   @NonNls public static final String COMPONENT_NAME = "FacetManager";
index f4478315aa8ff6a92daa276087cc289c06962298..694a45e34c25441ba6cc64860f56de3410734c74 100644 (file)
@@ -359,7 +359,7 @@ public class ModuleImpl extends PlatformComponentManagerImpl implements ModuleEx
     return Extensions.getArea(this).getPicoContainer();
   }
 
-  @State(name = "DeprecatedModuleOptionManager", storages = @Storage(StoragePathMacros.MODULE_FILE))
+  @State(name = "DeprecatedModuleOptionManager")
   static class DeprecatedModuleOptionManager implements PersistentStateComponent<DeprecatedModuleOptionManager.State> {
     static final class State {
       @Property(surroundWithTag = false)
index a96211f138bbe9827f2fe28e66ad78f152a16cee..84d0a54cd8c81c776ecef41a77b7ca92ffef09c2 100644 (file)
@@ -36,10 +36,10 @@ public @interface State {
    * <p>Application-level: optional if you need to load only default state ({@link #defaultStateAsResource} must be true in this case).</p>
    *
    * <p>Project-level: optional, standard project file will be used by default
-   * (
-   * {@code *.ipr} file for file-based and
-   * {@code .idea/misc.xml} for directory-based
-   * ).</p>
+   * ({@code *.ipr} file for file-based and
+   * {@code .idea/misc.xml} for directory-based).</p>
+   *
+   * <p>Module-level: optional, corresponding module file will be used (<code>*.iml</code>).</p>
    */
   Storage[] storages() default {};
 
index 6b275e3741c86c7e1d729c1827ab5cfd22ff5a78..081b76d998c37695f121646849b05e28d11cf07c 100644 (file)
@@ -35,7 +35,8 @@ public @interface Storage {
    * Relative to component container configuration root path.
    * Consider to use shorthand form - <code>@Storage("yourName.xml")</code> (when you need to specify only file path).
    */
-  @NonNls String value() default "";
+  @NonNls
+  String value() default "";
 
   /**
    * If deprecated: Data will be removed on write. And ignored on read if (and only if) new storage exists.
index 5a4cb27b74ba305499c8d759a4f881233f1f4331..ccce409c83c2bb1885c0475f9a3c24a5c43da73f 100644 (file)
@@ -17,8 +17,6 @@ package com.intellij.openapi.roots.impl;
 
 import com.intellij.openapi.components.PersistentStateComponent;
 import com.intellij.openapi.components.State;
-import com.intellij.openapi.components.Storage;
-import com.intellij.openapi.components.StoragePathMacros;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.module.ModulePointer;
 import com.intellij.openapi.module.ModulePointerManager;
@@ -30,10 +28,7 @@ import org.jetbrains.annotations.Nullable;
 /**
  * @author nik
  */
-@State(
-  name = "TestModuleProperties",
-  storages = @Storage(StoragePathMacros.MODULE_FILE)
-)
+@State(name = "TestModuleProperties")
 public class TestModulePropertiesImpl extends TestModuleProperties implements PersistentStateComponent<TestModulePropertiesImpl.TestModulePropertiesState> {
   private final ModulePointerManager myModulePointerManager;
   private ModulePointer myProductionModulePointer;
index be41c81a5077797afabd1044b7bc7a5a4591bdcd..25373a3de65c6287e2df8001194d33e6871cfb72 100644 (file)
@@ -21,8 +21,6 @@ import com.intellij.openapi.application.Result;
 import com.intellij.openapi.application.WriteAction;
 import com.intellij.openapi.components.PersistentStateComponent;
 import com.intellij.openapi.components.State;
-import com.intellij.openapi.components.Storage;
-import com.intellij.openapi.components.StoragePathMacros;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.module.ModuleServiceManager;
 import com.intellij.openapi.module.ModuleType;
@@ -50,7 +48,7 @@ import org.jetbrains.idea.devkit.module.PluginModuleType;
 
 import java.io.File;
 
-@State(name = "DevKit.ModuleBuildProperties", storages = @Storage(StoragePathMacros.MODULE_FILE))
+@State(name = "DevKit.ModuleBuildProperties")
 public class PluginBuildConfiguration implements PersistentStateComponent<PluginBuildConfiguration.State> {
   private final Module myModule;
   private final ConfigFileContainer myPluginXmlContainer;
index a868c72bfc7e1454a10897ca79ec52ef67124ab7..a7f47fc7058af45929a0776a2ff340c73a196e37 100644 (file)
@@ -34,10 +34,7 @@ import java.util.LinkedHashSet;
 import java.util.Map;
 import java.util.Set;
 
-@State(
-  name = "EclipseModuleManager",
-  storages = @Storage(StoragePathMacros.MODULE_FILE)
-)
+@State(name = "EclipseModuleManager")
 public class EclipseModuleManagerImpl implements EclipseModuleManager, PersistentStateComponent<Element>, StateStorageChooserEx {
   @NonNls private static final String VALUE_ATTR = "value";
   @NonNls private static final String VARELEMENT = "varelement";
index 0660d95a8afee136b8389975a886d13e742ebc42..456a6cf8d01e3f9d5242acb9329000f21f44e88a 100644 (file)
@@ -17,8 +17,6 @@ package com.jetbrains.python;
 
 import com.intellij.openapi.components.PersistentStateComponent;
 import com.intellij.openapi.components.State;
-import com.intellij.openapi.components.Storage;
-import com.intellij.openapi.components.StoragePathMacros;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.module.ModuleServiceManager;
 import com.intellij.util.xmlb.XmlSerializerUtil;
@@ -27,10 +25,7 @@ import org.jetbrains.annotations.NotNull;
 /**
  * User: catherine
  */
-@State(
-  name = "ReSTService",
-  storages = @Storage(StoragePathMacros.MODULE_FILE)
-)
+@State(name = "ReSTService")
 public class ReSTService implements PersistentStateComponent<ReSTService> {
   public String DOC_DIR = "";
   public boolean TXT_IS_RST = false;
index 07ff8b611dc5a6b0b3df6a8d154bb165f06b7f15..fd43b67011b128fb2ddc4600e5a364b39cdb098d 100644 (file)
@@ -17,8 +17,6 @@ package com.jetbrains.python.documentation;
 
 import com.intellij.openapi.components.PersistentStateComponent;
 import com.intellij.openapi.components.State;
-import com.intellij.openapi.components.Storage;
-import com.intellij.openapi.components.StoragePathMacros;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.module.ModuleServiceManager;
 import com.intellij.openapi.util.text.StringUtil;
@@ -39,10 +37,7 @@ import java.util.List;
 /**
  * @author yole
  */
-@State(
-  name = "PyDocumentationSettings",
-  storages = @Storage(StoragePathMacros.MODULE_FILE)
-)
+@State(name = "PyDocumentationSettings")
 public class PyDocumentationSettings implements PersistentStateComponent<PyDocumentationSettings> {
   public static final DocStringFormat DEFAULT_DOCSTRING_FORMAT = DocStringFormat.REST;
 
index ceb43efa9965eacdc60f587285d8fc5bb276219c..614f14f8d40719a069906f8b0a54dd5992cc5579 100644 (file)
@@ -17,8 +17,6 @@ package com.jetbrains.python.packaging;
 
 import com.intellij.openapi.components.PersistentStateComponent;
 import com.intellij.openapi.components.State;
-import com.intellij.openapi.components.Storage;
-import com.intellij.openapi.components.StoragePathMacros;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.module.ModuleServiceManager;
 import com.intellij.util.xmlb.XmlSerializerUtil;
@@ -27,7 +25,7 @@ import org.jetbrains.annotations.NotNull;
 /**
  * @author vlan
  */
-@State(name = "PackageRequirementsSettings", storages = @Storage(StoragePathMacros.MODULE_FILE))
+@State(name = "PackageRequirementsSettings")
 public class PyPackageRequirementsSettings implements PersistentStateComponent<PyPackageRequirementsSettings> {
   public static final String DEFAULT_REQUIREMENTS_PATH = "requirements.txt";
 
index 02f5cb8cf682f6db6a87a5495fcf456c3e995aa5..04c8e2cb141a3edb253a666bf42b5bb02a8b4de1 100644 (file)
@@ -17,8 +17,6 @@ package com.jetbrains.python.testing;
 
 import com.intellij.openapi.components.PersistentStateComponent;
 import com.intellij.openapi.components.State;
-import com.intellij.openapi.components.Storage;
-import com.intellij.openapi.components.StoragePathMacros;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.module.ModuleServiceManager;
 import com.intellij.util.xmlb.XmlSerializerUtil;
@@ -30,10 +28,7 @@ import java.util.List;
 /**
  * User: catherine
  */
-@State(
-  name = "TestRunnerService",
-  storages = @Storage(StoragePathMacros.MODULE_FILE)
-)
+@State(name = "TestRunnerService")
 public class TestRunnerService implements PersistentStateComponent<TestRunnerService> {
   private List<String> myConfigurations = new ArrayList<String>();
   public String PROJECT_TEST_RUNNER = "";