Skip to content

Commit

Permalink
Fix wrapper types from peer projects (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewparmet authored Sep 3, 2023
1 parent 50b30d1 commit 77c3257
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ workflows:
matrix:
parameters:
jdk: ["8", "11", "17"]
kotlin: ["1.5.32", "1.6.21", "1.7.20", "1.8.0"]
kotlin: ["1.6.21", "1.7.21", "1.8.22"]
- release:
context: OSS
filters:
Expand Down
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/Lint.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fun Project.lint() {
ktlint()
target("**/*.kt")
targetExclude("**/generated-sources/**")
targetExclude("**/generated/source/**")
}

kotlinGradle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package com.toasttab.protokt.gradle

import com.google.protobuf.gradle.GenerateProtoTask
import com.google.protobuf.gradle.ProtobufExtension
import com.google.protobuf.gradle.ProtobufExtract
import com.google.protobuf.gradle.id
import org.gradle.api.Project
import org.gradle.api.file.FileCollection
Expand All @@ -25,6 +26,7 @@ import org.gradle.jvm.tasks.Jar
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.withType
import java.net.URLEncoder

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

// Must explicitly register input files here; if any extensions dependencies are project dependencies then Gradle
// won't pick them up as dependencies unless we do this. There may be a better way to do this but for now just
// manually do what protobuf-gradle-plugin used to do.
// https://github.com/google/protobuf-gradle-plugin/commit/0521fe707ccedee7a0b4ce0fb88409eefb04e59d
project.tasks.withType<ProtobufExtract> {
if (name.startsWith("extractInclude")) {
inputFiles.from(extensions)
}
}

return extensions.joinToString(";") { URLEncoder.encode(it.path, "UTF-8") }
}

Expand Down
4 changes: 2 additions & 2 deletions gradle-plugin-integration-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ buildscript {

dependencies {
classpath("com.toasttab.protokt:protokt-gradle-plugin:$version")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${System.getProperty("kotlin.version", "1.4.32")}")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${System.getProperty("kotlin.version", "1.6.32")}")
classpath("com.diffplug.spotless:spotless-plugin-gradle:5.15.0")
}
}
Expand Down Expand Up @@ -63,7 +63,7 @@ subprojects {
apiVersion =
System.getProperty("kotlin.version")
?.substringBeforeLast(".")
?: "1.4"
?: "1.6"

languageVersion = apiVersion
}
Expand Down
1 change: 1 addition & 0 deletions gradle-plugin-integration-test/jvm-lite/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ tasks {

dependencies {
protoktExtensions("com.toasttab.protokt:protokt-extensions-lite:$version")
protoktExtensions(project(":wrapper-types"))

testImplementation(kotlin("test-junit5"))
testImplementation("org.junit.jupiter:junit-jupiter:5.7.2")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2023 Toast, Inc.
*
* 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.
*/

syntax = "proto3";

package toasttab.protokt.testing;

option java_package = "com.toasttab.protokt.testing";

import "protokt/protokt.proto";

message WrapperTest {
bytes foo = 1 [(.protokt.property).wrap = "Id"];
}
1 change: 1 addition & 0 deletions gradle-plugin-integration-test/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ rootProject.name = "gradle-plugin-integration-test"
listOf(
"jvm-regular",
"jvm-lite",
"wrapper-types"
).forEach { include(it) }
31 changes: 31 additions & 0 deletions gradle-plugin-integration-test/wrapper-types/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2023 Toast, Inc.
*
* 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.
*/

plugins {
kotlin("jvm")
kotlin("kapt")
}

dependencies {
implementation("com.toasttab.protokt:protokt-core:$version")
implementation("com.google.auto.service:auto-service-annotations:1.0.1")

kapt("com.google.auto.service:auto-service:1.0.1")
}

configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2023 Toast, Inc.
*
* 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 com.toasttab.protokt.testing

import com.google.auto.service.AutoService
import com.toasttab.protokt.ext.Converter

data class Id(val value: String)

@AutoService(Converter::class)
object IdConverter : Converter<Id, ByteArray> {
override val wrapper = Id::class

override val wrapped = ByteArray::class

override fun wrap(unwrapped: ByteArray) =
Id(String(unwrapped))

override fun unwrap(wrapped: Id) =
wrapped.value.toByteArray()
}

0 comments on commit 77c3257

Please sign in to comment.