From d294fe6c09872b8fc2282518f4b455f6f4a65c50 Mon Sep 17 00:00:00 2001 From: Jonas Tobias Hopusch Date: Sun, 19 Sep 2021 21:17:23 +0200 Subject: [PATCH 1/4] Ignore .zst archives --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7848be7..a1f8656 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,4 @@ build /de/jotoho/ /META-INF /.idea +*.zst From 09cf7a916817fd23ccf028b8855af7eab0965939 Mon Sep 17 00:00:00 2001 From: Jonas Tobias Hopusch Date: Sun, 19 Sep 2021 22:12:03 +0200 Subject: [PATCH 2/4] Go back to unclassed functions and use DummyClass instead --- .../jotoho/waituntil/{start.kt => Start.kt} | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) rename src/main/kotlin/de/jotoho/waituntil/{start.kt => Start.kt} (67%) diff --git a/src/main/kotlin/de/jotoho/waituntil/start.kt b/src/main/kotlin/de/jotoho/waituntil/Start.kt similarity index 67% rename from src/main/kotlin/de/jotoho/waituntil/start.kt rename to src/main/kotlin/de/jotoho/waituntil/Start.kt index 7a4275c..b87355b 100644 --- a/src/main/kotlin/de/jotoho/waituntil/start.kt +++ b/src/main/kotlin/de/jotoho/waituntil/Start.kt @@ -7,28 +7,30 @@ import kotlin.system.exitProcess // See README.md and LICENSE.md for license information // Author: Jonas Tobias Hopusch (@jotoho) + val langGerman: String = Locale.GERMAN.language val applicationOutputLanguage: String = if (Locale.getDefault().language.equals(Locale.GERMAN.language)) - Locale.GERMAN.language - else Locale.ENGLISH.language + Locale.GERMAN.language + else Locale.ENGLISH.language + +// For accessing package information +object DummyClass fun main(args: Array) { - val optionDictionary = mapOf(Pair("-h", "--help")) + val optionDictionary = mapOf(Pair("-h", "--help"), Pair("-v", "--version")) val options = HashSet() val words = HashSet() for (arg in args) { if (arg.startsWith("--")) { - options.add(arg.substring(startIndex=2)) - } - else if (arg.startsWith('-')) { + options.add(arg.substring(startIndex = 2)) + } else if (arg.startsWith('-')) { if (optionDictionary.containsKey(arg)) - options.add(optionDictionary[arg]!!.substring(startIndex=2)) + options.add(optionDictionary[arg]!!.substring(startIndex = 2)) else System.err.println("Short-hand '$arg' does not exist. Ignoring!") - } - else + } else words.add(arg) } @@ -39,12 +41,18 @@ fun main(args: Array) { println("Help is yet to come. (Not implemented)") } } - } - else if (words.size == 1) { + } else if (options.contains("version")) { + when (applicationOutputLanguage) { + langGerman -> { + val thisPackage = DummyClass.javaClass.`package` + val appVersion = thisPackage.implementationVersion ?: "UNKNOWN" + println("waituntil version $appVersion") + } + } + } else if (words.size == 1) { val target = calculateAndAnnounceTargetTime(words.iterator().next()) waitUntilTimeStamp(target) - } - else { + } else { when (applicationOutputLanguage) { langGerman -> System.err.println("FATAL: Es wurde exact ein nicht-flag Argument erwartet. (${words.size} erhalten)") else -> { From d62bbc5f909ddd350f6983d7ce84315a7b77705e Mon Sep 17 00:00:00 2001 From: Jonas Tobias Hopusch Date: Sun, 19 Sep 2021 22:12:31 +0200 Subject: [PATCH 3/4] Imports optimization --- src/main/kotlin/de/jotoho/waituntil/timecalc.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/de/jotoho/waituntil/timecalc.kt b/src/main/kotlin/de/jotoho/waituntil/timecalc.kt index 4a52357..f1b9036 100644 --- a/src/main/kotlin/de/jotoho/waituntil/timecalc.kt +++ b/src/main/kotlin/de/jotoho/waituntil/timecalc.kt @@ -6,7 +6,7 @@ import java.time.LocalTime import java.time.ZonedDateTime import java.time.format.DateTimeFormatter import java.time.format.FormatStyle -import java.util.TimeZone +import java.util.* fun calculateAndAnnounceTargetTime(userTimeInputRaw: String): ZonedDateTime { val userTimeInputRelative = LocalTime.parse(userTimeInputRaw) From ae13ce049f0861644f3ab516be454fd43f0856e6 Mon Sep 17 00:00:00 2001 From: Jonas Tobias Hopusch Date: Sun, 19 Sep 2021 22:13:22 +0200 Subject: [PATCH 4/4] Add jar metadata and support generating fat jars --- build.gradle.kts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index fbc3432..fbdefcc 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,6 +6,9 @@ plugins { // Apply the application plugin to add support for building a CLI application in Java. application + + // For generating fat jars + id("com.github.johnrengelman.shadow") version "latest.release" } group = "de.jotoho" @@ -39,6 +42,16 @@ tasks.test { useJUnitPlatform() } +tasks.jar { + manifest { + attributes( + "Implementation-Title" to "waituntil", + "Implementation-Version" to "${project.version}", + "Main-Class" to "de.jotoho.waituntil.StartKt" + ) + } +} + tasks.withType { kotlinOptions.jvmTarget = "16" }