Skip to content

Commit

Permalink
Support multiple source jars (#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
jongerrish authored Nov 4, 2020
1 parent 730d9ef commit c8350b7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
18 changes: 18 additions & 0 deletions examples/dagger/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,29 @@ rm TeaPot.kt
toolchains = ["@bazel_tools//tools/jdk:current_host_java_runtime"],
)

genrule(
name = "chai_lib_src",
outs = ["chai_lib_src.srcjar"],
cmd = """
cat << EOF > ChaiCup.kt
package chai
object ChaiCup {
fun isEmpty() = true
}
EOF
$(JAVABASE)/bin/jar -cf $@ ChaiCup.kt
rm ChaiCup.kt
""",
toolchains = ["@bazel_tools//tools/jdk:current_host_java_runtime"],
)


kt_jvm_library(
name = "coffee_lib",
srcs = glob(["src/**"]) + [
# Adding a file ending with .srcjar is how code generation patterns are implemented.
":tea_lib_src",
":chai_lib_src",
],
deps = [
"//third_party:dagger",
Expand Down
3 changes: 2 additions & 1 deletion examples/dagger/src/coffee/CoffeeApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package coffee
import dagger.Component
import kotlinx.coroutines.runBlocking
import tea.TeaPot
import chai.ChaiCup
import javax.inject.Singleton

class CoffeeApp {
Expand All @@ -30,7 +31,7 @@ class CoffeeApp {
companion object {
@JvmStatic
fun main(args: Array<String>) {
if (TeaPot.isEmpty()) {
if (TeaPot.isEmpty() && ChaiCup.isEmpty()) {
val coffeeShop = DaggerCoffeeApp_CoffeeShop.builder().build()
runBlocking {
coffeeShop.maker().brew()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ class SourceJarExtractor(destDir: Path, val fileMatcher: Predicate<String> = Pre
val sourcesList = mutableListOf<String>()

override fun preWrite(isDirectory: Boolean, target: Path): Boolean {
if (!isDirectory && fileMatcher.test(target.toString())) {
if (isDirectory) {
return true
}

if (fileMatcher.test(target.toString())) {
sourcesList.add(target.toString())
return true
}
return true
return false
}

fun execute() {
Expand Down

0 comments on commit c8350b7

Please sign in to comment.