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

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

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.classpath
.project
.settings/
target/
.idea/

17
.woodpecker.yml Normal file
View File

@ -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

View File

@ -1,4 +1,4 @@
Copyright (c) <year> <owner> 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: Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

112
pom.xml Normal file
View File

@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>tech.bitgoblin</groupId>
<artifactId>Pigeon</artifactId>
<version>0.1.0</version>
<name>Pigeon</name>
<url>https://www.bitgoblin.tech</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.tomlj</groupId>
<artifactId>tomlj</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<!-- DO NOT include log4j.properties file in your Jar -->
<excludes>
<exclude>**/log4j.properties</exclude>
</excludes>
<archive>
<manifest>
<!-- Jar file entry point -->
<mainClass>tech.bitgoblin.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<mainClass>tech.bitgoblin.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

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