From 990cdaf1a4f811ff729cd8f48b443f59a11c514c Mon Sep 17 00:00:00 2001 From: Lars Westermann Date: Thu, 6 Jun 2019 17:24:19 +0200 Subject: [PATCH] Fix jar --- build.gradle | 53 ++++++++----- src/jvmMain/kotlin/de/kif/backend/Main.kt | 76 +++++++++---------- .../kotlin/de/kif/backend/Resources.kt | 3 + 3 files changed, 73 insertions(+), 59 deletions(-) diff --git a/build.gradle b/build.gradle index fb47a9d..97fff2d 100644 --- a/build.gradle +++ b/build.gradle @@ -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")})" } } diff --git a/src/jvmMain/kotlin/de/kif/backend/Main.kt b/src/jvmMain/kotlin/de/kif/backend/Main.kt index 2df11b7..3c926c3 100644 --- a/src/jvmMain/kotlin/de/kif/backend/Main.kt +++ b/src/jvmMain/kotlin/de/kif/backend/Main.kt @@ -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) { - Resources.init() +@Suppress("UnusedMainParameter") +fun main(args: Array) { + 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) } diff --git a/src/jvmMain/kotlin/de/kif/backend/Resources.kt b/src/jvmMain/kotlin/de/kif/backend/Resources.kt index c799e84..0e4dc63 100644 --- a/src/jvmMain/kotlin/de/kif/backend/Resources.kt +++ b/src/jvmMain/kotlin/de/kif/backend/Resources.kt @@ -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())