From 0ade9ee9bf4b5e3e9214920dace86d9b467f2ffa Mon Sep 17 00:00:00 2001 From: Jonas Tobias Hopusch Date: Sun, 19 Sep 2021 19:18:11 +0200 Subject: [PATCH 01/17] Ignore .idea folder in root dir --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 010b909..7848be7 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,4 @@ build # Ignore manual compilation results /de/jotoho/ /META-INF +/.idea From 4718ff7379bb486e2db25f584f261778774798d2 Mon Sep 17 00:00:00 2001 From: Jonas Tobias Hopusch Date: Sun, 19 Sep 2021 19:18:24 +0200 Subject: [PATCH 02/17] Follow official kotlin code style --- gradle.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/gradle.properties b/gradle.properties index 6b1823d..43d3784 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1,2 @@ org.gradle.daemon=false +kotlin.code.style=official From 6c795316d6d8dbf7ea3cc93352ebcf2ac4cfe1ab Mon Sep 17 00:00:00 2001 From: Jonas Tobias Hopusch Date: Thu, 9 Sep 2021 23:04:55 +0200 Subject: [PATCH 03/17] Switch to unversioned kotlin-stdlib and specify Java 16 for testing --- app/build.gradle.kts | 10 ++++++---- app/src/test/kotlin/waituntil/AppTest.kt | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 061be2a..36fbf08 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -24,10 +24,7 @@ dependencies { implementation(platform("org.jetbrains.kotlin:kotlin-bom")) // Use the Kotlin JDK 8 standard library. - implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") - - // This dependency is used by the application. - implementation("com.google.guava:guava:30.1.1-jre") + implementation("org.jetbrains.kotlin:kotlin-stdlib") // Use the Kotlin test library. testImplementation("org.jetbrains.kotlin:kotlin-test") @@ -47,6 +44,11 @@ tasks { jvmTarget = "16" } } + compileTestKotlin { + kotlinOptions { + jvmTarget = "16" + } + } } application { diff --git a/app/src/test/kotlin/waituntil/AppTest.kt b/app/src/test/kotlin/waituntil/AppTest.kt index 73edc1c..b39b0d4 100644 --- a/app/src/test/kotlin/waituntil/AppTest.kt +++ b/app/src/test/kotlin/waituntil/AppTest.kt @@ -7,8 +7,10 @@ import kotlin.test.Test import kotlin.test.assertNotNull class AppTest { + /* @Test fun appHasAGreeting() { val classUnderTest = App() assertNotNull(classUnderTest.greeting, "app should have a greeting") } + */ } From adc0b754054d720e655e84ebeb4825f75ff1b1f3 Mon Sep 17 00:00:00 2001 From: Jonas Tobias Hopusch Date: Thu, 9 Sep 2021 23:09:03 +0200 Subject: [PATCH 04/17] Make kotlinc use all .kt files in root package --- compile.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compile.sh b/compile.sh index 94bbae6..b7de14a 100755 --- a/compile.sh +++ b/compile.sh @@ -1,3 +1,3 @@ #!/bin/sh -kotlinc app/src/main/kotlin/de/jotoho/waituntil/start.kt -jvm-target 16 -include-runtime -d waituntil.jar +kotlinc app/src/main/kotlin/de/jotoho/waituntil/*.kt -jvm-target 16 -include-runtime -d waituntil.jar From 090616d05d81c8b52d6a1fb2eec16e3c4f9ad452 Mon Sep 17 00:00:00 2001 From: Jonas Tobias Hopusch Date: Thu, 9 Sep 2021 23:09:26 +0200 Subject: [PATCH 05/17] Move functions into separate kotlin files --- .../kotlin/de/jotoho/waituntil/sleeping.kt | 25 +++++++++++ .../main/kotlin/de/jotoho/waituntil/start.kt | 41 ++----------------- .../kotlin/de/jotoho/waituntil/timecalc.kt | 41 +++++++++++++++++++ 3 files changed, 69 insertions(+), 38 deletions(-) create mode 100644 app/src/main/kotlin/de/jotoho/waituntil/sleeping.kt create mode 100644 app/src/main/kotlin/de/jotoho/waituntil/timecalc.kt diff --git a/app/src/main/kotlin/de/jotoho/waituntil/sleeping.kt b/app/src/main/kotlin/de/jotoho/waituntil/sleeping.kt new file mode 100644 index 0000000..8feb564 --- /dev/null +++ b/app/src/main/kotlin/de/jotoho/waituntil/sleeping.kt @@ -0,0 +1,25 @@ +package de.jotoho.waituntil + +import java.lang.Math +import java.time.Instant +import java.time.ZonedDateTime +import java.time.format.DateTimeFormatter +import java.time.format.FormatStyle +import java.time.temporal.ChronoUnit +import java.util.TimeZone + +public fun waitUntilTimeStamp(timestamp: ZonedDateTime) { + Thread.sleep(Math.max(Instant.now().until(timestamp, ChronoUnit.MILLIS), 0)) + + val formattedTimeStamp: String = + DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG) + .withZone(TimeZone.getDefault().toZoneId()) + .format(Instant.now()) + + when (applicationOutputLanguage) { + langGerman -> System.err.println("Erfolgreich bis $formattedTimeStamp gewartet!") + else -> { + System.err.println("Successfully waited until $formattedTimeStamp") + } + } +} diff --git a/app/src/main/kotlin/de/jotoho/waituntil/start.kt b/app/src/main/kotlin/de/jotoho/waituntil/start.kt index 32f4911..abfdc68 100644 --- a/app/src/main/kotlin/de/jotoho/waituntil/start.kt +++ b/app/src/main/kotlin/de/jotoho/waituntil/start.kt @@ -2,7 +2,6 @@ package de.jotoho.waituntil import java.util.Locale import java.time.format.DateTimeFormatter -import java.time.format.FormatStyle import java.util.TimeZone import java.time.Instant import java.time.LocalTime @@ -10,6 +9,9 @@ import java.time.LocalDate import java.time.ZonedDateTime import java.time.temporal.ChronoUnit +import de.jotoho.waituntil.waitUntilTimeStamp +import de.jotoho.waituntil.calculateAndAnnounceTargetTime + // This file contains the main function and other utility function necessary for interpreting the terminal arguments. // See README.md and LICENSE.md for license information // Author: Jonas Tobias Hopusch (@jotoho) @@ -19,43 +21,6 @@ val applicationOutputLanguage: String = if (Locale.getDefault().getLanguage().eq Locale.GERMAN.getLanguage() else Locale.ENGLISH.getLanguage(); -fun waitUntilTimeStamp(timestamp: ZonedDateTime) { - Thread.sleep( - Math.max(Instant.now().until(timestamp, ChronoUnit.MILLIS), 0) - ); - - val formattedTimeStamp: String = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG) - .withZone(TimeZone.getDefault().toZoneId()) - .format(Instant.now()); - - when (applicationOutputLanguage) { - langGerman -> System.err.println("Erfolgreich bis $formattedTimeStamp gewartet!"); - else -> { - System.err.println("Successfully waited until $formattedTimeStamp"); - } - } -} - -fun calculateAndAnnounceTargetTime(userTimeInputRaw: String): ZonedDateTime { - val userTimeInputRelative = LocalTime.parse(userTimeInputRaw); - val userTimeInputAbsolute = ZonedDateTime.of(LocalDate.now(), userTimeInputRelative, TimeZone.getDefault().toZoneId()); - - val userTimeInputFinal = if (Instant.now().isBefore(userTimeInputAbsolute.toInstant())) userTimeInputAbsolute else userTimeInputAbsolute.plusDays(1); - - val formattedTimeStamp = userTimeInputFinal.format( - DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG) - ); - - when (applicationOutputLanguage) { - langGerman -> System.err.println("Dieses Program wird bis zum $formattedTimeStamp warten."); - else -> { - println("WaitUntil will suspend until $formattedTimeStamp"); - } - } - - return userTimeInputFinal; -} - fun main(args: Array) { val optionDictionary = mapOf(Pair("-h", "--help")); diff --git a/app/src/main/kotlin/de/jotoho/waituntil/timecalc.kt b/app/src/main/kotlin/de/jotoho/waituntil/timecalc.kt new file mode 100644 index 0000000..36c17a8 --- /dev/null +++ b/app/src/main/kotlin/de/jotoho/waituntil/timecalc.kt @@ -0,0 +1,41 @@ +package de.jotoho.waituntil + +import java.time.Instant +import java.time.LocalDate +import java.time.LocalTime +import java.time.ZonedDateTime +import java.time.format.DateTimeFormatter +import java.time.format.FormatStyle +import java.util.TimeZone + +public fun calculateAndAnnounceTargetTime(userTimeInputRaw: String): ZonedDateTime { + val userTimeInputRelative = LocalTime.parse(userTimeInputRaw) + val userTimeInputAbsolute = + ZonedDateTime.of( + LocalDate.now(), + userTimeInputRelative, + TimeZone.getDefault().toZoneId() + ) + + val userTimeInputFinal = + if (Instant.now().isBefore(userTimeInputAbsolute.toInstant())) + userTimeInputAbsolute + else userTimeInputAbsolute.plusDays(1) + + val formattedTimeStamp = + userTimeInputFinal.format( + DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG) + ) + + when (applicationOutputLanguage) { + langGerman -> + System.err.println( + "Dieses Program wird bis zum $formattedTimeStamp warten." + ) + else -> { + println("WaitUntil will suspend until $formattedTimeStamp") + } + } + + return userTimeInputFinal +} From 8059cccc50d93cd675bb86e11e0b66255ff26028 Mon Sep 17 00:00:00 2001 From: Jonas Tobias Hopusch Date: Sun, 19 Sep 2021 19:23:45 +0200 Subject: [PATCH 06/17] Specifiy group id in build gradle file instead of settings --- app/build.gradle.kts | 3 +++ settings.gradle.kts | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 36fbf08..d1d401e 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -14,6 +14,9 @@ plugins { application } +group = "de.jotoho" +version = "0.1.0" + repositories { // Use Maven Central for resolving dependencies. mavenCentral() diff --git a/settings.gradle.kts b/settings.gradle.kts index 9c984f8..d59993a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -7,5 +7,5 @@ * in the user manual at https://docs.gradle.org/7.2/userguide/multi_project_builds.html */ -rootProject.name = "de.jotoho.waituntil" +rootProject.name = "waituntil" include("app") From 3fe9ed5b9303a20d0605e445800828e0bc7f4ec0 Mon Sep 17 00:00:00 2001 From: Jonas Tobias Hopusch Date: Sun, 19 Sep 2021 19:24:20 +0200 Subject: [PATCH 07/17] Use improved syntax for setting Java Version --- app/build.gradle.kts | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index d1d401e..8302635 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -41,17 +41,8 @@ java { targetCompatibility = JavaVersion.VERSION_16 } -tasks { - compileKotlin { - kotlinOptions { - jvmTarget = "16" - } - } - compileTestKotlin { - kotlinOptions { - jvmTarget = "16" - } - } +tasks.withType() { + kotlinOptions.jvmTarget = "16" } application { From 7f725b345c591d352d131c07d0aef3e73cee0d2d Mon Sep 17 00:00:00 2001 From: Jonas Tobias Hopusch Date: Sun, 19 Sep 2021 19:25:59 +0200 Subject: [PATCH 08/17] Upgrade project to Java 17 --- app/build.gradle.kts | 6 +++--- compile.sh | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 8302635..cd8a815 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -37,12 +37,12 @@ dependencies { } java { - sourceCompatibility = JavaVersion.VERSION_16 - targetCompatibility = JavaVersion.VERSION_16 + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } tasks.withType() { - kotlinOptions.jvmTarget = "16" + kotlinOptions.jvmTarget = "17" } application { diff --git a/compile.sh b/compile.sh index b7de14a..ad9d42d 100755 --- a/compile.sh +++ b/compile.sh @@ -1,3 +1,3 @@ #!/bin/sh -kotlinc app/src/main/kotlin/de/jotoho/waituntil/*.kt -jvm-target 16 -include-runtime -d waituntil.jar +kotlinc app/src/main/kotlin/de/jotoho/waituntil/*.kt -jvm-target 17 -include-runtime -d waituntil.jar From 365a0c2a172511a0a103d153091f61ffcde6d7ae Mon Sep 17 00:00:00 2001 From: Jonas Tobias Hopusch Date: Sun, 19 Sep 2021 19:33:39 +0200 Subject: [PATCH 09/17] Restructure folders --- app/src/test/kotlin/waituntil/AppTest.kt | 16 ---------------- app/build.gradle.kts => build.gradle.kts | 10 ++++++++-- settings.gradle.kts | 1 - .../main/kotlin/de/jotoho/waituntil/sleeping.kt | 3 +-- .../main/kotlin/de/jotoho/waituntil/start.kt | 12 +----------- .../main/kotlin/de/jotoho/waituntil/timecalc.kt | 0 6 files changed, 10 insertions(+), 32 deletions(-) delete mode 100644 app/src/test/kotlin/waituntil/AppTest.kt rename app/build.gradle.kts => build.gradle.kts (89%) rename {app/src => src}/main/kotlin/de/jotoho/waituntil/sleeping.kt (94%) rename {app/src => src}/main/kotlin/de/jotoho/waituntil/start.kt (85%) rename {app/src => src}/main/kotlin/de/jotoho/waituntil/timecalc.kt (100%) diff --git a/app/src/test/kotlin/waituntil/AppTest.kt b/app/src/test/kotlin/waituntil/AppTest.kt deleted file mode 100644 index b39b0d4..0000000 --- a/app/src/test/kotlin/waituntil/AppTest.kt +++ /dev/null @@ -1,16 +0,0 @@ -/* - * This Kotlin source file was generated by the Gradle 'init' task. - */ -package de.jotoho.waituntil - -import kotlin.test.Test -import kotlin.test.assertNotNull - -class AppTest { - /* - @Test fun appHasAGreeting() { - val classUnderTest = App() - assertNotNull(classUnderTest.greeting, "app should have a greeting") - } - */ -} diff --git a/app/build.gradle.kts b/build.gradle.kts similarity index 89% rename from app/build.gradle.kts rename to build.gradle.kts index cd8a815..cf34629 100644 --- a/app/build.gradle.kts +++ b/build.gradle.kts @@ -6,6 +6,8 @@ * User Manual available at https://docs.gradle.org/7.2/userguide/building_java_projects.html */ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + plugins { // Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin. id("org.jetbrains.kotlin.jvm") version "1.+" @@ -26,7 +28,7 @@ dependencies { // Align versions of all Kotlin components implementation(platform("org.jetbrains.kotlin:kotlin-bom")) - // Use the Kotlin JDK 8 standard library. + // Use the Kotlin standard library. implementation("org.jetbrains.kotlin:kotlin-stdlib") // Use the Kotlin test library. @@ -41,7 +43,11 @@ java { targetCompatibility = JavaVersion.VERSION_17 } -tasks.withType() { +tasks.test { + useJUnitPlatform() +} + +tasks.withType() { kotlinOptions.jvmTarget = "17" } diff --git a/settings.gradle.kts b/settings.gradle.kts index d59993a..599ab7a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -8,4 +8,3 @@ */ rootProject.name = "waituntil" -include("app") diff --git a/app/src/main/kotlin/de/jotoho/waituntil/sleeping.kt b/src/main/kotlin/de/jotoho/waituntil/sleeping.kt similarity index 94% rename from app/src/main/kotlin/de/jotoho/waituntil/sleeping.kt rename to src/main/kotlin/de/jotoho/waituntil/sleeping.kt index 8feb564..b318873 100644 --- a/app/src/main/kotlin/de/jotoho/waituntil/sleeping.kt +++ b/src/main/kotlin/de/jotoho/waituntil/sleeping.kt @@ -1,12 +1,11 @@ package de.jotoho.waituntil -import java.lang.Math import java.time.Instant import java.time.ZonedDateTime import java.time.format.DateTimeFormatter import java.time.format.FormatStyle import java.time.temporal.ChronoUnit -import java.util.TimeZone +import java.util.* public fun waitUntilTimeStamp(timestamp: ZonedDateTime) { Thread.sleep(Math.max(Instant.now().until(timestamp, ChronoUnit.MILLIS), 0)) diff --git a/app/src/main/kotlin/de/jotoho/waituntil/start.kt b/src/main/kotlin/de/jotoho/waituntil/start.kt similarity index 85% rename from app/src/main/kotlin/de/jotoho/waituntil/start.kt rename to src/main/kotlin/de/jotoho/waituntil/start.kt index abfdc68..4ed1795 100644 --- a/app/src/main/kotlin/de/jotoho/waituntil/start.kt +++ b/src/main/kotlin/de/jotoho/waituntil/start.kt @@ -1,16 +1,6 @@ package de.jotoho.waituntil -import java.util.Locale -import java.time.format.DateTimeFormatter -import java.util.TimeZone -import java.time.Instant -import java.time.LocalTime -import java.time.LocalDate -import java.time.ZonedDateTime -import java.time.temporal.ChronoUnit - -import de.jotoho.waituntil.waitUntilTimeStamp -import de.jotoho.waituntil.calculateAndAnnounceTargetTime +import java.util.* // This file contains the main function and other utility function necessary for interpreting the terminal arguments. // See README.md and LICENSE.md for license information diff --git a/app/src/main/kotlin/de/jotoho/waituntil/timecalc.kt b/src/main/kotlin/de/jotoho/waituntil/timecalc.kt similarity index 100% rename from app/src/main/kotlin/de/jotoho/waituntil/timecalc.kt rename to src/main/kotlin/de/jotoho/waituntil/timecalc.kt From c8dbcc3f494990e9e85d27761eacd2ba7f262666 Mon Sep 17 00:00:00 2001 From: Jonas Tobias Hopusch Date: Sun, 19 Sep 2021 19:42:56 +0200 Subject: [PATCH 10/17] Use latest release for all dependencies --- build.gradle.kts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index cf34629..626c728 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -10,7 +10,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { // Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin. - id("org.jetbrains.kotlin.jvm") version "1.+" + id("org.jetbrains.kotlin.jvm") version "latest.release" // Apply the application plugin to add support for building a CLI application in Java. application @@ -26,16 +26,16 @@ repositories { dependencies { // Align versions of all Kotlin components - implementation(platform("org.jetbrains.kotlin:kotlin-bom")) + implementation(platform("org.jetbrains.kotlin:kotlin-bom:latest.release")) // Use the Kotlin standard library. - implementation("org.jetbrains.kotlin:kotlin-stdlib") + implementation("org.jetbrains.kotlin:kotlin-stdlib:latest.release") // Use the Kotlin test library. - testImplementation("org.jetbrains.kotlin:kotlin-test") + testImplementation("org.jetbrains.kotlin:kotlin-test:latest.release") // Use the Kotlin JUnit integration. - testImplementation("org.jetbrains.kotlin:kotlin-test-junit") + testImplementation("org.jetbrains.kotlin:kotlin-test-junit:latest.release") } java { From 92a226dd0201c8fd2238d7acd269b649aa4dcb14 Mon Sep 17 00:00:00 2001 From: Jonas Tobias Hopusch Date: Sun, 19 Sep 2021 19:52:14 +0200 Subject: [PATCH 11/17] Specify dependencies with kotlin helper function --- build.gradle.kts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 626c728..61b5f90 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -10,7 +10,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { // Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin. - id("org.jetbrains.kotlin.jvm") version "latest.release" + kotlin("jvm") version "latest.release" // Apply the application plugin to add support for building a CLI application in Java. application @@ -26,16 +26,16 @@ repositories { dependencies { // Align versions of all Kotlin components - implementation(platform("org.jetbrains.kotlin:kotlin-bom:latest.release")) + implementation(platform(kotlin("bom", "latest.release"))) // Use the Kotlin standard library. - implementation("org.jetbrains.kotlin:kotlin-stdlib:latest.release") + implementation(kotlin("stdlib", "latest.release")) // Use the Kotlin test library. - testImplementation("org.jetbrains.kotlin:kotlin-test:latest.release") + testImplementation(kotlin("test", "latest.release")) // Use the Kotlin JUnit integration. - testImplementation("org.jetbrains.kotlin:kotlin-test-junit:latest.release") + testImplementation(kotlin("test-junit", "latest.release")) } java { From ad869f734649823dc3addf7a3121c232165f4f75 Mon Sep 17 00:00:00 2001 From: Jonas Tobias Hopusch Date: Sun, 19 Sep 2021 19:58:37 +0200 Subject: [PATCH 12/17] Back to Java version 16 Gradle and Kotlin don't yet support Java 17, apparently. :( This commit reverts 7f725b345c591d352d131c07d0aef3e73cee0d2d --- build.gradle.kts | 6 +++--- compile.sh | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 61b5f90..aa6a0b2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -39,8 +39,8 @@ dependencies { } java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 + sourceCompatibility = JavaVersion.VERSION_16 + targetCompatibility = JavaVersion.VERSION_16 } tasks.test { @@ -48,7 +48,7 @@ tasks.test { } tasks.withType() { - kotlinOptions.jvmTarget = "17" + kotlinOptions.jvmTarget = "16" } application { diff --git a/compile.sh b/compile.sh index ad9d42d..b7de14a 100755 --- a/compile.sh +++ b/compile.sh @@ -1,3 +1,3 @@ #!/bin/sh -kotlinc app/src/main/kotlin/de/jotoho/waituntil/*.kt -jvm-target 17 -include-runtime -d waituntil.jar +kotlinc app/src/main/kotlin/de/jotoho/waituntil/*.kt -jvm-target 16 -include-runtime -d waituntil.jar From 9aba3f156a6e4df4e628bc99f5ee5f797d37ecef Mon Sep 17 00:00:00 2001 From: Jonas Tobias Hopusch Date: Sun, 19 Sep 2021 20:08:50 +0200 Subject: [PATCH 13/17] Apply IntelliJ code formatting and alternatives suggestions --- .../kotlin/de/jotoho/waituntil/sleeping.kt | 4 +- src/main/kotlin/de/jotoho/waituntil/start.kt | 37 ++++++++++--------- .../kotlin/de/jotoho/waituntil/timecalc.kt | 2 +- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/main/kotlin/de/jotoho/waituntil/sleeping.kt b/src/main/kotlin/de/jotoho/waituntil/sleeping.kt index b318873..ae031b7 100644 --- a/src/main/kotlin/de/jotoho/waituntil/sleeping.kt +++ b/src/main/kotlin/de/jotoho/waituntil/sleeping.kt @@ -7,8 +7,8 @@ import java.time.format.FormatStyle import java.time.temporal.ChronoUnit import java.util.* -public fun waitUntilTimeStamp(timestamp: ZonedDateTime) { - Thread.sleep(Math.max(Instant.now().until(timestamp, ChronoUnit.MILLIS), 0)) +fun waitUntilTimeStamp(timestamp: ZonedDateTime) { + Thread.sleep(Instant.now().until(timestamp, ChronoUnit.MILLIS).coerceAtLeast(0)) val formattedTimeStamp: String = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG) diff --git a/src/main/kotlin/de/jotoho/waituntil/start.kt b/src/main/kotlin/de/jotoho/waituntil/start.kt index 4ed1795..16a0ce6 100644 --- a/src/main/kotlin/de/jotoho/waituntil/start.kt +++ b/src/main/kotlin/de/jotoho/waituntil/start.kt @@ -1,56 +1,57 @@ package de.jotoho.waituntil import java.util.* +import kotlin.system.exitProcess // This file contains the main function and other utility function necessary for interpreting the terminal arguments. // See README.md and LICENSE.md for license information // Author: Jonas Tobias Hopusch (@jotoho) -val langGerman: String = Locale.GERMAN.getLanguage(); -val applicationOutputLanguage: String = if (Locale.getDefault().getLanguage().equals(Locale.GERMAN.getLanguage())) - Locale.GERMAN.getLanguage() - else Locale.ENGLISH.getLanguage(); +val langGerman: String = Locale.GERMAN.language +val applicationOutputLanguage: String = if (Locale.getDefault().language.equals(Locale.GERMAN.language)) + Locale.GERMAN.language + else Locale.ENGLISH.language fun main(args: Array) { - val optionDictionary = mapOf(Pair("-h", "--help")); + val optionDictionary = mapOf(Pair("-h", "--help")) - val options = HashSet(); - val words = HashSet(); + val options = HashSet() + val words = HashSet() for (arg in args) { if (arg.startsWith("--")) { options.add(arg.substring(startIndex=2)) } else if (arg.startsWith('-')) { - val translation = optionDictionary.get(arg); + val translation = optionDictionary[arg] if (translation != null) - options.add(translation.substring(startIndex=2)); + options.add(translation.substring(startIndex=2)) else - System.err.println("Short-hand '$arg' does not exist. Ignoring!"); + System.err.println("Short-hand '$arg' does not exist. Ignoring!") } else - words.add(arg); + words.add(arg) } if (options.contains("help")) { when (applicationOutputLanguage) { - langGerman -> println("Hilfe kommt noch. (Nicht implementiert)"); + langGerman -> println("Hilfe kommt noch. (Nicht implementiert)") else -> { - println("Help is yet to come. (Not implemented)"); + println("Help is yet to come. (Not implemented)") } } } else if (words.size == 1) { - val target = calculateAndAnnounceTargetTime(words.iterator().next()); - waitUntilTimeStamp(target); + val target = calculateAndAnnounceTargetTime(words.iterator().next()) + waitUntilTimeStamp(target) } else { when (applicationOutputLanguage) { - langGerman -> System.err.println("FATAL: Es wurde exact ein nicht-flag Argument erwartet. (${words.size} erhalten)"); + langGerman -> System.err.println("FATAL: Es wurde exact ein nicht-flag Argument erwartet. (${words.size} erhalten)") else -> { - System.err.println("FATAL: Expected one non-flag argument. (Got ${words.size})"); + System.err.println("FATAL: Expected one non-flag argument. (Got ${words.size})") } } - System.exit(1); + exitProcess(1) } } diff --git a/src/main/kotlin/de/jotoho/waituntil/timecalc.kt b/src/main/kotlin/de/jotoho/waituntil/timecalc.kt index 36c17a8..4a52357 100644 --- a/src/main/kotlin/de/jotoho/waituntil/timecalc.kt +++ b/src/main/kotlin/de/jotoho/waituntil/timecalc.kt @@ -8,7 +8,7 @@ import java.time.format.DateTimeFormatter import java.time.format.FormatStyle import java.util.TimeZone -public fun calculateAndAnnounceTargetTime(userTimeInputRaw: String): ZonedDateTime { +fun calculateAndAnnounceTargetTime(userTimeInputRaw: String): ZonedDateTime { val userTimeInputRelative = LocalTime.parse(userTimeInputRaw) val userTimeInputAbsolute = ZonedDateTime.of( From 5919c26c106f2ae79388bd7db65e32288dc50619 Mon Sep 17 00:00:00 2001 From: Jonas Tobias Hopusch Date: Sun, 19 Sep 2021 20:10:36 +0200 Subject: [PATCH 14/17] Apply formatting suggestion for build config --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index aa6a0b2..e2bcb37 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -47,7 +47,7 @@ tasks.test { useJUnitPlatform() } -tasks.withType() { +tasks.withType { kotlinOptions.jvmTarget = "16" } From a48f1222961023266799f9c8a8932f379af41399 Mon Sep 17 00:00:00 2001 From: Jonas Tobias Hopusch Date: Sun, 19 Sep 2021 20:13:14 +0200 Subject: [PATCH 15/17] Delete unneeded comment from build config --- build.gradle.kts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index e2bcb37..603c97b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,11 +1,3 @@ -/* - * This file was generated by the Gradle 'init' task. - * - * This generated file contains a sample Kotlin application project to get you started. - * For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle - * User Manual available at https://docs.gradle.org/7.2/userguide/building_java_projects.html - */ - import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { From 4ab78f4028576bfbdc67c73be140d0122a8f15b8 Mon Sep 17 00:00:00 2001 From: Jonas Tobias Hopusch Date: Sun, 19 Sep 2021 20:23:26 +0200 Subject: [PATCH 16/17] Avoid unnecessary temporary variable in short-hand translation --- src/main/kotlin/de/jotoho/waituntil/start.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/de/jotoho/waituntil/start.kt b/src/main/kotlin/de/jotoho/waituntil/start.kt index 16a0ce6..7a4275c 100644 --- a/src/main/kotlin/de/jotoho/waituntil/start.kt +++ b/src/main/kotlin/de/jotoho/waituntil/start.kt @@ -23,9 +23,8 @@ fun main(args: Array) { options.add(arg.substring(startIndex=2)) } else if (arg.startsWith('-')) { - val translation = optionDictionary[arg] - if (translation != null) - options.add(translation.substring(startIndex=2)) + if (optionDictionary.containsKey(arg)) + options.add(optionDictionary[arg]!!.substring(startIndex=2)) else System.err.println("Short-hand '$arg' does not exist. Ignoring!") } From 5a80ac71698564ed0132d65a203dae7ec9f85e26 Mon Sep 17 00:00:00 2001 From: Jonas Tobias Hopusch Date: Sun, 19 Sep 2021 20:27:26 +0200 Subject: [PATCH 17/17] Fix compile script using old source path --- compile.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compile.sh b/compile.sh index b7de14a..5c8fa93 100755 --- a/compile.sh +++ b/compile.sh @@ -1,3 +1,5 @@ #!/bin/sh -kotlinc app/src/main/kotlin/de/jotoho/waituntil/*.kt -jvm-target 16 -include-runtime -d waituntil.jar +# shellcheck disable=SC2046 +# Word splitting in find results is intentional! +kotlinc $(find src/main -type f -iname '*.kt') -jvm-target 16 -include-runtime -d waituntil.jar