60 // everything must be initialised at this point |
61 // everything must be initialised at this point |
61 return false; |
62 return false; |
62 } |
63 } |
63 TString appName; |
64 TString appName; |
64 TString appVersion; |
65 TString appVersion; |
65 AutoFreePtr<ISectionalPropertyContainer> config = platform.GetConfigFile(platform.GetConfigFileName()); |
66 AutoFreePtr<ISectionalPropertyContainer> config = |
|
67 platform.GetConfigFile(platform.GetConfigFileName()); |
66 std::map<TString, TString> keys = platform.GetKeys(); |
68 std::map<TString, TString> keys = platform.GetKeys(); |
67 config->GetValue(keys[CONFIG_SECTION_APPLICATION], keys[APP_NAME_KEY], appName); |
69 config->GetValue(keys[CONFIG_SECTION_APPLICATION], |
68 config->GetValue(keys[CONFIG_SECTION_APPLICATION], keys[CONFIG_VERSION], appVersion); |
70 keys[APP_NAME_KEY], appName); |
|
71 config->GetValue(keys[CONFIG_SECTION_APPLICATION], |
|
72 keys[CONFIG_VERSION], appVersion); |
69 TString singleInstance; |
73 TString singleInstance; |
70 config->GetValue(keys[CONFIG_SECTION_APPLICATION], keys[CONFIG_APPLICATION_INSTANCE], singleInstance); |
74 config->GetValue(keys[CONFIG_SECTION_APPLICATION], |
|
75 keys[CONFIG_APPLICATION_INSTANCE], singleInstance); |
71 if (singleInstance == _T("single")) { |
76 if (singleInstance == _T("single")) { |
72 TString uniqueID = appName + FBootFields->FAppID + appVersion; |
77 TString uniqueID = appName + FBootFields->FAppID + appVersion; |
73 // if another instance is running, later we can try to reactivate it |
78 // if another instance is running, later we can try to reactivate it |
74 return platform.CheckForSingleInstance(uniqueID); |
79 return platform.CheckForSingleInstance(uniqueID); |
75 } |
80 } |
86 FBootFields = new PackageBootFields(); |
91 FBootFields = new PackageBootFields(); |
87 FDebugging = dsNone; |
92 FDebugging = dsNone; |
88 |
93 |
89 FBootFields->FPackageRootDirectory = platform.GetPackageRootDirectory(); |
94 FBootFields->FPackageRootDirectory = platform.GetPackageRootDirectory(); |
90 FBootFields->FPackageAppDirectory = platform.GetPackageAppDirectory(); |
95 FBootFields->FPackageAppDirectory = platform.GetPackageAppDirectory(); |
91 FBootFields->FPackageLauncherDirectory = platform.GetPackageLauncherDirectory(); |
96 FBootFields->FPackageLauncherDirectory = |
|
97 platform.GetPackageLauncherDirectory(); |
92 FBootFields->FAppDataDirectory = platform.GetAppDataDirectory(); |
98 FBootFields->FAppDataDirectory = platform.GetAppDataDirectory(); |
93 |
99 |
94 std::map<TString, TString> keys = platform.GetKeys(); |
100 std::map<TString, TString> keys = platform.GetKeys(); |
95 |
101 |
96 // Read from configure.cfg/Info.plist |
102 // Read from configure.cfg/Info.plist |
97 AutoFreePtr<ISectionalPropertyContainer> config = platform.GetConfigFile(platform.GetConfigFileName()); |
103 AutoFreePtr<ISectionalPropertyContainer> config = |
98 |
104 platform.GetConfigFile(platform.GetConfigFileName()); |
99 config->GetValue(keys[CONFIG_SECTION_APPLICATION], keys[CONFIG_APP_ID_KEY], FBootFields->FAppID); |
105 |
100 config->GetValue(keys[CONFIG_SECTION_APPLICATION], keys[PACKAGER_APP_DATA_DIR], FBootFields->FPackageAppDataDirectory); |
106 config->GetValue(keys[CONFIG_SECTION_APPLICATION], |
101 FBootFields->FPackageAppDataDirectory = FilePath::FixPathForPlatform(FBootFields->FPackageAppDataDirectory); |
107 keys[CONFIG_APP_ID_KEY], FBootFields->FAppID); |
|
108 config->GetValue(keys[CONFIG_SECTION_APPLICATION], |
|
109 keys[PACKAGER_APP_DATA_DIR], FBootFields->FPackageAppDataDirectory); |
|
110 FBootFields->FPackageAppDataDirectory = |
|
111 FilePath::FixPathForPlatform(FBootFields->FPackageAppDataDirectory); |
102 |
112 |
103 // Main JAR. |
113 // Main JAR. |
104 config->GetValue(keys[CONFIG_SECTION_APPLICATION], keys[CONFIG_MAINJAR_KEY], FBootFields->FMainJar); |
114 config->GetValue(keys[CONFIG_SECTION_APPLICATION], |
105 FBootFields->FMainJar = FilePath::IncludeTrailingSeparater(GetPackageAppDirectory()) + |
115 keys[CONFIG_MAINJAR_KEY], FBootFields->FMainJar); |
106 FilePath::FixPathForPlatform(FBootFields->FMainJar); |
116 FBootFields->FMainJar = |
|
117 FilePath::IncludeTrailingSeparator(GetPackageAppDirectory()) |
|
118 + FilePath::FixPathForPlatform(FBootFields->FMainJar); |
107 |
119 |
108 // Main Module. |
120 // Main Module. |
109 config->GetValue(keys[CONFIG_SECTION_APPLICATION], keys[CONFIG_MAINMODULE_KEY], FBootFields->FMainModule); |
121 config->GetValue(keys[CONFIG_SECTION_APPLICATION], |
|
122 keys[CONFIG_MAINMODULE_KEY], FBootFields->FMainModule); |
110 |
123 |
111 // Classpath. |
124 // Classpath. |
112 // 1. If the provided class path contains main jar then only use provided class path. |
125 // 1. If the provided class path contains main jar then only use |
|
126 // provided class path. |
113 // 2. If class path provided by config file is empty then add main jar. |
127 // 2. If class path provided by config file is empty then add main jar. |
114 // 3. If main jar is not in provided class path then add it. |
128 // 3. If main jar is not in provided class path then add it. |
115 config->GetValue(keys[CONFIG_SECTION_APPLICATION], keys[CONFIG_CLASSPATH_KEY], FBootFields->FClassPath); |
129 config->GetValue(keys[CONFIG_SECTION_APPLICATION], |
116 FBootFields->FClassPath = FilePath::FixPathSeparatorForPlatform(FBootFields->FClassPath); |
130 keys[CONFIG_CLASSPATH_KEY], FBootFields->FClassPath); |
|
131 FBootFields->FClassPath = |
|
132 FilePath::FixPathSeparatorForPlatform(FBootFields->FClassPath); |
117 |
133 |
118 if (FBootFields->FClassPath.empty() == true) { |
134 if (FBootFields->FClassPath.empty() == true) { |
119 FBootFields->FClassPath = GetMainJar(); |
135 FBootFields->FClassPath = GetMainJar(); |
120 } |
136 } else if (FBootFields->FClassPath.find(GetMainJar()) == TString::npos) { |
121 else if (FBootFields->FClassPath.find(GetMainJar()) == TString::npos) { |
137 FBootFields->FClassPath = GetMainJar() |
122 FBootFields->FClassPath = GetMainJar() + FilePath::PathSeparator() + FBootFields->FClassPath; |
138 + FilePath::PathSeparator() + FBootFields->FClassPath; |
123 } |
139 } |
124 |
140 |
125 // Modulepath. |
141 // Modulepath. |
126 config->GetValue(keys[CONFIG_SECTION_APPLICATION], keys[CONFIG_MODULEPATH_KEY], FBootFields->FModulePath); |
142 config->GetValue(keys[CONFIG_SECTION_APPLICATION], |
127 FBootFields->FModulePath = FilePath::FixPathSeparatorForPlatform(FBootFields->FModulePath); |
143 keys[CONFIG_MODULEPATH_KEY], FBootFields->FModulePath); |
|
144 FBootFields->FModulePath = |
|
145 FilePath::FixPathSeparatorForPlatform(FBootFields->FModulePath); |
128 |
146 |
129 // Main Class. |
147 // Main Class. |
130 config->GetValue(keys[CONFIG_SECTION_APPLICATION], keys[CONFIG_MAINCLASSNAME_KEY], FBootFields->FMainClassName); |
148 config->GetValue(keys[CONFIG_SECTION_APPLICATION], |
|
149 keys[CONFIG_MAINCLASSNAME_KEY], FBootFields->FMainClassName); |
131 |
150 |
132 // Splash Screen. |
151 // Splash Screen. |
133 if (config->GetValue(keys[CONFIG_SECTION_APPLICATION], keys[CONFIG_SPLASH_KEY], FBootFields->FSplashScreenFileName) == true) { |
152 if (config->GetValue(keys[CONFIG_SECTION_APPLICATION], |
134 FBootFields->FSplashScreenFileName = FilePath::IncludeTrailingSeparater(GetPackageAppDirectory()) + |
153 keys[CONFIG_SPLASH_KEY], |
135 FilePath::FixPathForPlatform(FBootFields->FSplashScreenFileName); |
154 FBootFields->FSplashScreenFileName) == true) { |
|
155 FBootFields->FSplashScreenFileName = |
|
156 FilePath::IncludeTrailingSeparator(GetPackageAppDirectory()) |
|
157 + FilePath::FixPathForPlatform(FBootFields->FSplashScreenFileName); |
136 |
158 |
137 if (FilePath::FileExists(FBootFields->FSplashScreenFileName) == false) { |
159 if (FilePath::FileExists(FBootFields->FSplashScreenFileName) == false) { |
138 FBootFields->FSplashScreenFileName = _T(""); |
160 FBootFields->FSplashScreenFileName = _T(""); |
139 } |
161 } |
140 } |
162 } |
141 |
163 |
142 // Runtime. |
164 // Runtime. |
143 config->GetValue(keys[CONFIG_SECTION_APPLICATION], keys[JVM_RUNTIME_KEY], FBootFields->FJVMRuntimeDirectory); |
165 config->GetValue(keys[CONFIG_SECTION_APPLICATION], |
|
166 keys[JVM_RUNTIME_KEY], FBootFields->FJVMRuntimeDirectory); |
144 |
167 |
145 // Read jvmargs. |
168 // Read jvmargs. |
146 PromoteAppCDSState(config); |
169 PromoteAppCDSState(config); |
147 ReadJVMArgs(config); |
170 ReadJVMArgs(config); |
148 |
171 |
154 FBootFields->FArgs = Helpers::MapToNameValueList(args); |
177 FBootFields->FArgs = Helpers::MapToNameValueList(args); |
155 } |
178 } |
156 } |
179 } |
157 |
180 |
158 // Read jvmuserarg defaults. |
181 // Read jvmuserarg defaults. |
159 config->GetSection(keys[CONFIG_SECTION_JVMUSEROPTIONS], FDefaultJVMUserArgs); |
182 config->GetSection(keys[CONFIG_SECTION_JVMUSEROPTIONS], |
|
183 FDefaultJVMUserArgs); |
160 |
184 |
161 // Load JVM user overrides. |
185 // Load JVM user overrides. |
162 TString jvmUserArgsConfigFileName = GetJVMUserArgsConfigFileName(); |
186 TString jvmUserArgsConfigFileName = GetJVMUserArgsConfigFileName(); |
163 |
187 |
164 if (FilePath::FileExists(jvmUserArgsConfigFileName) == true) { |
188 if (FilePath::FileExists(jvmUserArgsConfigFileName) == true) { |
165 // Load new location for user VM overrides. |
189 // Load new location for user VM overrides. |
166 IniFile userConfig; |
190 IniFile userConfig; |
167 |
191 |
168 if (userConfig.LoadFromFile(jvmUserArgsConfigFileName) == false) { |
192 if (userConfig.LoadFromFile(jvmUserArgsConfigFileName) == false) { |
169 // New property file format was not found, attempt to load old property file format. |
193 // New property file format was not found, |
170 userConfig.GetSection(keys[CONFIG_SECTION_JVMUSEROVERRIDESOPTIONS], FJVMUserArgsOverrides); |
194 // attempt to load old property file format. |
171 } |
195 userConfig.GetSection(keys[CONFIG_SECTION_JVMUSEROVERRIDESOPTIONS], |
172 |
196 FJVMUserArgsOverrides); |
173 userConfig.GetSection(keys[CONFIG_SECTION_JVMUSEROVERRIDESOPTIONS], FJVMUserArgsOverrides); |
197 } |
174 } |
198 |
175 else { |
199 userConfig.GetSection(keys[CONFIG_SECTION_JVMUSEROVERRIDESOPTIONS], |
|
200 FJVMUserArgsOverrides); |
|
201 } else { |
176 // Attemp to load java.util.prefs for legacy JVM user overrides. |
202 // Attemp to load java.util.prefs for legacy JVM user overrides. |
177 AutoFreePtr<JavaUserPreferences> javaPreferences(JavaUserPreferences::CreateInstance()); |
203 AutoFreePtr<JavaUserPreferences> javaPreferences( |
|
204 JavaUserPreferences::CreateInstance()); |
178 |
205 |
179 if (javaPreferences->Load(GetAppID()) == true) { |
206 if (javaPreferences->Load(GetAppID()) == true) { |
180 FJVMUserArgsOverrides = javaPreferences->GetData(); |
207 FJVMUserArgsOverrides = javaPreferences->GetData(); |
181 } |
208 } |
182 } |
209 } |
183 |
210 |
184 // Auto Memory. |
211 // Auto Memory. |
185 TString autoMemory; |
212 TString autoMemory; |
186 |
213 |
187 if (config->GetValue(keys[CONFIG_SECTION_APPLICATION], keys[CONFIG_APP_MEMORY], autoMemory) == true) { |
214 if (config->GetValue(keys[CONFIG_SECTION_APPLICATION], |
|
215 keys[CONFIG_APP_MEMORY], autoMemory) == true) { |
188 if (autoMemory == _T("auto") || autoMemory == _T("100%")) { |
216 if (autoMemory == _T("auto") || autoMemory == _T("100%")) { |
189 FBootFields->FMemoryState = PackageBootFields::msAuto; |
217 FBootFields->FMemoryState = PackageBootFields::msAuto; |
190 FBootFields->FMemorySize = platform.GetMemorySize(); |
218 FBootFields->FMemorySize = platform.GetMemorySize(); |
191 } |
219 } else if (autoMemory.length() == 2 && isdigit(autoMemory[0]) && |
192 else if (autoMemory.length() == 2 && isdigit(autoMemory[0]) && autoMemory[1] == '%') { |
220 autoMemory[1] == '%') { |
193 FBootFields->FMemoryState = PackageBootFields::msAuto; |
221 FBootFields->FMemoryState = PackageBootFields::msAuto; |
194 FBootFields->FMemorySize = StringToPercentageOfNumber(autoMemory.substr(0, 1), platform.GetMemorySize()); |
222 FBootFields->FMemorySize = |
195 } |
223 StringToPercentageOfNumber(autoMemory.substr(0, 1), |
196 else if (autoMemory.length() == 3 && isdigit(autoMemory[0]) && isdigit(autoMemory[1]) && autoMemory[2] == '%') { |
224 platform.GetMemorySize()); |
|
225 } else if (autoMemory.length() == 3 && isdigit(autoMemory[0]) && |
|
226 isdigit(autoMemory[1]) && autoMemory[2] == '%') { |
197 FBootFields->FMemoryState = PackageBootFields::msAuto; |
227 FBootFields->FMemoryState = PackageBootFields::msAuto; |
198 FBootFields->FMemorySize = StringToPercentageOfNumber(autoMemory.substr(0, 2), platform.GetMemorySize()); |
228 FBootFields->FMemorySize = |
199 } |
229 StringToPercentageOfNumber(autoMemory.substr(0, 2), |
200 else { |
230 platform.GetMemorySize()); |
|
231 } else { |
201 FBootFields->FMemoryState = PackageBootFields::msManual; |
232 FBootFields->FMemoryState = PackageBootFields::msManual; |
202 FBootFields->FMemorySize = 0; |
233 FBootFields->FMemorySize = 0; |
203 } |
234 } |
204 } |
235 } |
205 |
236 |
206 // Debug |
237 // Debug |
207 TString debug; |
238 TString debug; |
208 if (config->GetValue(keys[CONFIG_SECTION_APPLICATION], keys[CONFIG_APP_DEBUG], debug) == true) { |
239 if (config->GetValue(keys[CONFIG_SECTION_APPLICATION], |
|
240 keys[CONFIG_APP_DEBUG], debug) == true) { |
209 FBootFields->FArgs.push_back(debug); |
241 FBootFields->FArgs.push_back(debug); |
210 } |
242 } |
211 |
243 |
212 MergeJVMDefaultsWithOverrides(); |
244 MergeJVMDefaultsWithOverrides(); |
213 } |
245 } |
245 // Do nothing. |
278 // Do nothing. |
246 break; |
279 break; |
247 } |
280 } |
248 |
281 |
249 case cdsUninitialized: { |
282 case cdsUninitialized: { |
250 if (Config->ContainsSection(keys[CONFIG_SECTION_APPCDSJVMOPTIONS]) == true) { |
283 if (Config->ContainsSection( |
|
284 keys[CONFIG_SECTION_APPCDSJVMOPTIONS]) == true) { |
251 // If the AppCDS section is present then enable AppCDS. |
285 // If the AppCDS section is present then enable AppCDS. |
252 TString appCDSCacheValue; |
286 TString appCDSCacheValue; |
253 |
287 |
254 // If running with AppCDS enabled, and the configuration has been setup so "auto" is enabled, then |
288 // If running with AppCDS enabled, and the configuration has |
255 // the launcher will attempt to generate the cache file automatically and run the application. |
289 // been setup so "auto" is enabled, then |
256 if (Config->GetValue(keys[CONFIG_SECTION_APPLICATION], _T("app.appcds.cache"), appCDSCacheValue) == true && |
290 // the launcher will attempt to generate the cache file |
|
291 // automatically and run the application. |
|
292 if (Config->GetValue(keys[CONFIG_SECTION_APPLICATION], |
|
293 _T("app.appcds.cache"), appCDSCacheValue) == true && |
257 appCDSCacheValue == _T("auto")) { |
294 appCDSCacheValue == _T("auto")) { |
258 platform.SetAppCDSState(cdsAuto); |
295 platform.SetAppCDSState(cdsAuto); |
259 } |
296 } |
260 else { |
297 else { |
261 platform.SetAppCDSState(cdsEnabled); |
298 platform.SetAppCDSState(cdsEnabled); |
262 } |
299 } |
263 } |
300 } else { |
264 else { |
|
265 |
301 |
266 platform.SetAppCDSState(cdsDisabled); |
302 platform.SetAppCDSState(cdsDisabled); |
267 } |
303 } |
268 } |
304 } |
269 } |
305 } |
275 |
311 |
276 // Evaluate based on the current AppCDS state. |
312 // Evaluate based on the current AppCDS state. |
277 switch (platform.GetAppCDSState()) { |
313 switch (platform.GetAppCDSState()) { |
278 case cdsUninitialized: { |
314 case cdsUninitialized: { |
279 throw Exception(_T("Internal Error")); |
315 throw Exception(_T("Internal Error")); |
280 } |
316 } |
281 |
317 |
282 case cdsDisabled: { |
318 case cdsDisabled: { |
283 Config->GetSection(keys[CONFIG_SECTION_JVMOPTIONS], FBootFields->FJVMArgs); |
319 Config->GetSection(keys[CONFIG_SECTION_JVMOPTIONS], |
|
320 FBootFields->FJVMArgs); |
284 break; |
321 break; |
285 } |
322 } |
286 |
323 |
287 case cdsGenCache: { |
324 case cdsGenCache: { |
288 Config->GetSection(keys[CONFIG_SECTION_APPCDSGENERATECACHEJVMOPTIONS], FBootFields->FJVMArgs); |
325 Config->GetSection(keys[ |
|
326 CONFIG_SECTION_APPCDSGENERATECACHEJVMOPTIONS], |
|
327 FBootFields->FJVMArgs); |
289 break; |
328 break; |
290 } |
329 } |
291 |
330 |
292 case cdsAuto: |
331 case cdsAuto: |
293 case cdsEnabled: { |
332 case cdsEnabled: { |
294 if (Config->GetValue(keys[CONFIG_SECTION_APPCDSJVMOPTIONS], |
333 if (Config->GetValue(keys[CONFIG_SECTION_APPCDSJVMOPTIONS], |
295 _T( "-XX:SharedArchiveFile"), FBootFields->FAppCDSCacheFileName) == true) { |
334 _T( "-XX:SharedArchiveFile"), |
296 // File names may contain the incorrect path separators. The cache file name must be |
335 FBootFields->FAppCDSCacheFileName) == true) { |
297 // corrected at this point. |
336 // File names may contain the incorrect path separators. |
|
337 // The cache file name must be corrected at this point. |
298 if (FBootFields->FAppCDSCacheFileName.empty() == false) { |
338 if (FBootFields->FAppCDSCacheFileName.empty() == false) { |
299 IniFile* iniConfig = dynamic_cast<IniFile*>(Config); |
339 IniFile* iniConfig = dynamic_cast<IniFile*>(Config); |
300 |
340 |
301 if (iniConfig != NULL) { |
341 if (iniConfig != NULL) { |
302 FBootFields->FAppCDSCacheFileName = FilePath::FixPathForPlatform(FBootFields->FAppCDSCacheFileName); |
342 FBootFields->FAppCDSCacheFileName = |
303 iniConfig->SetValue(keys[CONFIG_SECTION_APPCDSJVMOPTIONS], |
343 FilePath::FixPathForPlatform( |
304 _T( "-XX:SharedArchiveFile"), FBootFields->FAppCDSCacheFileName); |
344 FBootFields->FAppCDSCacheFileName); |
|
345 iniConfig->SetValue(keys[ |
|
346 CONFIG_SECTION_APPCDSJVMOPTIONS], |
|
347 _T( "-XX:SharedArchiveFile"), |
|
348 FBootFields->FAppCDSCacheFileName); |
305 } |
349 } |
306 } |
350 } |
307 |
351 |
308 Config->GetSection(keys[CONFIG_SECTION_APPCDSJVMOPTIONS], FBootFields->FJVMArgs); |
352 Config->GetSection(keys[CONFIG_SECTION_APPCDSJVMOPTIONS], |
|
353 FBootFields->FJVMArgs); |
309 } |
354 } |
310 |
355 |
311 break; |
356 break; |
312 } |
357 } |
313 } |
358 } |
429 void Package::SetJVMUserArgOverrides(OrderedMap<TString, TString> Value) { |
477 void Package::SetJVMUserArgOverrides(OrderedMap<TString, TString> Value) { |
430 OrderedMap<TString, TString> defaults = GetDefaultJVMUserArgs(); |
478 OrderedMap<TString, TString> defaults = GetDefaultJVMUserArgs(); |
431 OrderedMap<TString, TString> overrides = Value; |
479 OrderedMap<TString, TString> overrides = Value; |
432 |
480 |
433 // 1. Remove entries in the overrides that are the same as the defaults. |
481 // 1. Remove entries in the overrides that are the same as the defaults. |
434 std::vector<TString> overrideKeys = GetKeysThatAreNotDuplicates(defaults, overrides); |
482 std::vector<TString> overrideKeys = |
|
483 GetKeysThatAreNotDuplicates(defaults, overrides); |
435 |
484 |
436 // 2. Create an ordered map from the overrides that weren't removed. |
485 // 2. Create an ordered map from the overrides that weren't removed. |
437 FJVMUserArgsOverrides = CreateOrderedMapFromKeyList(overrides, overrideKeys); |
486 FJVMUserArgsOverrides = |
|
487 CreateOrderedMapFromKeyList(overrides, overrideKeys); |
438 |
488 |
439 // 3. Overwrite JVM user config overrides with provided key/value pair. |
489 // 3. Overwrite JVM user config overrides with provided key/value pair. |
440 SaveJVMUserArgOverrides(FJVMUserArgsOverrides); |
490 SaveJVMUserArgOverrides(FJVMUserArgsOverrides); |
441 |
491 |
442 // 4. Merge defaults and overrides to produce FJVMUserArgs. |
492 // 4. Merge defaults and overrides to produce FJVMUserArgs. |
445 |
495 |
446 void Package::SaveJVMUserArgOverrides(OrderedMap<TString, TString> Data) { |
496 void Package::SaveJVMUserArgOverrides(OrderedMap<TString, TString> Data) { |
447 IniFile userConfig; |
497 IniFile userConfig; |
448 Platform& platform = Platform::GetInstance(); |
498 Platform& platform = Platform::GetInstance(); |
449 std::map<TString, TString> keys = platform.GetKeys(); |
499 std::map<TString, TString> keys = platform.GetKeys(); |
450 userConfig.AppendSection(keys[CONFIG_SECTION_JVMUSEROVERRIDESOPTIONS], Data); |
500 userConfig.AppendSection( |
|
501 keys[CONFIG_SECTION_JVMUSEROVERRIDESOPTIONS], Data); |
451 userConfig.SaveToFile(GetJVMUserArgsConfigFileName()); |
502 userConfig.SaveToFile(GetJVMUserArgsConfigFileName()); |
452 } |
503 } |
453 |
504 |
454 OrderedMap<TString, TString> Package::GetJVMUserArgs() { |
505 OrderedMap<TString, TString> Package::GetJVMUserArgs() { |
455 return FJVMUserArgs; |
506 return FJVMUserArgs; |
456 } |
507 } |
457 |
508 |
458 std::vector<TString> GetKeysThatAreNotOverridesOfDefaultValues(OrderedMap<TString, TString> &Defaults, |
509 std::vector<TString> GetKeysThatAreNotOverridesOfDefaultValues( |
459 OrderedMap<TString, TString> &Overrides) { |
510 OrderedMap<TString, TString> &Defaults, OrderedMap<TString, |
|
511 TString> &Overrides) { |
460 std::vector<TString> result; |
512 std::vector<TString> result; |
461 std::vector<TString> keys = Overrides.GetKeys(); |
513 std::vector<TString> keys = Overrides.GetKeys(); |
462 |
514 |
463 for (unsigned int index = 0; index< keys.size(); index++) { |
515 for (unsigned int index = 0; index< keys.size(); index++) { |
464 TString key = keys[index]; |
516 TString key = keys[index]; |
478 |
530 |
479 return result; |
531 return result; |
480 } |
532 } |
481 |
533 |
482 void Package::MergeJVMDefaultsWithOverrides() { |
534 void Package::MergeJVMDefaultsWithOverrides() { |
483 // Merge jvmuserarg defaults and jvmuserarg overrides to populate FJVMUserArgs. |
535 // Merge jvmuserarg defaults and jvmuserarg overrides to populate |
484 // 1. If the key is in the config file and not the java.user.preferences the default value is used, |
536 // FJVMUserArgs. |
|
537 // 1. If the key is in the config file and not the |
|
538 // java.user.preferences the default value is used, |
485 // the one from the config file. |
539 // the one from the config file. |
486 // 2. If the key is in the java.user.preferences then the value from the java.user.preferences is used and |
540 // 2. If the key is in the java.user.preferences then the value |
|
541 // from the java.user.preferences is used and |
487 // the config file value is ignored. |
542 // the config file value is ignored. |
488 // 3. If the key is not in the config file but it is in the java.user.preferences then it is added anyway. |
543 // 3. If the key is not in the config file but it is in |
|
544 // the java.user.preferences then it is added anyway. |
489 // And if it is removed it won't show back up. |
545 // And if it is removed it won't show back up. |
490 FJVMUserArgs.Clear(); |
546 FJVMUserArgs.Clear(); |
491 FJVMUserArgs.Append(FDefaultJVMUserArgs); |
547 FJVMUserArgs.Append(FDefaultJVMUserArgs); |
492 |
548 |
493 OrderedMap<TString, TString> overrides = GetJVMUserArgOverrides(); |
549 OrderedMap<TString, TString> overrides = GetJVMUserArgOverrides(); |
494 |
550 |
495 // 1. Iterate over all elements in overrides to see if any items |
551 // 1. Iterate over all elements in overrides to see if any items |
496 // override a default value. |
552 // override a default value. |
497 std::vector<TString> keys = GetKeysThatAreNotOverridesOfDefaultValues(FJVMUserArgs, overrides); |
553 std::vector<TString> keys = |
|
554 GetKeysThatAreNotOverridesOfDefaultValues(FJVMUserArgs, overrides); |
498 |
555 |
499 |
556 |
500 // 2. All remaining items in overrides are appended to the end. |
557 // 2. All remaining items in overrides are appended to the end. |
501 for (unsigned int index = 0; index< keys.size(); index++) { |
558 for (unsigned int index = 0; index< keys.size(); index++) { |
502 TString key = keys[index]; |
559 TString key = keys[index]; |
535 |
592 |
536 TString Package::GetJVMUserArgsConfigFileName() { |
593 TString Package::GetJVMUserArgsConfigFileName() { |
537 if (FJVMUserArgsConfigFileName.empty()) { |
594 if (FJVMUserArgsConfigFileName.empty()) { |
538 Platform& platform = Platform::GetInstance(); |
595 Platform& platform = Platform::GetInstance(); |
539 |
596 |
540 FJVMUserArgsConfigFileName = FilePath::IncludeTrailingSeparater(platform.GetAppDataDirectory()) + |
597 FJVMUserArgsConfigFileName = FilePath::IncludeTrailingSeparator( |
541 FilePath::IncludeTrailingSeparater(GetPackageAppDataDirectory()) + |
598 platform.GetAppDataDirectory()) |
542 FilePath::IncludeTrailingSeparater(_T("packager")) + |
599 + FilePath::IncludeTrailingSeparator( |
543 _T("jvmuserargs.cfg"); |
600 GetPackageAppDataDirectory()) |
|
601 + FilePath::IncludeTrailingSeparator(_T("packager")) |
|
602 + _T("jvmuserargs.cfg"); |
544 } |
603 } |
545 |
604 |
546 return FJVMUserArgsConfigFileName; |
605 return FJVMUserArgsConfigFileName; |
547 } |
606 } |
548 |
607 |
549 TString Package::GetAppCDSCacheDirectory() { |
608 TString Package::GetAppCDSCacheDirectory() { |
550 if (FAppCDSCacheDirectory.empty()) { |
609 if (FAppCDSCacheDirectory.empty()) { |
551 Platform& platform = Platform::GetInstance(); |
610 Platform& platform = Platform::GetInstance(); |
552 FAppCDSCacheDirectory = FilePath::IncludeTrailingSeparater(platform.GetAppDataDirectory()) + |
611 FAppCDSCacheDirectory = FilePath::IncludeTrailingSeparator( |
553 FilePath::IncludeTrailingSeparater(GetPackageAppDataDirectory()) + |
612 platform.GetAppDataDirectory()) |
554 _T("cache"); |
613 + FilePath::IncludeTrailingSeparator( |
|
614 GetPackageAppDataDirectory()) + _T("cache"); |
555 |
615 |
556 Macros& macros = Macros::GetInstance(); |
616 Macros& macros = Macros::GetInstance(); |
557 FAppCDSCacheDirectory = macros.ExpandMacros(FAppCDSCacheDirectory); |
617 FAppCDSCacheDirectory = macros.ExpandMacros(FAppCDSCacheDirectory); |
558 FAppCDSCacheDirectory = FilePath::FixPathForPlatform(FAppCDSCacheDirectory); |
618 FAppCDSCacheDirectory = |
|
619 FilePath::FixPathForPlatform(FAppCDSCacheDirectory); |
559 } |
620 } |
560 |
621 |
561 return FAppCDSCacheDirectory; |
622 return FAppCDSCacheDirectory; |
562 } |
623 } |
563 |
624 |
564 TString Package::GetAppCDSCacheFileName() { |
625 TString Package::GetAppCDSCacheFileName() { |
565 assert(FBootFields != NULL); |
626 assert(FBootFields != NULL); |
566 |
627 |
567 if (FBootFields->FAppCDSCacheFileName.empty() == false) { |
628 if (FBootFields->FAppCDSCacheFileName.empty() == false) { |
568 Macros& macros = Macros::GetInstance(); |
629 Macros& macros = Macros::GetInstance(); |
569 FBootFields->FAppCDSCacheFileName = macros.ExpandMacros(FBootFields->FAppCDSCacheFileName); |
630 FBootFields->FAppCDSCacheFileName = |
570 FBootFields->FAppCDSCacheFileName = FilePath::FixPathForPlatform(FBootFields->FAppCDSCacheFileName); |
631 macros.ExpandMacros(FBootFields->FAppCDSCacheFileName); |
|
632 FBootFields->FAppCDSCacheFileName = |
|
633 FilePath::FixPathForPlatform(FBootFields->FAppCDSCacheFileName); |
571 } |
634 } |
572 |
635 |
573 return FBootFields->FAppCDSCacheFileName; |
636 return FBootFields->FAppCDSCacheFileName; |
574 } |
637 } |
575 |
638 |