forked from emc-mongoose/mongoose-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExtensionBase.java
48 lines (41 loc) · 1.41 KB
/
ExtensionBase.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.emc.mongoose.base.env;
import static com.emc.mongoose.base.Constants.DIR_CONFIG;
import static com.emc.mongoose.base.Exceptions.throwUncheckedIfInterrupted;
import com.emc.mongoose.base.config.ConfigUtil;
import com.emc.mongoose.base.logging.LogUtil;
import com.github.akurilov.confuse.Config;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
import org.apache.logging.log4j.Level;
public abstract class ExtensionBase extends InstallableJarResources implements Extension {
@Override
public final Config defaults(final Path appHomePath) {
final var schemaProvider = schemaProvider();
final Map<String, Object> schema;
if (schemaProvider == null) {
schema = null;
} else {
try {
schema = schemaProvider.schema();
} catch (final Exception e) {
LogUtil.exception(Level.WARN, e, "{}: failed to load the schema", schemaProvider);
return null;
}
}
final var defaultsFileName = defaultsFileName();
if (defaultsFileName == null) {
return null;
}
final var defaultsFile = Paths.get(appHomePath.toString(), DIR_CONFIG, defaultsFileName).toFile();
try {
return ConfigUtil.loadConfig(defaultsFile, schema);
} catch (final Exception e) {
throwUncheckedIfInterrupted(e);
LogUtil.exception(
Level.WARN, e, "Failed to load the defaults config from \"{}\"", defaultsFile);
return null;
}
}
protected abstract String defaultsFileName();
}