From a766bedf7c32cb3e39b98aa98a763780ea482dea Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 18 May 2012 16:04:21 +0200 Subject: [PATCH] pull StorageData to upper level --- .../impl/stores/IdeaProjectStoreImpl.java | 10 +- .../stores/ModuleStateStorageManager.java | 4 +- .../impl/stores/ModuleStoreImpl.java | 6 +- .../impl/stores/ApplicationStoreImpl.java | 2 +- .../stores/BaseFileConfigurableStoreImpl.java | 6 +- .../stores/ProjectStateStorageManager.java | 6 +- .../impl/stores/ProjectStoreImpl.java | 6 +- .../impl/stores/StateStorageManagerImpl.java | 4 +- .../components/impl/stores/StorageData.java | 221 ++++++++++++++++++ .../impl/stores/XmlElementStorage.java | 206 +--------------- .../components/XmlConfigurationMerger.java | 2 +- 11 files changed, 250 insertions(+), 223 deletions(-) create mode 100644 platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StorageData.java rename platform/{platform-api => projectModel-api}/src/com/intellij/openapi/components/XmlConfigurationMerger.java (95%) diff --git a/java/idea-ui/src/com/intellij/openapi/components/impl/stores/IdeaProjectStoreImpl.java b/java/idea-ui/src/com/intellij/openapi/components/impl/stores/IdeaProjectStoreImpl.java index 6407ae5ac140..bd32731c8b39 100644 --- a/java/idea-ui/src/com/intellij/openapi/components/impl/stores/IdeaProjectStoreImpl.java +++ b/java/idea-ui/src/com/intellij/openapi/components/impl/stores/IdeaProjectStoreImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -34,11 +34,11 @@ public class IdeaProjectStoreImpl extends ProjectWithModulesStoreImpl { protected StateStorageManager createStateStorageManager() { return new ProjectStateStorageManager(PathMacroManager.getInstance(getComponentManager()).createTrackingSubstitutor(), myProject) { - public XmlElementStorage.StorageData createWsStorageData() { + public StorageData createWsStorageData() { return new IdeaWsStorageData(ROOT_TAG_NAME, myProject); } - public XmlElementStorage.StorageData createIprStorageData() { + public StorageData createIprStorageData() { return new IdeaIprStorageData(ROOT_TAG_NAME, myProject); } }; @@ -53,7 +53,7 @@ public class IdeaProjectStoreImpl extends ProjectWithModulesStoreImpl { super(storageData); } - public XmlElementStorage.StorageData clone() { + public StorageData clone() { return new IdeaWsStorageData(this); } } @@ -68,7 +68,7 @@ public class IdeaProjectStoreImpl extends ProjectWithModulesStoreImpl { super(storageData); } - public XmlElementStorage.StorageData clone() { + public StorageData clone() { return new IdeaIprStorageData(this); } diff --git a/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStateStorageManager.java b/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStateStorageManager.java index a6932b6b2e4d..614c466319f1 100644 --- a/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStateStorageManager.java +++ b/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStateStorageManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -32,7 +32,7 @@ class ModuleStateStorageManager extends StateStorageManagerImpl { myModule = module; } - protected XmlElementStorage.StorageData createStorageData(String storageSpec) { + protected StorageData createStorageData(String storageSpec) { return new ModuleStoreImpl.ModuleFileData(ROOT_TAG_NAME, myModule); } diff --git a/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStoreImpl.java b/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStoreImpl.java index c7304c1774ea..905e35591f44 100644 --- a/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStoreImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/components/impl/stores/ModuleStoreImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -145,7 +145,7 @@ public class ModuleStoreImpl extends BaseFileConfigurableStoreImpl implements IM return root; } - public XmlElementStorage.StorageData clone() { + public StorageData clone() { return new ModuleFileData(this); } @@ -154,7 +154,7 @@ public class ModuleStoreImpl extends BaseFileConfigurableStoreImpl implements IM } @Nullable - public Set getDifference(final XmlElementStorage.StorageData storageData, PathMacroSubstitutor substitutor) { + public Set getDifference(final StorageData storageData, PathMacroSubstitutor substitutor) { final ModuleFileData data = (ModuleFileData)storageData; if (!myOptions.equals(data.myOptions)) return null; return super.getDifference(storageData, substitutor); diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ApplicationStoreImpl.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ApplicationStoreImpl.java index af32c65f518c..a2ae2f43aae1 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ApplicationStoreImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ApplicationStoreImpl.java @@ -48,7 +48,7 @@ class ApplicationStoreImpl extends ComponentStoreImpl implements IApplicationSto public ApplicationStoreImpl(final ApplicationImpl application, PathMacroManager pathMacroManager) { myApplication = application; myStateStorageManager = new StateStorageManagerImpl(pathMacroManager.createTrackingSubstitutor(), ROOT_ELEMENT_NAME, application, application.getPicoContainer()) { - protected XmlElementStorage.StorageData createStorageData(String storageSpec) { + protected StorageData createStorageData(String storageSpec) { return new FileBasedStorage.FileStorageData(ROOT_ELEMENT_NAME); } diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/BaseFileConfigurableStoreImpl.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/BaseFileConfigurableStoreImpl.java index c0fe7ca8a302..a2c3538139ff 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/BaseFileConfigurableStoreImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/BaseFileConfigurableStoreImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -83,7 +83,7 @@ abstract class BaseFileConfigurableStoreImpl extends ComponentStoreImpl { } @Override - public XmlElementStorage.StorageData clone() { + public StorageData clone() { return new BaseStorageData(this); } @@ -96,7 +96,7 @@ abstract class BaseFileConfigurableStoreImpl extends ComponentStoreImpl { @Override @Nullable - public Set getDifference(final XmlElementStorage.StorageData storageData, PathMacroSubstitutor substitutor) { + public Set getDifference(final StorageData storageData, PathMacroSubstitutor substitutor) { final BaseStorageData data = (BaseStorageData)storageData; if (myVersion != data.myVersion) return null; return super.getDifference(storageData, substitutor); diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ProjectStateStorageManager.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ProjectStateStorageManager.java index c63627836cf2..06daccdabd6d 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ProjectStateStorageManager.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ProjectStateStorageManager.java @@ -32,17 +32,17 @@ class ProjectStateStorageManager extends StateStorageManagerImpl { myProject = project; } - protected XmlElementStorage.StorageData createStorageData(String storageSpec) { + protected StorageData createStorageData(String storageSpec) { if (storageSpec.equals(StoragePathMacros.PROJECT_FILE)) return createIprStorageData(); if (storageSpec.equals(StoragePathMacros.WORKSPACE_FILE)) return createWsStorageData(); return new ProjectStoreImpl.ProjectStorageData(ROOT_TAG_NAME, myProject); } - public XmlElementStorage.StorageData createWsStorageData() { + public StorageData createWsStorageData() { return new ProjectStoreImpl.WsStorageData(ROOT_TAG_NAME, myProject); } - public XmlElementStorage.StorageData createIprStorageData() { + public StorageData createIprStorageData() { return new ProjectStoreImpl.IprStorageData(ROOT_TAG_NAME, myProject); } diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ProjectStoreImpl.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ProjectStoreImpl.java index 816f17681b13..2d9f8af2d243 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ProjectStoreImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/ProjectStoreImpl.java @@ -418,7 +418,7 @@ class ProjectStoreImpl extends BaseFileConfigurableStoreImpl implements IProject myProject = storageData.myProject; } - public XmlElementStorage.StorageData clone() { + public StorageData clone() { return new ProjectStorageData(this); } } @@ -432,7 +432,7 @@ class ProjectStoreImpl extends BaseFileConfigurableStoreImpl implements IProject super(storageData); } - public XmlElementStorage.StorageData clone() { + public StorageData clone() { return new WsStorageData(this); } } @@ -461,7 +461,7 @@ class ProjectStoreImpl extends BaseFileConfigurableStoreImpl implements IProject protected void convert(final Element root, final int originalVersion) { } - public XmlElementStorage.StorageData clone() { + public StorageData clone() { return new IprStorageData(this); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StateStorageManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StateStorageManagerImpl.java index a8f94b8a3fb5..f94de9961761 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StateStorageManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StateStorageManagerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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. @@ -376,7 +376,7 @@ public abstract class StateStorageManagerImpl implements StateStorageManager, Di } - protected abstract XmlElementStorage.StorageData createStorageData(String storageSpec); + protected abstract StorageData createStorageData(String storageSpec); private static final Pattern MACRO_PATTERN = Pattern.compile("(\\$[^\\$]*\\$)"); diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StorageData.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StorageData.java new file mode 100644 index 000000000000..b18833db0870 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StorageData.java @@ -0,0 +1,221 @@ +/* + * Copyright 2000-2012 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.components.impl.stores; + +import com.intellij.openapi.components.PathMacroSubstitutor; +import com.intellij.openapi.components.TrackingPathMacroSubstitutor; +import com.intellij.openapi.components.XmlConfigurationMerger; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.extensions.ExtensionPoint; +import com.intellij.openapi.extensions.Extensions; +import com.intellij.openapi.util.JDOMUtil; +import com.intellij.util.ArrayUtil; +import gnu.trove.THashMap; +import org.jdom.Attribute; +import org.jdom.Element; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.IOException; +import java.util.*; + +public class StorageData { + private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.components.impl.stores.StorageData"); + @NonNls public static final String COMPONENT = "component"; + @NonNls public static final String NAME = "name"; + + final Map myComponentStates; + protected final String myRootElementName; + private Integer myHash; + + public StorageData(final String rootElementName) { + myComponentStates = new THashMap(); + myRootElementName = rootElementName; + } + + StorageData(StorageData storageData) { + myRootElementName = storageData.myRootElementName; + myComponentStates = new THashMap(storageData.myComponentStates); + } + + protected void load(@NotNull Element rootElement) throws IOException { + final Element[] elements = JDOMUtil.getElements(rootElement); + for (Element element : elements) { + if (element.getName().equals(COMPONENT)) { + final String name = element.getAttributeValue(NAME); + + if (name == null) { + LOG.info("Broken content in file : " + this); + continue; + } + + element.detach(); + + if (element.getAttributes().size() > 1 || !element.getChildren().isEmpty()) { + assert element.getAttributeValue(NAME) != null : "No name attribute for component: " + name + " in " + this; + + Element existingElement = myComponentStates.get(name); + + if (existingElement != null) { + element = mergeElements(name, element, existingElement); + } + + myComponentStates.put(name, element); + } + } + } + } + + private static Element mergeElements(final String name, final Element element1, final Element element2) { + ExtensionPoint point = Extensions.getRootArea().getExtensionPoint("com.intellij.componentConfigurationMerger"); + XmlConfigurationMerger[] mergers = point.getExtensions(); + for (XmlConfigurationMerger merger : mergers) { + if (merger.getComponentName().equals(name)) { + return merger.merge(element1, element2); + } + } + return element1; + } + + @NotNull + protected Element save() { + Element rootElement = new Element(myRootElementName); + String[] componentNames = ArrayUtil.toStringArray(myComponentStates.keySet()); + Arrays.sort(componentNames); + for (String componentName : componentNames) { + assert componentName != null; + final Element element = myComponentStates.get(componentName); + + if (element.getAttribute(NAME) == null) element.setAttribute(NAME, componentName); + + rootElement.addContent((Element)element.clone()); + } + + return rootElement; + } + + @Nullable + Element getState(final String name) { + final Element e = myComponentStates.get(name); + + if (e != null) { + assert e.getAttributeValue(NAME) != null : "No name attribute for component: " + name + " in " + this; + e.removeAttribute(NAME); + } + + return e; + } + + void removeState(final String componentName) { + myComponentStates.remove(componentName); + clearHash(); + } + + void setState(@NotNull final String componentName, final Element element) { + element.setName(COMPONENT); + + //componentName should be first! + final List attributes = new ArrayList(element.getAttributes()); + for (Object attribute : attributes) { + Attribute attr = (Attribute)attribute; + element.removeAttribute(attr); + } + + element.setAttribute(NAME, componentName); + + for (Object attribute : attributes) { + Attribute attr = (Attribute)attribute; + element.setAttribute(attr.getName(), attr.getValue()); + } + + myComponentStates.put(componentName, element); + clearHash(); + } + + @Override + public StorageData clone() { + return new StorageData(this); + } + + public final int getHash() { + if (myHash == null) { + myHash = computeHash(); + } + return myHash.intValue(); + } + + protected int computeHash() { + int result = 0; + + for (String name : myComponentStates.keySet()) { + result = 31*result + name.hashCode(); + result = 31*result + JDOMUtil.getTreeHash(myComponentStates.get(name)); + } + + return result; + } + + protected void clearHash() { + myHash = null; + } + + public Set getDifference(final StorageData storageData, PathMacroSubstitutor substitutor) { + Set bothStates = new HashSet(myComponentStates.keySet()); + bothStates.retainAll(storageData.myComponentStates.keySet()); + + Set diffs = new HashSet(); + diffs.addAll(storageData.myComponentStates.keySet()); + diffs.addAll(myComponentStates.keySet()); + diffs.removeAll(bothStates); + + for (String componentName : bothStates) { + final Element e1 = myComponentStates.get(componentName); + final Element e2 = storageData.myComponentStates.get(componentName); + + // some configurations want to collapse path elements in writeExternal so make sure paths are expanded + if (substitutor != null) { + substitutor.expandPaths(e2); + } + + if (!JDOMUtil.areElementsEqual(e1, e2)) { + diffs.add(componentName); + } + } + + + return diffs; + } + + public boolean isEmpty() { + return myComponentStates.size() == 0; + } + + public boolean hasState(final String componentName) { + return myComponentStates.containsKey(componentName); + } + + public void checkUnknownMacros(TrackingPathMacroSubstitutor pathMacroSubstitutor) { + if (pathMacroSubstitutor == null) return; + + for (String componentName : myComponentStates.keySet()) { + final Set unknownMacros = StorageUtil.getMacroNames(myComponentStates.get(componentName)); + if (!unknownMacros.isEmpty()) { + pathMacroSubstitutor.addUnknownMacros(componentName, unknownMacros); + } + } + } +} diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/XmlElementStorage.java b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/XmlElementStorage.java index b45195bbbad0..700c9e97f943 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/XmlElementStorage.java +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/XmlElementStorage.java @@ -18,19 +18,15 @@ package com.intellij.openapi.components.impl.stores; import com.intellij.openapi.Disposable; import com.intellij.openapi.components.*; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.extensions.ExtensionPoint; -import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.options.StreamProvider; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.WriteExternalException; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.util.ArrayUtil; import com.intellij.util.containers.StringInterner; import com.intellij.util.io.fs.IFile; import gnu.trove.THashMap; -import org.jdom.Attribute; import org.jdom.Document; import org.jdom.Element; import org.jetbrains.annotations.NonNls; @@ -41,14 +37,9 @@ import java.io.IOException; import java.util.*; public abstract class XmlElementStorage implements StateStorage, Disposable { - @NonNls private static final Set OBSOLETE_COMPONENT_NAMES = new HashSet(Arrays.asList( - "Palette" - )); private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.components.impl.stores.XmlElementStorage"); - @NonNls private static final String COMPONENT = "component"; @NonNls private static final String ATTR_NAME = "name"; - @NonNls private static final String NAME = ATTR_NAME; protected TrackingPathMacroSubstitutor myPathMacroSubstitutor; @NotNull private final String myRootElementName; @@ -530,7 +521,7 @@ public abstract class XmlElementStorage implements StateStorage, Disposable { private Map loadVersions(Document copy) { THashMap result = new THashMap(); - List list = copy.getRootElement().getChildren(COMPONENT); + List list = copy.getRootElement().getChildren(StorageData.COMPONENT); for (Object o : list) { if (o instanceof Element) { Element component = (Element)o; @@ -552,191 +543,6 @@ public abstract class XmlElementStorage implements StateStorage, Disposable { myDisposed = true; } - protected static class StorageData { - private final Map myComponentStates; - protected final String myRootElementName; - private Integer myHash; - - public StorageData(final String rootElementName) { - myComponentStates = new THashMap(); - myRootElementName = rootElementName; - } - - protected StorageData(StorageData storageData) { - myRootElementName = storageData.myRootElementName; - myComponentStates = new THashMap(storageData.myComponentStates); - } - - protected void load(@NotNull Element rootElement) throws IOException { - final Element[] elements = JDOMUtil.getElements(rootElement); - for (Element element : elements) { - if (element.getName().equals(COMPONENT)) { - final String name = element.getAttributeValue(NAME); - - if (name == null) { - LOG.info("Broken content in file : " + this); - continue; - } - - if (OBSOLETE_COMPONENT_NAMES.contains(name)) continue; - - element.detach(); - - if (element.getAttributes().size() > 1 || !element.getChildren().isEmpty()) { - assert element.getAttributeValue(NAME) != null : "No name attribute for component: " + name + " in " + this; - - Element existingElement = myComponentStates.get(name); - - if (existingElement != null) { - element = mergeElements(name, element, existingElement); - } - - myComponentStates.put(name, element); - } - } - } - } - - private Element mergeElements(final String name, final Element element1, final Element element2) { - ExtensionPoint point = Extensions.getRootArea().getExtensionPoint("com.intellij.componentConfigurationMerger"); - XmlConfigurationMerger[] mergers = point.getExtensions(); - for (XmlConfigurationMerger merger : mergers) { - if (merger.getComponentName().equals(name)) { - return merger.merge(element1, element2); - } - } - return element1; - } - - @NotNull - protected Element save() { - Element rootElement = new Element(myRootElementName); - String[] componentNames = ArrayUtil.toStringArray(myComponentStates.keySet()); - Arrays.sort(componentNames); - for (String componentName : componentNames) { - assert componentName != null; - final Element element = myComponentStates.get(componentName); - - if (element.getAttribute(NAME) == null) element.setAttribute(NAME, componentName); - - rootElement.addContent((Element)element.clone()); - } - - return rootElement; - } - - @Nullable - private Element getState(final String name) { - final Element e = myComponentStates.get(name); - - if (e != null) { - assert e.getAttributeValue(NAME) != null : "No name attribute for component: " + name + " in " + this; - e.removeAttribute(NAME); - } - - return e; - } - - private void removeState(final String componentName) { - myComponentStates.remove(componentName); - clearHash(); - } - - private void setState(@NotNull final String componentName, final Element element) { - element.setName(COMPONENT); - - //componentName should be first! - final List attributes = new ArrayList(element.getAttributes()); - for (Object attribute : attributes) { - Attribute attr = (Attribute)attribute; - element.removeAttribute(attr); - } - - element.setAttribute(NAME, componentName); - - for (Object attribute : attributes) { - Attribute attr = (Attribute)attribute; - element.setAttribute(attr.getName(), attr.getValue()); - } - - myComponentStates.put(componentName, element); - clearHash(); - } - - @Override - public StorageData clone() { - return new StorageData(this); - } - - public final int getHash() { - if (myHash == null) { - myHash = computeHash(); - } - return myHash.intValue(); - } - - protected int computeHash() { - int result = 0; - - for (String name : myComponentStates.keySet()) { - result = 31*result + name.hashCode(); - result = 31*result + JDOMUtil.getTreeHash(myComponentStates.get(name)); - } - - return result; - } - - protected void clearHash() { - myHash = null; - } - - public Set getDifference(final StorageData storageData, PathMacroSubstitutor substitutor) { - Set bothStates = new HashSet(myComponentStates.keySet()); - bothStates.retainAll(storageData.myComponentStates.keySet()); - - Set diffs = new HashSet(); - diffs.addAll(storageData.myComponentStates.keySet()); - diffs.addAll(myComponentStates.keySet()); - diffs.removeAll(bothStates); - - for (String componentName : bothStates) { - final Element e1 = myComponentStates.get(componentName); - final Element e2 = storageData.myComponentStates.get(componentName); - - // some configurations want to collapse path elements in writeExternal so make sure paths are expanded - if (substitutor != null) { - substitutor.expandPaths(e2); - } - - if (!JDOMUtil.areElementsEqual(e1, e2)) { - diffs.add(componentName); - } - } - - - return diffs; - } - - public boolean isEmpty() { - return myComponentStates.size() == 0; - } - - public boolean hasState(final String componentName) { - return myComponentStates.containsKey(componentName); - } - - public void checkUnknownMacros(TrackingPathMacroSubstitutor pathMacroSubstitutor) { - if (pathMacroSubstitutor == null) return; - - for (String componentName : myComponentStates.keySet()) { - final Set unknownMacros = StorageUtil.getMacroNames(myComponentStates.get(componentName)); - if (!unknownMacros.isEmpty()) { - pathMacroSubstitutor.addUnknownMacros(componentName, unknownMacros); - } - } - } - } - public void resetData(){ myLoadedData = null; } @@ -756,7 +562,7 @@ public abstract class XmlElementStorage implements StateStorage, Disposable { if (!storageData.myComponentStates.containsKey(componentToRetain) && myStorageComponentStates.containsKey(componentToRetain)) { Element emptyElement = new Element("component"); LOG.info("Create empty component element for " + componentsToRetain); - emptyElement.setAttribute(NAME, componentToRetain); + emptyElement.setAttribute(StorageData.NAME, componentToRetain); storageData.myComponentStates.put(componentToRetain, emptyElement); } } @@ -768,13 +574,13 @@ public abstract class XmlElementStorage implements StateStorage, Disposable { } private void filterComponentsDisabledForRoaming(final Element element, final RoamingType roamingType) { - final List components = element.getChildren(COMPONENT); + final List components = element.getChildren(StorageData.COMPONENT); List toDelete = new ArrayList(); for (Object componentObj : components) { final Element componentElement = (Element)componentObj; - final String nameAttr = componentElement.getAttributeValue(NAME); + final String nameAttr = componentElement.getAttributeValue(StorageData.NAME); if (myComponentRoamingManager.getRoamingType(nameAttr) != roamingType) { toDelete.add(componentElement); @@ -787,13 +593,13 @@ public abstract class XmlElementStorage implements StateStorage, Disposable { } private void filterOutOfDateComponents(final Element element) { - final List components = element.getChildren(COMPONENT); + final List components = element.getChildren(StorageData.COMPONENT); List toDelete = new ArrayList(); for (Object componentObj : components) { final Element componentElement = (Element)componentObj; - final String nameAttr = componentElement.getAttributeValue(NAME); + final String nameAttr = componentElement.getAttributeValue(StorageData.NAME); if (myRemoteVersionProvider.getVersion(nameAttr) <= myLocalVersionProvider.getVersion(nameAttr)) { toDelete.add(componentElement); diff --git a/platform/platform-api/src/com/intellij/openapi/components/XmlConfigurationMerger.java b/platform/projectModel-api/src/com/intellij/openapi/components/XmlConfigurationMerger.java similarity index 95% rename from platform/platform-api/src/com/intellij/openapi/components/XmlConfigurationMerger.java rename to platform/projectModel-api/src/com/intellij/openapi/components/XmlConfigurationMerger.java index 4a3f57f5991a..a8384caef60d 100644 --- a/platform/platform-api/src/com/intellij/openapi/components/XmlConfigurationMerger.java +++ b/platform/projectModel-api/src/com/intellij/openapi/components/XmlConfigurationMerger.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 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.