Class DirectoryUtils
java.lang.Object
studentrepoloader.filesystem.DirectoryUtils
Utility methods for managing directory and log file creation.
This class provides common file-system operations used by the cloning infrastructure, including safe file creation, log writing, and repository detection.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
createFolder
(Path folderName) Ensures the given path exists as a directory.static boolean
Checks whether the target path contains a cloned Git repository.static void
resetLogFile
(Path logFileName) Initializes a global log file by deleting any existing instance and creating an empty replacement.static void
Writes a single line of text to the specified log file.
-
Constructor Details
-
DirectoryUtils
public DirectoryUtils()
-
-
Method Details
-
isCloned
Checks whether the target path contains a cloned Git repository.This is determined by the presence of a
.git/
subdirectory.- Parameters:
targetPath
- the directory to check- Returns:
true
if the directory contains a Git repository, otherwisefalse
-
createFolder
Ensures the given path exists as a directory.Equivalent to
Files.createDirectories(...)
, and throwsRuntimeException
if creation fails.- Parameters:
folderName
- the directory path to ensure exists
-
writeLog
Writes a single line of text to the specified log file.Automatically creates all necessary parent directories. Controls whether the log file is overwritten or appended to.
- Parameters:
logContent
- the content to write (a line)logFileName
- the target log fileappend
- if true, appends to the log; if false, overwrites the file- Throws:
RuntimeException
- if the write operation fails
-
resetLogFile
Initializes a global log file by deleting any existing instance and creating an empty replacement.Ensures the parent directory exists before writing.
Useful for resetting log state before a new processing batch (e.g., cleaning steps, errors, etc.).
- Parameters:
logFileName
- absolute or relative path to the log file being reset- Throws:
RuntimeException
- if the file or parent directory cannot be created
-