From 0a34e50f742ab74598c81f153cfe8ad90bf3a859 Mon Sep 17 00:00:00 2001 From: Filipe Regadas Date: Thu, 3 Jun 2021 07:27:36 +0100 Subject: [PATCH] Update chill-protobuf with protobuf 3.17.1 (#571) --- build.sbt | 6 +- .../twitter/chill/protobuf/TestMessages.java | 569 ------------------ .../src/test/protobuf/test_messages.proto | 16 + chill-protobuf/src/test/resources/genproto.sh | 1 - .../src/test/resources/test_messages.proto | 13 - .../twitter/chill/protobuf/ProtobufTest.scala | 14 +- project/plugins.sbt | 3 + 7 files changed, 34 insertions(+), 588 deletions(-) delete mode 100644 chill-protobuf/src/test/java/com/twitter/chill/protobuf/TestMessages.java create mode 100644 chill-protobuf/src/test/protobuf/test_messages.proto delete mode 100755 chill-protobuf/src/test/resources/genproto.sh delete mode 100644 chill-protobuf/src/test/resources/test_messages.proto diff --git a/build.sbt b/build.sbt index 0cb705bd..3dc4820b 100644 --- a/build.sbt +++ b/build.sbt @@ -6,6 +6,7 @@ val bijectionVersion = "0.9.7" val kryoVersion = "4.0.2" val scroogeVersion = "21.2.0" val asmVersion = "4.15" +val protobufVersion = "3.17.1" def scalaVersionSpecificFolders(srcBaseDir: java.io.File, scalaVersion: String): List[File] = CrossVersion.partialVersion(scalaVersion) match { @@ -260,8 +261,9 @@ lazy val chillProtobuf = module("protobuf") .settings( crossPaths := false, autoScalaLibrary := false, - libraryDependencies ++= Seq( - "com.google.protobuf" % "protobuf-java" % "2.3.0" % "provided" + libraryDependencies += "com.google.protobuf" % "protobuf-java" % protobufVersion % Provided, + Test / PB.targets := Seq( + PB.gens.java(protobufVersion) -> (Test / sourceManaged).value ) ) .dependsOn(chillJava) diff --git a/chill-protobuf/src/test/java/com/twitter/chill/protobuf/TestMessages.java b/chill-protobuf/src/test/java/com/twitter/chill/protobuf/TestMessages.java deleted file mode 100644 index 1824ac00..00000000 --- a/chill-protobuf/src/test/java/com/twitter/chill/protobuf/TestMessages.java +++ /dev/null @@ -1,569 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: test_messages.proto - -package com.twitter.chill.protobuf; - -public final class TestMessages { - private TestMessages() {} - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistry registry) { - } - public enum Gender - implements com.google.protobuf.ProtocolMessageEnum { - MALE(0, 0), - FEMALE(1, 1), - ; - - - public final int getNumber() { return value; } - - public static Gender valueOf(int value) { - switch (value) { - case 0: return MALE; - case 1: return FEMALE; - default: return null; - } - } - - public static com.google.protobuf.Internal.EnumLiteMap - internalGetValueMap() { - return internalValueMap; - } - private static com.google.protobuf.Internal.EnumLiteMap - internalValueMap = - new com.google.protobuf.Internal.EnumLiteMap() { - public Gender findValueByNumber(int number) { - return Gender.valueOf(number) - ; } - }; - - public final com.google.protobuf.Descriptors.EnumValueDescriptor - getValueDescriptor() { - return getDescriptor().getValues().get(index); - } - public final com.google.protobuf.Descriptors.EnumDescriptor - getDescriptorForType() { - return getDescriptor(); - } - public static final com.google.protobuf.Descriptors.EnumDescriptor - getDescriptor() { - return com.twitter.chill.protobuf.TestMessages.getDescriptor().getEnumTypes().get(0); - } - - private static final Gender[] VALUES = { - MALE, FEMALE, - }; - public static Gender valueOf( - com.google.protobuf.Descriptors.EnumValueDescriptor desc) { - if (desc.getType() != getDescriptor()) { - throw new java.lang.IllegalArgumentException( - "EnumValueDescriptor is not for this type."); - } - return VALUES[desc.getIndex()]; - } - private final int index; - private final int value; - private Gender(int index, int value) { - this.index = index; - this.value = value; - } - - static { - com.twitter.chill.protobuf.TestMessages.getDescriptor(); - } - - // @@protoc_insertion_point(enum_scope:com.twitter.chill.protobuf.Gender) - } - - public static final class FatigueCount extends - com.google.protobuf.GeneratedMessage { - // Use FatigueCount.newBuilder() to construct. - private FatigueCount() { - initFields(); - } - private FatigueCount(boolean noInit) {} - - private static final FatigueCount defaultInstance; - public static FatigueCount getDefaultInstance() { - return defaultInstance; - } - - public FatigueCount getDefaultInstanceForType() { - return defaultInstance; - } - - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return com.twitter.chill.protobuf.TestMessages.internal_static_com_twitter_chill_protobuf_FatigueCount_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return com.twitter.chill.protobuf.TestMessages.internal_static_com_twitter_chill_protobuf_FatigueCount_fieldAccessorTable; - } - - // required int64 target_id = 1; - public static final int TARGET_ID_FIELD_NUMBER = 1; - private boolean hasTargetId; - private long targetId_ = 0L; - public boolean hasTargetId() { return hasTargetId; } - public long getTargetId() { return targetId_; } - - // required int64 suggested_id = 2; - public static final int SUGGESTED_ID_FIELD_NUMBER = 2; - private boolean hasSuggestedId; - private long suggestedId_ = 0L; - public boolean hasSuggestedId() { return hasSuggestedId; } - public long getSuggestedId() { return suggestedId_; } - - // required int32 serve_count = 3; - public static final int SERVE_COUNT_FIELD_NUMBER = 3; - private boolean hasServeCount; - private int serveCount_ = 0; - public boolean hasServeCount() { return hasServeCount; } - public int getServeCount() { return serveCount_; } - - // repeated int64 recent_clicks = 4; - public static final int RECENT_CLICKS_FIELD_NUMBER = 4; - private java.util.List recentClicks_ = - java.util.Collections.emptyList(); - public java.util.List getRecentClicksList() { - return recentClicks_; - } - public int getRecentClicksCount() { return recentClicks_.size(); } - public long getRecentClicks(int index) { - return recentClicks_.get(index); - } - - private void initFields() { - } - public final boolean isInitialized() { - if (!hasTargetId) return false; - if (!hasSuggestedId) return false; - if (!hasServeCount) return false; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - getSerializedSize(); - if (hasTargetId()) { - output.writeInt64(1, getTargetId()); - } - if (hasSuggestedId()) { - output.writeInt64(2, getSuggestedId()); - } - if (hasServeCount()) { - output.writeInt32(3, getServeCount()); - } - for (long element : getRecentClicksList()) { - output.writeInt64(4, element); - } - getUnknownFields().writeTo(output); - } - - private int memoizedSerializedSize = -1; - public int getSerializedSize() { - int size = memoizedSerializedSize; - if (size != -1) return size; - - size = 0; - if (hasTargetId()) { - size += com.google.protobuf.CodedOutputStream - .computeInt64Size(1, getTargetId()); - } - if (hasSuggestedId()) { - size += com.google.protobuf.CodedOutputStream - .computeInt64Size(2, getSuggestedId()); - } - if (hasServeCount()) { - size += com.google.protobuf.CodedOutputStream - .computeInt32Size(3, getServeCount()); - } - { - int dataSize = 0; - for (long element : getRecentClicksList()) { - dataSize += com.google.protobuf.CodedOutputStream - .computeInt64SizeNoTag(element); - } - size += dataSize; - size += 1 * getRecentClicksList().size(); - } - size += getUnknownFields().getSerializedSize(); - memoizedSerializedSize = size; - return size; - } - - public static com.twitter.chill.protobuf.TestMessages.FatigueCount parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return newBuilder().mergeFrom(data).buildParsed(); - } - public static com.twitter.chill.protobuf.TestMessages.FatigueCount parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return newBuilder().mergeFrom(data, extensionRegistry) - .buildParsed(); - } - public static com.twitter.chill.protobuf.TestMessages.FatigueCount parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return newBuilder().mergeFrom(data).buildParsed(); - } - public static com.twitter.chill.protobuf.TestMessages.FatigueCount parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return newBuilder().mergeFrom(data, extensionRegistry) - .buildParsed(); - } - public static com.twitter.chill.protobuf.TestMessages.FatigueCount parseFrom(java.io.InputStream input) - throws java.io.IOException { - return newBuilder().mergeFrom(input).buildParsed(); - } - public static com.twitter.chill.protobuf.TestMessages.FatigueCount parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return newBuilder().mergeFrom(input, extensionRegistry) - .buildParsed(); - } - public static com.twitter.chill.protobuf.TestMessages.FatigueCount parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - Builder builder = newBuilder(); - if (builder.mergeDelimitedFrom(input)) { - return builder.buildParsed(); - } else { - return null; - } - } - public static com.twitter.chill.protobuf.TestMessages.FatigueCount parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - Builder builder = newBuilder(); - if (builder.mergeDelimitedFrom(input, extensionRegistry)) { - return builder.buildParsed(); - } else { - return null; - } - } - public static com.twitter.chill.protobuf.TestMessages.FatigueCount parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return newBuilder().mergeFrom(input).buildParsed(); - } - public static com.twitter.chill.protobuf.TestMessages.FatigueCount parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return newBuilder().mergeFrom(input, extensionRegistry) - .buildParsed(); - } - - public static Builder newBuilder() { return Builder.create(); } - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder(com.twitter.chill.protobuf.TestMessages.FatigueCount prototype) { - return newBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { return newBuilder(this); } - - public static final class Builder extends - com.google.protobuf.GeneratedMessage.Builder { - private com.twitter.chill.protobuf.TestMessages.FatigueCount result; - - // Construct using com.twitter.chill.protobuf.TestMessages.FatigueCount.newBuilder() - private Builder() {} - - private static Builder create() { - Builder builder = new Builder(); - builder.result = new com.twitter.chill.protobuf.TestMessages.FatigueCount(); - return builder; - } - - protected com.twitter.chill.protobuf.TestMessages.FatigueCount internalGetResult() { - return result; - } - - public Builder clear() { - if (result == null) { - throw new IllegalStateException( - "Cannot call clear() after build()."); - } - result = new com.twitter.chill.protobuf.TestMessages.FatigueCount(); - return this; - } - - public Builder clone() { - return create().mergeFrom(result); - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return com.twitter.chill.protobuf.TestMessages.FatigueCount.getDescriptor(); - } - - public com.twitter.chill.protobuf.TestMessages.FatigueCount getDefaultInstanceForType() { - return com.twitter.chill.protobuf.TestMessages.FatigueCount.getDefaultInstance(); - } - - public boolean isInitialized() { - return result.isInitialized(); - } - public com.twitter.chill.protobuf.TestMessages.FatigueCount build() { - if (result != null && !isInitialized()) { - throw newUninitializedMessageException(result); - } - return buildPartial(); - } - - private com.twitter.chill.protobuf.TestMessages.FatigueCount buildParsed() - throws com.google.protobuf.InvalidProtocolBufferException { - if (!isInitialized()) { - throw newUninitializedMessageException( - result).asInvalidProtocolBufferException(); - } - return buildPartial(); - } - - public com.twitter.chill.protobuf.TestMessages.FatigueCount buildPartial() { - if (result == null) { - throw new IllegalStateException( - "build() has already been called on this Builder."); - } - if (result.recentClicks_ != java.util.Collections.EMPTY_LIST) { - result.recentClicks_ = - java.util.Collections.unmodifiableList(result.recentClicks_); - } - com.twitter.chill.protobuf.TestMessages.FatigueCount returnMe = result; - result = null; - return returnMe; - } - - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof com.twitter.chill.protobuf.TestMessages.FatigueCount) { - return mergeFrom((com.twitter.chill.protobuf.TestMessages.FatigueCount)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(com.twitter.chill.protobuf.TestMessages.FatigueCount other) { - if (other == com.twitter.chill.protobuf.TestMessages.FatigueCount.getDefaultInstance()) return this; - if (other.hasTargetId()) { - setTargetId(other.getTargetId()); - } - if (other.hasSuggestedId()) { - setSuggestedId(other.getSuggestedId()); - } - if (other.hasServeCount()) { - setServeCount(other.getServeCount()); - } - if (!other.recentClicks_.isEmpty()) { - if (result.recentClicks_.isEmpty()) { - result.recentClicks_ = new java.util.ArrayList(); - } - result.recentClicks_.addAll(other.recentClicks_); - } - this.mergeUnknownFields(other.getUnknownFields()); - return this; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder( - this.getUnknownFields()); - while (true) { - int tag = input.readTag(); - switch (tag) { - case 0: - this.setUnknownFields(unknownFields.build()); - return this; - default: { - if (!parseUnknownField(input, unknownFields, - extensionRegistry, tag)) { - this.setUnknownFields(unknownFields.build()); - return this; - } - break; - } - case 8: { - setTargetId(input.readInt64()); - break; - } - case 16: { - setSuggestedId(input.readInt64()); - break; - } - case 24: { - setServeCount(input.readInt32()); - break; - } - case 32: { - addRecentClicks(input.readInt64()); - break; - } - case 34: { - int length = input.readRawVarint32(); - int limit = input.pushLimit(length); - while (input.getBytesUntilLimit() > 0) { - addRecentClicks(input.readInt64()); - } - input.popLimit(limit); - break; - } - } - } - } - - - // required int64 target_id = 1; - public boolean hasTargetId() { - return result.hasTargetId(); - } - public long getTargetId() { - return result.getTargetId(); - } - public Builder setTargetId(long value) { - result.hasTargetId = true; - result.targetId_ = value; - return this; - } - public Builder clearTargetId() { - result.hasTargetId = false; - result.targetId_ = 0L; - return this; - } - - // required int64 suggested_id = 2; - public boolean hasSuggestedId() { - return result.hasSuggestedId(); - } - public long getSuggestedId() { - return result.getSuggestedId(); - } - public Builder setSuggestedId(long value) { - result.hasSuggestedId = true; - result.suggestedId_ = value; - return this; - } - public Builder clearSuggestedId() { - result.hasSuggestedId = false; - result.suggestedId_ = 0L; - return this; - } - - // required int32 serve_count = 3; - public boolean hasServeCount() { - return result.hasServeCount(); - } - public int getServeCount() { - return result.getServeCount(); - } - public Builder setServeCount(int value) { - result.hasServeCount = true; - result.serveCount_ = value; - return this; - } - public Builder clearServeCount() { - result.hasServeCount = false; - result.serveCount_ = 0; - return this; - } - - // repeated int64 recent_clicks = 4; - public java.util.List getRecentClicksList() { - return java.util.Collections.unmodifiableList(result.recentClicks_); - } - public int getRecentClicksCount() { - return result.getRecentClicksCount(); - } - public long getRecentClicks(int index) { - return result.getRecentClicks(index); - } - public Builder setRecentClicks(int index, long value) { - result.recentClicks_.set(index, value); - return this; - } - public Builder addRecentClicks(long value) { - if (result.recentClicks_.isEmpty()) { - result.recentClicks_ = new java.util.ArrayList(); - } - result.recentClicks_.add(value); - return this; - } - public Builder addAllRecentClicks( - java.lang.Iterable values) { - if (result.recentClicks_.isEmpty()) { - result.recentClicks_ = new java.util.ArrayList(); - } - super.addAll(values, result.recentClicks_); - return this; - } - public Builder clearRecentClicks() { - result.recentClicks_ = java.util.Collections.emptyList(); - return this; - } - - // @@protoc_insertion_point(builder_scope:com.twitter.chill.protobuf.FatigueCount) - } - - static { - defaultInstance = new FatigueCount(true); - com.twitter.chill.protobuf.TestMessages.internalForceInit(); - defaultInstance.initFields(); - } - - // @@protoc_insertion_point(class_scope:com.twitter.chill.protobuf.FatigueCount) - } - - private static com.google.protobuf.Descriptors.Descriptor - internal_static_com_twitter_chill_protobuf_FatigueCount_descriptor; - private static - com.google.protobuf.GeneratedMessage.FieldAccessorTable - internal_static_com_twitter_chill_protobuf_FatigueCount_fieldAccessorTable; - - public static com.google.protobuf.Descriptors.FileDescriptor - getDescriptor() { - return descriptor; - } - private static com.google.protobuf.Descriptors.FileDescriptor - descriptor; - static { - java.lang.String[] descriptorData = { - "\n\023test_messages.proto\022\032com.twitter.chill" + - ".protobuf\"c\n\014FatigueCount\022\021\n\ttarget_id\030\001" + - " \002(\003\022\024\n\014suggested_id\030\002 \002(\003\022\023\n\013serve_coun" + - "t\030\003 \002(\005\022\025\n\rrecent_clicks\030\004 \003(\003*\036\n\006Gender" + - "\022\010\n\004MALE\020\000\022\n\n\006FEMALE\020\001" - }; - com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = - new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { - public com.google.protobuf.ExtensionRegistry assignDescriptors( - com.google.protobuf.Descriptors.FileDescriptor root) { - descriptor = root; - internal_static_com_twitter_chill_protobuf_FatigueCount_descriptor = - getDescriptor().getMessageTypes().get(0); - internal_static_com_twitter_chill_protobuf_FatigueCount_fieldAccessorTable = new - com.google.protobuf.GeneratedMessage.FieldAccessorTable( - internal_static_com_twitter_chill_protobuf_FatigueCount_descriptor, - new java.lang.String[] { "TargetId", "SuggestedId", "ServeCount", "RecentClicks", }, - com.twitter.chill.protobuf.TestMessages.FatigueCount.class, - com.twitter.chill.protobuf.TestMessages.FatigueCount.Builder.class); - return null; - } - }; - com.google.protobuf.Descriptors.FileDescriptor - .internalBuildGeneratedFileFrom(descriptorData, - new com.google.protobuf.Descriptors.FileDescriptor[] { - }, assigner); - } - - public static void internalForceInit() {} - - // @@protoc_insertion_point(outer_class_scope) -} diff --git a/chill-protobuf/src/test/protobuf/test_messages.proto b/chill-protobuf/src/test/protobuf/test_messages.proto new file mode 100644 index 00000000..bb5f11c9 --- /dev/null +++ b/chill-protobuf/src/test/protobuf/test_messages.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; +package com.twitter.chill.protobuf; + +message FatigueCount { + int64 target_id = 1; + int64 suggested_id = 2; + int32 serve_count = 3; + repeated int64 recent_clicks = 4; + Gender gender = 5; +} + +enum Gender { + MALE = 0; + FEMALE = 1; + NONBINARY = 2; +} diff --git a/chill-protobuf/src/test/resources/genproto.sh b/chill-protobuf/src/test/resources/genproto.sh deleted file mode 100755 index 20ac0020..00000000 --- a/chill-protobuf/src/test/resources/genproto.sh +++ /dev/null @@ -1 +0,0 @@ -protoc -I=. --java_out=../java ./test_messages.proto diff --git a/chill-protobuf/src/test/resources/test_messages.proto b/chill-protobuf/src/test/resources/test_messages.proto deleted file mode 100644 index 830b26b7..00000000 --- a/chill-protobuf/src/test/resources/test_messages.proto +++ /dev/null @@ -1,13 +0,0 @@ -package com.twitter.chill.protobuf; - -message FatigueCount { - required int64 target_id = 1; - required int64 suggested_id = 2; - required int32 serve_count = 3; - repeated int64 recent_clicks = 4; -} - -enum Gender { - MALE = 0; - FEMALE = 1; -} diff --git a/chill-protobuf/src/test/scala/com/twitter/chill/protobuf/ProtobufTest.scala b/chill-protobuf/src/test/scala/com/twitter/chill/protobuf/ProtobufTest.scala index 9f2de1d4..2a5345db 100644 --- a/chill-protobuf/src/test/scala/com/twitter/chill/protobuf/ProtobufTest.scala +++ b/chill-protobuf/src/test/scala/com/twitter/chill/protobuf/ProtobufTest.scala @@ -20,6 +20,7 @@ import com.twitter.chill.{KryoInstantiator, KryoPool} import com.twitter.chill.protobuf.TestMessages.FatigueCount import com.esotericsoftware.kryo.Kryo +import com.esotericsoftware.kryo.serializers.FieldSerializer import com.google.protobuf.Message @@ -57,9 +58,16 @@ class ProtobufTest extends AnyWordSpec with Matchers { buildFatigueCount(12L, -1L, 42, List(1L, 2L)) ) - // Without the protobuf serializer, this fails: - val kpoolBusted = KryoPool.withByteArrayOutputStream(1, new KryoInstantiator) - an[Exception] should be thrownBy kpoolBusted.deepCopy(buildFatigueCount(12L, -1L, 42, List(1L, 2L))) + // Without the protobuf serializer, it will use FieldSerializer + // With newer versions of protoc code gen this might be ok but not advisable! + val kryoInstantiator = new KryoInstantiator() + val ser = kryoInstantiator.newKryo().getSerializer(classOf[Message]) + ser shouldBe a[FieldSerializer[_]] + + val kpoolBusted = KryoPool.withByteArrayOutputStream(1, kryoInstantiator) + kpoolBusted.deepCopy(buildFatigueCount(12L, -1L, 42, List(1L, 2L))) should equal( + buildFatigueCount(12L, -1L, 42, List(1L, 2L)) + ) } "Default Instance of Should be Ser-DeSer correctly" in { diff --git a/project/plugins.sbt b/project/plugins.sbt index d2400aa9..9b54ffe1 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -6,3 +6,6 @@ addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.8.2") addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2") addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.29") addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.7") +addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.0") + +libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.10.10"