External project storage — setting in the Maven Importing Settings instead of global...
authorVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Tue, 27 Jun 2017 11:45:21 +0000 (13:45 +0200)
committerVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Tue, 27 Jun 2017 13:04:28 +0000 (15:04 +0200)
19 files changed:
java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java
java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerImpl.java
platform/configuration-store-impl/src/ModuleStateStorageManager.kt
platform/configuration-store-impl/src/ProjectStateStorageManager.kt
platform/configuration-store-impl/src/StateStorageManagerImpl.kt
platform/external-system-impl/src/com/intellij/openapi/externalSystem/configurationStore/ExternalSystemStreamProviderFactory.kt
platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ExternalProjectsManagerImpl.java
platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ExternalProjectsState.java
platform/lang-impl/src/com/intellij/facet/FacetFromExternalSourcesStorage.java
platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java
platform/projectModel-api/src/com/intellij/configurationStore/StreamProvider.kt
platform/projectModel-api/src/com/intellij/openapi/components/StateSplitterEx.java
platform/projectModel-api/src/com/intellij/openapi/project/ProjectUtilCore.kt
platform/projectModel-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryImpl.java
platform/projectModel-impl/src/com/intellij/openapi/roots/impl/libraries/ProjectLibraryTable.kt
plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenImportingConfigurable.java
plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenImportingSettingsForm.form
plugins/maven/src/main/java/org/jetbrains/idea/maven/project/MavenImportingSettingsForm.java
plugins/maven/src/main/java/org/jetbrains/idea/maven/wizards/MavenProjectImportStep.java

index 4056f016738d38f9d7c682ea73e79ca1f398d927..ab24db83d126811feffa9d4ff3bd99eb5013c414 100644 (file)
@@ -24,7 +24,6 @@ import com.intellij.compiler.impl.javaCompiler.BackendCompiler;
 import com.intellij.compiler.impl.javaCompiler.javac.JavacConfiguration;
 import com.intellij.compiler.server.impl.BuildProcessClasspathManager;
 import com.intellij.concurrency.JobScheduler;
-import com.intellij.configurationStore.StreamProviderKt;
 import com.intellij.execution.ExecutionException;
 import com.intellij.execution.ExecutionListener;
 import com.intellij.execution.ExecutionManager;
@@ -52,10 +51,7 @@ import com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl;
 import com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.module.ModuleManager;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.project.ProjectManager;
-import com.intellij.openapi.project.ProjectManagerListener;
-import com.intellij.openapi.project.ProjectUtil;
+import com.intellij.openapi.project.*;
 import com.intellij.openapi.projectRoots.*;
 import com.intellij.openapi.projectRoots.ex.JavaSdkUtil;
 import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl;
@@ -1140,7 +1136,7 @@ public class BuildManager implements Disposable {
       cmdLine.addParameter("-Dpreload.config.path=" + FileUtil.toCanonicalPath(PathManager.getOptionsPath()));
     }
 
-    if (StreamProviderKt.isExternalStorageEnabled()) {
+    if (ProjectUtilCore.isExternalStorageEnabled(project)) {
       cmdLine.addParameter("-D" + GlobalOptions.EXTERNAL_PROJECT_CONFIG + "=" + ProjectUtil.getExternalConfigurationDir(project));
     }
 
index ab10a1c5b0927ac31836ffcc30f9e00fb30cf4d3..1fc36fbba31982a2495de38fe50c6a1d6ca679a9 100644 (file)
@@ -25,6 +25,7 @@ import com.intellij.openapi.components.Storage;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.module.ProjectLoadingErrorsNotifier;
 import com.intellij.openapi.project.Project;
+import com.intellij.openapi.project.ProjectUtilCore;
 import com.intellij.openapi.roots.ExternalProjectSystemRegistry;
 import com.intellij.openapi.roots.ProjectModelExternalSource;
 import com.intellij.openapi.roots.ex.ProjectRootManagerEx;
@@ -32,7 +33,6 @@ import com.intellij.openapi.updateSettings.impl.pluginsAdvertisement.UnknownFeat
 import com.intellij.openapi.util.ModificationTracker;
 import com.intellij.openapi.util.Pair;
 import com.intellij.openapi.util.SimpleModificationTracker;
-import com.intellij.openapi.util.registry.Registry;
 import com.intellij.openapi.vfs.LocalFileSystem;
 import com.intellij.openapi.vfs.VirtualFileManager;
 import com.intellij.packaging.artifacts.*;
@@ -126,7 +126,7 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo
         artifactState.setRootElement(serializePackagingElement(artifact.getRootElement()));
         artifactState.setArtifactType(artifact.getArtifactType().getId());
         ProjectModelExternalSource externalSource = artifact.getExternalSource();
-        if (externalSource != null && Registry.is("store.imported.project.elements.separately")) {
+        if (externalSource != null && ProjectUtilCore.isExternalStorageEnabled(myProject)) {
           //we can add this attribute only if the artifact configuration will be stored separately, otherwise we will get modified files in .idea/artifacts.
           artifactState.setExternalSystemId(externalSource.getId());
         }
index ae6c3d8113c4c6ffa6e6d6721e2c2cfcdbe0bdff..4ad61017068166ab0643c1149c5b2b0b5d5b73fb 100644 (file)
@@ -22,6 +22,7 @@ import com.intellij.openapi.module.impl.ModuleEx
 import com.intellij.openapi.module.impl.ModuleManagerImpl
 import com.intellij.openapi.module.impl.getModuleNameByFilePath
 import com.intellij.openapi.project.ProjectBundle
+import com.intellij.openapi.project.isExternalStorageEnabled
 import com.intellij.openapi.vfs.newvfs.events.VFileEvent
 import com.intellij.util.LineSeparator
 import com.intellij.util.io.systemIndependentPath
@@ -80,6 +81,9 @@ internal class ModuleStateStorageManager(macroSubstitutor: TrackingPathMacroSubs
     element.setAttribute(ProjectStateStorageManager.VERSION_OPTION, "4")
   }
 
+  override val isExternalSystemStorageEnabled: Boolean
+    get() = (componentManager as Module).project.isExternalStorageEnabled
+
   override fun createFileBasedStorage(path: String, collapsedPath: String, roamingType: RoamingType, rootTagName: String?): StateStorage
     = ModuleFileStorage(this, Paths.get(path), collapsedPath, rootTagName, roamingType, getMacroSubstitutor(collapsedPath), if (roamingType == RoamingType.DISABLED) null else compoundStreamProvider)
 
index a73abe689fbc6718b12ab1a310116d33bcefbbc1..4d5990c3a65fd627ccc10cbf38af2638c4f8ce29 100644 (file)
@@ -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.project.impl.ProjectImpl
+import com.intellij.openapi.project.isExternalStorageEnabled
 import org.jdom.Element
 
 // extended in upsource
@@ -52,4 +53,7 @@ open class ProjectStateStorageManager(macroSubstitutor: TrackingPathMacroSubstit
     }
     return PROJECT_FILE
   }
+
+  override val isExternalSystemStorageEnabled: Boolean
+    get() = project.isExternalStorageEnabled
 }
\ No newline at end of file
index be4d21d80d1c088e52a63bb88d3ec343d61aa119..288b7307a6ffa60ba3ce1d161528e5898da8c210 100644 (file)
@@ -311,13 +311,16 @@ open class StateStorageManagerImpl(private val rootTagName: String,
     }
 
     override fun getResolution(component: PersistentStateComponent<*>, operation: StateStorageOperation): Resolution {
-      if (operation == StateStorageOperation.WRITE && component is ProjectModelElement && isExternalStorageEnabled && component.externalSource != null) {
+      if (operation == StateStorageOperation.WRITE && component is ProjectModelElement && storageManager.isExternalSystemStorageEnabled && component.externalSource != null) {
         return Resolution.CLEAR
       }
       return Resolution.DO
     }
   }
 
+  protected open val isExternalSystemStorageEnabled: Boolean
+    get() = false
+
   protected open fun beforeElementSaved(element: Element) {
   }
 
index c6278ed83751e34e2b9c3a6a371d5a76100bcf42..9a3ad777bed1f25b21e764e40ada0283b1e26c1a 100644 (file)
@@ -18,7 +18,6 @@ package com.intellij.openapi.externalSystem.configurationStore
 import com.intellij.ProjectTopics
 import com.intellij.configurationStore.FileStorageAnnotation
 import com.intellij.configurationStore.StreamProviderFactory
-import com.intellij.configurationStore.isExternalStorageEnabled
 import com.intellij.openapi.application.ApplicationManager
 import com.intellij.openapi.components.*
 import com.intellij.openapi.diagnostic.logger
@@ -27,6 +26,7 @@ import com.intellij.openapi.module.Module
 import com.intellij.openapi.project.ModuleListener
 import com.intellij.openapi.project.Project
 import com.intellij.openapi.project.ex.ProjectEx
+import com.intellij.openapi.project.isExternalStorageEnabled
 import com.intellij.openapi.roots.ProjectModelElement
 import com.intellij.util.Function
 import org.jdom.Element
@@ -73,7 +73,9 @@ internal class ExternalSystemStreamProviderFactory(private val project: Project)
   }
 
   override fun customizeStorageSpecs(component: PersistentStateComponent<*>, componentManager: ComponentManager, storages: List<Storage>, operation: StateStorageOperation): List<Storage>? {
-    if (!isExternalStorageEnabled) {
+    val project = componentManager as? Project ?: (componentManager as Module).project
+    // we store isExternalStorageEnabled option in the project workspace file, so, for such components external storage is always disabled and not applicable
+    if ((storages.size == 1 && storages.first().value == StoragePathMacros.WORKSPACE_FILE) || !project.isExternalStorageEnabled) {
       return null
     }
 
index 7f832a8a7628eefbbf1cea8a8b87cd146a7db3a4..bb768b947438af833c63d43c428a280a92aa1321 100644 (file)
@@ -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.
@@ -18,7 +18,6 @@ package com.intellij.openapi.externalSystem.service.project.manage;
 import com.intellij.openapi.Disposable;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.components.*;
-import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.externalSystem.ExternalSystemManager;
 import com.intellij.openapi.externalSystem.importing.ImportSpec;
 import com.intellij.openapi.externalSystem.model.DataNode;
@@ -35,6 +34,7 @@ import com.intellij.openapi.externalSystem.view.ExternalProjectsView;
 import com.intellij.openapi.externalSystem.view.ExternalProjectsViewImpl;
 import com.intellij.openapi.externalSystem.view.ExternalProjectsViewState;
 import com.intellij.openapi.project.Project;
+import com.intellij.openapi.project.ProjectFileStoreOptionManager;
 import com.intellij.openapi.util.Disposer;
 import com.intellij.util.SmartList;
 import com.intellij.util.containers.ContainerUtil;
@@ -56,9 +56,7 @@ import static com.intellij.openapi.externalSystem.model.ProjectKeys.TASK;
  * @since 10/23/2014
  */
 @State(name = "ExternalProjectsManager", storages = {@Storage(StoragePathMacros.WORKSPACE_FILE)})
-public class ExternalProjectsManagerImpl implements ExternalProjectsManager, PersistentStateComponent<ExternalProjectsState>, Disposable {
-  private static final Logger LOG = Logger.getInstance(ExternalProjectsManager.class);
-
+public class ExternalProjectsManagerImpl implements ExternalProjectsManager, PersistentStateComponent<ExternalProjectsState>, Disposable, ProjectFileStoreOptionManager {
   private final AtomicBoolean isInitializationFinished = new AtomicBoolean();
   private final AtomicBoolean isInitializationStarted = new AtomicBoolean();
   private final CompositeRunnable myPostInitializationActivities = new CompositeRunnable();
@@ -86,6 +84,15 @@ public class ExternalProjectsManagerImpl implements ExternalProjectsManager, Per
     return (ExternalProjectsManagerImpl)service;
   }
 
+  @Override
+  public boolean isStoredExternally() {
+    return myState.storeExternally;
+  }
+
+  public void setStoreExternally(boolean value) {
+    myState.storeExternally = value;
+  }
+
   @NotNull
   @Override
   public Project getProject() {
index e8117f78224cc218859b4bfb92a72067046dbad8..c1ef849a637e3d9b345737c95353cb32e784ce08 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2014 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.
@@ -17,10 +17,11 @@ package com.intellij.openapi.externalSystem.service.project.manage;
 
 import com.intellij.openapi.externalSystem.view.ExternalProjectsViewState;
 import com.intellij.util.containers.FactoryMap;
+import com.intellij.util.xmlb.annotations.Attribute;
 import com.intellij.util.xmlb.annotations.MapAnnotation;
 import com.intellij.util.xmlb.annotations.Property;
 import com.intellij.util.xmlb.annotations.Tag;
-import org.jetbrains.annotations.Nullable;
+import org.jetbrains.annotations.NotNull;
 
 import java.util.LinkedHashMap;
 import java.util.Map;
@@ -30,10 +31,8 @@ import java.util.Map;
  * @since 10/23/2014
  */
 public class ExternalProjectsState {
-
-
   private final Map<String, State> myExternalSystemsState = new NullSafeMap<String, State>() {
-    @Nullable
+    @NotNull
     @Override
     protected State create(String key) {
       return new State();
@@ -51,13 +50,15 @@ public class ExternalProjectsState {
   public void setExternalSystemsState(Map<String, State> externalSystemsState) {
   }
 
+  @Attribute
+  public boolean storeExternally;
 
   @Tag("state")
   public static class State {
     private ExternalProjectsViewState projectsViewState = new ExternalProjectsViewState();
 
     private final Map<String, TaskActivationState> myExternalSystemsTaskActivation = new NullSafeMap<String, TaskActivationState>() {
-      @Nullable
+      @NotNull
       @Override
       protected TaskActivationState create(String key) {
         return new TaskActivationState();
index 042651dfdd904c1c6f0e8365cee2423a23d02257..4405ae0ed98c40b7398f4fc1846f955290b4095b 100644 (file)
@@ -46,7 +46,7 @@ public class FacetFromExternalSourcesStorage implements PersistentStateComponent
   @Override
   @NotNull
   public FacetManagerState getState() {
-    myState = ((FacetManagerImpl)FacetManager.getInstance(myModule)).saveState(FacetManagerImpl.getImportedFacetPredicate());
+    myState = ((FacetManagerImpl)FacetManager.getInstance(myModule)).saveState(FacetManagerImpl.getImportedFacetPredicate(myModule.getProject()));
     return myState;
   }
 
index c2470010503cd065392fc0ef3be5f89d1b5e2d0b..d788090b9e6cd20004cb281ff5040220c36ca113 100644 (file)
@@ -32,12 +32,13 @@ import com.intellij.openapi.module.Module;
 import com.intellij.openapi.module.ModuleComponent;
 import com.intellij.openapi.module.ModuleType;
 import com.intellij.openapi.module.ProjectLoadingErrorsNotifier;
+import com.intellij.openapi.project.Project;
 import com.intellij.openapi.project.ProjectBundle;
+import com.intellij.openapi.project.ProjectUtilCore;
 import com.intellij.openapi.roots.ExternalProjectSystemRegistry;
 import com.intellij.openapi.roots.ProjectModelExternalSource;
 import com.intellij.openapi.updateSettings.impl.pluginsAdvertisement.UnknownFeaturesCollector;
 import com.intellij.openapi.util.*;
-import com.intellij.openapi.util.registry.Registry;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.util.containers.ContainerUtil;
 import com.intellij.util.messages.MessageBus;
@@ -254,7 +255,7 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P
     }
 
     F facet = null;
-    if (!facetsOfThisType.isEmpty() && Registry.is("store.imported.project.elements.separately")) {
+    if (!facetsOfThisType.isEmpty() && ProjectUtilCore.isExternalStorageEnabled(myModule.getProject())) {
       facet = facetsOfThisType.stream().filter(f -> f.getName().equals(state.getName())).findFirst().orElse(null);
       if (facet != null) {
         Element newConfiguration = state.getConfiguration();
@@ -298,12 +299,12 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P
   @Override
   @NotNull
   public FacetManagerState getState() {
-    return saveState(getImportedFacetPredicate().negate());
+    return saveState(getImportedFacetPredicate(myModule.getProject()).negate());
   }
 
   @NotNull
-  static Predicate<Facet> getImportedFacetPredicate() {
-    if (Registry.is("store.imported.project.elements.separately")) {
+  static Predicate<Facet> getImportedFacetPredicate(@NotNull Project project) {
+    if (ProjectUtilCore.isExternalStorageEnabled(project)) {
       //we can store imported facets in a separate component only if that component will be stored separately, otherwise we will get modified *.iml files
       return facet -> facet.getExternalSource() != null;
     }
@@ -323,7 +324,7 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P
       if (!filter.test(facet)) continue;
       final Facet underlyingFacet = facet.getUnderlyingFacet();
 
-      FacetState facetState = createFacetState(facet);
+      FacetState facetState = createFacetState(facet, myModule.getProject());
       if (!(facet instanceof InvalidFacet)) {
         final Element config;
         try {
@@ -340,7 +341,7 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P
         facetState.setConfiguration(config);
       }
 
-      getOrCreateTargetFacetList(underlyingFacet, states).add(facetState);
+      getOrCreateTargetFacetList(underlyingFacet, states, myModule.getProject()).add(facetState);
       states.put(facet, facetState.getSubFacets());
     }
     return managerState;
@@ -350,25 +351,25 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P
    * Configuration of some facet may be stored in one file, but configuration of its underlying facet may be stored in another file. For such
    * sub-facets we create parent elements which don't store configuration but only name and type.
    */
-  private static List<FacetState> getOrCreateTargetFacetList(Facet underlyingFacet, Map<Facet, List<FacetState>> states) {
+  private static List<FacetState> getOrCreateTargetFacetList(Facet underlyingFacet, Map<Facet, List<FacetState>> states, @NotNull Project project) {
     List<FacetState> facetStateList = states.get(underlyingFacet);
     if (facetStateList == null) {
-      FacetState state = createFacetState(underlyingFacet);
-      getOrCreateTargetFacetList(underlyingFacet.getUnderlyingFacet(), states).add(state);
+      FacetState state = createFacetState(underlyingFacet, project);
+      getOrCreateTargetFacetList(underlyingFacet.getUnderlyingFacet(), states, project).add(state);
       facetStateList = state.getSubFacets();
       states.put(underlyingFacet, facetStateList);
     }
     return facetStateList;
   }
 
-  private static FacetState createFacetState(Facet facet) {
+  private static FacetState createFacetState(@NotNull Facet facet, @NotNull Project project) {
     if (facet instanceof InvalidFacet) {
       return ((InvalidFacet)facet).getConfiguration().getFacetState();
     }
     else {
       FacetState facetState = new FacetState();
       ProjectModelExternalSource externalSource = facet.getExternalSource();
-      if (externalSource != null && Registry.is("store.imported.project.elements.separately")) {
+      if (externalSource != null && ProjectUtilCore.isExternalStorageEnabled(project)) {
         //set this attribute only if such facets will be stored separately, otherwise we will get modified *.iml files
         facetState.setExternalSystemId(externalSource.getId());
       }
index e978c13515d8e6c1f6f1396c1f0ae4c84febbc13..5f74c156631601a7025213a18e25029b7ccec0ab 100644 (file)
@@ -17,16 +17,12 @@ package com.intellij.configurationStore
 
 import com.intellij.openapi.components.RoamingType
 import com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream
-import com.intellij.openapi.util.registry.Registry
 import org.jetbrains.annotations.TestOnly
 import java.io.InputStream
 
 @set:TestOnly
 var IS_EXTERNAL_STORAGE_ENABLED = false
 
-val isExternalStorageEnabled: Boolean
-  get() = Registry.`is`("store.imported.project.elements.separately", false) || IS_EXTERNAL_STORAGE_ENABLED
-
 interface StreamProvider {
   val enabled: Boolean
     get() = true
index aa010f629179b3e0e94163e88b110b44840bd47f..5034bc820f9514b0ff792e16ac5cb4d42678c2ce 100644 (file)
@@ -15,7 +15,6 @@
  */
 package com.intellij.openapi.components;
 
-import com.intellij.configurationStore.StreamProviderKt;
 import com.intellij.openapi.util.JDOMUtil;
 import com.intellij.openapi.util.Pair;
 import com.intellij.openapi.util.io.FileUtil;
@@ -28,7 +27,7 @@ import java.util.List;
 
 @SuppressWarnings("deprecation")
 public abstract class StateSplitterEx implements StateSplitter {
-  public static final String EXTERNAL_SYSTEM_ID_ATTRIBUTE = "external-system-id";
+  public static final String EXTERNAL_SYSTEM_ID_ATTRIBUTE = "__external-system-id";
 
   @Override
   public abstract List<Pair<Element, String>> splitState(@NotNull Element state);
@@ -44,16 +43,10 @@ public abstract class StateSplitterEx implements StateSplitter {
 
   @NotNull
   protected static List<Pair<Element, String>> splitState(@NotNull Element state, @NotNull String attributeName) {
-    return splitState(state, attributeName, false);
-  }
-
-  @NotNull
-  protected static List<Pair<Element, String>> splitState(@NotNull Element state, @NotNull String attributeName, boolean filterOutExternalElements) {
     UniqueNameGenerator generator = new UniqueNameGenerator();
     List<Pair<Element, String>> result = new SmartList<>();
-    boolean isExternalStorageEnabled = filterOutExternalElements && StreamProviderKt.isExternalStorageEnabled();
     for (Element subState : state.getChildren()) {
-      if (!isExternalStorageEnabled || subState.getAttribute(EXTERNAL_SYSTEM_ID_ATTRIBUTE) == null) {
+      if (subState.getAttribute(EXTERNAL_SYSTEM_ID_ATTRIBUTE) == null) {
         result.add(createItem(subState.getAttributeValue(attributeName), generator, subState));
       }
     }
index d31f9a1c383d89e61250e42fde5b859f9f3f8fed..613f84a660d3d2d59c4c69f86932a28ae95f6334 100644 (file)
 @file:JvmName("ProjectUtilCore")
 package com.intellij.openapi.project
 
+import com.intellij.configurationStore.IS_EXTERNAL_STORAGE_ENABLED
 import com.intellij.openapi.module.ModuleUtilCore
 import com.intellij.openapi.roots.JdkOrderEntry
 import com.intellij.openapi.roots.libraries.LibraryUtil
 import com.intellij.openapi.util.SystemInfo
+import com.intellij.openapi.util.registry.Registry
 import com.intellij.openapi.vfs.LocalFileProvider
 import com.intellij.openapi.vfs.VirtualFile
 
@@ -58,4 +60,14 @@ fun displayUrlRelativeToProject(file: VirtualFile, url: String, project: Project
   else {
     "[${module.name}] - $result"
   }
-}
\ No newline at end of file
+}
+
+interface ProjectFileStoreOptionManager {
+  val isStoredExternally: Boolean
+}
+
+val Project.isExternalStorageEnabled: Boolean
+  get() {
+    val manager = picoContainer.getComponentInstance("com.intellij.openapi.externalSystem.service.project.manage.ExternalProjectsManager") as? ProjectFileStoreOptionManager ?: return false
+    return manager.isStoredExternally || Registry.`is`("store.imported.project.elements.separately", false) || IS_EXTERNAL_STORAGE_ENABLED
+  }
\ No newline at end of file
index 6bea7abd4a161b46361885fcf9a38bf9eee9230d..550bbc31cccc05f624eaf6b58572e0c213fed702 100644 (file)
@@ -20,12 +20,13 @@ import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.components.ComponentSerializationUtil;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.module.Module;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.project.ProjectUtilCore;
 import com.intellij.openapi.roots.*;
 import com.intellij.openapi.roots.impl.RootModelImpl;
 import com.intellij.openapi.roots.impl.RootProviderBaseImpl;
 import com.intellij.openapi.roots.libraries.*;
 import com.intellij.openapi.util.*;
-import com.intellij.openapi.util.registry.Registry;
 import com.intellij.openapi.vfs.StandardFileSystems;
 import com.intellij.openapi.vfs.VfsUtilCore;
 import com.intellij.openapi.vfs.VirtualFile;
@@ -74,6 +75,7 @@ public class LibraryImpl extends TraceableDisposable implements LibraryEx.Modifi
   private LibraryProperties myProperties;
 
   private final MyRootProviderImpl myRootProvider = new MyRootProviderImpl();
+  @Nullable
   private final ModifiableRootModel myRootModel;
   private boolean myDisposed;
   private final Disposable myPointersDisposable = Disposer.newDisposable();
@@ -134,7 +136,7 @@ public class LibraryImpl extends TraceableDisposable implements LibraryEx.Modifi
   }
 
   // primary
-  private LibraryImpl(LibraryTable table, ModifiableRootModel rootModel, LibraryImpl newSource, String name,
+  private LibraryImpl(LibraryTable table, @Nullable ModifiableRootModel rootModel, LibraryImpl newSource, String name,
                       @Nullable final PersistentLibraryKind<?> kind, @Nullable ProjectModelExternalSource externalSource) {
     super(true);
     myLibraryTable = table;
@@ -372,9 +374,19 @@ public class LibraryImpl extends TraceableDisposable implements LibraryEx.Modifi
       }
     }
 
-    if (myExternalSource != null && Registry.is("store.imported.project.elements.separately")) {
-      //we can add this attribute only if the library configuration will be stored separately, otherwise we will get modified files in .idea/libraries.
-      element.setAttribute(EXTERNAL_SYSTEM_ID_ATTRIBUTE, myExternalSource.getId());
+    if (myExternalSource != null) {
+      Module module = getModule();
+      Project project;
+      if (module == null) {
+        project = myLibraryTable instanceof ProjectLibraryTable ? ((ProjectLibraryTable)myLibraryTable).getProject() : null;
+      }
+      else {
+        project = module.getProject();
+      }
+      if (ProjectUtilCore.isExternalStorageEnabled(project)) {
+        //we can add this attribute only if the library configuration will be stored separately, otherwise we will get modified files in .idea/libraries.
+        element.setAttribute(EXTERNAL_SYSTEM_ID_ATTRIBUTE, myExternalSource.getId());
+      }
     }
 
     ArrayList<OrderRootType> storableRootTypes = new ArrayList<>();
index 4c5e33d9da1c5b8bafa7d88f10ebb5e1a03f7714..fb0dd81f1b2db1c7a14f5c713b1c84c3b8dcc883 100644 (file)
@@ -28,7 +28,7 @@ import com.intellij.openapi.util.Pair
 import org.jdom.Element
 
 @State(name = "libraryTable", storages = arrayOf(Storage(value = "libraries", stateSplitter = ProjectLibraryTable.LibraryStateSplitter::class)))
-open class ProjectLibraryTable : LibraryTableBase() {
+open class ProjectLibraryTable(val project: Project) : LibraryTableBase() {
   companion object {
     @JvmStatic
     fun getInstance(project: Project): LibraryTable = project.service<ProjectLibraryTable>()
@@ -39,7 +39,7 @@ open class ProjectLibraryTable : LibraryTableBase() {
   override fun getPresentation() = PROJECT_LIBRARY_TABLE_PRESENTATION
 
   class LibraryStateSplitter : StateSplitterEx() {
-    override fun splitState(state: Element): MutableList<Pair<Element, String>> = StateSplitterEx.splitState(state, LibraryImpl.LIBRARY_NAME_ATTR, true)
+    override fun splitState(state: Element): MutableList<Pair<Element, String>> = StateSplitterEx.splitState(state, LibraryImpl.LIBRARY_NAME_ATTR)
   }
 }
 
index b7c6434578e41497c3fdf9955a5b56260f917f22..7288b387b5a59d63bbbd1b037e54c0ca27b57f4e 100644 (file)
@@ -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,6 +15,8 @@
  */
 package org.jetbrains.idea.maven.project;
 
+import com.intellij.openapi.externalSystem.service.project.manage.ExternalProjectsManagerImpl;
+import com.intellij.openapi.externalSystem.service.ui.ExternalSystemJdkComboBox;
 import com.intellij.openapi.options.ConfigurationException;
 import com.intellij.openapi.options.SearchableConfigurable;
 import com.intellij.openapi.options.UnnamedConfigurable;
@@ -22,7 +24,6 @@ import com.intellij.openapi.project.Project;
 import org.jetbrains.annotations.Nls;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
-import com.intellij.openapi.externalSystem.service.ui.ExternalSystemJdkComboBox;
 import org.jetbrains.idea.maven.server.MavenServerManager;
 
 import javax.swing.*;
@@ -38,7 +39,10 @@ public class MavenImportingConfigurable implements SearchableConfigurable {
   private final JTextField myEmbedderVMOptions;
   private final ExternalSystemJdkComboBox myEmbedderJdk;
 
-  public MavenImportingConfigurable(Project project) {
+  private final Project myProject;
+
+  public MavenImportingConfigurable(@NotNull Project project) {
+    myProject = project;
     myImportingSettings = MavenProjectsManager.getInstance(project).getImportingSettings();
 
     myAdditionalConfigurables = new ArrayList<>();
@@ -108,11 +112,12 @@ public class MavenImportingConfigurable implements SearchableConfigurable {
       return true;
     }
 
-    return mySettingsForm.isModified(myImportingSettings);
+    return mySettingsForm.isModified(myImportingSettings, myProject);
   }
 
   public void apply() throws ConfigurationException {
     mySettingsForm.getData(myImportingSettings);
+    ExternalProjectsManagerImpl.getInstance(myProject).setStoreExternally(mySettingsForm.isStoreExternally());
 
     MavenServerManager.getInstance().setMavenEmbedderVMOptions(myEmbedderVMOptions.getText());
     String jdk = myEmbedderJdk.getSelectedValue();
@@ -126,7 +131,7 @@ public class MavenImportingConfigurable implements SearchableConfigurable {
   }
 
   public void reset() {
-    mySettingsForm.setData(myImportingSettings);
+    mySettingsForm.setData(myImportingSettings, myProject);
 
     myEmbedderVMOptions.setText(MavenServerManager.getInstance().getMavenEmbedderVMOptions());
     myEmbedderJdk.refreshData(MavenServerManager.getInstance().getEmbedderJdk());
index 280176aa92820bc719b8566e9cd016d1d5f83d12..055e653203539c2fb965e6534bcd96cb2ae85551 100644 (file)
@@ -3,7 +3,7 @@
   <grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="19" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
     <margin top="0" left="0" bottom="0" right="0"/>
     <constraints>
-      <xy x="20" y="20" width="769" height="577"/>
+      <xy x="20" y="20" width="769" height="588"/>
     </constraints>
     <properties/>
     <border type="none"/>
           </hspacer>
         </children>
       </grid>
-      <grid id="7fb78" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+      <grid id="7fb78" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
         <margin top="0" left="0" bottom="10" right="0"/>
         <constraints>
           <grid row="3" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
             </constraints>
             <properties/>
           </component>
+          <component id="a42a0" class="javax.swing.JCheckBox" binding="myStoreProjectFilesExternally">
+            <constraints>
+              <grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+            </constraints>
+            <properties>
+              <text value="Store generated project files externally"/>
+            </properties>
+          </component>
         </children>
       </grid>
       <vspacer id="5d738">
index 85ab5991417770a967aa35fb7118f9b305f08c44..0f4132ee55fa6b8e71fe49c096a8f9e330621051 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2012 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,7 +16,9 @@
 package org.jetbrains.idea.maven.project;
 
 import com.intellij.ide.util.projectWizard.WizardContext;
+import com.intellij.openapi.externalSystem.service.project.manage.ExternalProjectsManagerImpl;
 import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
+import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.TextFieldWithBrowseButton;
 import com.intellij.openapi.updateSettings.impl.LabelTextReplacingUtil;
 import com.intellij.openapi.util.io.FileUtil;
@@ -24,6 +26,8 @@ import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.projectImport.ProjectFormatPanel;
 import com.intellij.ui.EnumComboBoxModel;
 import com.intellij.ui.ListCellRendererWrapper;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 import java.awt.event.ActionEvent;
@@ -53,6 +57,7 @@ public class MavenImportingSettingsForm {
   private JComboBox myGeneratedSourcesComboBox;
   private JCheckBox myExcludeTargetFolderCheckBox;
   private JTextField myDependencyTypes;
+  private JCheckBox myStoreProjectFilesExternally;
 
   public MavenImportingSettingsForm(boolean isImportStep, boolean isCreatingNewProject) {
     mySearchRecursivelyCheckBox.setVisible(isImportStep);
@@ -105,7 +110,7 @@ public class MavenImportingSettingsForm {
     return myPanel;
   }
 
-  public void getData(MavenImportingSettings data) {
+  public void getData(@NotNull MavenImportingSettings data) {
     data.setLookForNested(mySearchRecursivelyCheckBox.isSelected());
     data.setDedicatedModuleDir(mySeparateModulesDirCheckBox.isSelected() ? mySeparateModulesDirChooser.getText() : "");
 
@@ -126,7 +131,7 @@ public class MavenImportingSettingsForm {
     data.setDependencyTypes(myDependencyTypes.getText());
   }
 
-  public void setData(MavenImportingSettings data) {
+  public void setData(MavenImportingSettings data, @Nullable Project project) {
     mySearchRecursivelyCheckBox.setSelected(data.isLookForNested());
 
     mySeparateModulesDirCheckBox.setSelected(!StringUtil.isEmptyOrSpaces(data.getDedicatedModuleDir()));
@@ -137,6 +142,13 @@ public class MavenImportingSettingsForm {
     myCreateGroupsCheckBox.setSelected(data.isCreateModuleGroups());
 
     myKeepSourceFoldersCheckBox.setSelected(data.isKeepSourceFolders());
+    if (project == null) {
+      myStoreProjectFilesExternally.setVisible(false);
+    }
+    else {
+      myStoreProjectFilesExternally.setVisible(true);
+      myStoreProjectFilesExternally.setSelected(ExternalProjectsManagerImpl.getInstance(project).isStoredExternally());
+    }
     myExcludeTargetFolderCheckBox.setSelected(data.isExcludeTargetFolder());
     myUseMavenOutputCheckBox.setSelected(data.isUseMavenOutput());
 
@@ -151,12 +163,20 @@ public class MavenImportingSettingsForm {
     updateControls();
   }
 
-  public boolean isModified(MavenImportingSettings settings) {
+  public boolean isModified(@NotNull MavenImportingSettings settings, @Nullable Project project) {
+    if (project != null && ExternalProjectsManagerImpl.getInstance(project).isStoredExternally() != isStoreExternally()) {
+      return true;
+    }
+
     MavenImportingSettings formData = new MavenImportingSettings();
     getData(formData);
     return !formData.equals(settings);
   }
 
+  boolean isStoreExternally() {
+    return myStoreProjectFilesExternally.isSelected();
+  }
+
   public void updateData(WizardContext wizardContext) {
     myProjectFormatPanel.updateData(wizardContext);
   }
index aac7633725398760c7ba78b00040fd83c987884c..fdbcdd5f0b163bb7153b4cec5a3061108a264434 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2009 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.
@@ -119,7 +119,7 @@ public class MavenProjectImportStep extends ProjectImportWizardStep {
       myRootPathComponent.setPath(FileUtil.toSystemDependentName(path));
       myRootPathComponent.getPathComponent().selectAll();
     }
-    myImportingSettingsForm.setData(getImportingSettings());
+    myImportingSettingsForm.setData(getImportingSettings(), null);
   }
 
   public JComponent getPreferredFocusedComponent() {