|
8 | 8 | package org.phoebus.framework.workbench; |
9 | 9 |
|
10 | 10 | import java.io.File; |
| 11 | +import java.util.ArrayList; |
11 | 12 | import java.util.Collection; |
| 13 | +import java.util.List; |
| 14 | +import java.util.logging.Level; |
12 | 15 | import java.util.logging.Logger; |
13 | | -import java.util.stream.Collectors; |
| 16 | +import java.util.prefs.Preferences; |
14 | 17 |
|
15 | 18 | import org.phoebus.framework.preferences.AnnotatedPreferences; |
16 | 19 | import org.phoebus.framework.preferences.Preference; |
17 | | -import org.phoebus.framework.preferences.PreferencesReader; |
18 | 20 |
|
19 | 21 | /** Workbench Preferences |
20 | 22 | * @author Kay Kasemir |
21 | 23 | */ |
22 | 24 | public class WorkbenchPreferences |
23 | 25 | { |
| 26 | + // This class gets initialized quite early because other code uses this logger. |
| 27 | + // The external apps are thus read on demand via getExternalApps(), |
| 28 | + // they are not constructed in the static... code below because |
| 29 | + // that might happen before all the `-settings` from the command line have been applied. |
| 30 | + |
24 | 31 | /** Logger for the 'workbench' package */ |
25 | 32 | public static final Logger logger = Logger.getLogger(WorkbenchPreferences.class.getPackageName()); |
26 | 33 |
|
27 | 34 | /** directory of external applications */ |
28 | 35 | @Preference public static File external_apps_directory; |
29 | | - |
| 36 | + |
30 | 37 | /** Phoebus memento folder name default from $(phoebus.folder.name.preference) System property */ |
31 | 38 | @Preference public static String phoebus_folder_name; |
32 | | - |
| 39 | + |
33 | 40 | /** Phoebus user home directory contents memento default from $(phoebus.user) System property */ |
34 | 41 | @Preference public static File phoebus_user; |
35 | | - |
36 | | - /** external applications */ |
37 | | - public static final Collection<String> external_apps; |
| 42 | + |
| 43 | + /** @return external application definitions */ |
| 44 | + public static Collection<String> getExternalApps() |
| 45 | + { |
| 46 | + Preferences prefs = Preferences.userNodeForPackage(WorkbenchPreferences.class); |
| 47 | + final List<String> external = new ArrayList<>(); |
| 48 | + try |
| 49 | + { |
| 50 | + for (String key : prefs.keys()) |
| 51 | + if (key.startsWith("external_app_")) |
| 52 | + external.add(prefs.get(key, "")); |
| 53 | + } |
| 54 | + catch (Exception ex) |
| 55 | + { |
| 56 | + logger.log(Level.WARNING, "Cannot read external_app_* entries", ex); |
| 57 | + } |
| 58 | + return external; |
| 59 | + } |
38 | 60 |
|
39 | 61 | static |
40 | 62 | { |
41 | | - final PreferencesReader prefs = AnnotatedPreferences.initialize(WorkbenchPreferences.class, "/workbench_preferences.properties"); |
42 | | - external_apps = prefs.getKeys("external_app_.*").stream().map(prefs::get).collect(Collectors.toList()); |
| 63 | + AnnotatedPreferences.initialize(WorkbenchPreferences.class, "/workbench_preferences.properties"); |
43 | 64 | } |
44 | 65 | } |
0 commit comments