drop config logging
This commit is contained in:
parent
82dd72c811
commit
9a19a2d7c9
13 changed files with 22 additions and 94 deletions
|
@ -1,12 +1,8 @@
|
||||||
import org.xbib.config.ConfigLogger;
|
|
||||||
import org.xbib.config.NullConfigLogger;
|
|
||||||
import org.xbib.config.SystemConfigLogger;
|
|
||||||
import org.xbib.settings.SettingsLoader;
|
import org.xbib.settings.SettingsLoader;
|
||||||
|
|
||||||
module org.xbib.config {
|
module org.xbib.config {
|
||||||
requires transitive org.xbib.settings.datastructures;
|
requires transitive org.xbib.settings.datastructures;
|
||||||
|
requires java.logging;
|
||||||
exports org.xbib.config;
|
exports org.xbib.config;
|
||||||
uses ConfigLogger;
|
|
||||||
uses SettingsLoader;
|
uses SettingsLoader;
|
||||||
provides ConfigLogger with NullConfigLogger, SystemConfigLogger;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import org.xbib.settings.Settings;
|
import org.xbib.settings.Settings;
|
||||||
import org.xbib.settings.SettingsBuilder;
|
import org.xbib.settings.SettingsBuilder;
|
||||||
|
@ -29,7 +31,7 @@ public class ConfigLoader {
|
||||||
|
|
||||||
private static final Map<ConfigParams, Settings> map = new HashMap<>();
|
private static final Map<ConfigParams, Settings> map = new HashMap<>();
|
||||||
|
|
||||||
private ConfigLogger logger;
|
private static final Logger logger = Logger.getLogger(ConfigLoader.class.getName());
|
||||||
|
|
||||||
private ConfigLoader() {
|
private ConfigLoader() {
|
||||||
}
|
}
|
||||||
|
@ -38,11 +40,6 @@ public class ConfigLoader {
|
||||||
return new ConfigLoader();
|
return new ConfigLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigLoader withLogger(ConfigLogger logger) {
|
|
||||||
this.logger = logger;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized Settings load(ConfigParams configParams) throws ConfigException {
|
public synchronized Settings load(ConfigParams configParams) throws ConfigException {
|
||||||
map.computeIfAbsent(configParams, p -> internalLoad(p)
|
map.computeIfAbsent(configParams, p -> internalLoad(p)
|
||||||
.replacePropertyPlaceholders()
|
.replacePropertyPlaceholders()
|
||||||
|
@ -185,13 +182,9 @@ public class ConfigLoader {
|
||||||
int pos = settingsFileName.lastIndexOf('.');
|
int pos = settingsFileName.lastIndexOf('.');
|
||||||
String suffix = (pos > 0 ? settingsFileName.substring(pos + 1) : "").toLowerCase(Locale.ROOT);
|
String suffix = (pos > 0 ? settingsFileName.substring(pos + 1) : "").toLowerCase(Locale.ROOT);
|
||||||
Path path = Paths.get(settingsFileName);
|
Path path = Paths.get(settingsFileName);
|
||||||
if (logger != null) {
|
logger.log(Level.INFO, "trying " + path);
|
||||||
logger.info("trying " + path);
|
|
||||||
}
|
|
||||||
if (Files.exists(path)) {
|
if (Files.exists(path)) {
|
||||||
if (logger != null) {
|
logger.log(Level.INFO, "found path: " + path);
|
||||||
logger.info("found path: " + path);
|
|
||||||
}
|
|
||||||
System.setProperty("config.path", path.getParent().toString());
|
System.setProperty("config.path", path.getParent().toString());
|
||||||
try {
|
try {
|
||||||
InputStream inputStream = Files.newInputStream(path);
|
InputStream inputStream = Files.newInputStream(path);
|
||||||
|
@ -216,9 +209,7 @@ public class ConfigLoader {
|
||||||
params.directoryName + '-' + fileNameWithoutSuffix + suffix : fileNameWithoutSuffix + suffix;
|
params.directoryName + '-' + fileNameWithoutSuffix + suffix : fileNameWithoutSuffix + suffix;
|
||||||
InputStream inputStream = classLoader.getResourceAsStream(path);
|
InputStream inputStream = classLoader.getResourceAsStream(path);
|
||||||
if (inputStream != null) {
|
if (inputStream != null) {
|
||||||
if (logger != null) {
|
logger.log(Level.INFO, "found resource: " + path);
|
||||||
logger.info("found resource: " + path);
|
|
||||||
}
|
|
||||||
SettingsBuilder streamSettings = createSettingsFromStream(inputStream, suffix);
|
SettingsBuilder streamSettings = createSettingsFromStream(inputStream, suffix);
|
||||||
if (streamSettings != null) {
|
if (streamSettings != null) {
|
||||||
settings.put(streamSettings.build());
|
settings.put(streamSettings.build());
|
||||||
|
@ -231,9 +222,7 @@ public class ConfigLoader {
|
||||||
private SettingsBuilder createSettingsFromStream(InputStream inputStream,
|
private SettingsBuilder createSettingsFromStream(InputStream inputStream,
|
||||||
String suffix) throws ConfigException {
|
String suffix) throws ConfigException {
|
||||||
if (inputStream == null) {
|
if (inputStream == null) {
|
||||||
if (logger != null) {
|
logger.log(Level.WARNING, "unable to open input stream");
|
||||||
logger.error("unable to open input stream");
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return createSettingsFromReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8), suffix);
|
return createSettingsFromReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8), suffix);
|
||||||
|
@ -242,9 +231,7 @@ public class ConfigLoader {
|
||||||
private SettingsBuilder createSettingsFromReader(Reader reader,
|
private SettingsBuilder createSettingsFromReader(Reader reader,
|
||||||
String suffix) throws ConfigException {
|
String suffix) throws ConfigException {
|
||||||
if (reader == null) {
|
if (reader == null) {
|
||||||
if (logger != null) {
|
logger.log(Level.WARNING, "unable to open reader");
|
||||||
logger.error("unable to open reader");
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
SettingsLoader settingsLoader = SettingsLoaderService.getInstance().loaderFromResource(suffix);
|
SettingsLoader settingsLoader = SettingsLoaderService.getInstance().loaderFromResource(suffix);
|
||||||
|
@ -258,9 +245,7 @@ public class ConfigLoader {
|
||||||
}
|
}
|
||||||
return settings;
|
return settings;
|
||||||
} else {
|
} else {
|
||||||
if (logger != null) {
|
logger.log(Level.WARNING, "suffix is invalid: " + suffix);
|
||||||
logger.error("suffix is invalid: " + suffix);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
package org.xbib.config;
|
|
||||||
|
|
||||||
public interface ConfigLogger {
|
|
||||||
|
|
||||||
void info(String string);
|
|
||||||
|
|
||||||
void warn(String string);
|
|
||||||
|
|
||||||
void error(String message);
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
package org.xbib.config;
|
|
||||||
|
|
||||||
public class NullConfigLogger implements ConfigLogger {
|
|
||||||
|
|
||||||
public NullConfigLogger() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void info(String string) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void warn(String message) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void error(String message) {
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
package org.xbib.config;
|
|
||||||
|
|
||||||
public class SystemConfigLogger implements ConfigLogger {
|
|
||||||
|
|
||||||
public SystemConfigLogger() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void info(String string) {
|
|
||||||
System.err.println("info: " + string);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void warn(String message) {
|
|
||||||
System.err.println("warning: " + message);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void error(String message) {
|
|
||||||
System.err.println("error: " + message);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +0,0 @@
|
||||||
/**
|
|
||||||
* Classes for configuration setup.
|
|
||||||
*/
|
|
||||||
package org.xbib.config;
|
|
|
@ -1,4 +0,0 @@
|
||||||
/**
|
|
||||||
* Test classes for config.
|
|
||||||
*/
|
|
||||||
package org.xbib.config.test;
|
|
|
@ -1,2 +0,0 @@
|
||||||
org.xbib.config.NullConfigLogger
|
|
||||||
org.xbib.config.SystemConfigLogger
|
|
|
@ -2,3 +2,9 @@ dependencies {
|
||||||
testImplementation testLibs.assertj
|
testImplementation testLibs.assertj
|
||||||
testImplementation testLibs.compile.testing
|
testImplementation testLibs.compile.testing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test {
|
||||||
|
jvmArgs '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED',
|
||||||
|
'--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED',
|
||||||
|
'--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED'
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.xbib.datastructures.xslx;
|
package org.xbib.datastructures.xslx;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
@ -9,9 +10,10 @@ import java.nio.file.Paths;
|
||||||
|
|
||||||
public class SimpleWriterTest {
|
public class SimpleWriterTest {
|
||||||
|
|
||||||
|
@Disabled("we need an existing test.xslx file")
|
||||||
@Test
|
@Test
|
||||||
public void testXLSXWrite() throws Exception {
|
public void testXLSXWrite() throws Exception {
|
||||||
Path path = Paths.get("build/test.xlsx");
|
Path path = Paths.get("test.xlsx");
|
||||||
SimpleXLSXWorkbook workbook = new SimpleXLSXWorkbook();
|
SimpleXLSXWorkbook workbook = new SimpleXLSXWorkbook();
|
||||||
Sheet sheet = workbook.getSheet(0);
|
Sheet sheet = workbook.getSheet(0);
|
||||||
int columnCount = 5;
|
int columnCount = 5;
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
group = org.xbib
|
group = org.xbib
|
||||||
name = datastructures
|
name = datastructures
|
||||||
version = 5.1.1
|
version = 5.2.0
|
||||||
|
|
|
@ -12,8 +12,8 @@ test {
|
||||||
failFast = false
|
failFast = false
|
||||||
testLogging {
|
testLogging {
|
||||||
events 'STARTED', 'PASSED', 'FAILED', 'SKIPPED'
|
events 'STARTED', 'PASSED', 'FAILED', 'SKIPPED'
|
||||||
|
showStandardStreams = true
|
||||||
}
|
}
|
||||||
systemProperty 'java.util.logging.config.file', 'src/test/resources/logging.properties'
|
|
||||||
afterSuite { desc, result ->
|
afterSuite { desc, result ->
|
||||||
if (!desc.parent) {
|
if (!desc.parent) {
|
||||||
println "\nTest result: ${result.resultType}"
|
println "\nTest result: ${result.resultType}"
|
||||||
|
|
|
@ -36,7 +36,7 @@ dependencyResolutionManagement {
|
||||||
library('google-truth', 'com.google.truth', 'truth').version('0.32')
|
library('google-truth', 'com.google.truth', 'truth').version('0.32')
|
||||||
library('okio', 'com.squareup.okio', 'okio').version('1.13.0')
|
library('okio', 'com.squareup.okio', 'okio').version('1.13.0')
|
||||||
library('assertj', 'org.assertj', 'assertj-core').version('3.22.0')
|
library('assertj', 'org.assertj', 'assertj-core').version('3.22.0')
|
||||||
library('compile-testing', 'com.google.testing.compile', 'compile-testing').version('0.19')
|
library('compile-testing', 'com.google.testing.compile', 'compile-testing').version('0.21.0')
|
||||||
library('jackson', 'com.fasterxml.jackson.core', 'jackson-databind').versionRef('jackson')
|
library('jackson', 'com.fasterxml.jackson.core', 'jackson-databind').versionRef('jackson')
|
||||||
library('jackson-annotations', 'com.fasterxml.jackson.core', 'jackson-annotations').versionRef('jackson')
|
library('jackson-annotations', 'com.fasterxml.jackson.core', 'jackson-annotations').versionRef('jackson')
|
||||||
library('jackson-databind', 'com.fasterxml.jackson.core', 'jackson-databind').versionRef('jackson')
|
library('jackson-databind', 'com.fasterxml.jackson.core', 'jackson-databind').versionRef('jackson')
|
||||||
|
|
Loading…
Reference in a new issue