Initial Maven project structure
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
2022-05-03 13:59:03 -04:00
parent 3cea90739b
commit 178a902cf3
9 changed files with 278 additions and 1 deletions

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

View 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()));
}
}

View 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;
}
}

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

View 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();
}
}