Class DirectoryUtils

java.lang.Object
studentrepoloader.filesystem.DirectoryUtils

public class DirectoryUtils extends Object
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    createFolder(Path folderName)
    Ensures the given path exists as a directory.
    static boolean
    isCloned(Path targetPath)
    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
    writeLog(String logContent, Path logFileName, boolean append)
    Writes a single line of text to the specified log file.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DirectoryUtils

      public DirectoryUtils()
  • Method Details

    • isCloned

      public static boolean isCloned(Path targetPath)
      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, otherwise false
    • createFolder

      public static void createFolder(Path folderName)
      Ensures the given path exists as a directory.

      Equivalent to Files.createDirectories(...), and throws RuntimeException if creation fails.

      Parameters:
      folderName - the directory path to ensure exists
    • writeLog

      public static void writeLog(String logContent, Path logFileName, boolean append)
      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 file
      append - if true, appends to the log; if false, overwrites the file
      Throws:
      RuntimeException - if the write operation fails
    • resetLogFile

      public static void resetLogFile(Path logFileName)
      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