From 2bd28085f80d84c6e4ec45b547bcd6b5f77e91b4 Mon Sep 17 00:00:00 2001 From: Jonathan Gerrish Date: Wed, 4 Nov 2020 09:15:05 -0800 Subject: [PATCH 1/2] Support multiple source jars --- examples/dagger/BUILD | 18 ++++++++++++++++++ .../builder/utils/jars/SourceJarExtractor.kt | 9 +++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/examples/dagger/BUILD b/examples/dagger/BUILD index 1d567601d..15d49c594 100644 --- a/examples/dagger/BUILD +++ b/examples/dagger/BUILD @@ -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", diff --git a/src/main/kotlin/io/bazel/kotlin/builder/utils/jars/SourceJarExtractor.kt b/src/main/kotlin/io/bazel/kotlin/builder/utils/jars/SourceJarExtractor.kt index 3a61e5e08..7039837fb 100644 --- a/src/main/kotlin/io/bazel/kotlin/builder/utils/jars/SourceJarExtractor.kt +++ b/src/main/kotlin/io/bazel/kotlin/builder/utils/jars/SourceJarExtractor.kt @@ -24,10 +24,15 @@ class SourceJarExtractor(destDir: Path, val fileMatcher: Predicate = Pre val sourcesList = mutableListOf() 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() { From e37da46230b3d7770baa52e1cb6cc3125370541c Mon Sep 17 00:00:00 2001 From: Jonathan Gerrish Date: Wed, 4 Nov 2020 13:53:45 -0800 Subject: [PATCH 2/2] Add test --- examples/dagger/src/coffee/CoffeeApp.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/dagger/src/coffee/CoffeeApp.kt b/examples/dagger/src/coffee/CoffeeApp.kt index 68bd6732e..a465f358d 100644 --- a/examples/dagger/src/coffee/CoffeeApp.kt +++ b/examples/dagger/src/coffee/CoffeeApp.kt @@ -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 { @@ -30,7 +31,7 @@ class CoffeeApp { companion object { @JvmStatic fun main(args: Array) { - if (TeaPot.isEmpty()) { + if (TeaPot.isEmpty() && ChaiCup.isEmpty()) { val coffeeShop = DaggerCoffeeApp_CoffeeShop.builder().build() runBlocking { coffeeShop.maker().brew()