java.lang.Object
javafx.application.Application
page.codeberg.friedolyn.Main
public class Main
extends javafx.application.Application
The main class of the application.
Usage
-
--helpor-h: Prints ahelpmessage to the console. -
--useror-u: The username to log in at the University of Jena's Friedolin system. Required if no configuration file is specified. -
--passwordor-p: The password to log in at the University of Jena's Friedolin system. Required if no configuration file is specified. -
--degreesor-d: TheConfiguration.setAcademicDegrees(Set)academic degrees} to fetch the grades for. Required if no configuration file is specified. -
--directoryor-D: Thefolderwhere the configuration file and other application data shall be stored. -
--configor-c: The path to theconfiguration file. If this is specified, no other parameters are required. In fact, all other parameters are ignored. For more information on how the configuration file must be formatted, see configuration.schema.json. -
--verbose: Overrides the debug level withINFO, but only if it was not set toDEBUG, becauseDEBUGis more verbose thanINFO. -
--debug: Overrides the debug level withDEBUG.
--config file nor the --directory is specified, then the default directory
will be attempted to be used, which is the one most recently used or, if there is none, ~/.friedolyn.
The configuration file in the default directory is expected to be named config.json,
configuration.json or friedolyn.json.
If the --config file does not specify the app directory, then the parent directory of the configuration
file will be used. If that is not possible, the default directory will be attempted to be used.
More configuration options are available when using a --config file. See
configuration.schema.json for more info.
-
Nested Class Summary
Nested classes/interfaces inherited from class javafx.application.Application
javafx.application.Application.Parameters -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static ConfigurationThe user's preferences for the behaviour of the application.private static @NonNull DebugLevelHow verbose the program should be.protected static @NonNull com.beust.jcommander.JCommanderTheJCommanderobject that parses the command-line arguments and populatesparameters.protected static @NonNull CommandLineParametersThe command-line arguments passed to the program.static ResourceBundleFields inherited from class javafx.application.Application
STYLESHEET_CASPIAN, STYLESHEET_MODENA -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static @NonNull ConfigurationgetConfigurationFromCommandLine(@NonNull String[] arguments) Parses the command-line arguments and creates aConfigurationobject from them.static @NonNull Optional<Configuration> Tries to read the configuration file saved in thefilePreferenceof theFriedolynclass or, if that fails, from thedirectoryPreference or, if that fails, from the default directory, which is~/.friedolyn.private static @NonNull ConfigurationgetConfigurationFromDirectory(@NonNull File folder) Tries to read a configuration file from the given directory.static voidhelp()Prints a help message to the console explaining how to use the program.static voidLaunches the application and receives the command-line arguments.private static voidStartsto periodically fetch the grades from the University of Jena's Friedolin system.static voidsetLoggingLevel(@NonNull DebugLevel debugLevel) Updates thelogging levelof alllog4j loggersaccording to the givendebug level, whereDEBUGcorresponds toTRACE,INFOcorresponds toINFO,WARNcorresponds toWARN, andERRORcorresponds toERROR. Configures Log4J to log to the console and to alog filein thelogs directoryrelative to thedefault root directory.static voidsetLoggingLevel(@NonNull DebugLevel debugLevel, @NonNull Path logFilePath) Updates thelogging levelof alllog4j loggersaccording to the givendebug level, whereDEBUGcorresponds toTRACE,INFOcorresponds toINFO,WARNcorresponds toWARN, andERRORcorresponds toERROR. Configures Log4J to log to the console and to the file specified bylogFilePath.voidstart(@NonNull javafx.stage.Stage stage) Starts the graphical user interface.Methods inherited from class javafx.application.Application
getHostServices, getParameters, getUserAgentStylesheet, init, launch, launch, notifyPreloader, setUserAgentStylesheet, stop
-
Field Details
-
parameters
The command-line arguments passed to the program. -
jCommander
@NonNull protected static @NonNull com.beust.jcommander.JCommander jCommanderTheJCommanderobject that parses the command-line arguments and populatesparameters. -
configuration
The user's preferences for the behaviour of the application. -
debugLevel
How verbose the program should be. -
resourceBundle
-
-
Constructor Details
-
Main
public Main()
-
-
Method Details
-
main
Launches the application and receives the command-line arguments.- Parameters:
arguments- The command-line arguments passed to the program.
-
runHeadless
private static void runHeadless()Startsto periodically fetch the grades from the University of Jena's Friedolin system. The program will sleep until the JVM is killed. If the configuration isnull, the program will print an error message and exit. In either case, no code of the caller will be executed after the method call. -
getConfigurationFromCommandLine
@NonNull private static @NonNull Configuration getConfigurationFromCommandLine(@NonNull @NonNull String[] arguments) Parses the command-line arguments and creates aConfigurationobject from them. If the command-line arguments are invalid, the program will print an error message andexit.- Parameters:
arguments- The command-line arguments passed to the program.- Returns:
- A
Configurationobject that matches the command-line arguments.
-
setLoggingLevel
public static void setLoggingLevel(@NonNull @NonNull DebugLevel debugLevel, @NonNull @NonNull Path logFilePath) Updates thelogging levelof alllog4j loggersaccording to the givendebug level, whereDEBUGcorresponds toTRACE,INFOcorresponds toINFO,WARNcorresponds toWARN, andERRORcorresponds toERROR.
logFilePath. The log file will be created if it does not exist. Any pre-existing content will not be overwritten, but appended to.- Parameters:
debugLevel- The new minimum logging level at (or above) which messages will be logged. Lower-level messages will be ignored.logFilePath- The directory and file name of the log file to append the log messages to.
-
setLoggingLevel
Updates thelogging levelof alllog4j loggersaccording to the givendebug level, whereDEBUGcorresponds toTRACE,INFOcorresponds toINFO,WARNcorresponds toWARN, andERRORcorresponds toERROR.
log filein thelogs directoryrelative to thedefault root directory. The log file will be created if it does not exist. Any pre-existing content will not be overwritten, but appended to.- Parameters:
debugLevel- The new debug level at (or above) which messages will be logged. Lower-level messages will be ignored.
-
getConfigurationFromDefaultLocation
Tries to read the configuration file saved in thefilePreferenceof theFriedolynclass or, if that fails, from thedirectoryPreference or, if that fails, from the default directory, which is~/.friedolyn. If no valid configuration file is found, the program will print an error message and exit.- Returns:
- A
Configurationobject that matches the configuration file found in the default location.
-
getConfigurationFromDirectory
@NonNull private static @NonNull Configuration getConfigurationFromDirectory(@NonNull @NonNull File folder) throws IllegalArgumentException Tries to read a configuration file from the given directory. The configuration file must be one of the allowed configuration file names, which are specified inConfiguration.ALLOWED_CONFIGURATION_FILENAMES. The possible file names will be checked in the order they are listed in the array.- Parameters:
folder- The directory to read the configuration file from.- Returns:
- A
Configurationobject that matches the first valid configuration found in the given directory. - Throws:
IllegalArgumentException- If no valid configuration file is found in the given directory.
-
start
public void start(@NonNull @NonNull javafx.stage.Stage stage) Starts the graphical user interface. Ifconfigurationisnull, thefirst-launch windowwill be shown. If there is a configuration, themain windowwill be shown. Waits for the GUI to be closed.- Specified by:
startin classjavafx.application.Application- Parameters:
stage- the primary stage for this application, onto which the application scene can be set.- API Note:
- This method is only supposed to be called by JavaFX, not manually.
-
help
public static void help()Prints a help message to the console explaining how to use the program.
-