annotate antlib/Du.kt @ 30:098c4f5507c7

Convert to JDK 15.
author David Barts <n5jrn@me.com>
date Mon, 13 Jun 2022 11:31:49 -0700
parents e90d290a9a8d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29
e90d290a9a8d Remove dependence on Nashorn.
David Barts <n5jrn@me.com>
parents:
diff changeset
1 import java.io.File
e90d290a9a8d Remove dependence on Nashorn.
David Barts <n5jrn@me.com>
parents:
diff changeset
2 import java.io.IOException
e90d290a9a8d Remove dependence on Nashorn.
David Barts <n5jrn@me.com>
parents:
diff changeset
3
e90d290a9a8d Remove dependence on Nashorn.
David Barts <n5jrn@me.com>
parents:
diff changeset
4 class Du : org.apache.tools.ant.Task() {
e90d290a9a8d Remove dependence on Nashorn.
David Barts <n5jrn@me.com>
parents:
diff changeset
5 var path: String? = null
e90d290a9a8d Remove dependence on Nashorn.
David Barts <n5jrn@me.com>
parents:
diff changeset
6 var output: String? = null
e90d290a9a8d Remove dependence on Nashorn.
David Barts <n5jrn@me.com>
parents:
diff changeset
7
e90d290a9a8d Remove dependence on Nashorn.
David Barts <n5jrn@me.com>
parents:
diff changeset
8 override fun execute(): Unit {
e90d290a9a8d Remove dependence on Nashorn.
David Barts <n5jrn@me.com>
parents:
diff changeset
9 project.setProperty(output, du(path!!).toString())
e90d290a9a8d Remove dependence on Nashorn.
David Barts <n5jrn@me.com>
parents:
diff changeset
10 }
e90d290a9a8d Remove dependence on Nashorn.
David Barts <n5jrn@me.com>
parents:
diff changeset
11
e90d290a9a8d Remove dependence on Nashorn.
David Barts <n5jrn@me.com>
parents:
diff changeset
12 private fun du(path: String): Long {
e90d290a9a8d Remove dependence on Nashorn.
David Barts <n5jrn@me.com>
parents:
diff changeset
13 try {
e90d290a9a8d Remove dependence on Nashorn.
David Barts <n5jrn@me.com>
parents:
diff changeset
14 return File(path).walk().map { if (it.isFile()) { it.length() } else { 0L } }.sum()
e90d290a9a8d Remove dependence on Nashorn.
David Barts <n5jrn@me.com>
parents:
diff changeset
15 } catch (e: IOException) {
e90d290a9a8d Remove dependence on Nashorn.
David Barts <n5jrn@me.com>
parents:
diff changeset
16 return 0L
e90d290a9a8d Remove dependence on Nashorn.
David Barts <n5jrn@me.com>
parents:
diff changeset
17 }
e90d290a9a8d Remove dependence on Nashorn.
David Barts <n5jrn@me.com>
parents:
diff changeset
18 }
e90d290a9a8d Remove dependence on Nashorn.
David Barts <n5jrn@me.com>
parents:
diff changeset
19 }