Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple source jars #377

Merged
merged 2 commits into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
cgruber marked this conversation as resolved.
Show resolved Hide resolved
],
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()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

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