Package h07.util

Class Updater


  • public class Updater
    extends Object
    Updates the local tests if configured to do so.

    Assuming Config.CHECK_FOR_UPDATES is true, .test_metadata.xml is fetched from the repository. If the version-tag in that file is newer than the version of the local files, a message is printed to let the user know that an update is available. If Config.AUTO_UPDATE is true, the MD5-hash of each file will be compared with the one in .test_metadata.xml when an update is available. If the hashes don't match and Config.AUTO_UPDATE is true, the local file will be overwritten with the contents of the respective file from the repository. These tasks will be skipped for files that are in Config.EXCLUDED_FILES.
    • Field Detail

      • LOCAL_VERSION

        public static final String LOCAL_VERSION
        A String representing the version of currently installed tests in SemVer format
        See Also:
        Constant Field Values
      • root

        private static Node root
        The root node of .test_metadata.xml
      • xPath

        private static XPath xPath
        A XPath instance
    • Constructor Detail

      • Updater

        public Updater()
    • Method Detail

      • checkForUpdates

        public static boolean checkForUpdates()
                                       throws Exception
        Checks if tests in the repository are newer than the local copy. If Config.AUTO_UPDATE is true, hashes of local files will be generated for all files in .test_metadata.xml and compared to those in the file. If a mismatch occurs, the file will be downloaded from the repository and the contents of the local file will be overwritten with the ones from the remote file.
        Returns:
        whether any changes have been written to disk
        Throws:
        Exception
        See Also:
        Config.CHECK_FOR_UPDATES
      • getHttpResource

        private static HttpResponse<String> getHttpResource​(String resource)
        Requests a resource / file from the repository.
        Parameters:
        resource - The resource to fetch from the repository.
        Returns:
        a HttpResponse object for the requested resource
        See Also:
        REPOSITORY_URL
      • getHash

        private static String getHash​(File file)
        Calculates the MD5-hash of a file and returns it.
        Parameters:
        file - The file to generate the hash of.
        Returns:
        the hash as a hexadecimal string
      • updateLocal

        private static boolean updateLocal​(File file)
        Updates (overwrites) the specified file with the contents of the file at the repository.
        Parameters:
        file - The relative path to the file.
        Returns:
        whether any persistent changes have been written to disk