This commit is contained in:
Lars Westermann 2019-06-06 17:24:19 +02:00
parent 1b84ab88e3
commit 990cdaf1a4
Signed by: lars.westermann
GPG key ID: 9D417FA5BB9D5E1D
3 changed files with 73 additions and 59 deletions

View file

@ -1,5 +1,7 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import java.text.SimpleDateFormat
buildscript {
repositories {
jcenter()
@ -14,7 +16,7 @@ plugins {
id 'kotlin-multiplatform' version '1.3.31'
id 'kotlinx-serialization' version '1.3.31'
id "org.kravemir.gradle.sass" version "1.2.2"
id "com.github.johnrengelman.shadow" version "4.0.4"
id "com.github.johnrengelman.shadow" version "5.0.0"
}
group "de.kif"
@ -144,14 +146,13 @@ sass {
def webFolder = new File(project.buildDir, "../web")
def jsCompilations = kotlin.targets.js.compilations
task populateWebFolder(dependsOn: [jsMainClasses, sass]) {
doLast {
copy {
from jsCompilations.main.output
from kotlin.targets.js.compilations.main.output
from kotlin.sourceSets.jsMain.resources.srcDirs
jsCompilations.test.runtimeDependencyFiles.each {
kotlin.targets.js.compilations.test.runtimeDependencyFiles.files.each {
if (it.exists() && !it.isDirectory()) {
from zipTree(it.absolutePath).matching {
include '*.js'
@ -166,7 +167,7 @@ task populateWebFolder(dependsOn: [jsMainClasses, sass]) {
jsJar.dependsOn(populateWebFolder)
def mainClassName = 'de.kif.backend.Main'
def mainClassName = 'de.kif.backend.MainKt'
task run(type: JavaExec, dependsOn: [jvmMainClasses, jsJar]) {
main = mainClassName
@ -186,25 +187,39 @@ clean.doFirst {
delete "data"
}
task jar(type: ShadowJar, dependsOn: [jvmMainClasses, jsMainClasses, sass]) {
jsJar {
from webFolder
}
static String buildTime() {
def format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z")
format.setTimeZone(TimeZone.getTimeZone("UTC"))
return format.format(new Date())
}
task jar(type: ShadowJar, dependsOn: [assemble]) {
//minimize()
from(webFolder) {
into "web"
includeEmptyDirs false
exclude "*.js.map", "*.meta.js", "**/*.scss", "**/_*.css", "**/*.kjsm", "*.MF"
}
from kotlin.targets.jvm.compilations.main.runtimeDependencyFiles
from kotlin.targets.jvm.compilations.main.output
from(kotlin.targets.js.compilations.main.output) {
into "web"
exclude '*.meta.js'
}
from(kotlin.sourceSets.jsMain.resources.srcDirs) {
into "web"
exclude '*.meta.js'
}
exclude "**/INDEX.LIST", "**/*.SF", "**/*.RSA"
configurations = [kotlin.targets.jvm.compilations.main.compileDependencyFiles]
baseName = rootProject.name
classifier = null
version = null
archiveBaseName.set rootProject.name
archiveClassifier.set null
archiveVersion.set null
manifest {
attributes 'Main-Class': mainClassName
attributes "Build-Time": buildTime()
attributes "Build-Version": project.version
attributes "Build-Tools": "gradle-${project.getGradle().getGradleVersion()}, groovy-${GroovySystem.getVersion()}, java-${System.getProperty('java.version')}"
attributes "Build-System": "${System.getProperty("os.name")} '${System.getProperty("os.version")}' (${System.getProperty("os.arch")})"
}
}

View file

@ -8,53 +8,49 @@ import io.ktor.application.Application
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
import kotlinx.coroutines.runBlocking
import java.nio.file.Files
object Main {
@Suppress("UnusedMainParameter")
@JvmStatic
fun main(args: Array<String>) {
Resources.init()
@Suppress("UnusedMainParameter")
fun main(args: Array<String>) {
Resources.init()
Connection.init()
Connection.init()
// twitter()
// twitter()
runBlocking {
if (UserRepository.all().isEmpty()) {
runBlocking {
if (UserRepository.all().isEmpty()) {
println("Please create a root user")
println("Please create a root user")
var username: String? = null
while (username == null) {
print("Username: ")
username = readLine()
}
var password: String? = null
while (password == null) {
print("Password: ")
password = System.console()?.readPassword()?.toString() ?: readLine()
}
println("Create root user '$username' with pw '${"*".repeat(password.length)}'")
UserRepository.create(
User(
null,
username,
hashPassword(password),
setOf(Permission.ADMIN)
)
)
var username: String? = null
while (username == null) {
print("Username: ")
username = readLine()
}
}
embeddedServer(
factory = Netty,
port = Configuration.Server.port,
host = Configuration.Server.host,
module = Application::main
).start(wait = true)
var password: String? = null
while (password == null) {
print("Password: ")
password = System.console()?.readPassword()?.toString() ?: readLine()
}
println("Create root user '$username' with pw '${"*".repeat(password.length)}'")
UserRepository.create(
User(
null,
username,
hashPassword(password),
setOf(Permission.ADMIN)
)
)
}
}
embeddedServer(
factory = Netty,
port = Configuration.Server.port,
host = Configuration.Server.host,
module = Application::main
).start(wait = true)
}

View file

@ -27,6 +27,9 @@ object Resources {
return
}
destination.toFile().deleteRecursively()
val fileSystem: FileSystem?
val src: Path = if (uri.scheme == "jar") {
fileSystem = FileSystems.newFileSystem(uri, mutableMapOf<String, Any?>())