diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5f534f1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.classpath +.project +.settings/ +target/ +.idea/ diff --git a/.woodpecker.yml b/.woodpecker.yml new file mode 100644 index 0000000..9d8fc72 --- /dev/null +++ b/.woodpecker.yml @@ -0,0 +1,17 @@ +pipeline: + build: + image: maven:3-jdk-11 + commands: + - mvn clean package + + gitea_release: + image: plugins/gitea-release + settings: + api_key: + from_secret: gitea_api_key + base_url: https://git.metaunix.net + title: "${CI_COMMIT_TAG}" + files: + - target/Pigeon-*.jar + when: + event: tag diff --git a/LICENSE b/LICENSE index 5f662b3..e998b9b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) +Copyright (c) 2022, Bit Goblin Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..622c13b --- /dev/null +++ b/pom.xml @@ -0,0 +1,112 @@ + + + + 4.0.0 + + tech.bitgoblin + Pigeon + 0.1.0 + + Pigeon + https://www.bitgoblin.tech + + + UTF-8 + 11 + 11 + + + + + org.tomlj + tomlj + 1.0.0 + + + junit + junit + 4.11 + test + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + + **/log4j.properties + + + + + tech.bitgoblin.App + + + + + + maven-assembly-plugin + + + package + + single + + + + + + + tech.bitgoblin.App + + + + jar-with-dependencies + + + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + diff --git a/src/main/java/tech/bitgoblin/App.java b/src/main/java/tech/bitgoblin/App.java new file mode 100644 index 0000000..3b535a4 --- /dev/null +++ b/src/main/java/tech/bitgoblin/App.java @@ -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); + } + +} diff --git a/src/main/java/tech/bitgoblin/config/Config.java b/src/main/java/tech/bitgoblin/config/Config.java new file mode 100644 index 0000000..03060f0 --- /dev/null +++ b/src/main/java/tech/bitgoblin/config/Config.java @@ -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())); + } + +} diff --git a/src/main/java/tech/bitgoblin/io/IOUtils.java b/src/main/java/tech/bitgoblin/io/IOUtils.java new file mode 100644 index 0000000..a5363de --- /dev/null +++ b/src/main/java/tech/bitgoblin/io/IOUtils.java @@ -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; + } + +} diff --git a/src/test/java/tech/bitgoblin/AppTest.java b/src/test/java/tech/bitgoblin/AppTest.java new file mode 100644 index 0000000..48e0d65 --- /dev/null +++ b/src/test/java/tech/bitgoblin/AppTest.java @@ -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 ); + } +} diff --git a/src/test/java/tech/bitgoblin/io/IOUtilsTest.java b/src/test/java/tech/bitgoblin/io/IOUtilsTest.java new file mode 100644 index 0000000..8bfe43d --- /dev/null +++ b/src/test/java/tech/bitgoblin/io/IOUtilsTest.java @@ -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(); + } + +}