Skip to content

Instantly share code, notes, and snippets.

@turboBasic
Last active August 15, 2021 10:59
Show Gist options
  • Save turboBasic/4a5d030509cd2d46b1fa59766b9116fc to your computer and use it in GitHub Desktop.
Save turboBasic/4a5d030509cd2d46b1fa59766b9116fc to your computer and use it in GitHub Desktop.
Gradle task `printSourceSets` #gradle
plugins {
id 'groovy'
}
sourceSets {
// ...
}
tasks.register('printSourceSets') {
dependsOn test
doLast {
sourceSets.each { def ss ->
final String BOLD = '\u001b[38;5;226m'
final String EMPH = '\u001b[38;5;11m'
final String RST = '\u001b[0m'
println "\n${BOLD}Sourceset: $ss${RST}\n" + '-'*(ss.toString().length() + 11) + '\n'
println "${BOLD}properties${RST}: " + prettyfied(
ss.properties
.collect { it }
.groupBy { it.value.getClass().getCanonicalName() }
)
['allSource', 'allJava', 'resources', 'java'].each {
println "\n${BOLD}$it${RST}:"
println " destinationDirectory: " + ss.getProperty(it).getDestinationDirectory()
println " classesDirectory: " + ss.getProperty(it).getClassesDirectory()
println " ${EMPH}sourceDirectories${RST}: " + prettyfied(
ss.getProperty(it).getSourceDirectories().getFiles(), 1
)
}
println()
println "${BOLD}files in default container `allSource`${RST}:"
ss.allSource.each {
println " $it"
}
}
}
}
String prettyfied(Object o, int level = 0, int indent = 4) {
if (!(o in Map || o in Collection)) {
return o.toString()
}
if (!o) {
return (o in Map ? '[:]' : '[]')
}
List result = []
result << '['
o.each {
String line = ' ' * (level+1) * indent
if (o in Map) {
line += it.key + ': '
}
result << line + prettyfied(o in Map ? it.value : it, level+1, indent) + ', '
}
result << ' '*level*indent + ']'
result.join '\n'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment