Class Util


  • public class Util
    extends Object
    • Constructor Detail

      • Util

        public Util()
    • Method Detail

      • getRelativePath

        public static String getRelativePath​(File file,
                                             File baseDir)
        This returns relative path of given file with respect to given base directory
        Parameters:
        file - input file
        baseDir - base directory
        Returns:
        String with relative @file path with respect to its @baseDir
      • generateFileNameBase

        public static String generateFileNameBase​(Date date)
        Generates unique file name (without extension)
        Parameters:
        date - Date object for the timestamp
        Returns:
        unique filename
      • getFormattedDate

        public static String getFormattedDate​(String pattern,
                                              Date date)
        This returns timestamp String
        Parameters:
        pattern - A pattern used to format the timestamp
        date - Date used as timestamp
        Returns:
        timestamp String
      • createFileName

        public static String createFileName​(String fileName,
                                            String extension)
        Puts the filename and the extension together
        Parameters:
        fileName - filename without extension
        extension - extension of the file
        Returns:
        filename with extension
      • createBackupObjectFile

        public static File createBackupObjectFile​(BackupObject backupObject,
                                                  String destinationDir,
                                                  String fileNameBase)
                                           throws IOException
        Creates the backupObject File from given BackupObject, fileNameBase and destination path
        Parameters:
        backupObject - BackupObject given to be serialized
        destinationDir - String with path to the directory where the file will be created
        fileNameBase - first part of the filename
        Returns:
        serialized BackupObject File
        Throws:
        IOException - If an IO problem occurs
      • isValidBackupObjectFile

        public static boolean isValidBackupObjectFile​(File backupObjectFile)
                                               throws IOException
        This test if a given file is a valid serialized BackupObject file
        Parameters:
        backupObjectFile - File to test
        Returns:
        true if valid, false otherwise
        Throws:
        IOException - If an IO problem occurs
      • extensionFileFilter

        public static FileFilter extensionFileFilter​(String extension)
        Creates FileFilter for files with the given extension
        Parameters:
        extension - file extension
        Returns:
        FileFilter
      • getExtension

        public static String getExtension​(File f)
        This returns extension of the given File object, returns null if the file has no extension
        Parameters:
        f - given File
        Returns:
        String with the extension of the given file
      • isWritableDirectory

        public static boolean isWritableDirectory​(File directory)
      • listFiles

        public static File[] listFiles​(@Nonnull
                                       File directory)
                                throws org.jenkinsci.plugins.periodicbackup.PeriodicBackupException
        Throws:
        org.jenkinsci.plugins.periodicbackup.PeriodicBackupException
      • listFiles

        @Nonnull
        @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class)
        public static File[] listFiles​(@Nonnull
                                       File directory,
                                       @CheckForNull
                                       FileFilter fileFilter)
                                throws org.jenkinsci.plugins.periodicbackup.PeriodicBackupException
        Secure version of the listFiles() logic
        Parameters:
        directory - Directory to be listed
        fileFilter - Optional file filter
        Returns:
        Files in the directory. If the directory does not exist, an empty list will be returned
        Throws:
        org.jenkinsci.plugins.periodicbackup.PeriodicBackupException - Whatever error