diff --git a/.gitignore b/.gitignore
index 70a4e08..551e7b7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -37,5 +37,6 @@ gradlew.bat
# Ignore manual compilation results
/de/jotoho/
/META-INF
-/.idea
+/.idea/*
+!/.idea/codeStyles/
*.zst
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..05caf41
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,78 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..79ee123
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/build.gradle.kts b/build.gradle.kts
index 1b1fbfe..956e774 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -6,7 +6,7 @@ plugins {
application
java
- id ("com.github.johnrengelman.shadow") version "7.1.2"
+ id("com.github.johnrengelman.shadow") version "7.1.2"
}
repositories {
@@ -15,7 +15,9 @@ repositories {
}
dependencies {
- implementation(group="commons-cli", name="commons-cli", version="1.5.0")
+ implementation(group = "commons-cli",
+ name = "commons-cli",
+ version = "1.5.0")
}
fun versionBanner(): String {
@@ -38,10 +40,9 @@ java {
tasks.jar {
manifest {
- attributes(
- "Implementation-Title" to project.name,
- "Implementation-Version" to project.version,
- "Main-Class" to "de.jotoho.waituntil.Main"
+ attributes("Implementation-Title" to project.name,
+ "Implementation-Version" to project.version,
+ "Main-Class" to "de.jotoho.waituntil.Main"
//"Main-Module" to "de.jotoho.waituntil.main"
)
}
diff --git a/src/main/java/de/jotoho/waituntil/AppOptions.java b/src/main/java/de/jotoho/waituntil/AppOptions.java
index 0b400a1..86fce7f 100644
--- a/src/main/java/de/jotoho/waituntil/AppOptions.java
+++ b/src/main/java/de/jotoho/waituntil/AppOptions.java
@@ -22,7 +22,21 @@ import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
final class AppOptions {
- public final Option help = Option.builder().argName("h").longOpt("help").desc("Shows this help " + "message and exits").build();
- public final Option version = Option.builder().argName("v").longOpt("version").desc("Shows version information and exits").build();
- public final Options options = new Options().addOption(help).addOption(version);
+ public final Option help = Option
+ .builder()
+ .argName("h")
+ .longOpt("help")
+ .desc("Shows this help " + "message and exits")
+ .build();
+
+ public final Option version = Option
+ .builder()
+ .argName("v")
+ .longOpt("version")
+ .desc("Shows version information and exits")
+ .build();
+
+ public final Options options = new Options()
+ .addOption(help)
+ .addOption(version);
}
diff --git a/src/main/java/de/jotoho/waituntil/GlobalConf.java b/src/main/java/de/jotoho/waituntil/GlobalConf.java
index fad2f75..5d2046a 100644
--- a/src/main/java/de/jotoho/waituntil/GlobalConf.java
+++ b/src/main/java/de/jotoho/waituntil/GlobalConf.java
@@ -22,5 +22,12 @@ import java.util.Locale;
public record GlobalConf() {
public static final String langGerman = "de";
- public static final String applicationOutputLanguage = (Locale.getDefault().getLanguage().equals(Locale.GERMAN.getLanguage())) ? Locale.GERMAN.getLanguage() : Locale.ENGLISH.getLanguage();
+ public static final String applicationOutputLanguage = (Locale
+ .getDefault()
+ .getLanguage()
+ .equals(Locale.GERMAN.getLanguage()))
+ ?
+ Locale.GERMAN.getLanguage()
+ :
+ Locale.ENGLISH.getLanguage();
}
diff --git a/src/main/java/de/jotoho/waituntil/Main.java b/src/main/java/de/jotoho/waituntil/Main.java
index 1830114..857a5de 100644
--- a/src/main/java/de/jotoho/waituntil/Main.java
+++ b/src/main/java/de/jotoho/waituntil/Main.java
@@ -18,13 +18,16 @@ package de.jotoho.waituntil;
along with this program. If not, see .
*/
+import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DefaultParser;
+import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import static de.jotoho.waituntil.GlobalConf.applicationOutputLanguage;
import static java.lang.System.Logger.Level;
-// This file contains the main function and other utility function necessary for interpreting the terminal arguments.
+// 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)
@@ -33,56 +36,96 @@ public final class Main {
private static void printVersionInformation() {
final var thisPackage = Main.class.getPackage();
- final var appVersion = thisPackage.getImplementationVersion() != null ? thisPackage.getImplementationVersion() : "version unknown";
+ final var
+ appVersion =
+ thisPackage.getImplementationVersion() != null
+ ? thisPackage.getImplementationVersion()
+ : "version unknown";
+
System.out.println("waituntil " + appVersion);
System.out.println("""
- Project Repository: https://gitea.jotoho.de/jotoho/waituntil
+ Project Repository: https://gitea.jotoho.de/jotoho/waituntil
- This program is free software: you can redistribute it and/or modify it under the terms of the
- GNU General Public License as published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
+ This program is free software: you can redistribute it and/or modify it under the terms of the
+ GNU General Public License as published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the GNU General Public License for more details.""");
+ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU General Public License for more details.""");
}
private static void printHelpInformation() {
switch (applicationOutputLanguage) {
- case GlobalConf.langGerman -> logger.log(Level.ERROR, "Hilfe kommt noch. (Nicht implementiert)");
- default -> logger.log(Level.ERROR, "Help is yet to come. (Not implemented)");
+ case GlobalConf.langGerman -> logger.log(Level.ERROR,
+ "Hilfe " +
+ "kommt noch. (Nicht " +
+ "implementiert)");
+ default -> logger.log(Level.ERROR,
+ "Help is yet to come. (Not " +
+ "implemented)");
}
}
- public static void main(final String[] args) {
- final var appOptions = new AppOptions();
- try {
- final var parsedArguments = DefaultParser.builder().setStripLeadingAndTrailingQuotes(true).build().parse(appOptions.options, args);
+ private static CommandLine parseArgs(final Options options,
+ final String[] args)
+ throws ParseException {
+ return DefaultParser
+ .builder()
+ .setStripLeadingAndTrailingQuotes(true)
+ .build()
+ .parse(options, args);
+ }
+ public synchronized static void main(final String[] args) {
+ // Retrieve defined CLI options
+ final var appOptions = new AppOptions();
+
+ try {
+ // Parse CLI
+ final var parsedArguments = parseArgs(appOptions.options, args);
final var userData = parsedArguments.getArgs();
+ // Differentiate between usage scenarios
if (parsedArguments.hasOption(appOptions.help)) {
printHelpInformation();
} else if (parsedArguments.hasOption(appOptions.version)) {
printVersionInformation();
} else if (userData.length == 0) {
switch (applicationOutputLanguage) {
- case GlobalConf.langGerman -> logger.log(Level.ERROR, "Es wurde keine Uhrzeit angegeben.");
- default -> logger.log(Level.ERROR, "No target time was provided.");
+ case GlobalConf.langGerman -> logger.log(Level.ERROR,
+ "Es" +
+ " wurde keine " +
+ "Uhrzeit " +
+ "angegeben.");
+ default -> logger.log(Level.ERROR,
+ "No target time was " + "provided.");
}
System.exit(1);
} else if (userData.length > 1) {
switch (applicationOutputLanguage) {
- case GlobalConf.langGerman -> logger.log(Level.ERROR, "Zu viele Argumente wurden angegeben.");
- default -> logger.log(Level.ERROR, "Too many arguments provided.");
+ case GlobalConf.langGerman -> logger.log(Level.ERROR,
+ "Zu" + " viele " +
+ "Argumente " +
+ "wurden " +
+ "angegeben.");
+ default -> logger.log(Level.ERROR,
+ "Too many arguments " + "provided.");
}
System.exit(1);
} else {
- final var target = TimeCalculator.calculateAndAnnounceTargetTime(userData[0]);
+ final var
+ target =
+ TimeCalculator.calculateAndAnnounceTargetTime(userData[0]);
Sleep.waitUntilTimeStamp(target);
}
} catch (final ParseException e) {
- System.getLogger("main").log(Level.ERROR, "Parsing of arguments failed and the program cannot continue.", e);
+ System
+ .getLogger("main")
+ .log(Level.ERROR,
+ "Parsing of arguments " +
+ "failed and the program cannot " + "continue.",
+ e);
System.exit(1);
}
}
diff --git a/src/main/java/de/jotoho/waituntil/Sleep.java b/src/main/java/de/jotoho/waituntil/Sleep.java
index 072c69b..1e532aa 100644
--- a/src/main/java/de/jotoho/waituntil/Sleep.java
+++ b/src/main/java/de/jotoho/waituntil/Sleep.java
@@ -30,14 +30,19 @@ import static java.lang.System.Logger.Level;
public final class Sleep {
public static void waitUntilTimeStamp(ZonedDateTime timestamp) {
try {
- Thread.sleep(Math.max(0, Instant.now().until(timestamp, ChronoUnit.MILLIS)));
+ Thread.sleep(Math.max(0,
+ Instant
+ .now()
+ .until(timestamp, ChronoUnit.MILLIS)));
} catch (final InterruptedException ignored) {
}
- final String formattedTimeStamp =
- DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG)
- .withZone(TimeZone.getDefault().toZoneId())
- .format(Instant.now());
+ final String formattedTimeStamp = DateTimeFormatter
+ .ofLocalizedDateTime(FormatStyle.LONG)
+ .withZone(TimeZone
+ .getDefault()
+ .toZoneId())
+ .format(Instant.now());
final String msg = switch (GlobalConf.applicationOutputLanguage) {
case GlobalConf.langGerman -> "Erfolgreich bis %s gewartet!";
@@ -45,6 +50,8 @@ public final class Sleep {
};
final String msgWithData = msg.formatted(formattedTimeStamp);
- System.getLogger("sleep").log(Level.INFO, msgWithData);
+ System
+ .getLogger("sleep")
+ .log(Level.INFO, msgWithData);
}
}
diff --git a/src/main/java/de/jotoho/waituntil/TimeCalculator.java b/src/main/java/de/jotoho/waituntil/TimeCalculator.java
index 20b40fc..0b74e2a 100644
--- a/src/main/java/de/jotoho/waituntil/TimeCalculator.java
+++ b/src/main/java/de/jotoho/waituntil/TimeCalculator.java
@@ -32,28 +32,31 @@ public final class TimeCalculator {
public static ZonedDateTime calculateAndAnnounceTargetTime(final String userTimeInputRaw) {
final var userTimeInputRelative = LocalTime.parse(userTimeInputRaw);
- final var userTimeInputAbsolute =
- ZonedDateTime.of(
- LocalDate.now(),
- userTimeInputRelative,
- TimeZone.getDefault().toZoneId()
- );
+ final var userTimeInputAbsolute = ZonedDateTime.of(LocalDate.now(),
+ userTimeInputRelative,
+ TimeZone
+ .getDefault()
+ .toZoneId());
- final var userTimeInputFinal = (Instant.now().isBefore(userTimeInputAbsolute.toInstant()))
- ? userTimeInputAbsolute
- : userTimeInputAbsolute.plusDays(1);
+ final var userTimeInputFinal = (Instant
+ .now()
+ .isBefore(userTimeInputAbsolute.toInstant()))
+ ? userTimeInputAbsolute
+ : userTimeInputAbsolute.plusDays(1);
- final var formattedTimeStamp =
- userTimeInputFinal.format(
- DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG)
- );
+ final var formattedTimeStamp = userTimeInputFinal.format(
+ DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG));
final String msg = switch (GlobalConf.applicationOutputLanguage) {
- case GlobalConf.langGerman -> "Dieses Program wird bis zum %s warten."
- .formatted(formattedTimeStamp);
- default -> "WaitUntil will suspend until %s".formatted(formattedTimeStamp);
+ case GlobalConf.langGerman -> ("Dieses Program wird bis zum %s " +
+ "warten.").formatted(
+ formattedTimeStamp);
+ default -> "WaitUntil will suspend until %s".formatted(
+ formattedTimeStamp);
};
- System.getLogger("timecalculator").log(Level.INFO, msg);
+ System
+ .getLogger("timecalculator")
+ .log(Level.INFO, msg);
return userTimeInputFinal;
}