| ... |
... |
@@ -53,7 +53,10 @@ import javax.script.ScriptException; |
|
53
|
53
|
import javax.swing.UIManager;
|
|
54
|
54
|
import java.io.File;
|
|
55
|
55
|
import java.io.IOException;
|
|
|
56
|
+import java.nio.file.Files;
|
|
|
57
|
+import java.nio.file.Path;
|
|
56
|
58
|
import java.util.Arrays;
|
|
|
59
|
+import java.util.Comparator;
|
|
57
|
60
|
import java.util.Date;
|
|
58
|
61
|
import java.util.Locale;
|
|
59
|
62
|
import java.util.Properties;
|
| ... |
... |
@@ -121,47 +124,29 @@ public abstract class ObserveRunner extends ApplicationRunner { |
|
121
|
124
|
|
|
122
|
125
|
I18n.close();
|
|
123
|
126
|
|
|
124
|
|
- File i18nDirectory = config.getI18nDirectory();
|
|
|
127
|
+ Path i18nDirectory = config.getI18nDirectory().toPath();
|
|
125
|
128
|
|
|
126
|
|
- UserI18nBootLoader i18nInitializer = new UserI18nBootLoader(i18nDirectory.toPath(), new DefaultI18nBootLoader(I18nConfiguration.createDefaultConfiguration())) {
|
|
127
|
|
-//
|
|
128
|
|
-// @Override
|
|
129
|
|
-// protected void createUserI18nLayout(File directory) throws Exception {
|
|
130
|
|
-// if (config.getI18nDefinitionFile().exists()) {
|
|
131
|
|
-// return;
|
|
132
|
|
-// }
|
|
133
|
|
-// super.createUserI18nLayout(directory);
|
|
134
|
|
-//
|
|
135
|
|
-// // add also a archive with all i18n stupuff (says i18n bundle + templates)
|
|
136
|
|
-//
|
|
137
|
|
-// URL resource = ObserveResourceManager.getResource(ObserveResourceManager.OBSERVE_I18N_ARCHIVE);
|
|
138
|
|
-// File archive = new File(directory.getParent(), ObserveResourceManager.OBSERVE_I18N_ARCHIVE.substring(1));
|
|
139
|
|
-// try {
|
|
140
|
|
-// resourceManager.copyResource(resource, archive, "Copy i18n archive");
|
|
141
|
|
-// ZipUtil.uncompressFiltred(archive, directory.getParentFile());
|
|
142
|
|
-// } finally {
|
|
143
|
|
-// if (Files.exists(archive.toPath())) {
|
|
144
|
|
-// try {
|
|
145
|
|
-// Files.delete(archive.toPath());
|
|
146
|
|
-// } catch (IOException e) {
|
|
147
|
|
-// log.error(String.format("Could not delete i18n archive %s", archive));
|
|
148
|
|
-// }
|
|
149
|
|
-// }
|
|
150
|
|
-// }
|
|
151
|
|
-//
|
|
152
|
|
-// }
|
|
153
|
|
- };
|
|
|
129
|
+ if (config.getBuildVersion().isSnapshot() && Files.exists(i18nDirectory)) {
|
|
|
130
|
+ // always regenerate i18n
|
|
|
131
|
+ try {
|
|
|
132
|
+ Files.walk(i18nDirectory)
|
|
|
133
|
+ .sorted(Comparator.reverseOrder())
|
|
|
134
|
+ .map(Path::toFile)
|
|
|
135
|
+ .forEach(File::delete);
|
|
|
136
|
+ } catch (IOException e) {
|
|
|
137
|
+ throw new IllegalStateException("Can't delete i18n directory: "+i18nDirectory, e);
|
|
|
138
|
+ }
|
|
154
|
139
|
|
|
|
140
|
+ }
|
|
|
141
|
+ UserI18nBootLoader i18nInitializer = new UserI18nBootLoader(i18nDirectory, new DefaultI18nBootLoader(I18nConfiguration.createDefaultConfiguration()));
|
|
155
|
142
|
long t00 = System.nanoTime();
|
|
156
|
143
|
|
|
157
|
144
|
Locale locale = config.getLocale();
|
|
158
|
145
|
|
|
159
|
146
|
I18n.init(i18nInitializer, locale);
|
|
160
|
147
|
|
|
161
|
|
- if (log.isDebugEnabled()) {
|
|
162
|
148
|
log.debug("i18n language : " + locale);
|
|
163
|
149
|
log.debug("i18n loading time : " + StringUtil.convertTime(t00, System.nanoTime()));
|
|
164
|
|
- }
|
|
165
|
150
|
}
|
|
166
|
151
|
|
|
167
|
152
|
public abstract String getRunnerName();
|
| ... |
... |
@@ -217,9 +202,7 @@ public abstract class ObserveRunner extends ApplicationRunner { |
|
217
|
202
|
@Override
|
|
218
|
203
|
protected void onInit() throws Exception {
|
|
219
|
204
|
|
|
220
|
|
- if (log.isInfoEnabled()) {
|
|
221
|
|
- log.info(t("observe.runner.init", new Date(), Arrays.toString(args)));
|
|
222
|
|
- }
|
|
|
205
|
+ log.info(t("observe.runner.init", new Date(), Arrays.toString(args)));
|
|
223
|
206
|
|
|
224
|
207
|
long t0 = System.nanoTime();
|
|
225
|
208
|
|
| ... |
... |
@@ -227,30 +210,22 @@ public abstract class ObserveRunner extends ApplicationRunner { |
|
227
|
210
|
|
|
228
|
211
|
ClientConfig config = initConfig();
|
|
229
|
212
|
|
|
230
|
|
- if (log.isInfoEnabled()) {
|
|
231
|
|
- log.info(t("observe.runner.config.loaded", config.getVersion()));
|
|
232
|
|
- }
|
|
|
213
|
+ log.info(t("observe.runner.config.loaded", config.getVersion()));
|
|
233
|
214
|
|
|
234
|
215
|
// 2 - preparation des répertoires utilisateurs
|
|
235
|
216
|
|
|
236
|
217
|
initUserDirectories(config);
|
|
237
|
218
|
|
|
238
|
219
|
// 3 - Chargement de la configuration des logs utilisateur
|
|
239
|
|
- if (!config.isDevMode()) {
|
|
240
|
|
- initLog(config);
|
|
241
|
|
- }
|
|
|
220
|
+ initLog(config);
|
|
242
|
221
|
|
|
243
|
|
- if (log.isInfoEnabled()) {
|
|
244
|
|
- log.info(t("observe.runner.user.directories.loaded", config.getDataDirectory()));
|
|
245
|
|
- }
|
|
|
222
|
+ log.info(t("observe.runner.user.directories.loaded", config.getDataDirectory()));
|
|
246
|
223
|
|
|
247
|
224
|
// 3 - preparation i18n
|
|
248
|
225
|
|
|
249
|
226
|
initI18n(config);
|
|
250
|
227
|
|
|
251
|
|
- if (log.isInfoEnabled()) {
|
|
252
|
|
- log.info(t("observe.runner.i18n.loaded", config.getLocale().getDisplayLanguage()));
|
|
253
|
|
- }
|
|
|
228
|
+ log.info(t("observe.runner.i18n.loaded", config.getLocale().getDisplayLanguage()));
|
|
254
|
229
|
|
|
255
|
230
|
// 4 - preparation de la configuration des ui
|
|
256
|
231
|
|
| ... |
... |
@@ -266,9 +241,7 @@ public abstract class ObserveRunner extends ApplicationRunner { |
|
266
|
241
|
|
|
267
|
242
|
String time = StringUtil.convertTime(t0, System.nanoTime());
|
|
268
|
243
|
|
|
269
|
|
- if (log.isInfoEnabled()) {
|
|
270
|
|
- log.info(t("observe.runner.context.loaded", time));
|
|
271
|
|
- }
|
|
|
244
|
+ log.info(t("observe.runner.context.loaded", time));
|
|
272
|
245
|
}
|
|
273
|
246
|
|
|
274
|
247
|
private void initLog(ClientConfig config) throws IOException {
|
| ... |
... |
@@ -287,9 +260,7 @@ public abstract class ObserveRunner extends ApplicationRunner { |
|
287
|
260
|
@Override
|
|
288
|
261
|
protected void onStart() throws Exception {
|
|
289
|
262
|
|
|
290
|
|
- if (log.isInfoEnabled()) {
|
|
291
|
|
- log.info(t("observe.runner.start", new Date(), Arrays.toString(args)));
|
|
292
|
|
- }
|
|
|
263
|
+ log.info(t("observe.runner.start", new Date(), Arrays.toString(args)));
|
|
293
|
264
|
|
|
294
|
265
|
ObserveSwingApplicationContext context = ObserveSwingApplicationContext.get();
|
|
295
|
266
|
|
| ... |
... |
@@ -304,9 +275,7 @@ public abstract class ObserveRunner extends ApplicationRunner { |
|
304
|
275
|
config.get().doAction(ClientConfig.Step.AfterInit.ordinal());
|
|
305
|
276
|
|
|
306
|
277
|
if (!config.isDisplayMainUI()) {
|
|
307
|
|
- if (log.isInfoEnabled()) {
|
|
308
|
|
- log.info(t("observe.runner.quit.withno.ui"));
|
|
309
|
|
- }
|
|
|
278
|
+ log.info(t("observe.runner.quit.withno.ui"));
|
|
310
|
279
|
|
|
311
|
280
|
unlock();
|
|
312
|
281
|
return;
|
| ... |
... |
@@ -320,9 +289,7 @@ public abstract class ObserveRunner extends ApplicationRunner { |
|
320
|
289
|
|
|
321
|
290
|
ObserveMainUI ui = startUI(context, config);
|
|
322
|
291
|
|
|
323
|
|
- if (log.isInfoEnabled()) {
|
|
324
|
|
- log.info(t("observe.runner.ui.loaded"));
|
|
325
|
|
- }
|
|
|
292
|
+ log.info(t("observe.runner.ui.loaded"));
|
|
326
|
293
|
|
|
327
|
294
|
Boolean h2ServerMode = ObserveSwingApplicationContext.Entries.H2_SERVER_MODE.get();
|
|
328
|
295
|
|
| ... |
... |
@@ -357,18 +324,14 @@ public abstract class ObserveRunner extends ApplicationRunner { |
|
357
|
324
|
protected void onClose(boolean reload) {
|
|
358
|
325
|
if (ObserveSwingApplicationContext.isInit()) {
|
|
359
|
326
|
|
|
360
|
|
- if (log.isDebugEnabled()) {
|
|
361
|
|
- log.debug("Will close context...");
|
|
362
|
|
- }
|
|
|
327
|
+ log.debug("Will close context...");
|
|
363
|
328
|
ObserveSwingApplicationContext.get().close();
|
|
364
|
329
|
}
|
|
365
|
330
|
}
|
|
366
|
331
|
|
|
367
|
332
|
@Override
|
|
368
|
333
|
protected void onShutdown() {
|
|
369
|
|
- if (log.isInfoEnabled()) {
|
|
370
|
|
- log.info("ObServe shutdown at " + new Date());
|
|
371
|
|
- }
|
|
|
334
|
+ log.info("ObServe shutdown at " + new Date());
|
|
372
|
335
|
|
|
373
|
336
|
try {
|
|
374
|
337
|
|
| ... |
... |
@@ -392,9 +355,7 @@ public abstract class ObserveRunner extends ApplicationRunner { |
|
392
|
355
|
|
|
393
|
356
|
@Override
|
|
394
|
357
|
protected void onShutdown(Exception ex) {
|
|
395
|
|
- if (log.isErrorEnabled()) {
|
|
396
|
|
- log.error("error while closing " + ex.getMessage(), ex);
|
|
397
|
|
- }
|
|
|
358
|
+ log.error("error while closing " + ex.getMessage(), ex);
|
|
398
|
359
|
Runtime.getRuntime().halt(1);
|
|
399
|
360
|
}
|
|
400
|
361
|
|
| ... |
... |
@@ -424,9 +385,7 @@ public abstract class ObserveRunner extends ApplicationRunner { |
|
424
|
385
|
|
|
425
|
386
|
File dataDirectory = resourceManager.createDirectory(config, DATA_DIRECTORY);
|
|
426
|
387
|
|
|
427
|
|
- if (log.isDebugEnabled()) {
|
|
428
|
|
- log.debug("user data directory : " + dataDirectory);
|
|
429
|
|
- }
|
|
|
388
|
+ log.debug("user data directory : " + dataDirectory);
|
|
430
|
389
|
|
|
431
|
390
|
resourceManager.createParentDirectory(config, DB_DIRECTORY, INITIAL_DB_DUMP);
|
|
432
|
391
|
|
| ... |
... |
@@ -445,9 +404,7 @@ public abstract class ObserveRunner extends ApplicationRunner { |
|
445
|
404
|
|
|
446
|
405
|
File resourcesDirectory = resourceManager.createDirectory(config, RESOURCES_DIRECTORY);
|
|
447
|
406
|
|
|
448
|
|
- if (log.isDebugEnabled()) {
|
|
449
|
|
- log.debug("user resource data directory : " + resourcesDirectory);
|
|
450
|
|
- }
|
|
|
407
|
+ log.debug("user resource data directory : " + resourcesDirectory);
|
|
451
|
408
|
|
|
452
|
409
|
// 5 - application ui
|
|
453
|
410
|
|
| ... |
... |
@@ -504,18 +461,14 @@ public abstract class ObserveRunner extends ApplicationRunner { |
|
504
|
461
|
boolean hasLocalStorage = new File(config.getLocalDBDirectory(), ClientConfig.DB_NAME).exists();
|
|
505
|
462
|
config.setLocalStorageExist(hasLocalStorage);
|
|
506
|
463
|
if (!hasLocalStorage) {
|
|
507
|
|
- if (log.isInfoEnabled()) {
|
|
508
|
|
- log.info(t("observe.init.no.local.db.detected", config.getLocalDBDirectory()));
|
|
509
|
|
- }
|
|
|
464
|
+ log.info(t("observe.init.no.local.db.detected", config.getLocalDBDirectory()));
|
|
510
|
465
|
}
|
|
511
|
466
|
|
|
512
|
467
|
boolean hasInitialDb = config.getInitialDbDump().exists();
|
|
513
|
468
|
config.setInitialDumpExist(hasInitialDb);
|
|
514
|
469
|
|
|
515
|
470
|
if (!hasInitialDb) {
|
|
516
|
|
- if (log.isInfoEnabled()) {
|
|
517
|
|
- log.info(t("observe.init.no.initial.dump.detected", config.getInitialDbDump()));
|
|
518
|
|
- }
|
|
|
471
|
+ log.info(t("observe.init.no.initial.dump.detected", config.getInitialDbDump()));
|
|
519
|
472
|
}
|
|
520
|
473
|
}
|
|
521
|
474
|
|
| ... |
... |
@@ -526,13 +479,9 @@ public abstract class ObserveRunner extends ApplicationRunner { |
|
526
|
479
|
UIHelper.initNimbusLoookAndFeel();
|
|
527
|
480
|
} catch (Exception e) {
|
|
528
|
481
|
// could not find nimbus look-and-feel
|
|
529
|
|
- if (log.isWarnEnabled()) {
|
|
530
|
|
- log.warn(t("observe.warning.nimbus.landf"));
|
|
531
|
|
- }
|
|
|
482
|
+ log.warn(t("observe.warning.nimbus.landf"));
|
|
532
|
483
|
} catch (Throwable e) {
|
|
533
|
|
- if (log.isWarnEnabled()) {
|
|
534
|
|
- log.warn(t("observe.warning.no.ui"));
|
|
535
|
|
- }
|
|
|
484
|
+ log.warn(t("observe.warning.no.ui"));
|
|
536
|
485
|
// pas d'environnement d'ui
|
|
537
|
486
|
config.setCanUseUI(false);
|
|
538
|
487
|
}
|
| ... |
... |
@@ -562,9 +511,7 @@ public abstract class ObserveRunner extends ApplicationRunner { |
|
562
|
511
|
}
|
|
563
|
512
|
}
|
|
564
|
513
|
|
|
565
|
|
- if (log.isInfoEnabled()) {
|
|
566
|
|
- log.info(t("observe.runner.loading.ui.configuration", file));
|
|
567
|
|
- }
|
|
|
514
|
+ log.info(t("observe.runner.loading.ui.configuration", file));
|
|
568
|
515
|
try {
|
|
569
|
516
|
Properties p = resourceManager.getResource(file);
|
|
570
|
517
|
UIHelper.loadUIConfig(p);
|