Package h07.util
Class Updater
- java.lang.Object
-
- h07.util.Updater
-
public class Updater extends Object
Updates the local tests if configured to do so.
AssumingConfig.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. IfConfig.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 andConfig.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 inConfig.EXCLUDED_FILES
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
Updater.Version
A limited implementation of Semantic Versioning.
-
Field Summary
Fields Modifier and Type Field Description static String
ASSIGNMENT_ID
The ID of this assignmentstatic String
LOCAL_VERSION
AString
representing the version of currently installed tests in SemVer formatstatic String
REPOSITORY_URL
The URL of the repository to useprivate static Node
root
The root node of.test_metadata.xml
private static XPath
xPath
A XPath instance
-
Constructor Summary
Constructors Constructor Description Updater()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
checkForUpdates()
Checks if tests in the repository are newer than the local copy.private static String
getHash(File file)
Calculates the MD5-hash of a file and returns it.private static HttpResponse<String>
getHttpResource(String resource)
Requests a resource / file from the repository.private static void
updateConfig()
Updates the configuration file, keeping all data written between the markers ">>>##" and "##<<<".private static boolean
updateLocal(File file)
Updates (overwrites) the specified file with the contents of the file at the repository.
-
-
-
Field Detail
-
LOCAL_VERSION
public static final String LOCAL_VERSION
AString
representing the version of currently installed tests in SemVer format- See Also:
- Constant Field Values
-
ASSIGNMENT_ID
public static final String ASSIGNMENT_ID
The ID of this assignment- See Also:
- Constant Field Values
-
REPOSITORY_URL
public static final String REPOSITORY_URL
The URL of the repository to use- 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
-
-
Method Detail
-
checkForUpdates
public static boolean checkForUpdates() throws Exception
Checks if tests in the repository are newer than the local copy. IfConfig.AUTO_UPDATE
istrue
, 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
-
updateConfig
private static void updateConfig() throws XPathExpressionException
Updates the configuration file, keeping all data written between the markers ">>>##" and "##<<<".- Throws:
XPathExpressionException
- See Also:
Config
-
-