Skip to content

Commit

Permalink
Update ksp tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zalewskise committed Mar 28, 2024
1 parent 99ee58f commit 2f7e08c
Show file tree
Hide file tree
Showing 9 changed files with 379 additions and 127 deletions.
6 changes: 3 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ maven.install(
"com.google.auto.service:auto-service-annotations:1.0.1",
"com.google.auto.value:auto-value:1.10.1",
"com.google.auto.value:auto-value-annotations:1.10.1",
"com.google.dagger:dagger:2.43.2",
"com.google.dagger:dagger-compiler:2.43.2",
"com.google.dagger:dagger-producers:2.43.2",
"com.google.dagger:dagger:2.51",
"com.google.dagger:dagger-compiler:2.51",
"com.google.dagger:dagger-producers:2.51",
"javax.annotation:javax.annotation-api:1.3.2",
"javax.inject:javax.inject:1",
"org.pantsbuild:jarjar:1.7.2",
Expand Down
180 changes: 87 additions & 93 deletions kotlin_rules_maven_install.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/main/starlark/core/repositories/setup.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def kt_configure():
"com.google.auto.service:auto-service-annotations:1.0.1",
"com.google.auto.value:auto-value:1.10.1",
"com.google.auto.value:auto-value-annotations:1.10.1",
"com.google.dagger:dagger:2.43.2",
"com.google.dagger:dagger-compiler:2.43.2",
"com.google.dagger:dagger-producers:2.43.2",
"com.google.dagger:dagger:2.51",
"com.google.dagger:dagger-compiler:2.51",
"com.google.dagger:dagger-producers:2.51",
"javax.annotation:javax.annotation-api:1.3.2",
"javax.inject:javax.inject:1",
"org.pantsbuild:jarjar:1.7.2",
Expand Down
108 changes: 99 additions & 9 deletions src/test/data/jvm/ksp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,26 @@ load("//kotlin:jvm.bzl", "kt_jvm_library")
# limitations under the License.
package(default_visibility = ["//visibility:private"])

kt_ksp_plugin(
name = "dagger",
generates_java = True,
processor_class = "dagger.internal.codegen.KspComponentProcessor",
target_embedded_compiler = True,
deps = ["@kotlin_rules_maven//:com_google_dagger_dagger_compiler"],
)

kt_ksp_plugin(
name = "dagger_no_java",
generates_java = False,
processor_class = "dagger.internal.codegen.KspComponentProcessor",
target_embedded_compiler = True,
deps = ["@kotlin_rules_maven//:com_google_dagger_dagger_compiler"],
)

kt_ksp_plugin(
name = "autoservice",
processor_class = "dev.zacsweers.autoservice.ksp.AutoServiceSymbolProcessor$Provider",
deps = [
"@kotlin_rules_maven//:dev_zacsweers_autoservice_auto_service_ksp",
],
deps = ["@kotlin_rules_maven//:dev_zacsweers_autoservice_auto_service_ksp"],
)

kt_ksp_plugin(
Expand All @@ -35,7 +49,7 @@ kt_ksp_plugin(
)

kt_jvm_library(
name = "moshi_lib",
name = "ksp_kotlin_resources",
srcs = ["CoffeeAppModel.kt"],
plugins = [":moshi"],
deps = [
Expand All @@ -46,19 +60,95 @@ kt_jvm_library(
)

kt_jvm_library(
name = "coffee_lib",
srcs = ["CoffeeAppService.java"],
plugins = [":autoservice"],
name = "ksp_kotlin_resources_missing_plugin",
srcs = ["CoffeeAppModel.kt"],
deps = [
"@kotlin_rules_maven//:com_squareup_moshi_moshi",
"@kotlin_rules_maven//:com_squareup_moshi_moshi_kotlin",
"@kotlin_rules_maven//:com_squareup_moshi_moshi_kotlin_codegen",
],
)

kt_jvm_library(
name = "ksp_kotlin_resources_multiple_plugins",
srcs = [
"CoffeeAppModel.kt",
"DripCoffeeModule.kt",
],
plugins = [
":dagger",
":moshi",
],
deps = [
"@kotlin_rules_maven//:com_google_dagger_dagger",
"@kotlin_rules_maven//:com_squareup_moshi_moshi",
"@kotlin_rules_maven//:com_squareup_moshi_moshi_kotlin",
"@kotlin_rules_maven//:com_squareup_moshi_moshi_kotlin_codegen",
],
)

kt_jvm_library(
name = "ksp_kotlin_resources_multiple_plugins_no_java_gen",
srcs = [
"CoffeeAppModel.kt",
"DripCoffeeModule.kt",
],
plugins = [
":dagger_no_java",
":moshi",
],
deps = [
"@kotlin_rules_maven//:com_google_dagger_dagger",
"@kotlin_rules_maven//:com_squareup_moshi_moshi",
"@kotlin_rules_maven//:com_squareup_moshi_moshi_kotlin",
"@kotlin_rules_maven//:com_squareup_moshi_moshi_kotlin_codegen",
],
)

kt_jvm_library(
name = "ksp_mixed_resources",
srcs = [
"CoffeeApp.kt",
"CoffeeBean.java",
"CoffeeMaker.kt",
"DripCoffeeModule.kt",
],
plugins = [":dagger"],
deps = ["@kotlin_rules_maven//:com_google_dagger_dagger"],
)

kt_jvm_library(
name = "ksp_mixed_resources_multiple_plugins",
srcs = [
"CoffeeApp.kt",
"CoffeeAppModel.kt",
"CoffeeAppService.java",
"CoffeeMaker.kt",
"DripCoffeeModule.kt",
],
plugins = [
":autoservice",
":dagger",
":moshi",
],
deps = [
"@kotlin_rules_maven//:com_google_dagger_dagger",
"@kotlin_rules_maven//:com_squareup_moshi_moshi",
"@kotlin_rules_maven//:com_squareup_moshi_moshi_kotlin",
"@kotlin_rules_maven//:com_squareup_moshi_moshi_kotlin_codegen",
"@kotlin_rules_maven//:dev_zacsweers_autoservice_auto_service_ksp",
],
)

filegroup(
name = "ksp",
srcs = [
":coffee_lib.jar",
":moshi_lib.jar",
":ksp_kotlin_resources.jar",
":ksp_kotlin_resources_missing_plugin.jar",
":ksp_kotlin_resources_multiple_plugins.jar",
":ksp_kotlin_resources_multiple_plugins_no_java_gen.jar",
":ksp_mixed_resources.jar",
":ksp_mixed_resources_multiple_plugins.jar",
],
visibility = ["//visibility:public"],
)
17 changes: 10 additions & 7 deletions src/test/data/jvm/ksp/CoffeeApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package coffee
package src.test.data.jvm.ksp

import com.squareup.moshi.Moshi
import dagger.Component
import javax.inject.Singleton

class CoffeeApp {

companion object {
@Singleton
@Component(modules = [DripCoffeeModule::class])
interface CoffeeShop {
fun maker(): CoffeeMaker
}

private val adapter = CoffeeAppModelJsonAdapter(Moshi.Builder().build())
private val d = AutoValue_CoffeeAppJavaModel.Builder()
.setCoffeeAppModel(CoffeeAppModel("1"))
.build()
companion object {
private val coffeeShop = DaggerCoffeeApp_CoffeeShop.builder().build()
}
}
7 changes: 7 additions & 0 deletions src/test/data/jvm/ksp/CoffeeBean.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package src.test.data.jvm.ksp;

public class CoffeeBean {
public Boolean isGood() {
return true;
}
}
30 changes: 30 additions & 0 deletions src/test/data/jvm/ksp/CoffeeMaker.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2018 The Bazel Authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package src.test.data.jvm.ksp

import dagger.Lazy
import javax.inject.Inject

class CoffeeMaker @Inject internal constructor(
private val heater: Lazy<Heater>,
) {

fun brew() {
heater.get().on()
println(" [_]P coffee! [_]P ")
heater.get().off()
}
}
48 changes: 48 additions & 0 deletions src/test/data/jvm/ksp/DripCoffeeModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2018 The Bazel Authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package src.test.data.jvm.ksp

import dagger.Module
import dagger.Provides
import javax.inject.Singleton

@Module
internal class DripCoffeeModule {
@Provides
@Singleton
fun provideHeater(): Heater {
return ElectricHeater()
}
}

internal interface Heater {
val isHot: Boolean
fun on()
fun off()
}

internal class ElectricHeater : Heater {
override var isHot: Boolean = false

override fun on() {
println("~ ~ ~ heating ~ ~ ~")
this.isHot = true
}

override fun off() {
this.isHot = false
}
}
Loading

0 comments on commit 2f7e08c

Please sign in to comment.