@@ -77,6 +77,19 @@ public void load(File file) throws IOException {
7777 load (new FileInputStream (file ));
7878 }
7979
80+ protected String processPlatformSuffix (String key , String suffix , boolean isCurrentPlatform ) {
81+ if (key == null )
82+ return null ;
83+ // Key does not end with the given suffix? Process as normal
84+ if (!key .endsWith (suffix ))
85+ return key ;
86+ // Not the current platform? Ignore this key
87+ if (!isCurrentPlatform )
88+ return null ;
89+ // Strip the suffix from the key
90+ return key .substring (0 , key .length () - suffix .length ());
91+ }
92+
8093 /**
8194 * Parse a property list stream and put key/value pairs into the Map
8295 *
@@ -91,28 +104,15 @@ public void load(InputStream input) throws IOException {
91104
92105 int equals = line .indexOf ('=' );
93106 if (equals != -1 ) {
94- String key = line .substring (0 , equals );
95- String value = line .substring (equals + 1 );
96- put (key .trim (), value .trim ());
97- }
98- }
107+ String key = line .substring (0 , equals ).trim ();
108+ String value = line .substring (equals + 1 ).trim ();
99109
100- // This is needed to avoid ConcurrentAccessExceptions
101- Set <String > keys = new LinkedHashSet <String >(keySet ());
110+ key = processPlatformSuffix (key , ".linux" , Base .isLinux ());
111+ key = processPlatformSuffix (key , ".windows" , Base .isWindows ());
112+ key = processPlatformSuffix (key , ".macosx" , Base .isMacOS ());
102113
103- // Override keys that have OS specific versions
104- for (String key : keys ) {
105- boolean replace = false ;
106- if (Base .isLinux () && key .endsWith (".linux" ))
107- replace = true ;
108- if (Base .isWindows () && key .endsWith (".windows" ))
109- replace = true ;
110- if (Base .isMacOS () && key .endsWith (".macos" ))
111- replace = true ;
112- if (replace ) {
113- int dot = key .lastIndexOf ('.' );
114- String overridenKey = key .substring (0 , dot );
115- put (overridenKey , get (key ));
114+ if (key != null )
115+ put (key , value );
116116 }
117117 }
118118 }
0 commit comments