diff --git a/gradle.properties b/gradle.properties index c774e22..0974f2a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ id = hmci group = biz.nellemann.hmci -version = 1.1.5 +version = 1.1.6 diff --git a/src/main/java/biz/nellemann/hmci/Application.java b/src/main/java/biz/nellemann/hmci/Application.java index 6953eac..bb1a26a 100644 --- a/src/main/java/biz/nellemann/hmci/Application.java +++ b/src/main/java/biz/nellemann/hmci/Application.java @@ -32,7 +32,7 @@ import java.util.concurrent.Callable; public class Application implements Callable { @Option(names = { "-c", "--conf" }, description = "Configuration file [default: '/etc/hmci.toml'].", defaultValue = "/etc/hmci.toml", paramLabel = "") - private String configurationFile; + private File configurationFile; @Option(names = { "-d", "--debug" }, description = "Enable debugging [default: 'false'].") private boolean[] enableDebug = new boolean[0]; @@ -50,9 +50,8 @@ public class Application implements Callable { InfluxClient influxClient; List threadList = new ArrayList<>(); - File file = new File(configurationFile); - if(!file.exists()) { - System.err.println("Error - No configuration file found at: " + file.toString()); + if(!configurationFile.exists()) { + System.err.println("Error - No configuration file found at: " + configurationFile.toString()); return -1; } @@ -66,7 +65,7 @@ public class Application implements Callable { } try { - configuration = new Configuration(configurationFile); + configuration = new Configuration(configurationFile.toPath()); influxClient = new InfluxClient(configuration.getInflux()); influxClient.login(); diff --git a/src/main/java/biz/nellemann/hmci/Configuration.java b/src/main/java/biz/nellemann/hmci/Configuration.java index 847b2a0..0c99c54 100644 --- a/src/main/java/biz/nellemann/hmci/Configuration.java +++ b/src/main/java/biz/nellemann/hmci/Configuration.java @@ -6,7 +6,6 @@ import org.tomlj.TomlTable; import java.io.IOException; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; @@ -20,10 +19,9 @@ public final class Configuration { final private InfluxObject influx; final private List hmcList; - Configuration(String configurationFile) throws IOException { + Configuration(Path configurationFile) throws IOException { - Path source = Paths.get(configurationFile); - TomlParseResult result = Toml.parse(source); + TomlParseResult result = Toml.parse(configurationFile); result.errors().forEach(error -> System.err.println(error.toString())); if(result.contains("hmci.update")) { diff --git a/src/test/groovy/biz/nellemann/hmci/ConfigurationTest.groovy b/src/test/groovy/biz/nellemann/hmci/ConfigurationTest.groovy index 5725185..3b82c50 100644 --- a/src/test/groovy/biz/nellemann/hmci/ConfigurationTest.groovy +++ b/src/test/groovy/biz/nellemann/hmci/ConfigurationTest.groovy @@ -2,10 +2,13 @@ package biz.nellemann.hmci import spock.lang.Specification +import java.nio.file.Path +import java.nio.file.Paths + class ConfigurationTest extends Specification { - String testConfigurationFile = new File(getClass().getResource('/hmci.toml').toURI()).absolutePath + Path testConfigurationFile = Paths.get(getClass().getResource('/hmci.toml').toURI()) void "test parsing"() {