diff --git a/platform/util/src/com/intellij/openapi/application/PathManager.java b/platform/util/src/com/intellij/openapi/application/PathManager.java index d532642b842f..4001fd0138ef 100644 --- a/platform/util/src/com/intellij/openapi/application/PathManager.java +++ b/platform/util/src/com/intellij/openapi/application/PathManager.java @@ -320,19 +320,19 @@ public class PathManager { if (propFile != null) { try { - InputStream fis = new BufferedInputStream(new FileInputStream(propFile)); + Reader fis = new BufferedReader(new FileReader(propFile)); try { - final PropertyResourceBundle bundle = new PropertyResourceBundle(fis); - final Enumeration keys = bundle.getKeys(); - String home = (String)bundle.handleGetObject("idea.home"); + Map properties = FileUtil.loadProperties(fis); + + String home = properties.get("idea.home"); if (home != null && ourHomePath == null) { ourHomePath = getAbsolutePath(substituteVars(home)); } - final Properties sysProperties = System.getProperties(); - while (keys.hasMoreElements()) { - String key = (String)keys.nextElement(); + + Properties sysProperties = System.getProperties(); + for (String key : properties.keySet()) { if (sysProperties.getProperty(key, null) == null) { // load the property from the property file only if it is not defined yet - final String value = substituteVars(bundle.getString(key)); + String value = substituteVars(properties.get(key)); sysProperties.setProperty(key, value); } } diff --git a/platform/util/src/com/intellij/openapi/util/io/FileUtil.java b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java index fa0f436d5e0d..d8078d0f511f 100644 --- a/platform/util/src/com/intellij/openapi/util/io/FileUtil.java +++ b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java @@ -1438,4 +1438,23 @@ public class FileUtil extends FileUtilRt { return true; } + + /** + * Like {@link Properties#load(java.io.Reader)}, but preserves the order of key/value pairs. + */ + @NotNull + public static Map loadProperties(@NotNull Reader reader) throws IOException { + final Map map = ContainerUtil.newLinkedHashMap(); + + new Properties() { + @Override + public synchronized Object put(Object key, Object value) { + map.put(String.valueOf(key), String.valueOf(value)); + //noinspection UseOfPropertiesAsHashtable + return super.put(key, value); + } + }.load(reader); + + return map; + } } diff --git a/platform/util/testSrc/com/intellij/openapi/util/io/FileUtilLightTest.java b/platform/util/testSrc/com/intellij/openapi/util/io/FileUtilLightTest.java index 710e0c871d4b..1e1295cfa727 100644 --- a/platform/util/testSrc/com/intellij/openapi/util/io/FileUtilLightTest.java +++ b/platform/util/testSrc/com/intellij/openapi/util/io/FileUtilLightTest.java @@ -19,12 +19,16 @@ import com.intellij.openapi.util.SystemInfo; import com.intellij.util.ArrayUtil; import com.intellij.util.PairProcessor; import com.intellij.util.ThreeState; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.Convertor; import org.junit.Test; +import java.io.IOException; +import java.io.StringReader; import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.Map; import static org.junit.Assert.*; @@ -145,4 +149,11 @@ public class FileUtilLightTest { assertFalse(FileUtil.startsWith("c:/idea2", "c:/idea")); assertFalse(FileUtil.startsWith("c:/idea_branches/i18n", "c:/idea")); } + + @Test + public void testLoadProperties() throws IOException { + String data = "key2=value2\nkey1=value1\nkey3=value3"; + Map map = FileUtil.loadProperties(new StringReader(data)); + assertEquals(ContainerUtil.newArrayList("key2", "key1", "key3"), ContainerUtil.newArrayList(map.keySet())); + } }