1
0

Initial commit

This commit is contained in:
Hubert Van De Walle 2020-09-10 13:20:55 +02:00
commit 00fec096cb
19 changed files with 463 additions and 0 deletions

29
.gitignore vendored Normal file
View File

@ -0,0 +1,29 @@
# Java
.mtj.tmp/
*.class
*.jar
*.war
*.ear
*.nar
hs_err_pid*
# Maven
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
pom.xml.bak
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
# IntelliJ
out/
.idea/
.idea_modules/
*.iml
*.ipr
*.iws

52
config.toml Normal file
View File

@ -0,0 +1,52 @@
[dependencies]
[dependencies.http4k]
groupId = "org.http4k"
artifactId = "http4k-core"
version = "3.260.0"
[dependencies.javalin]
groupId = "io.javalin"
artifactId = "javalin"
version = "3.10.1"
[dependencies.pebble]
groupId = "io.pebbletemplates"
artifactId = "pebble"
version = "3.1.4"
[dependencies.logback]
groupId = "ch.qos.logback"
artifactId = "logback-classic"
version = "1.2.3"
default = true
[dependencies.mariadb]
groupId = "org.mariadb.jdbc"
artifactId = "mariadb-java-client"
version = "2.6.2"
[dependencies.h2]
groupId = "com.h2database"
artifactId = "h2"
version = "1.4.200"
[dependencies.flyway]
groupId = "org.flywaydb"
artifactId = "flyway-core"
version = "6.5.4"
[dependencies.HikariCP]
groupId = "com.zaxxer"
artifactId = "HikariCP"
version = "3.4.5"
[dependencies.Ktorm]
groupId = "me.liuwj.ktorm"
artifactId = "ktorm-core"
version = "3.0.0"
[dependencies.Ktorm-Mysql]
groupId = "me.liuwj.ktorm"
artifactId = "ktorm-support-mysql"
version = "3.0.0"

107
pom.xml Normal file
View File

@ -0,0 +1,107 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>starter</groupId>
<artifactId>kotlin-starter</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.version>1.4.10</kotlin.version>
</properties>
<repositories>
<repository>
<id>jcenter</id>
<name>jcenter</name>
<url>https://jcenter.bintray.com</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.pebbletemplates</groupId>
<artifactId>pebble</artifactId>
<version>3.1.4</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>com.electronwill.night-config</groupId>
<artifactId>toml</artifactId>
<version>3.6.3</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>io.javalin</groupId>
<artifactId>javalin</artifactId>
<version>3.10.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>false</minimizeJar>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>starter.KotlinStarterKt</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmTarget>11</jvmTarget>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,20 @@
package starter
import com.electronwill.nightconfig.core.Config as NightConfig
import com.electronwill.nightconfig.core.file.FileConfig
data class StarterConfig(val dependencies: List<Dependency>)
class Config {
fun load(): StarterConfig {
val cfg = FileConfig.of("config.toml")
cfg.load()
val dependenciesNode: NightConfig = cfg["dependencies"]
@Suppress("UNCHECKED_CAST") val valueMap = dependenciesNode.valueMap() as Map<String, NightConfig>
val dependencies = valueMap.map { (name, values) ->
Dependency(name, values.get("groupId"), values.get("artifactId"), values.get("version"), values.getOrElse("default", false))
}
return StarterConfig(dependencies)
}
}

View File

@ -0,0 +1,8 @@
package starter
fun main() {
val config = Config()
val loaded = config.load()
val server = Server(Views(PebbleModule().engine()),loaded)
server.run()
}

View File

@ -0,0 +1,4 @@
package starter
data class Dependency(val name: String, val groupId: String, val artifactId: String, val version: String, val default: Boolean)
data class Input(val name: String, val value: String? = null)

View File

@ -0,0 +1,15 @@
package starter
import com.mitchellbosecke.pebble.PebbleEngine
import com.mitchellbosecke.pebble.loader.ClasspathLoader
class PebbleModule {
fun engine(): PebbleEngine {
val loader = ClasspathLoader()
loader.suffix = ".twig"
return PebbleEngine.Builder()
.loader(loader)
.cacheActive(false)
.build()
}
}

View File

@ -0,0 +1,30 @@
package starter
import io.javalin.Javalin
class Server(private val views: Views, private val conf: StarterConfig) {
fun run() {
val app = Javalin.create().start(7000)
app.get("/") { ctx ->
val inputs = listOf(
Input("name", "example"),
Input("basePackage", "org.example")
)
ctx.result(views.index(conf.dependencies, inputs))
ctx.contentType("text/html")
}
app.post("/") { ctx ->
val name = ctx.formParam("name")!!
val basePackage = ctx.formParam("basePackage")!!
val deps = conf.dependencies.filter {
ctx.formParam(it.name) != null
}
ctx.result(views.pom(deps, name, basePackage))
ctx.contentType("text/xml")
}
}
}

View File

@ -0,0 +1,25 @@
package starter
import com.mitchellbosecke.pebble.PebbleEngine
import java.io.StringWriter
private fun PebbleEngine.render(name: String, args: Map<String, Any?> = mapOf()): String {
val template = getTemplate(name)
val writer = StringWriter()
template.evaluate(writer, args)
return writer.toString()
}
class Views(private val engine: PebbleEngine) {
fun index(dependencies: List<Dependency>, inputs: List<Input>) = engine.render("views/index",
mapOf("dependencies" to dependencies, "inputs" to inputs)
)
fun pom(dependencies: List<Dependency>, name: String, basePackage: String) = engine.render("starter/pom",
mapOf(
"dependencies" to dependencies,
"name" to name,
"basePackage" to basePackage
)
)
}

View File

@ -0,0 +1,14 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<withJansi>true</withJansi>
<encoder>
<pattern>%cyan(%d{YYYY-MM-dd HH:mm:ss.SSS}) [%thread] %highlight(%-5level) %green(%logger{36}) - %msg%n
</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="STDOUT"/>
</root>
<logger name="com.mitchellbosecke.pebble" level="INFO"/>
<logger name="org.eclipse.jetty" level="INFO"/>
</configuration>

View File

@ -0,0 +1,9 @@
<dependencies>
{% for dep in dependencies %}
<dependency>
<groupId>{{ dep.groupId }}</groupId>
<artifactId>{{ dep.artifactId }}</artifactId>
<version>{{ dep.version }}</version>
</dependency>
{% endfor %}
</dependencies>

View File

@ -0,0 +1,11 @@
<build>
<plugins>
{% include "starter/plugins/@default" %}
{% include "starter/plugins/@kotlin" %}
{% include "starter/plugins/@shade" %}
</plugins>
</build>

View File

@ -0,0 +1,7 @@
<repositories>
<repository>
<id>jcenter</id>
<name>jcenter</name>
<url>https://jcenter.bintray.com</url>
</repository>
</repositories>

View File

@ -0,0 +1,24 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit-platform</artifactId>
<version>3.0.0-M4</version>
</dependency>
</dependencies>
</plugin>

View File

@ -0,0 +1,24 @@
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmTarget>14</jvmTarget>
</configuration>
</plugin>

View File

@ -0,0 +1,22 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${main.class}</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>

View File

@ -0,0 +1,21 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>{{ basePackage }}</groupId>
<artifactId>{{ name | lower }}</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.target>14</maven.compiler.target>
<maven.compiler.source>14</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<main.class>{{ basePackage }}/{{ name | lower | capitalize }}Kt</main.class>
</properties>
{% include "starter/@dependencies" %}
{% include "starter/@repositories" %}
{% include "starter/@plugins" %}
</project>

View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Kotlin Starter</title>
</head>
<body>
{% block content %}
{% endblock %}
</body>
</html>

View File

@ -0,0 +1,30 @@
{% extends "views/@base" %}
{% macro dependency(dependency) %}
<label>
<input name="{{ dependency.name }}" type="checkbox"{% if dependency.default %} checked{% endif %}>
<span>{{ dependency.name }}</span>
</label>
{% endmacro %}
{% macro input(input) %}
<label>
<span>{{ input.name }}</span>
<input name="{{ input.name }}" type="text"{% if input.value %} value="{{ input.value }}"{% endif %}>
</label>
{% endmacro %}
{% block content %}
<h1>Kotlin Starter</h1>
<form method="post">
{% for input in inputs %}
{{ input(input) }}
{% endfor %}
<br>
{% for dependency in dependencies %}
{{ dependency(dependency) }}
{% endfor %}
<br>
<button type="submit">Submit</button>
</form>
{% endblock %}