@Impure @Override protected final void execute() throws Exception { Log.debugging("The initializer " + this + " begins its execution."); final long start = System.currentTimeMillis(); executeWithoutLogging(); final long end = System.currentTimeMillis(); Log.debugging("The initializer " + this + " ends its execution in " + (end - start) + " ms."); }
/** * Initializes the default uncaught exception handler as early as possible. */ @PureWithSideEffects @Initialize(target = UtilityInitializer.class) public static void initializeDefaultUncaughtExceptionHandler() throws FileNotFoundException { // NetBeans 8.1 crashes if you use type annotations on anonymous classes and lambda expressions! Thread.setDefaultUncaughtExceptionHandler((Thread thread, Throwable throwable) -> Log.fatal("The following problem caused this thread to terminate.", throwable)); }
/** * Reads a line from the standard input and returns it. */ @Impure private static @Nonnull String readLine() { try { final @Nullable String input = reader.readLine(); if (input == null) { throw new IOException("The end of the standard input has been reached."); } Log.information("Read the line $ from the console.", input); return input; } catch (@Nonnull IOException exception) { throw UncheckedExceptionBuilder.withCause(exception).build(); } }
ProcessingLog.initialize(getClass().getSimpleName()); } catch (@Nonnull IllegalArgumentException exception) { Log.error("The logging configuration is invalid:", exception); } catch (@Nonnull FileNotFoundException exception) { Log.error("Could not find the logging file:", exception); Log.error("The compilation failed due to the following problem:", throwable); ProcessingLog.error("An unexpected compilation error occurred: $. Please consult the log file under target/processor-logs/GeneratorProcessor.log for details.", Throwables.getSummary(throwable)); throw throwable;
/** * Initializes the logger with a rotating file logger. */ @PureWithSideEffects @Initialize(target = Logger.class) public static void initializeLogger() throws FileNotFoundException { if (Logger.logger.get() instanceof StandardOutputLogger) { Logger.logger.set(RotatingFileLogger.withDefaultDirectory()); Log.verbose("Replaced the default standard output logger with a rotating file logger."); } else { Log.verbose("Did not replace the non-default logger with a rotating file logger."); } }
} catch (@Nonnull FailedClassGenerationException exception) { ProcessingLog.error("The type $ is NOT generatable:", exception.getSourcePosition(), typeInformation == null ? typeElement : typeInformation, exception.getMessage()); Log.error("The compilation failed due to the following problem:", exception);
/** * Initializes the configuration directory with '~/.digitalid/'. */ @PureWithSideEffects @Initialize(target = Files.class, dependencies = UtilityInitializer.class) public static void initializeDirectory() throws IOException { if (!Files.directory.isSet()) { final @Nonnull @Absolute @ExistentParent File directory = Files.relativeToWorkingDirectory(System.getProperty("user.home") + "/.digitalid/"); if (directory.isDirectory() || directory.mkdir()) { Files.directory.set(directory); Log.verbose("Set the configuration directory to '~/.digitalid/'."); } else { throw new IOException("Could not create the directory '~/.digitalid/'."); } } else { Log.verbose("Did not set the configuration directory to '~/.digitalid/' because it is already set to $.", Files.directory.get().getAbsolutePath()); } }
/** * Writes the generated file to the file system and returns whether it was successful. */ @Impure @NonWrittenRecipient public final boolean write() { requireNotWritten(); try { writeOnce(); } catch (@Nonnull IOException exception) { ProcessingLog.error("A problem occurred while generating the file $.", getName()); Log.error("Problem:", exception); return false; } ProcessingLog.information("Generated the file $.", getName()); this.written = true; return true; }
/** * Writes the given message to the standard output without terminating the line. * Each dollar sign in the message is replaced with the corresponding argument. */ @Impure public static void write(@Nonnull CharSequence message, @NonCaptured @Unmodified @Nonnull @NullableElements Object... arguments) { final @Nonnull String formattedMessage = Strings.format(message, arguments); System.out.print(formattedMessage); Log.information("Wrote the string $ to the console.", formattedMessage); }
/** * Initializes the logging filter with a configuration-based logging filter. * * @throws IllegalArgumentException if a rule has an invalid level. */ @PureWithSideEffects @Initialize(target = LoggingFilter.class, dependencies = Files.class) public static void initializeLoggingFilter() throws IllegalArgumentException { if (LoggingFilter.filter.get() instanceof LevelBasedLoggingFilter) { LoggingFilter.filter.set(ConfigurationBasedLoggingFilter.with(Files.relativeToConfigurationDirectory("configs/logging.conf"), LoggingRule.with(Level.INFORMATION))); Log.verbose("Replaced the default level-based logging filter with a configuration-based logging filter."); } else { Log.verbose("Did not replace the non-default logging filter with a configuration-based logging filter."); } }
/** * Creates and registers this initializer with the given target and dependencies. */ protected LoggingInitializer(@NonCaptured @Modified @Nonnull Configuration<?> target, @NonCaptured @Unmodified @Nonnull @NonNullableElements Configuration<?>... dependencies) { super(target, dependencies); Log.debugging("The initializer " + this + " was loaded."); }
/** * Writes the given message to the standard output and terminates the line. * Each dollar sign in the message is replaced with the corresponding argument. */ @Impure public static void writeLine(@Nonnull CharSequence message, @NonCaptured @Unmodified @Nonnull @NullableElements Object... arguments) { final @Nonnull String formattedMessage = Strings.format(message, arguments); System.out.println(formattedMessage); Log.information("Wrote the line $ to the console.", formattedMessage); }