@@ -43,42 +43,44 @@ import java.security.MessageDigest
4343def createChecksumsTask = tasks. register(' createChecksums' ) {
4444 group = ' publishing'
4545 description = ' Create .sha1, .sha256, and .md5 checksum files for the fatJars.'
46- String sourceDir = " ${ rootProject.getBuildDir()} /libs"
47- def files = fileTree(dir : " ${ sourceDir} " , include : ' **/*.jar' )
48- def algorithms = [" MD5" , " SHA-1" , " SHA-256" ]
49- algorithms. each {algorithm ->
50- MessageDigest md = MessageDigest . getInstance(algorithm)
51- files. each { File jarFile ->
52- InputStream is = null
53- DigestInputStream dis = null
54- byte [] buffer = new byte [2048 ]
55- try {
56- is = Files . newInputStream(Paths . get(jarFile. absolutePath))
57- dis = new DigestInputStream (is, md)
58- while (dis. read(buffer) != -1 ) {
59- // just need to read through the file
60- }
61- dis. close()
62- is. close()
63- } finally {
64- if (dis != null ) {
46+ doLast {
47+ String sourceDir = " ${ rootProject.getBuildDir()} /libs"
48+ def files = fileTree(dir : " ${ sourceDir} " , include : ' **/*.jar' )
49+ def algorithms = [" MD5" , " SHA-1" , " SHA-256" ]
50+ algorithms. each { algorithm ->
51+ MessageDigest md = MessageDigest . getInstance(algorithm)
52+ files. each { File jarFile ->
53+ InputStream is = null
54+ DigestInputStream dis = null
55+ byte [] buffer = new byte [2048 ]
56+ try {
57+ is = Files . newInputStream(Paths . get(jarFile. absolutePath))
58+ dis = new DigestInputStream (is, md)
59+ while (dis. read(buffer) != -1 ) {
60+ // just need to read through the file
61+ }
6562 dis. close()
66- }
67- if (is != null ) {
6863 is. close()
64+ } finally {
65+ if (dis != null ) {
66+ dis. close()
67+ }
68+ if (is != null ) {
69+ is. close()
70+ }
6971 }
70- }
7172
72- byte [] digest = md. digest()
73- StringBuilder sb = new StringBuilder ()
74- for (int b= 0 ; b < digest. length; b++ ) {
75- sb. append(Integer . toString((digest[b] & 0xff ) + 0x100 , 16 ). substring(1 ))
76- }
77- String checksum = sb. toString()
78- def ext = algorithm. toLowerCase(). replace(" -" ," " )
79- String outputFilename = " ${ buildDir} /libs/${ jarFile.getName()} .${ ext} "
80- new File (outputFilename). withWriter { writer ->
81- writer. write checksum
73+ byte [] digest = md. digest()
74+ StringBuilder sb = new StringBuilder ()
75+ for (int b = 0 ; b < digest. length; b++ ) {
76+ sb. append(Integer . toString((digest[b] & 0xff ) + 0x100 , 16 ). substring(1 ))
77+ }
78+ String checksum = sb. toString()
79+ def ext = algorithm. toLowerCase(). replace(" -" , " " )
80+ String outputFilename = " ${ buildDir} /libs/${ jarFile.getName()} .${ ext} "
81+ new File (outputFilename). withWriter { writer ->
82+ writer. write checksum
83+ }
8284 }
8385 }
8486 }
0 commit comments