Adding kotlin bazel tests
diff --git a/java/kotlin/BUILD b/java/kotlin/BUILD
new file mode 100644
index 0000000..97c8162
--- /dev/null
+++ b/java/kotlin/BUILD
@@ -0,0 +1,278 @@
+load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library", "kt_jvm_test", "kt_jvm_binary")
+load("@rules_java//java:defs.bzl", "java_proto_library")
+load("@rules_jvm_external//:defs.bzl", "java_export")
+load("@rules_proto//proto:defs.bzl", "proto_library")
+load("//:protobuf_version.bzl", "PROTOBUF_VERSION")
+
+# Kotlin generated protos depend on this and only this.
+kt_jvm_library(
+ name = "shared_runtime",
+ srcs = [
+ "src/main/kotlin/com/google/protobuf/DslList.kt",
+ "src/main/kotlin/com/google/protobuf/DslMap.kt",
+ "src/main/kotlin/com/google/protobuf/DslProxy.kt",
+ "src/main/kotlin/com/google/protobuf/ExtensionList.kt",
+ "src/main/kotlin/com/google/protobuf/ProtoDslMarker.kt",
+ "src/main/kotlin/com/google/protobuf/UnmodifiableCollections.kt",
+ ],
+ visibility = ["//visibility:public"],
+ deps = [
+ ":only_for_use_in_proto_generated_code_its_generator_and_tests",
+ "//java/lite",
+ ],
+)
+
+kt_jvm_library(
+ name = "only_for_use_in_proto_generated_code_its_generator_and_tests",
+ srcs = ["src/main/kotlin/com/google/protobuf/OnlyForUseByGeneratedProtoCode.kt"],
+ visibility = ["//java:__subpackages__"],
+)
+
+kt_jvm_library(
+ name = "bytestring_lib",
+ srcs = ["src/main/kotlin/com/google/protobuf/ByteStrings.kt"],
+ deps = ["//java/lite"],
+)
+
+kt_jvm_library(
+ name = "full_extensions",
+ srcs = ["src/main/kotlin/com/google/protobuf/ExtendableMessageExtensions.kt"],
+ deps = ["//java/core"],
+)
+
+test_suite(
+ name = "tests",
+ tests = [
+ "bytestring_test",
+ "shared_tests",
+ "test_extensions",
+ "proto2_test",
+ "proto3_test",
+ ],
+)
+
+kt_jvm_test(
+ name = "bytestring_test",
+ srcs = ["src/test/kotlin/com/google/protobuf/ByteStringsTest.kt"],
+ deps = [
+ ":bytestring_lib",
+ "//java/lite",
+ "@com_github_jetbrains_kotlin//:kotlin-test",
+ "@maven//:com_google_truth_truth",
+ "@maven//:junit_junit",
+ ],
+ test_class = "com.google.protobuf.kotlin.ByteStringsTest",
+)
+
+proto_library(
+ name = "example_extensible_message_proto",
+ srcs = ["src/test/proto/com/google/protobuf/example_extensible_message.proto"],
+ visibility = ["//visibility:public"],
+)
+
+java_proto_library(
+ name = "example_extensible_message_java_proto",
+ deps = [":example_extensible_message_proto"],
+)
+
+kt_jvm_test(
+ name = "shared_tests",
+ srcs = [
+ "src/test/kotlin/com/google/protobuf/DslListTest.kt",
+ "src/test/kotlin/com/google/protobuf/DslMapTest.kt",
+ "src/test/kotlin/com/google/protobuf/ExtensionListTest.kt",
+ ],
+ deps = [
+ ":bytestring_lib",
+ ":example_extensible_message_java_proto",
+ ":only_for_use_in_proto_generated_code_its_generator_and_tests",
+ ":shared_runtime",
+ "@com_github_jetbrains_kotlin//:kotlin-test",
+ "@maven//:com_google_truth_truth",
+ "@maven//:com_google_guava_guava_testlib",
+ "@maven//:junit_junit",
+ ],
+ test_class = "com.google.protobuf.kotlin.DslListTest",
+)
+
+kt_jvm_test(
+ name = "test_extensions",
+ srcs = ["src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt"],
+ deps = [
+ ":example_extensible_message_java_proto",
+ ":full_extensions",
+ "//java/lite",
+ ":only_for_use_in_proto_generated_code_its_generator_and_tests",
+ ":shared_runtime",
+ "@com_github_jetbrains_kotlin//:kotlin-test",
+ "@maven//:com_google_truth_truth",
+ "@maven//:junit_junit",
+ ],
+ test_class = "com.google.protobuf.kotlin.ExtendableMessageExtensionsTest",
+)
+
+proto_library(
+ name = "evil_names_proto2",
+ srcs = ["src/test/proto/com/google/protobuf/evil_names_proto2.proto"],
+ visibility = ["//:__subpackages__"],
+)
+
+proto_library(
+ name = "evil_names_proto3",
+ srcs = ["src/test/proto/com/google/protobuf/evil_names_proto3.proto"],
+ visibility = ["//:__subpackages__"],
+)
+
+java_proto_library(
+ name = "evil_names_proto2_java_proto",
+ deps = [":evil_names_proto2"],
+)
+
+java_proto_library(
+ name = "evil_names_proto3_java_proto",
+ deps = [":evil_names_proto3"],
+)
+
+proto_library(
+ name = "multiple_files_proto3",
+ srcs = ["src/test/proto/com/google/protobuf/multiple_files_proto3.proto"],
+ visibility = ["//:__subpackages__"],
+)
+
+java_proto_library( name = "multiple_files_proto3_java_proto",
+ deps = [":multiple_files_proto3"],
+)
+
+genrule(
+ name = "gen_kotlin_proto3_java_multiple_files",
+ srcs = ["src/test/proto/com/google/protobuf/multiple_files_proto3.proto"],
+ outs = [
+ "MultipleFilesMessageAKt.kt",
+ "MultipleFilesMessageBKt.kt",
+ "MultipleFilesProto3Kt.kt",
+ ],
+ cmd = "$(location //:protoc) " +
+ "--kotlin_out=shared,immutable:$(@D) " +
+ "$(location src/test/proto/com/google/protobuf/multiple_files_proto3.proto) && " +
+ "cp $(@D)/com/google/protobuf/kotlin/generator/MultipleFilesMessageAKt.kt " +
+ "$(location MultipleFilesMessageAKt.kt) && " +
+ "cp $(@D)/com/google/protobuf/kotlin/generator/MultipleFilesMessageBKt.kt " +
+ "$(location MultipleFilesMessageBKt.kt) && " +
+ "cp $(@D)/com/google/protobuf/kotlin/generator/MultipleFilesProto3Kt.kt " +
+ "$(location MultipleFilesProto3Kt.kt)",
+ tools = ["//:protoc"],
+)
+
+genrule(
+ name = "gen_evil_names_proto2",
+ srcs = ["src/test/proto/com/google/protobuf/evil_names_proto2.proto"],
+ outs = [
+ "EvilNamesProto2Kt.kt",
+ "HardKeywordsAllTypesProto2Kt.kt",
+ "InterfaceKt.kt",
+ ],
+ cmd = "$(location //:protoc) " +
+ "--kotlin_out=shared,immutable:$(@D) " +
+ "$(location src/test/proto/com/google/protobuf/evil_names_proto2.proto) && " +
+ "cp $(@D)/com/google/protobuf/kotlin/generator/EvilNamesProto2Kt.kt " +
+ "$(location EvilNamesProto2Kt.kt) && " +
+ "cp $(@D)/com/google/protobuf/kotlin/generator/HardKeywordsAllTypesProto2Kt.kt " +
+ "$(location HardKeywordsAllTypesProto2Kt.kt) && " +
+ "cp $(@D)/com/google/protobuf/kotlin/generator/InterfaceKt.kt " +
+ "$(location InterfaceKt.kt)",
+ tools = ["//:protoc"],
+)
+
+genrule(
+ name = "gen_evil_names_proto3",
+ srcs = ["src/test/proto/com/google/protobuf/evil_names_proto3.proto"],
+ outs = [
+ "ClassKt.kt",
+ "EvilNamesProto3Kt.kt",
+ "HardKeywordsAllTypesProto3Kt.kt",
+ ],
+ cmd = "$(location //:protoc) " +
+ "--kotlin_out=shared,immutable:$(@D) " +
+ "$(location src/test/proto/com/google/protobuf/evil_names_proto3.proto) && " +
+ "cp $(@D)/com/google/protobuf/kotlin/generator/ClassKt.kt " +
+ "$(location ClassKt.kt) && " +
+ "cp $(@D)/com/google/protobuf/kotlin/generator/EvilNamesProto3Kt.kt " +
+ "$(location EvilNamesProto3Kt.kt) && " +
+ "cp $(@D)/com/google/protobuf/kotlin/generator/HardKeywordsAllTypesProto3Kt.kt " +
+ "$(location HardKeywordsAllTypesProto3Kt.kt)",
+ tools = ["//:protoc"],
+)
+
+kt_jvm_library(
+ name = "kotlin_unittest",
+ srcs = [
+ ":gen_evil_names_proto2",
+ "//:gen_kotlin_unittest",
+ ],
+ deps = [
+ ":evil_names_proto2_java_proto",
+ "//java/core:core",
+ ":only_for_use_in_proto_generated_code_its_generator_and_tests",
+ ":shared_runtime",
+ "//:java_test_protos",
+ ],
+)
+
+kt_jvm_library(
+ name = "kotlin_proto3_unittest",
+ srcs = [
+ ":gen_evil_names_proto3",
+ ":gen_kotlin_proto3_java_multiple_files",
+ "//:gen_kotlin_proto3_unittest",
+ ],
+ deps = [
+ ":evil_names_proto3_java_proto",
+ ":multiple_files_proto3_java_proto",
+ "//java/core:core",
+ ":only_for_use_in_proto_generated_code_its_generator_and_tests",
+ ":shared_runtime",
+ "//:java_test_protos",
+ ],
+)
+
+kt_jvm_test(
+ name = "proto2_test",
+ srcs = ["src/test/kotlin/com/google/protobuf/Proto2Test.kt"],
+ deps = [
+ ":kotlin_unittest",
+ "//java/core:test_util",
+ "@maven//:com_google_truth_truth",
+ "@maven//:junit_junit",
+ ],
+ test_class = "com.google.protobuf.kotlin.Proto2Test",
+)
+
+kt_jvm_test(
+ name = "proto3_test",
+ srcs = ["src/test/kotlin/com/google/protobuf/Proto3Test.kt"],
+ deps = [
+ ":kotlin_proto3_unittest",
+ "//java/core:test_util",
+ "@maven//:com_google_truth_truth",
+ "@maven//:junit_junit",
+ ],
+ test_class = "com.google.protobuf.kotlin.Proto3Test",
+)
+
+java_export(
+ name = "kotlin_mvn",
+ maven_coordinates = "com.google.protobuf:protobuf-kotlin:%s" % PROTOBUF_VERSION,
+ pom_template = "pom_template.xml",
+ runtime_deps = [":shared_runtime"],
+)
+
+filegroup(
+ name = "release",
+ srcs = [
+ ":kotlin_mvn-docs",
+ ":kotlin_mvn-maven-source",
+ ":kotlin_mvn-pom",
+ ":kotlin_mvn-project",
+ ],
+ visibility = ["//java:__pkg__"],
+)
diff --git a/java/kotlin/pom.xml b/java/kotlin/pom.xml
index a275f24..4157a53 100644
--- a/java/kotlin/pom.xml
+++ b/java/kotlin/pom.xml
@@ -9,9 +9,9 @@
<artifactId>protobuf-kotlin</artifactId>
- <name>Protocol Buffers [Core]</name>
+ <name>Protocol Buffers [Kotlin-Core]</name>
<description>
- Core Protocol Buffers library. Protocol Buffers are a way of encoding structured data in an
+ Kotlin core Protocol Buffers library. Protocol Buffers are a way of encoding structured data in an
efficient yet extensible format.
</description>
diff --git a/java/kotlin/pom_template.xml b/java/kotlin/pom_template.xml
new file mode 100644
index 0000000..3231fb3
--- /dev/null
+++ b/java/kotlin/pom_template.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>{groupId}</groupId>
+ <artifactId>protobuf-parent</artifactId>
+ <version>{version}</version>
+ </parent>
+
+ <artifactId>{artifactId}</artifactId>
+ <packaging>{type}</packaging>
+
+ <name>Protocol Buffers [Kotlin]</name>
+ <description>
+ Kotlin core Protocol Buffers library. Protocol Buffers are a way of encoding structured data in an
+ efficient yet extensible format.
+ </description>
+
+ <properties>
+ <kotlin.version>1.5.0</kotlin.version>
+ </properties>
+
+</project>
diff --git a/java/kotlin/src/main/kotlin/com/google/protobuf/ExtendableMessageLiteExtensions.kt b/java/kotlin/src/main/kotlin/com/google/protobuf/ExtendableMessageLiteExtensions.kt
deleted file mode 100644
index 6c208b2..0000000
--- a/java/kotlin/src/main/kotlin/com/google/protobuf/ExtendableMessageLiteExtensions.kt
+++ /dev/null
@@ -1,58 +0,0 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// https://developers.google.com/protocol-buffers/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-package com.google.protobuf.kotlin
-
-import com.google.protobuf.ExtensionLite
-import com.google.protobuf.GeneratedMessageLite
-
-/** Gets the value of the proto extension. */
-operator fun <
- M : GeneratedMessageLite.ExtendableMessage<M, *>,
- MOrBT : GeneratedMessageLite.ExtendableMessageOrBuilder<M, *>,
- T : Any
- > MOrBT.get(extension: ExtensionLite<M, T>): T = getExtension(extension)
-
-/** Sets the current value of the proto extension in this builder. */
-operator fun <
- M : GeneratedMessageLite.ExtendableMessage<M, B>,
- B : GeneratedMessageLite.ExtendableBuilder<M, B>,
- T : Any
- > B.set(extension: ExtensionLite<M, T>, value: T) {
- setExtension(extension, value)
-}
-
-/** Returns true if the specified extension is set. */
-operator fun <
- M : GeneratedMessageLite.ExtendableMessage<M, *>,
- MorBT : GeneratedMessageLite.ExtendableMessageOrBuilder<M, *>
- > MorBT.contains(
- extension: ExtensionLite<M, *>
-): Boolean = hasExtension(extension)