-
Notifications
You must be signed in to change notification settings - Fork 1
/
checksums.gradle
82 lines (74 loc) · 2.18 KB
/
checksums.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* checksums.gradle
*
* Mass checksum calculation for files in the specified folder (recursive to subfolders).
*
* Written by Andrey Hihlovskiy (akhikhl AT gmail DOT com).
* Licensed under the MIT (http://opensource.org/licenses/MIT).
* Date: 05.06.2013
*
* @author Andrey Hihlovskiy
* @version 1.0.0
* @requires gradle 1.6 or later
*
* Get complete sources and documentation at:
*
* https://github.com/akhikhl/checksums
*
**/
buildscript {
apply plugin: "maven"
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath "commons-codec:commons-codec:1.8"
}
}
import org.apache.commons.codec.digest.DigestUtils
task "generateCheckSums" {
def sourceTree = fileTree(dir: projectDir, includes: ["**/*.xml", "**/*.jar", "**/*.pom"])
outputs.upToDateWhen {
!sourceTree.find {File file ->
File fileMd5 = new File(file.absolutePath + ".md5")
File fileSha1 = new File(file.absolutePath + ".sha1")
if(!fileMd5.exists() || !fileSha1.exists())
return true;
String checksum;
file.withInputStream { ins -> checksum = DigestUtils.md5Hex(ins) }
if(fileMd5.text != checksum)
return true;
file.withInputStream { ins -> checksum = DigestUtils.sha1Hex(ins) }
if(fileSha1.text != checksum)
return true;
}
}
doLast {
sourceTree.each {File file ->
File fileMd5 = new File(file.absolutePath + ".md5")
File fileSha1 = new File(file.absolutePath + ".sha1")
String checksum;
file.withInputStream { ins -> checksum = DigestUtils.md5Hex(ins) }
fileMd5.text = checksum
file.withInputStream { ins -> checksum = DigestUtils.sha1Hex(ins) }
fileSha1.text = checksum
}
}
}
task "cleanCheckSums" {
def sourceTree = fileTree(dir: projectDir, includes: ["**/*.xml", "**/*.jar", "**/*.pom"])
outputs.upToDateWhen {
!sourceTree.find {File file ->
new File(file.absolutePath + ".md5").exists() ||
new File(file.absolutePath + ".sha1").exists()
}
}
doLast {
sourceTree.each {File file ->
new File(file.absolutePath + ".md5").delete()
new File(file.absolutePath + ".sha1").delete()
}
}
}
defaultTasks "generateCheckSums"