|
7 | 7 | import java.nio.file.Path; |
8 | 8 | import java.util.Arrays; |
9 | 9 | import java.util.List; |
10 | | -import java.util.Map; |
11 | 10 |
|
12 | 11 | import org.jabref.cli.ArgumentProcessor; |
13 | 12 | import org.jabref.gui.JabRefGUI; |
@@ -51,51 +50,56 @@ public enum MultipleInstanceAction { |
51 | 50 | } |
52 | 51 |
|
53 | 52 | public static void main(String[] args) { |
54 | | - initLogging(args); |
55 | | - |
56 | | - Injector.setModelOrService(BuildInfo.class, new BuildInfo()); |
57 | | - |
58 | | - final JabRefGuiPreferences preferences = JabRefGuiPreferences.getInstance(); |
59 | | - |
60 | | - ArgumentProcessor argumentProcessor = new ArgumentProcessor( |
61 | | - args, |
62 | | - ArgumentProcessor.Mode.INITIAL_START, |
63 | | - preferences); |
| 53 | + try { |
| 54 | + initLogging(args); |
| 55 | + |
| 56 | + Injector.setModelOrService(BuildInfo.class, new BuildInfo()); |
| 57 | + |
| 58 | + final JabRefGuiPreferences preferences = JabRefGuiPreferences.getInstance(); |
| 59 | + |
| 60 | + ArgumentProcessor argumentProcessor = new ArgumentProcessor( |
| 61 | + args, |
| 62 | + ArgumentProcessor.Mode.INITIAL_START, |
| 63 | + preferences); |
| 64 | + |
| 65 | + if (!argumentProcessor.getGuiCli().usageHelpRequested) { |
| 66 | + Injector.setModelOrService(CliPreferences.class, preferences); |
| 67 | + Injector.setModelOrService(GuiPreferences.class, preferences); |
| 68 | + |
| 69 | + // Early exit in case another instance is already running |
| 70 | + MultipleInstanceAction instanceAction = handleMultipleAppInstances(args, preferences.getRemotePreferences()); |
| 71 | + if (instanceAction == MultipleInstanceAction.SHUTDOWN) { |
| 72 | + systemExit(); |
| 73 | + } else if (instanceAction == MultipleInstanceAction.FOCUS) { |
| 74 | + // Send focus command to running instance |
| 75 | + RemotePreferences remotePreferences = preferences.getRemotePreferences(); |
| 76 | + RemoteClient remoteClient = new RemoteClient(remotePreferences.getPort()); |
| 77 | + remoteClient.sendFocus(); |
| 78 | + systemExit(); |
| 79 | + } |
64 | 80 |
|
65 | | - if (!argumentProcessor.getGuiCli().usageHelpRequested) { |
66 | | - Injector.setModelOrService(CliPreferences.class, preferences); |
67 | | - Injector.setModelOrService(GuiPreferences.class, preferences); |
| 81 | + configureProxy(preferences.getProxyPreferences()); |
| 82 | + configureSSL(preferences.getSSLPreferences()); |
| 83 | + } |
68 | 84 |
|
69 | | - // Early exit in case another instance is already running |
70 | | - MultipleInstanceAction instanceAction = handleMultipleAppInstances(args, preferences.getRemotePreferences()); |
71 | | - if (instanceAction == MultipleInstanceAction.SHUTDOWN) { |
72 | | - systemExit(); |
73 | | - } else if (instanceAction == MultipleInstanceAction.FOCUS) { |
74 | | - // Send focus command to running instance |
75 | | - RemotePreferences remotePreferences = preferences.getRemotePreferences(); |
76 | | - RemoteClient remoteClient = new RemoteClient(remotePreferences.getPort()); |
77 | | - remoteClient.sendFocus(); |
| 85 | + List<UiCommand> uiCommands = argumentProcessor.processArguments(); |
| 86 | + if (argumentProcessor.shouldShutDown()) { |
78 | 87 | systemExit(); |
79 | 88 | } |
80 | 89 |
|
81 | | - configureProxy(preferences.getProxyPreferences()); |
82 | | - configureSSL(preferences.getSSLPreferences()); |
83 | | - } |
84 | | - |
85 | | - List<UiCommand> uiCommands = argumentProcessor.processArguments(); |
86 | | - if (argumentProcessor.shouldShutDown()) { |
87 | | - systemExit(); |
88 | | - } |
89 | | - |
90 | | - PreferencesMigrations.runMigrations(preferences); |
| 90 | + PreferencesMigrations.runMigrations(preferences); |
91 | 91 |
|
92 | | - PostgreServer postgreServer = new PostgreServer(); |
93 | | - Injector.setModelOrService(PostgreServer.class, postgreServer); |
| 92 | + PostgreServer postgreServer = new PostgreServer(); |
| 93 | + Injector.setModelOrService(PostgreServer.class, postgreServer); |
94 | 94 |
|
95 | | - CSLStyleLoader.loadInternalStyles(); |
| 95 | + CSLStyleLoader.loadInternalStyles(); |
96 | 96 |
|
97 | | - JabRefGUI.setup(uiCommands, preferences); |
98 | | - JabRefGUI.launch(JabRefGUI.class, args); |
| 97 | + JabRefGUI.setup(uiCommands, preferences); |
| 98 | + JabRefGUI.launch(JabRefGUI.class, args); |
| 99 | + } catch (Throwable throwable) { |
| 100 | + LOGGER.error("Could not launch JabRef", throwable); |
| 101 | + throw throwable; |
| 102 | + } |
99 | 103 | } |
100 | 104 |
|
101 | 105 | /** |
@@ -126,16 +130,15 @@ public static void initLogging(String[] args) { |
126 | 130 |
|
127 | 131 | // The "Shared File Writer" is explained at |
128 | 132 | // https://tinylog.org/v2/configuration/#shared-file-writer |
129 | | - Map<String, String> configuration = Map.of( |
130 | | - "level", logLevel.name().toLowerCase(), |
131 | | - "writerFile", "rolling file", |
132 | | - "writerFile.level", logLevel.name().toLowerCase(), |
133 | | - // We need to manually join the path, because ".resolve" does not work on Windows, because ":" is not allowed in file names on Windows |
134 | | - "writerFile.file", directory + File.separator + "log_{date:yyyy-MM-dd_HH-mm-ss}.txt", |
135 | | - "writerFile.charset", "UTF-8", |
136 | | - "writerFile.policies", "startup", |
137 | | - "writerFile.backups", "30"); |
138 | | - configuration.forEach(Configuration::set); |
| 133 | + Configuration.set("level", logLevel.name().toLowerCase()); |
| 134 | + Configuration.set("writerFile", "rolling file"); |
| 135 | + Configuration.set("writerFile.level", logLevel.name().toLowerCase()); |
| 136 | + // We need to manually join the path, because ".resolve" does not work on Windows, |
| 137 | + // because ":" is not allowed in file names on Windows |
| 138 | + Configuration.set("writerFile.file", directory + File.separator + "log_{date:yyyy-MM-dd_HH-mm-ss}.txt"); |
| 139 | + Configuration.set("writerFile.charset", "UTF-8"); |
| 140 | + Configuration.set("writerFile.policies", "startup"); |
| 141 | + Configuration.set("writerFile.backups", "30"); |
139 | 142 |
|
140 | 143 | LOGGER = LoggerFactory.getLogger(Launcher.class); |
141 | 144 | } |
|
0 commit comments