java.lang.Object
javafx.application.Application
page.codeberg.friedolyn.Main
public class Main
extends javafx.application.Application
The main class of the application.
Usage
-
--help
or-h
: Prints ahelp
message to the console. -
--user
or-u
: The username to log in at the University of Jena's Friedolin system. Required if no configuration file is specified. -
--password
or-p
: The password to log in at the University of Jena's Friedolin system. Required if no configuration file is specified. -
--degrees
or-d
: TheConfiguration.setAcademicDegrees(Set)
academic degrees} to fetch the grades for. Required if no configuration file is specified. -
--directory
or-D
: Thefolder
where the configuration file and other application data shall be stored. -
--config
or-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
, becauseDEBUG
is 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 Configuration
The user's preferences for the behaviour of the application.private static @NonNull DebugLevel
How verbose the program should be.protected static @NonNull com.beust.jcommander.JCommander
TheJCommander
object that parses the command-line arguments and populatesparameters
.protected static @NonNull CommandLineParameters
The command-line arguments passed to the program.static ResourceBundle
Fields inherited from class javafx.application.Application
STYLESHEET_CASPIAN, STYLESHEET_MODENA
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static @NonNull Configuration
getConfigurationFromCommandLine
(@NonNull String[] arguments) Parses the command-line arguments and creates aConfiguration
object from them.static @NonNull Optional
<Configuration> Tries to read the configuration file saved in thefile
Preference
of theFriedolyn
class or, if that fails, from thedirectory
Preference or, if that fails, from the default directory, which is~/.friedolyn
.private static @NonNull Configuration
getConfigurationFromDirectory
(@NonNull File folder) Tries to read a configuration file from the given directory.static void
help()
Prints a help message to the console explaining how to use the program.static void
Launches the application and receives the command-line arguments.private static void
Starts
to periodically fetch the grades from the University of Jena's Friedolin system.static void
setLoggingLevel
(@NonNull DebugLevel debugLevel) Updates thelogging level
of alllog4j loggers
according to the givendebug level
, whereDEBUG
corresponds toTRACE
,INFO
corresponds toINFO
,WARN
corresponds toWARN
, andERROR
corresponds toERROR
. Configures Log4J to log to the console and to alog file
in thelogs directory
relative to thedefault root directory
.static void
setLoggingLevel
(@NonNull DebugLevel debugLevel, @NonNull Path logFilePath) Updates thelogging level
of alllog4j loggers
according to the givendebug level
, whereDEBUG
corresponds toTRACE
,INFO
corresponds toINFO
,WARN
corresponds toWARN
, andERROR
corresponds toERROR
. Configures Log4J to log to the console and to the file specified bylogFilePath
.void
start
(@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 jCommanderTheJCommander
object 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()Starts
to 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 aConfiguration
object 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
Configuration
object that matches the command-line arguments.
-
setLoggingLevel
public static void setLoggingLevel(@NonNull @NonNull DebugLevel debugLevel, @NonNull @NonNull Path logFilePath) Updates thelogging level
of alllog4j loggers
according to the givendebug level
, whereDEBUG
corresponds toTRACE
,INFO
corresponds toINFO
,WARN
corresponds toWARN
, andERROR
corresponds 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 level
of alllog4j loggers
according to the givendebug level
, whereDEBUG
corresponds toTRACE
,INFO
corresponds toINFO
,WARN
corresponds toWARN
, andERROR
corresponds toERROR
.
log file
in thelogs directory
relative 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 thefile
Preference
of theFriedolyn
class or, if that fails, from thedirectory
Preference 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
Configuration
object 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
Configuration
object 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. Ifconfiguration
isnull
, thefirst-launch window
will be shown. If there is a configuration, themain window
will be shown. Waits for the GUI to be closed.- Specified by:
start
in 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.
-