Initial Maven project structure
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
18
src/main/java/tech/bitgoblin/App.java
Normal file
18
src/main/java/tech/bitgoblin/App.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package tech.bitgoblin;
|
||||
|
||||
import tech.bitgoblin.config.Config;
|
||||
|
||||
/**
|
||||
* The Bit Goblin video transcoder service.
|
||||
*
|
||||
*/
|
||||
public class App {
|
||||
|
||||
private static final String configFile = "~/.config/pigeon.toml";
|
||||
|
||||
public static void main(String[] args) {
|
||||
// read our config file
|
||||
Config c = new Config(configFile);
|
||||
}
|
||||
|
||||
}
|
42
src/main/java/tech/bitgoblin/config/Config.java
Normal file
42
src/main/java/tech/bitgoblin/config/Config.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package tech.bitgoblin.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import org.tomlj.Toml;
|
||||
import org.tomlj.TomlParseResult;
|
||||
import tech.bitgoblin.io.IOUtils;
|
||||
|
||||
public class Config {
|
||||
|
||||
private final String configPath;
|
||||
private TomlParseResult result;
|
||||
|
||||
public Config(String path) {
|
||||
this.configPath = IOUtils.resolveTilda(path);
|
||||
// parse config file
|
||||
try {
|
||||
this.parseConfig();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Unable to read config file; please check that " + this.configPath + " is available.");
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public String getString(String key) {
|
||||
return this.result.getString(key);
|
||||
}
|
||||
|
||||
public boolean contains(String key) {
|
||||
return this.result.contains(key);
|
||||
}
|
||||
|
||||
private void parseConfig() throws IOException {
|
||||
// parse config file
|
||||
Path source = Paths.get(this.configPath);
|
||||
this.result = Toml.parse(source);
|
||||
this.result.errors().forEach(error -> System.err.println(error.toString()));
|
||||
}
|
||||
|
||||
}
|
27
src/main/java/tech/bitgoblin/io/IOUtils.java
Normal file
27
src/main/java/tech/bitgoblin/io/IOUtils.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package tech.bitgoblin.io;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class IOUtils {
|
||||
|
||||
public static void createDirectory(String path) {
|
||||
File f = new File(path);
|
||||
boolean res = f.mkdir();
|
||||
|
||||
if (res) {
|
||||
System.out.println(path + " was created.");
|
||||
}
|
||||
}
|
||||
|
||||
public static String resolveTilda(String path) {
|
||||
if (path.startsWith("~" + File.separator) || path.equals("~")) {
|
||||
path = System.getProperty("user.home") + path.substring(1);
|
||||
} else if ((!path.equals("~")) && path.startsWith("~")) {
|
||||
// here you can implement reading homedir of other users if you care
|
||||
throw new UnsupportedOperationException("Home dir expansion not implemented for explicit usernames");
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
20
src/test/java/tech/bitgoblin/AppTest.java
Normal file
20
src/test/java/tech/bitgoblin/AppTest.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package tech.bitgoblin;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest
|
||||
{
|
||||
/**
|
||||
* Rigorous Test :-)
|
||||
*/
|
||||
@Test
|
||||
public void shouldAnswerWithTrue()
|
||||
{
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
36
src/test/java/tech/bitgoblin/io/IOUtilsTest.java
Normal file
36
src/test/java/tech/bitgoblin/io/IOUtilsTest.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package tech.bitgoblin.io;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class IOUtilsTest {
|
||||
|
||||
private static String testDir = "test-temp";
|
||||
|
||||
@Test
|
||||
public void shouldCreateDirectory() {
|
||||
IOUtils.createDirectory(testDir);
|
||||
assertTrue(new File(testDir).exists());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldExpandTilda() {
|
||||
String homeExpanded = IOUtils.resolveTilda("~");
|
||||
assertTrue(!homeExpanded.equals("~"));
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void shouldFailExpandExplicitTilda() {
|
||||
IOUtils.resolveTilda("~test");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanup() {
|
||||
new File(testDir).delete();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user