Class StreakBooster

java.lang.Object
StreakBooster

public class StreakBooster extends Object
An automation tool built in java.

This Java program automates the process of creating Git commits and pushing them to a remote repository. It writes timestamps to a file, commits the changes, and pushes them periodically. It retries the push in case of network failures. The program uses multithreading to handle Git process output.

🛠️ Features:

  • Generates and writes timestamps to a file
  • Executes Git commands (add, commit, push)
  • Retries Git push operations in case of failure
  • Logs output and errors to a log file
  • Multithreaded log handling
Since:
2025-02-14
Author:
Anurag Zete
  • Field Details

    • logger

      private static final Logger logger
      Logger for logging application events.
    • LOG_FILE_PATH

      private static final String LOG_FILE_PATH
      Path to the log file where application events are recorded.
      See Also:
    • TIMESTAMP_FILE_PATH

      private static final String TIMESTAMP_FILE_PATH
      Path to the file where commit timestamps are saved.
      See Also:
    • MAX_RETRIES

      private static final int MAX_RETRIES
      Maximum number of retries for Git push operations.
      See Also:
    • processOutputExecutor

      private static final ExecutorService processOutputExecutor
      Thread pool executor to handle concurrent process output logging.
  • Constructor Details

    • StreakBooster

      public StreakBooster()
      Default constructor. Initializes the StreakBooster class.
  • Method Details

    • main

      public static void main(String[] args)
      The main method that runs the StreakBooster. It performs the following tasks:
      • Configures the logger
      • Writes timestamp to a file
      • Executes Git add and commit commands
      • Checks for internet connectivity
      • Pushes changes with retries
      Parameters:
      args - Command-line arguments (not used)
    • configureLogger

      private static void configureLogger() throws IOException
      Configures the logger with a file handler and simple formatter. The logs are saved to `logRecords.log`.
      Throws:
      IOException - if the log file cannot be created or accessed.
    • writeTimestampToFile

      private static void writeTimestampToFile() throws IOException
      Writes the current timestamp to the `records.txt` file.
      Throws:
      IOException - if the file cannot be written.
    • executeGitCommands

      private static void executeGitCommands() throws IOException, InterruptedException
      Executes Git add and commit commands.
      • Adds `records.txt` and `logRecords.log` to the staging area
      • Commits the changes with an auto-generated message
      Throws:
      IOException - if the Git commands fail to execute.
      InterruptedException - if the process is interrupted.
    • isInternetConnected

      private static boolean isInternetConnected()
      Checks if the system is connected to the internet by sending a HEAD request to GitHub.
      Returns:
      true if connected, false otherwise.
    • executeGitPushWithRetries

      private static boolean executeGitPushWithRetries()
      Executes the Git push command with retries.

      If the push fails, the program retries up to MAX_RETRIES times, with a 60-second delay between attempts.

      Returns:
      true if the push is successful, false otherwise.
    • executeGitCommand

      private static void executeGitCommand(String... command) throws IOException, InterruptedException
      Executes a Git command using ProcessBuilder. It logs the output and errors concurrently using multiple threads.
      Parameters:
      command - The Git command and its arguments.
      Throws:
      IOException - if the command execution fails.
      InterruptedException - if the process is interrupted.
    • logStream

      private static void logStream(InputStream inputStream, Level level)
      Logs the output stream of a process. Uses a thread pool to handle multiple outputs concurrently.
      Parameters:
      inputStream - The stream to read.
      level - The log level (INFO or WARNING).
    • shutdown

      private static void shutdown()
      Shuts down the executor service and closes all logger handlers. Ensures proper cleanup of resources.