@@ -77,6 +77,19 @@ public void load(File file) throws IOException {
77
77
load (new FileInputStream (file ));
78
78
}
79
79
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
+
80
93
/**
81
94
* Parse a property list stream and put key/value pairs into the Map
82
95
*
@@ -91,28 +104,15 @@ public void load(InputStream input) throws IOException {
91
104
92
105
int equals = line .indexOf ('=' );
93
106
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 ();
99
109
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 ());
102
113
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 );
116
116
}
117
117
}
118
118
}
0 commit comments