From 316cd525326506481c1a8d2e5479a035ae293970 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 24 Feb 2015 10:52:53 +0100 Subject: [PATCH] remove default registry values from user properties --- .../openapi/util/registry/RegistryState.java | 24 ++++----------- .../openapi/util/registry/Registry.java | 29 +++++++++---------- .../openapi/util/registry/RegistryValue.java | 8 +++-- 3 files changed, 25 insertions(+), 36 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/util/registry/RegistryState.java b/platform/platform-api/src/com/intellij/openapi/util/registry/RegistryState.java index 73743f86d796..f81c6896b8f6 100644 --- a/platform/platform-api/src/com/intellij/openapi/util/registry/RegistryState.java +++ b/platform/platform-api/src/com/intellij/openapi/util/registry/RegistryState.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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,10 +15,12 @@ */ package com.intellij.openapi.util.registry; -import com.intellij.openapi.components.*; +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 org.jdom.Element; -import org.jetbrains.annotations.NotNull; import java.util.Map; import java.util.SortedMap; @@ -28,7 +30,7 @@ import java.util.TreeMap; name = "Registry", storages = @Storage(file = StoragePathMacros.APP_CONFIG + "/other.xml") ) -public class RegistryState implements BaseComponent, PersistentStateComponent { +public class RegistryState implements PersistentStateComponent { private static final Logger LOG = Logger.getInstance(RegistryState.class); @Override @@ -48,18 +50,4 @@ public class RegistryState implements BaseComponent, PersistentStateComponent myUserProperties = new LinkedHashMap(); - private final Map myLoadedUserProperties = new HashMap(); private final Map myValues = new ConcurrentHashMap(); private static final Registry ourInstance = new Registry(); @@ -119,20 +118,18 @@ public class Registry { } public void loadState(@NotNull Element state) { - final List entries = state.getChildren("entry"); - for (Object each : entries) { - final Element eachEntry = (Element) each; - final String eachKey = eachEntry.getAttributeValue("key"); - final String eachValue = eachEntry.getAttributeValue("value"); - if (eachKey != null && eachValue != null) { - myUserProperties.put(eachKey, eachValue); + myUserProperties.clear(); + for (Element eachEntry : state.getChildren("entry")) { + String key = eachEntry.getAttributeValue("key"); + String value = eachEntry.getAttributeValue("value"); + if (key != null && value != null) { + RegistryValue registryValue = get(key); + if (registryValue.isChangedFromDefault(value)) { + myUserProperties.put(key, value); + registryValue.resetCache(); + } } } - myLoadedUserProperties.putAll(myUserProperties); - - for (RegistryValue each : myValues.values()) { - each.resetCache(); - } } @NotNull @@ -165,11 +162,11 @@ public class Registry { } public boolean isInDefaultState() { - return getUserProperties().isEmpty(); + return myUserProperties.isEmpty(); } public boolean isRestartNeeded() { - return isRestartNeeded(myUserProperties) || isRestartNeeded(myLoadedUserProperties); + return isRestartNeeded(myUserProperties); } private static boolean isRestartNeeded(@NotNull Map map) { diff --git a/platform/util/src/com/intellij/openapi/util/registry/RegistryValue.java b/platform/util/src/com/intellij/openapi/util/registry/RegistryValue.java index 22e6214530cf..96ddb5330f1f 100644 --- a/platform/util/src/com/intellij/openapi/util/registry/RegistryValue.java +++ b/platform/util/src/com/intellij/openapi/util/registry/RegistryValue.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -109,7 +109,11 @@ public class RegistryValue { } public boolean isChangedFromDefault() { - return !asString().equals(getBundleValue(myKey, false)); + return isChangedFromDefault(asString()); + } + + boolean isChangedFromDefault(@NotNull String newValue) { + return !newValue.equals(getBundleValue(myKey, false)); } private String get(@NotNull String key, String defaultValue, boolean isValue) throws MissingResourceException {