Last active
May 13, 2019 13:59
-
-
Save jwheeler31/6d4de72449e9ac8297250d4bf58766b5 to your computer and use it in GitHub Desktop.
Naive Gradle replacement for Ant <uptodate/> task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Checks if the file at <tt>targetFilePath</tt> has a last modified time later | |
| * than <tt>srcFilePath</tt>. | |
| * | |
| * At the time of writing, the goal of this method was to create a replacement for | |
| * Apache Ant's <tt>uptodate</tt> task. This is a naive implementation of that | |
| * task. | |
| * | |
| * @param srcFilePath fully qualified path to source file | |
| * @param targetPath fully qualified path to the target | |
| * | |
| * @return <tt>true</tt> if File#lastModified() of target >= File#lastModified() of source | |
| * | |
| * @see https://ant.apache.org/manual/Tasks/uptodate.html | |
| * @see https://github.com/apache/ant/blob/master/src/main/org/apache/tools/ant/taskdefs/UpToDate.java | |
| */ | |
| boolean upToDate(String srcFilePath, String targetFilePath) { | |
| File srcFile = file(srcFilePath) | |
| File targetFile = file(targetFilePath) | |
| boolean current = targetFile.lastModified() >= srcFile.lastModified() | |
| // Log results | |
| if (current) { // target is newer | |
| logger.quiet("File:[${targetFile.getName()}] is newer than [${srcFile.getName()}]") | |
| } | |
| else { // target is older | |
| if (!srcFile.exists()) { | |
| logger.quiet("Source file:[${srcFile.exists()}] does not exist") | |
| } | |
| if (!targetFile.exists()) { | |
| logger.quiet("Target file:[${targetFile.getName()}] does not exist") | |
| } | |
| if (srcFile.exists() && targetFile.exists()) { | |
| logger.quiet("File:[${srcFile.getName()}] is newer than [${targetFile.getName()}]") | |
| } | |
| } | |
| return current | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment