drop config logging

This commit is contained in:
Jörg Prante 2024-07-06 22:41:27 +02:00
parent 82dd72c811
commit 9a19a2d7c9
13 changed files with 22 additions and 94 deletions

View file

@ -1,12 +1,8 @@
import org.xbib.config.ConfigLogger;
import org.xbib.config.NullConfigLogger;
import org.xbib.config.SystemConfigLogger;
import org.xbib.settings.SettingsLoader;
module org.xbib.config {
requires transitive org.xbib.settings.datastructures;
requires java.logging;
exports org.xbib.config;
uses ConfigLogger;
uses SettingsLoader;
provides ConfigLogger with NullConfigLogger, SystemConfigLogger;
}

View file

@ -16,6 +16,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.xbib.settings.Settings;
import org.xbib.settings.SettingsBuilder;
@ -29,7 +31,7 @@ public class ConfigLoader {
private static final Map<ConfigParams, Settings> map = new HashMap<>();
private ConfigLogger logger;
private static final Logger logger = Logger.getLogger(ConfigLoader.class.getName());
private ConfigLoader() {
}
@ -38,11 +40,6 @@ public class ConfigLoader {
return new ConfigLoader();
}
public ConfigLoader withLogger(ConfigLogger logger) {
this.logger = logger;
return this;
}
public synchronized Settings load(ConfigParams configParams) throws ConfigException {
map.computeIfAbsent(configParams, p -> internalLoad(p)
.replacePropertyPlaceholders()
@ -185,13 +182,9 @@ public class ConfigLoader {
int pos = settingsFileName.lastIndexOf('.');
String suffix = (pos > 0 ? settingsFileName.substring(pos + 1) : "").toLowerCase(Locale.ROOT);
Path path = Paths.get(settingsFileName);
if (logger != null) {
logger.info("trying " + path);
}
logger.log(Level.INFO, "trying " + path);
if (Files.exists(path)) {
if (logger != null) {
logger.info("found path: " + path);
}
logger.log(Level.INFO, "found path: " + path);
System.setProperty("config.path", path.getParent().toString());
try {
InputStream inputStream = Files.newInputStream(path);
@ -216,9 +209,7 @@ public class ConfigLoader {
params.directoryName + '-' + fileNameWithoutSuffix + suffix : fileNameWithoutSuffix + suffix;
InputStream inputStream = classLoader.getResourceAsStream(path);
if (inputStream != null) {
if (logger != null) {
logger.info("found resource: " + path);
}
logger.log(Level.INFO, "found resource: " + path);
SettingsBuilder streamSettings = createSettingsFromStream(inputStream, suffix);
if (streamSettings != null) {
settings.put(streamSettings.build());
@ -231,9 +222,7 @@ public class ConfigLoader {
private SettingsBuilder createSettingsFromStream(InputStream inputStream,
String suffix) throws ConfigException {
if (inputStream == null) {
if (logger != null) {
logger.error("unable to open input stream");
}
logger.log(Level.WARNING, "unable to open input stream");
return null;
}
return createSettingsFromReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8), suffix);
@ -242,9 +231,7 @@ public class ConfigLoader {
private SettingsBuilder createSettingsFromReader(Reader reader,
String suffix) throws ConfigException {
if (reader == null) {
if (logger != null) {
logger.error("unable to open reader");
}
logger.log(Level.WARNING, "unable to open reader");
return null;
}
SettingsLoader settingsLoader = SettingsLoaderService.getInstance().loaderFromResource(suffix);
@ -258,9 +245,7 @@ public class ConfigLoader {
}
return settings;
} else {
if (logger != null) {
logger.error("suffix is invalid: " + suffix);
}
logger.log(Level.WARNING, "suffix is invalid: " + suffix);
}
return null;
}

View file

@ -1,10 +0,0 @@
package org.xbib.config;
public interface ConfigLogger {
void info(String string);
void warn(String string);
void error(String message);
}

View file

@ -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) {
}
}

View file

@ -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);
}
}

View file

@ -1,4 +0,0 @@
/**
* Classes for configuration setup.
*/
package org.xbib.config;

View file

@ -1,4 +0,0 @@
/**
* Test classes for config.
*/
package org.xbib.config.test;

View file

@ -1,2 +0,0 @@
org.xbib.config.NullConfigLogger
org.xbib.config.SystemConfigLogger

View file

@ -2,3 +2,9 @@ dependencies {
testImplementation testLibs.assertj
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'
}

View file

@ -1,5 +1,6 @@
package org.xbib.datastructures.xslx;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.io.OutputStream;
@ -9,9 +10,10 @@ import java.nio.file.Paths;
public class SimpleWriterTest {
@Disabled("we need an existing test.xslx file")
@Test
public void testXLSXWrite() throws Exception {
Path path = Paths.get("build/test.xlsx");
Path path = Paths.get("test.xlsx");
SimpleXLSXWorkbook workbook = new SimpleXLSXWorkbook();
Sheet sheet = workbook.getSheet(0);
int columnCount = 5;

View file

@ -1,3 +1,3 @@
group = org.xbib
name = datastructures
version = 5.1.1
version = 5.2.0

View file

@ -12,8 +12,8 @@ test {
failFast = false
testLogging {
events 'STARTED', 'PASSED', 'FAILED', 'SKIPPED'
showStandardStreams = true
}
systemProperty 'java.util.logging.config.file', 'src/test/resources/logging.properties'
afterSuite { desc, result ->
if (!desc.parent) {
println "\nTest result: ${result.resultType}"

View file

@ -36,7 +36,7 @@ dependencyResolutionManagement {
library('google-truth', 'com.google.truth', 'truth').version('0.32')
library('okio', 'com.squareup.okio', 'okio').version('1.13.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-annotations', 'com.fasterxml.jackson.core', 'jackson-annotations').versionRef('jackson')
library('jackson-databind', 'com.fasterxml.jackson.core', 'jackson-databind').versionRef('jackson')