external project storage: fix saving and loading facets

This commit is contained in:
Vladimir Krivosheev
2018-01-19 18:21:38 +01:00
parent 852dea4f69
commit fd00aaa588
8 changed files with 36 additions and 68 deletions
@@ -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";
}
@@ -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;
}
@@ -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;
}
@@ -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
private fun Element.isMarkedAsExternal() = getAttribute(SerializationConstants.EXTERNAL_SYSTEM_ID_ATTRIBUTE) != null
@@ -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<FacetManagerState>, ProjectModelElement {
private FacetManagerState myState = new FacetManagerState();
private Module myModule;
@@ -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);
}
@@ -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<Pair<Element, String>> splitState(@NotNull Element state);
@@ -46,7 +31,7 @@ public abstract class StateSplitterEx implements StateSplitter {
UniqueNameGenerator generator = new UniqueNameGenerator();
List<Pair<Element, String>> 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));
}
}
@@ -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());
}
}