From fd00aaa588df4866ef2ca4a60c73292095964ee7 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 19 Jan 2018 18:20:59 +0100 Subject: [PATCH] external project storage: fix saving and loading facets --- .../serialization/SerializationConstants.java | 6 ++++ .../serialization/artifact/ArtifactState.java | 7 ++--- .../model/serialization/facet/FacetState.java | 7 ++--- .../ExternalSystemStorage.kt | 6 ++-- .../FacetFromExternalSourcesStorage.java | 18 ++--------- .../com/intellij/facet/FacetManagerImpl.java | 31 +++++++------------ .../openapi/components/StateSplitterEx.java | 21 ++----------- .../roots/impl/libraries/LibraryImpl.java | 8 ++--- 8 files changed, 36 insertions(+), 68 deletions(-) create mode 100644 jps/model-api/src/org/jetbrains/jps/model/serialization/SerializationConstants.java diff --git a/jps/model-api/src/org/jetbrains/jps/model/serialization/SerializationConstants.java b/jps/model-api/src/org/jetbrains/jps/model/serialization/SerializationConstants.java new file mode 100644 index 000000000000..80aa272a05b1 --- /dev/null +++ b/jps/model-api/src/org/jetbrains/jps/model/serialization/SerializationConstants.java @@ -0,0 +1,6 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package org.jetbrains.jps.model.serialization; + +public class SerializationConstants { + public static final String EXTERNAL_SYSTEM_ID_ATTRIBUTE = "__external-system-id"; +} diff --git a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/artifact/ArtifactState.java b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/artifact/ArtifactState.java index 4b9c6e604cbe..7396fee838ed 100644 --- a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/artifact/ArtifactState.java +++ b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/artifact/ArtifactState.java @@ -1,6 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.jps.model.serialization.artifact; import com.intellij.util.xmlb.annotations.Attribute; @@ -9,6 +7,7 @@ import com.intellij.util.xmlb.annotations.Tag; import com.intellij.util.xmlb.annotations.XCollection; import org.jdom.Element; import org.jetbrains.annotations.NonNls; +import org.jetbrains.jps.model.serialization.SerializationConstants; import java.util.ArrayList; import java.util.List; @@ -42,7 +41,7 @@ public class ArtifactState { return myBuildOnMake; } - @Attribute("external-system-id") + @Attribute(value = SerializationConstants.EXTERNAL_SYSTEM_ID_ATTRIBUTE) public String getExternalSystemId() { return myExternalSystemId; } diff --git a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/facet/FacetState.java b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/facet/FacetState.java index bba0c6198020..461e99031bde 100644 --- a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/facet/FacetState.java +++ b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/facet/FacetState.java @@ -1,6 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.jps.model.serialization.facet; @@ -9,6 +7,7 @@ import com.intellij.util.xmlb.annotations.Property; import com.intellij.util.xmlb.annotations.Tag; import com.intellij.util.xmlb.annotations.XCollection; import org.jdom.Element; +import org.jetbrains.jps.model.serialization.SerializationConstants; import java.util.ArrayList; import java.util.List; @@ -39,7 +38,7 @@ public class FacetState { return myConfiguration; } - @Attribute("external-system-id") + @Attribute(value = SerializationConstants.EXTERNAL_SYSTEM_ID_ATTRIBUTE) public String getExternalSystemId() { return myExternalSystemId; } diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/configurationStore/ExternalSystemStorage.kt b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/configurationStore/ExternalSystemStorage.kt index bc8b1860a3aa..034ea6811b3f 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/configurationStore/ExternalSystemStorage.kt +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/configurationStore/ExternalSystemStorage.kt @@ -1,14 +1,14 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.externalSystem.configurationStore import com.intellij.configurationStore.* import com.intellij.openapi.components.RoamingType -import com.intellij.openapi.components.StateSplitterEx import com.intellij.openapi.components.StoragePathMacros import com.intellij.openapi.module.Module import com.intellij.openapi.project.Project import com.intellij.openapi.util.JDOMUtil import org.jdom.Element +import org.jetbrains.jps.model.serialization.SerializationConstants internal class ExternalModuleStorage(private val module: Module, storageManager: StateStorageManager) : XmlElementStorage(StoragePathMacros.MODULE_FILE, "module", storageManager.macroSubstitutor, RoamingType.DISABLED) { private val manager = StreamProviderFactory.EP_NAME.getExtensions(module.project).first { it is ExternalSystemStreamProviderFactory } as ExternalSystemStreamProviderFactory @@ -48,4 +48,4 @@ internal class ExternalProjectFilteringStorage(fileSpec: String, project: Projec } } -private fun Element.isMarkedAsExternal() = getAttribute(StateSplitterEx.EXTERNAL_SYSTEM_ID_ATTRIBUTE) != null \ No newline at end of file +private fun Element.isMarkedAsExternal() = getAttribute(SerializationConstants.EXTERNAL_SYSTEM_ID_ATTRIBUTE) != null \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/facet/FacetFromExternalSourcesStorage.java b/platform/lang-impl/src/com/intellij/facet/FacetFromExternalSourcesStorage.java index 4405ae0ed98c..27968788da67 100644 --- a/platform/lang-impl/src/com/intellij/facet/FacetFromExternalSourcesStorage.java +++ b/platform/lang-impl/src/com/intellij/facet/FacetFromExternalSourcesStorage.java @@ -1,18 +1,4 @@ -/* - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.facet; import com.intellij.openapi.components.PersistentStateComponent; @@ -30,7 +16,7 @@ import org.jetbrains.jps.model.serialization.facet.FacetManagerState; /** * @author nik */ -@State(name = "FacetsFromExternalSources") +@State(name = "External" + FacetManagerImpl.COMPONENT_NAME, externalStorageOnly = true) public class FacetFromExternalSourcesStorage implements PersistentStateComponent, ProjectModelElement { private FacetManagerState myState = new FacetManagerState(); private Module myModule; diff --git a/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java b/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java index 77dd6558d8cc..758d5a9fd6ff 100644 --- a/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/facet/FacetManagerImpl.java @@ -1,18 +1,4 @@ -/* - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.facet; @@ -287,12 +273,19 @@ public class FacetManagerImpl extends FacetManager implements ModuleComponent, P } @Override - public void loadState(final FacetManagerState state) { + public void noStateLoaded() { + doLoadState(null); + } + + @Override + public void loadState(@NotNull FacetManagerState state) { + doLoadState(state); + } + + protected void doLoadState(@Nullable FacetManagerState state) { ModifiableFacetModel model = new FacetModelImpl(this); FacetManagerState importedFacetsState = FacetFromExternalSourcesStorage.getInstance(myModule).getLoadedState(); - - addFacets(ContainerUtil.concat(state.getFacets(), importedFacetsState.getFacets()), null, model); - + addFacets(ContainerUtil.concat(state == null ? Collections.emptyList() : state.getFacets(), importedFacetsState.getFacets()), null, model); commit(model, false); } diff --git a/platform/projectModel-api/src/com/intellij/openapi/components/StateSplitterEx.java b/platform/projectModel-api/src/com/intellij/openapi/components/StateSplitterEx.java index 5034bc820f95..54184556d068 100644 --- a/platform/projectModel-api/src/com/intellij/openapi/components/StateSplitterEx.java +++ b/platform/projectModel-api/src/com/intellij/openapi/components/StateSplitterEx.java @@ -1,18 +1,4 @@ -/* - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.components; import com.intellij.openapi.util.JDOMUtil; @@ -22,13 +8,12 @@ import com.intellij.util.SmartList; import com.intellij.util.text.UniqueNameGenerator; import org.jdom.Element; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jps.model.serialization.SerializationConstants; import java.util.List; @SuppressWarnings("deprecation") public abstract class StateSplitterEx implements StateSplitter { - public static final String EXTERNAL_SYSTEM_ID_ATTRIBUTE = "__external-system-id"; - @Override public abstract List> splitState(@NotNull Element state); @@ -46,7 +31,7 @@ public abstract class StateSplitterEx implements StateSplitter { UniqueNameGenerator generator = new UniqueNameGenerator(); List> result = new SmartList<>(); for (Element subState : state.getChildren()) { - if (subState.getAttribute(EXTERNAL_SYSTEM_ID_ATTRIBUTE) == null) { + if (subState.getAttribute(SerializationConstants.EXTERNAL_SYSTEM_ID_ATTRIBUTE) == null) { result.add(createItem(subState.getAttributeValue(attributeName), generator, subState)); } } diff --git a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryImpl.java b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryImpl.java index f4425bce71a0..f71c81326674 100644 --- a/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryImpl.java +++ b/platform/projectModel-impl/src/com/intellij/openapi/roots/impl/libraries/LibraryImpl.java @@ -1,10 +1,9 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.roots.impl.libraries; import com.intellij.configurationStore.ComponentSerializationUtil; import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.components.StateSplitterEx; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; @@ -35,6 +34,7 @@ import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.jps.model.serialization.SerializationConstants; import java.util.*; @@ -113,7 +113,7 @@ public class LibraryImpl extends TraceableDisposable implements LibraryEx.Modifi @Nullable private static ProjectModelExternalSource findExternalSource(Element element) { - @Nullable String externalSourceId = element.getAttributeValue(StateSplitterEx.EXTERNAL_SYSTEM_ID_ATTRIBUTE); + @Nullable String externalSourceId = element.getAttributeValue(SerializationConstants.EXTERNAL_SYSTEM_ID_ATTRIBUTE); return externalSourceId != null ? ExternalProjectSystemRegistry.getInstance().getSourceById(externalSourceId) : null; } @@ -376,7 +376,7 @@ public class LibraryImpl extends TraceableDisposable implements LibraryEx.Modifi } 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(StateSplitterEx.EXTERNAL_SYSTEM_ID_ATTRIBUTE, myExternalSource.getId()); + element.setAttribute(SerializationConstants.EXTERNAL_SYSTEM_ID_ATTRIBUTE, myExternalSource.getId()); } }