Skip to content

Commit

Permalink
Merge pull request apache#3 from mocobeta/add-task-show-all-packages
Browse files Browse the repository at this point in the history
Add a utility task to list all existing pacage names
  • Loading branch information
dweiss authored Dec 2, 2021
2 parents 77e5ec2 + ccff2e0 commit fc45e59
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions gradle/java/modules.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import java.util.jar.JarFile
import java.util.stream.Collectors

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
Expand Down Expand Up @@ -58,3 +59,28 @@ configure(rootProject) {
}
})
}

allprojects {
// Show all non-empty package names
// There should be a better way...
plugins.withType(JavaPlugin) {
tasks.register("showPackageNames", { task ->
doFirst {
var pkgNameSet = [] as Set<String>
sourceSets.main.each { sourceSet ->
var dirs = sourceSet.allJava.srcDirTrees.collect { it.dir.toPath() }
sourceSet.allJava.filter{ it.name != "module-info.java" && it.name != "package-info.java" }.each {srcFile ->
var srcPath = srcFile.toPath()
var dir = dirs.find { srcPath.startsWith(it) }
var pkgName = srcPath.subpath(dir.nameCount, srcPath.nameCount).parent.stream().map(Object::toString).collect(Collectors.joining('.'))
pkgNameSet.add(pkgName)
}
}
var pkgNames = pkgNameSet as List<String>
pkgNames.sort()
pkgNames.each { println(it) }
}
})
}
}

0 comments on commit fc45e59

Please sign in to comment.