Skip to content

Commit 77c3257

Browse files
authored
Fix wrapper types from peer projects (#194)
1 parent 50b30d1 commit 77c3257

File tree

9 files changed

+109
-3
lines changed

9 files changed

+109
-3
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ workflows:
122122
matrix:
123123
parameters:
124124
jdk: ["8", "11", "17"]
125-
kotlin: ["1.5.32", "1.6.21", "1.7.20", "1.8.0"]
125+
kotlin: ["1.6.21", "1.7.21", "1.8.22"]
126126
- release:
127127
context: OSS
128128
filters:

buildSrc/src/main/kotlin/Lint.kt

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ fun Project.lint() {
3131
ktlint()
3232
target("**/*.kt")
3333
targetExclude("**/generated-sources/**")
34+
targetExclude("**/generated/source/**")
3435
}
3536

3637
kotlinGradle {

buildSrc/src/main/kotlin/com/toasttab/protokt/gradle/ProtobufBuild.kt

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package com.toasttab.protokt.gradle
1717

1818
import com.google.protobuf.gradle.GenerateProtoTask
1919
import com.google.protobuf.gradle.ProtobufExtension
20+
import com.google.protobuf.gradle.ProtobufExtract
2021
import com.google.protobuf.gradle.id
2122
import org.gradle.api.Project
2223
import org.gradle.api.file.FileCollection
@@ -25,6 +26,7 @@ import org.gradle.jvm.tasks.Jar
2526
import org.gradle.kotlin.dsl.apply
2627
import org.gradle.kotlin.dsl.configure
2728
import org.gradle.kotlin.dsl.named
29+
import org.gradle.kotlin.dsl.withType
2830
import java.net.URLEncoder
2931

3032
internal fun configureProtobufPlugin(project: Project, ext: ProtoktExtension, binaryPath: String) {
@@ -73,6 +75,16 @@ private fun extraClasspath(project: Project, task: GenerateProtoTask): String {
7375
extensions += project.configurations.getByName(TEST_EXTENSIONS)
7476
}
7577

78+
// Must explicitly register input files here; if any extensions dependencies are project dependencies then Gradle
79+
// won't pick them up as dependencies unless we do this. There may be a better way to do this but for now just
80+
// manually do what protobuf-gradle-plugin used to do.
81+
// https://github.com/google/protobuf-gradle-plugin/commit/0521fe707ccedee7a0b4ce0fb88409eefb04e59d
82+
project.tasks.withType<ProtobufExtract> {
83+
if (name.startsWith("extractInclude")) {
84+
inputFiles.from(extensions)
85+
}
86+
}
87+
7688
return extensions.joinToString(";") { URLEncoder.encode(it.path, "UTF-8") }
7789
}
7890

gradle-plugin-integration-test/build.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ buildscript {
3030

3131
dependencies {
3232
classpath("com.toasttab.protokt:protokt-gradle-plugin:$version")
33-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${System.getProperty("kotlin.version", "1.4.32")}")
33+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${System.getProperty("kotlin.version", "1.6.32")}")
3434
classpath("com.diffplug.spotless:spotless-plugin-gradle:5.15.0")
3535
}
3636
}
@@ -63,7 +63,7 @@ subprojects {
6363
apiVersion =
6464
System.getProperty("kotlin.version")
6565
?.substringBeforeLast(".")
66-
?: "1.4"
66+
?: "1.6"
6767

6868
languageVersion = apiVersion
6969
}

gradle-plugin-integration-test/jvm-lite/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ tasks {
3030

3131
dependencies {
3232
protoktExtensions("com.toasttab.protokt:protokt-extensions-lite:$version")
33+
protoktExtensions(project(":wrapper-types"))
3334

3435
testImplementation(kotlin("test-junit5"))
3536
testImplementation("org.junit.jupiter:junit-jupiter:5.7.2")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2023 Toast, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
syntax = "proto3";
17+
18+
package toasttab.protokt.testing;
19+
20+
option java_package = "com.toasttab.protokt.testing";
21+
22+
import "protokt/protokt.proto";
23+
24+
message WrapperTest {
25+
bytes foo = 1 [(.protokt.property).wrap = "Id"];
26+
}

gradle-plugin-integration-test/settings.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ rootProject.name = "gradle-plugin-integration-test"
2929
listOf(
3030
"jvm-regular",
3131
"jvm-lite",
32+
"wrapper-types"
3233
).forEach { include(it) }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) 2023 Toast, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
plugins {
17+
kotlin("jvm")
18+
kotlin("kapt")
19+
}
20+
21+
dependencies {
22+
implementation("com.toasttab.protokt:protokt-core:$version")
23+
implementation("com.google.auto.service:auto-service-annotations:1.0.1")
24+
25+
kapt("com.google.auto.service:auto-service:1.0.1")
26+
}
27+
28+
configure<JavaPluginExtension> {
29+
sourceCompatibility = JavaVersion.VERSION_1_8
30+
targetCompatibility = JavaVersion.VERSION_1_8
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2023 Toast, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
package com.toasttab.protokt.testing
17+
18+
import com.google.auto.service.AutoService
19+
import com.toasttab.protokt.ext.Converter
20+
21+
data class Id(val value: String)
22+
23+
@AutoService(Converter::class)
24+
object IdConverter : Converter<Id, ByteArray> {
25+
override val wrapper = Id::class
26+
27+
override val wrapped = ByteArray::class
28+
29+
override fun wrap(unwrapped: ByteArray) =
30+
Id(String(unwrapped))
31+
32+
override fun unwrap(wrapped: Id) =
33+
wrapped.value.toByteArray()
34+
}

0 commit comments

Comments
 (0)