Class StreakBooster
java.lang.Object
StreakBooster
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 Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
Path to the log file where application events are recorded.private static final Logger
Logger for logging application events.private static final int
Maximum number of retries for Git push operations.private static final ExecutorService
Thread pool executor to handle concurrent process output logging.private static final String
Path to the file where commit timestamps are saved. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
Configures the logger with a file handler and simple formatter.private static void
executeGitCommand
(String... command) Executes a Git command usingProcessBuilder
.private static void
Executes Git add and commit commands.private static boolean
Executes the Git push command with retries.private static boolean
Checks if the system is connected to the internet by sending a HEAD request to GitHub.private static void
logStream
(InputStream inputStream, Level level) Logs the output stream of a process.static void
The main method that runs the StreakBooster.private static void
shutdown()
Shuts down the executor service and closes all logger handlers.private static void
Writes the current timestamp to the `records.txt` file.
-
Field Details
-
logger
Logger for logging application events. -
LOG_FILE_PATH
Path to the log file where application events are recorded.- See Also:
-
TIMESTAMP_FILE_PATH
Path to the file where commit timestamps are saved.- See Also:
-
MAX_RETRIES
private static final int MAX_RETRIESMaximum number of retries for Git push operations.- See Also:
-
processOutputExecutor
Thread pool executor to handle concurrent process output logging.
-
-
Constructor Details
-
StreakBooster
public StreakBooster()Default constructor. Initializes the StreakBooster class.
-
-
Method Details
-
main
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
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
Writes the current timestamp to the `records.txt` file.- Throws:
IOException
- if the file cannot be written.
-
executeGitCommands
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
Executes a Git command usingProcessBuilder
. 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
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.
-