Skip to content

Commit

Permalink
Update ksp test data (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
zalewskise committed Mar 20, 2024
1 parent 7e40ae8 commit 10e6c02
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 113 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.value:auto-value-annotations:1.10.1",
"com.google.auto.value:auto-value:1.10.1",
"com.google.code.findbugs:jsr305:3.0.2",
"com.google.dagger:dagger-compiler:2.43.2",
"com.google.dagger:dagger-producers:2.43.2",
"com.google.dagger:dagger:2.43.2",
"com.google.dagger:dagger-compiler:2.51",
"com.google.dagger:dagger-producers:2.51",
"com.google.dagger:dagger:2.51",
"com.google.guava:guava:27.1-jre",
"com.google.protobuf:protobuf-java-util:3.6.0",
"com.google.protobuf:protobuf-java:3.6.0",
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
25 changes: 20 additions & 5 deletions src/test/data/jvm/ksp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ 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 = "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 @@ -47,9 +53,18 @@ kt_jvm_library(

kt_jvm_library(
name = "coffee_lib",
srcs = ["CoffeeAppService.java"],
plugins = [":autoservice"],
srcs = [
"CoffeeApp.kt",
"CoffeeAppService.java",
"CoffeeMaker.kt",
"DripCoffeeModule.kt",
],
plugins = [
":autoservice",
":dagger",
],
deps = [
"@kotlin_rules_maven//:com_google_dagger_dagger",
"@kotlin_rules_maven//:dev_zacsweers_autoservice_auto_service_ksp",
],
)
Expand Down
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()
}
}
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
}
}
20 changes: 18 additions & 2 deletions src/test/kotlin/io/bazel/kotlin/KotlinJvmKspAssertionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,30 @@ class KotlinJvmKspAssertionTest: KotlinAssertionTestCase("src/test/data/jvm/ksp"
fun testKSPCopiesAllFilesFromMetaINF() {
jarTestCase("coffee_lib.jar", description = "Generated jar with ksp plugin contains meta-inf contents") {
assertContainsExactEntries(
"META-INF/",
"META-INF/MANIFEST.MF",
"META-INF/services/",
"META-INF/services/java.lang.Object",
"META-INF/src_test_data_jvm_ksp-coffee_lib.kotlin_module",
"src/",
"src/test/",
"src/test/data/",
"src/test/data/jvm/",
"src/test/data/jvm/ksp/",
"src/test/data/jvm/ksp/CoffeeApp.class",
"src/test/data/jvm/ksp/CoffeeAppService.class",
"META-INF/",
"META-INF/MANIFEST.MF"
"src/test/data/jvm/ksp/CoffeeApp\$CoffeeShop.class",
"src/test/data/jvm/ksp/CoffeeApp\$Companion.class",
"src/test/data/jvm/ksp/CoffeeMaker.class",
"src/test/data/jvm/ksp/CoffeeMaker_Factory.class",
"src/test/data/jvm/ksp/DaggerCoffeeApp_CoffeeShop\$1.class",
"src/test/data/jvm/ksp/DaggerCoffeeApp_CoffeeShop.class",
"src/test/data/jvm/ksp/DaggerCoffeeApp_CoffeeShop\$Builder.class",
"src/test/data/jvm/ksp/DaggerCoffeeApp_CoffeeShop\$CoffeeShopImpl.class",
"src/test/data/jvm/ksp/DripCoffeeModule.class",
"src/test/data/jvm/ksp/DripCoffeeModule_ProvideHeaterFactory.class",
"src/test/data/jvm/ksp/ElectricHeater.class",
"src/test/data/jvm/ksp/Heater.class",
)
}
}
Expand Down

0 comments on commit 10e6c02

Please sign in to comment.