From ed56a3941cc79b42e1798a4de7d8ed398385aad2 Mon Sep 17 00:00:00 2001 From: Andrey Litvitski Date: Thu, 20 Mar 2025 21:42:45 +0300 Subject: [PATCH] automate protobuf generation in tests Signed-off-by: Andrey Litvitski --- gradle/libs.versions.toml | 3 + .../spring-pulsar-reactive.gradle | 21 + .../pulsar/reactive/listener/Proto.java | 684 ------------------ .../src/test/proto/README.adoc | 1 - spring-pulsar/spring-pulsar.gradle | 23 + .../pulsar/listener/Proto.java | 682 ----------------- spring-pulsar/src/test/proto/README.adoc | 60 -- 7 files changed, 47 insertions(+), 1427 deletions(-) delete mode 100644 spring-pulsar-reactive/src/test/java/org/springframework/pulsar/reactive/listener/Proto.java delete mode 100644 spring-pulsar-reactive/src/test/proto/README.adoc delete mode 100644 spring-pulsar/src/test/java/org/springframework/pulsar/listener/Proto.java delete mode 100644 spring-pulsar/src/test/proto/README.adoc diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 05126397..87892830 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -37,6 +37,7 @@ nohttp = "0.0.11" shadow = "8.1.1" versions = "0.52.0" version-catalog-update = "0.8.5" +protobuf-plugin = "0.9.4" [libraries] # Product libs @@ -48,6 +49,7 @@ micrometer-bom = { module = "io.micrometer:micrometer-bom", version.ref = "micro micrometer-docs-gen = { module = "io.micrometer:micrometer-docs-generator", version.ref = "micrometer-docs-gen" } micrometer-tracing-bom = { module = "io.micrometer:micrometer-tracing-bom", version.ref = "micrometer-tracing" } protobuf-java = { module = "com.google.protobuf:protobuf-java", version.ref = "protobuf" } +protobuf-protoc = { module = "com.google.protobuf:protoc", version.ref = "protobuf" } pulsar-client-all = { module = "org.apache.pulsar:pulsar-client-all", version.ref = "pulsar" } pulsar-client-reactive-api = { module = "org.apache.pulsar:pulsar-client-reactive-api", version.ref = "pulsar-reactive" } pulsar-client-reactive-adapter = { module = "org.apache.pulsar:pulsar-client-reactive-adapter", version.ref = "pulsar-reactive" } @@ -80,3 +82,4 @@ spring-boot = { id = "org.springframework.boot", version.ref = "spring-boot" } spring-dep-mgmt = { id = "io.spring.dependency-management", version.ref = "spring-dep-mgmt" } versions = { id = "com.github.ben-manes.versions", version.ref = "versions" } version-catalog-update = { id = "nl.littlerobots.version-catalog-update", version.ref = "version-catalog-update" } +protobuf = { id = "com.google.protobuf", version.ref = "protobuf-plugin" } diff --git a/spring-pulsar-reactive/spring-pulsar-reactive.gradle b/spring-pulsar-reactive/spring-pulsar-reactive.gradle index 677c6cd2..5f2ef995 100644 --- a/spring-pulsar-reactive/spring-pulsar-reactive.gradle +++ b/spring-pulsar-reactive/spring-pulsar-reactive.gradle @@ -1,9 +1,30 @@ +import io.spring.javaformat.gradle.tasks.CheckFormat + plugins { id 'org.springframework.pulsar.spring-module' + alias(libs.plugins.protobuf) } description = 'Spring Pulsar Reactive Support' +tasks.named('extractIncludeProto') { enabled = false } +tasks.named('extractIncludeTestProto') { enabled = false } + +tasks.withType(CheckFormat).configureEach { task -> + task.source = project.files( + task.source.filter { file -> + !file.path.contains('build/generated/source/proto') + task.enabled = false + } + ) +} + +protobuf { + protoc { + artifact = libs.protobuf.protoc.get() + } +} + dependencies { api project (':spring-pulsar') api (libs.pulsar.client.reactive.api) { diff --git a/spring-pulsar-reactive/src/test/java/org/springframework/pulsar/reactive/listener/Proto.java b/spring-pulsar-reactive/src/test/java/org/springframework/pulsar/reactive/listener/Proto.java deleted file mode 100644 index 7b870eba..00000000 --- a/spring-pulsar-reactive/src/test/java/org/springframework/pulsar/reactive/listener/Proto.java +++ /dev/null @@ -1,684 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: person.proto - -// Protobuf Java Version: 3.25.6 -package org.springframework.pulsar.reactive.listener; - -public final class Proto { - - private Proto() { - } - - public static void registerAllExtensions(com.google.protobuf.ExtensionRegistryLite registry) { - } - - public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry registry) { - registerAllExtensions((com.google.protobuf.ExtensionRegistryLite) registry); - } - - public interface PersonOrBuilder extends - // @@protoc_insertion_point(interface_extends:Person) - com.google.protobuf.MessageOrBuilder { - - /** - * int32 id = 2; - * @return The id. - */ - int getId(); - - /** - * string name = 1; - * @return The name. - */ - java.lang.String getName(); - - /** - * string name = 1; - * @return The bytes for name. - */ - com.google.protobuf.ByteString getNameBytes(); - - } - - /** - * Protobuf type {@code Person} - */ - public static final class Person extends com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:Person) - PersonOrBuilder { - - private static final long serialVersionUID = 0L; - - // Use Person.newBuilder() to construct. - private Person(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - - private Person() { - name_ = ""; - } - - @java.lang.Override - @SuppressWarnings({ "unused" }) - protected java.lang.Object newInstance(UnusedPrivateParameter unused) { - return new Person(); - } - - public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { - return org.springframework.pulsar.reactive.listener.Proto.internal_static_Person_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { - return org.springframework.pulsar.reactive.listener.Proto.internal_static_Person_fieldAccessorTable - .ensureFieldAccessorsInitialized(org.springframework.pulsar.reactive.listener.Proto.Person.class, - org.springframework.pulsar.reactive.listener.Proto.Person.Builder.class); - } - - public static final int ID_FIELD_NUMBER = 2; - - private int id_ = 0; - - /** - * int32 id = 2; - * @return The id. - */ - @java.lang.Override - public int getId() { - return id_; - } - - public static final int NAME_FIELD_NUMBER = 1; - - @SuppressWarnings("serial") - private volatile java.lang.Object name_ = ""; - - /** - * string name = 1; - * @return The name. - */ - @java.lang.Override - public java.lang.String getName() { - java.lang.Object ref = name_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } - else { - com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - name_ = s; - return s; - } - } - - /** - * string name = 1; - * @return The bytes for name. - */ - @java.lang.Override - public com.google.protobuf.ByteString getNameBytes() { - java.lang.Object ref = name_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); - name_ = b; - return b; - } - else { - return (com.google.protobuf.ByteString) ref; - } - } - - private byte memoizedIsInitialized = -1; - - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) - return true; - if (isInitialized == 0) - return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); - } - if (id_ != 0) { - output.writeInt32(2, id_); - } - getUnknownFields().writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) - return size; - - size = 0; - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); - } - if (id_ != 0) { - size += com.google.protobuf.CodedOutputStream.computeInt32Size(2, id_); - } - size += getUnknownFields().getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof org.springframework.pulsar.reactive.listener.Proto.Person)) { - return super.equals(obj); - } - org.springframework.pulsar.reactive.listener.Proto.Person other = (org.springframework.pulsar.reactive.listener.Proto.Person) obj; - - if (getId() != other.getId()) - return false; - if (!getName().equals(other.getName())) - return false; - if (!getUnknownFields().equals(other.getUnknownFields())) - return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + ID_FIELD_NUMBER; - hash = (53 * hash) + getId(); - hash = (37 * hash) + NAME_FIELD_NUMBER; - hash = (53 * hash) + getName().hashCode(); - hash = (29 * hash) + getUnknownFields().hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static org.springframework.pulsar.reactive.listener.Proto.Person parseFrom(java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - - public static org.springframework.pulsar.reactive.listener.Proto.Person parseFrom(java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - - public static org.springframework.pulsar.reactive.listener.Proto.Person parseFrom( - com.google.protobuf.ByteString data) throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - - public static org.springframework.pulsar.reactive.listener.Proto.Person parseFrom( - com.google.protobuf.ByteString data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - - public static org.springframework.pulsar.reactive.listener.Proto.Person parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - - public static org.springframework.pulsar.reactive.listener.Proto.Person parseFrom(byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - - public static org.springframework.pulsar.reactive.listener.Proto.Person parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); - } - - public static org.springframework.pulsar.reactive.listener.Proto.Person parseFrom(java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input, extensionRegistry); - } - - public static org.springframework.pulsar.reactive.listener.Proto.Person parseDelimitedFrom( - java.io.InputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); - } - - public static org.springframework.pulsar.reactive.listener.Proto.Person parseDelimitedFrom( - java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input, - extensionRegistry); - } - - public static org.springframework.pulsar.reactive.listener.Proto.Person parseFrom( - com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); - } - - public static org.springframework.pulsar.reactive.listener.Proto.Person parseFrom( - com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { - return newBuilder(); - } - - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - - public static Builder newBuilder(org.springframework.pulsar.reactive.listener.Proto.Person prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - - /** - * Protobuf type {@code Person} - */ - public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:Person) - org.springframework.pulsar.reactive.listener.Proto.PersonOrBuilder { - - public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { - return org.springframework.pulsar.reactive.listener.Proto.internal_static_Person_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { - return org.springframework.pulsar.reactive.listener.Proto.internal_static_Person_fieldAccessorTable - .ensureFieldAccessorsInitialized(org.springframework.pulsar.reactive.listener.Proto.Person.class, - org.springframework.pulsar.reactive.listener.Proto.Person.Builder.class); - } - - // Construct using - // org.springframework.pulsar.reactive.listener.Proto.Person.newBuilder() - private Builder() { - - } - - private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - - } - - @java.lang.Override - public Builder clear() { - super.clear(); - bitField0_ = 0; - id_ = 0; - name_ = ""; - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { - return org.springframework.pulsar.reactive.listener.Proto.internal_static_Person_descriptor; - } - - @java.lang.Override - public org.springframework.pulsar.reactive.listener.Proto.Person getDefaultInstanceForType() { - return org.springframework.pulsar.reactive.listener.Proto.Person.getDefaultInstance(); - } - - @java.lang.Override - public org.springframework.pulsar.reactive.listener.Proto.Person build() { - org.springframework.pulsar.reactive.listener.Proto.Person result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public org.springframework.pulsar.reactive.listener.Proto.Person buildPartial() { - org.springframework.pulsar.reactive.listener.Proto.Person result = new org.springframework.pulsar.reactive.listener.Proto.Person( - this); - if (bitField0_ != 0) { - buildPartial0(result); - } - onBuilt(); - return result; - } - - private void buildPartial0(org.springframework.pulsar.reactive.listener.Proto.Person result) { - int from_bitField0_ = bitField0_; - if (((from_bitField0_ & 0x00000001) != 0)) { - result.id_ = id_; - } - if (((from_bitField0_ & 0x00000002) != 0)) { - result.name_ = name_; - } - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - - @java.lang.Override - public Builder setField(com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { - return super.setField(field, value); - } - - @java.lang.Override - public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - - @java.lang.Override - public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - - @java.lang.Override - public Builder setRepeatedField(com.google.protobuf.Descriptors.FieldDescriptor field, int index, - java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - - @java.lang.Override - public Builder addRepeatedField(com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof org.springframework.pulsar.reactive.listener.Proto.Person) { - return mergeFrom((org.springframework.pulsar.reactive.listener.Proto.Person) other); - } - else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(org.springframework.pulsar.reactive.listener.Proto.Person other) { - if (other == org.springframework.pulsar.reactive.listener.Proto.Person.getDefaultInstance()) - return this; - if (other.getId() != 0) { - setId(other.getId()); - } - if (!other.getName().isEmpty()) { - name_ = other.name_; - bitField0_ |= 0x00000002; - onChanged(); - } - this.mergeUnknownFields(other.getUnknownFields()); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 10: { - name_ = input.readStringRequireUtf8(); - bitField0_ |= 0x00000002; - break; - } // case 10 - case 16: { - id_ = input.readInt32(); - bitField0_ |= 0x00000001; - break; - } // case 16 - default: { - if (!super.parseUnknownField(input, extensionRegistry, tag)) { - done = true; // was an endgroup tag - } - break; - } // default: - } // switch (tag) - } // while (!done) - } - catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.unwrapIOException(); - } - finally { - onChanged(); - } // finally - return this; - } - - private int bitField0_; - - private int id_; - - /** - * int32 id = 2; - * @return The id. - */ - @java.lang.Override - public int getId() { - return id_; - } - - /** - * int32 id = 2; - * @param value The id to set. - * @return This builder for chaining. - */ - public Builder setId(int value) { - - id_ = value; - bitField0_ |= 0x00000001; - onChanged(); - return this; - } - - /** - * int32 id = 2; - * @return This builder for chaining. - */ - public Builder clearId() { - bitField0_ = (bitField0_ & ~0x00000001); - id_ = 0; - onChanged(); - return this; - } - - private java.lang.Object name_ = ""; - - /** - * string name = 1; - * @return The name. - */ - public java.lang.String getName() { - java.lang.Object ref = name_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - name_ = s; - return s; - } - else { - return (java.lang.String) ref; - } - } - - /** - * string name = 1; - * @return The bytes for name. - */ - public com.google.protobuf.ByteString getNameBytes() { - java.lang.Object ref = name_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = com.google.protobuf.ByteString - .copyFromUtf8((java.lang.String) ref); - name_ = b; - return b; - } - else { - return (com.google.protobuf.ByteString) ref; - } - } - - /** - * string name = 1; - * @param value The name to set. - * @return This builder for chaining. - */ - public Builder setName(java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - name_ = value; - bitField0_ |= 0x00000002; - onChanged(); - return this; - } - - /** - * string name = 1; - * @return This builder for chaining. - */ - public Builder clearName() { - name_ = getDefaultInstance().getName(); - bitField0_ = (bitField0_ & ~0x00000002); - onChanged(); - return this; - } - - /** - * string name = 1; - * @param value The bytes for name to set. - * @return This builder for chaining. - */ - public Builder setNameBytes(com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - name_ = value; - bitField0_ |= 0x00000002; - onChanged(); - return this; - } - - @java.lang.Override - public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - // @@protoc_insertion_point(builder_scope:Person) - - } - - // @@protoc_insertion_point(class_scope:Person) - private static final org.springframework.pulsar.reactive.listener.Proto.Person DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new org.springframework.pulsar.reactive.listener.Proto.Person(); - } - - public static org.springframework.pulsar.reactive.listener.Proto.Person getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public Person parsePartialFrom(com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - Builder builder = newBuilder(); - try { - builder.mergeFrom(input, extensionRegistry); - } - catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(builder.buildPartial()); - } - catch (com.google.protobuf.UninitializedMessageException e) { - throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); - } - catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException(e) - .setUnfinishedMessage(builder.buildPartial()); - } - return builder.buildPartial(); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public org.springframework.pulsar.reactive.listener.Proto.Person getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - private static final com.google.protobuf.Descriptors.Descriptor internal_static_Person_descriptor; - - private static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internal_static_Person_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\014person.proto\"\"\n\006Person\022\n\n\002id\030\002 \001(\005\022\014\n\004" - + "name\030\001 \001(\tB5\n,org.springframework.pulsar" - + ".reactive.listenerB\005Protob\006proto3" }; - descriptor = com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom(descriptorData, - new com.google.protobuf.Descriptors.FileDescriptor[] {}); - internal_static_Person_descriptor = getDescriptor().getMessageTypes().get(0); - internal_static_Person_fieldAccessorTable = new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_Person_descriptor, new java.lang.String[] { "Id", "Name", }); - } - - // @@protoc_insertion_point(outer_class_scope) - -} diff --git a/spring-pulsar-reactive/src/test/proto/README.adoc b/spring-pulsar-reactive/src/test/proto/README.adoc deleted file mode 100644 index 2c693b3d..00000000 --- a/spring-pulsar-reactive/src/test/proto/README.adoc +++ /dev/null @@ -1 +0,0 @@ -include::../../../../spring-pulsar/src/test/proto/README.adoc[] diff --git a/spring-pulsar/spring-pulsar.gradle b/spring-pulsar/spring-pulsar.gradle index f94dc6d5..4b340562 100644 --- a/spring-pulsar/spring-pulsar.gradle +++ b/spring-pulsar/spring-pulsar.gradle @@ -1,10 +1,32 @@ +import io.spring.javaformat.gradle.tasks.CheckFormat + plugins { id 'org.springframework.pulsar.spring-module' id 'java-test-fixtures' + alias(libs.plugins.protobuf) } description = 'Spring Pulsar Core' +tasks.named('extractIncludeProto') { enabled = false } +tasks.named('extractIncludeTestProto') { enabled = false } +tasks.named('extractIncludeTestFixturesProto') { enabled = false } + +tasks.withType(CheckFormat).configureEach { task -> + task.source = project.files( + task.source.filter { file -> + !file.path.contains('build/generated/source/proto') + task.enabled = false + } + ) +} + +protobuf { + protoc { + artifact = libs.protobuf.protoc.get() + } +} + dependencies { api 'io.micrometer:micrometer-observation' api (libs.pulsar.client.all) { @@ -56,3 +78,4 @@ dependencies { // Used by UserRecordDe/serializer in test fixtures testFixturesApi 'com.fasterxml.jackson.core:jackson-databind' } + diff --git a/spring-pulsar/src/test/java/org/springframework/pulsar/listener/Proto.java b/spring-pulsar/src/test/java/org/springframework/pulsar/listener/Proto.java deleted file mode 100644 index c1915a53..00000000 --- a/spring-pulsar/src/test/java/org/springframework/pulsar/listener/Proto.java +++ /dev/null @@ -1,682 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: person.proto - -// Protobuf Java Version: 3.25.6 -package org.springframework.pulsar.listener; - -public final class Proto { - - private Proto() { - } - - public static void registerAllExtensions(com.google.protobuf.ExtensionRegistryLite registry) { - } - - public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry registry) { - registerAllExtensions((com.google.protobuf.ExtensionRegistryLite) registry); - } - - public interface PersonOrBuilder extends - // @@protoc_insertion_point(interface_extends:Person) - com.google.protobuf.MessageOrBuilder { - - /** - * int32 id = 2; - * @return The id. - */ - int getId(); - - /** - * string name = 1; - * @return The name. - */ - java.lang.String getName(); - - /** - * string name = 1; - * @return The bytes for name. - */ - com.google.protobuf.ByteString getNameBytes(); - - } - - /** - * Protobuf type {@code Person} - */ - public static final class Person extends com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:Person) - PersonOrBuilder { - - private static final long serialVersionUID = 0L; - - // Use Person.newBuilder() to construct. - private Person(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - - private Person() { - name_ = ""; - } - - @java.lang.Override - @SuppressWarnings({ "unused" }) - protected java.lang.Object newInstance(UnusedPrivateParameter unused) { - return new Person(); - } - - public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { - return org.springframework.pulsar.listener.Proto.internal_static_Person_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { - return org.springframework.pulsar.listener.Proto.internal_static_Person_fieldAccessorTable - .ensureFieldAccessorsInitialized(org.springframework.pulsar.listener.Proto.Person.class, - org.springframework.pulsar.listener.Proto.Person.Builder.class); - } - - public static final int ID_FIELD_NUMBER = 2; - - private int id_ = 0; - - /** - * int32 id = 2; - * @return The id. - */ - @java.lang.Override - public int getId() { - return id_; - } - - public static final int NAME_FIELD_NUMBER = 1; - - @SuppressWarnings("serial") - private volatile java.lang.Object name_ = ""; - - /** - * string name = 1; - * @return The name. - */ - @java.lang.Override - public java.lang.String getName() { - java.lang.Object ref = name_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } - else { - com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - name_ = s; - return s; - } - } - - /** - * string name = 1; - * @return The bytes for name. - */ - @java.lang.Override - public com.google.protobuf.ByteString getNameBytes() { - java.lang.Object ref = name_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref); - name_ = b; - return b; - } - else { - return (com.google.protobuf.ByteString) ref; - } - } - - private byte memoizedIsInitialized = -1; - - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) - return true; - if (isInitialized == 0) - return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); - } - if (id_ != 0) { - output.writeInt32(2, id_); - } - getUnknownFields().writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) - return size; - - size = 0; - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); - } - if (id_ != 0) { - size += com.google.protobuf.CodedOutputStream.computeInt32Size(2, id_); - } - size += getUnknownFields().getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof org.springframework.pulsar.listener.Proto.Person)) { - return super.equals(obj); - } - org.springframework.pulsar.listener.Proto.Person other = (org.springframework.pulsar.listener.Proto.Person) obj; - - if (getId() != other.getId()) - return false; - if (!getName().equals(other.getName())) - return false; - if (!getUnknownFields().equals(other.getUnknownFields())) - return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + ID_FIELD_NUMBER; - hash = (53 * hash) + getId(); - hash = (37 * hash) + NAME_FIELD_NUMBER; - hash = (53 * hash) + getName().hashCode(); - hash = (29 * hash) + getUnknownFields().hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static org.springframework.pulsar.listener.Proto.Person parseFrom(java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - - public static org.springframework.pulsar.listener.Proto.Person parseFrom(java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - - public static org.springframework.pulsar.listener.Proto.Person parseFrom(com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - - public static org.springframework.pulsar.listener.Proto.Person parseFrom(com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - - public static org.springframework.pulsar.listener.Proto.Person parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - - public static org.springframework.pulsar.listener.Proto.Person parseFrom(byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - - public static org.springframework.pulsar.listener.Proto.Person parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); - } - - public static org.springframework.pulsar.listener.Proto.Person parseFrom(java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input, extensionRegistry); - } - - public static org.springframework.pulsar.listener.Proto.Person parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); - } - - public static org.springframework.pulsar.listener.Proto.Person parseDelimitedFrom(java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input, - extensionRegistry); - } - - public static org.springframework.pulsar.listener.Proto.Person parseFrom( - com.google.protobuf.CodedInputStream input) throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); - } - - public static org.springframework.pulsar.listener.Proto.Person parseFrom( - com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { - return newBuilder(); - } - - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - - public static Builder newBuilder(org.springframework.pulsar.listener.Proto.Person prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - - /** - * Protobuf type {@code Person} - */ - public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:Person) - org.springframework.pulsar.listener.Proto.PersonOrBuilder { - - public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { - return org.springframework.pulsar.listener.Proto.internal_static_Person_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internalGetFieldAccessorTable() { - return org.springframework.pulsar.listener.Proto.internal_static_Person_fieldAccessorTable - .ensureFieldAccessorsInitialized(org.springframework.pulsar.listener.Proto.Person.class, - org.springframework.pulsar.listener.Proto.Person.Builder.class); - } - - // Construct using - // org.springframework.pulsar.listener.Proto.Person.newBuilder() - private Builder() { - - } - - private Builder(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - - } - - @java.lang.Override - public Builder clear() { - super.clear(); - bitField0_ = 0; - id_ = 0; - name_ = ""; - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { - return org.springframework.pulsar.listener.Proto.internal_static_Person_descriptor; - } - - @java.lang.Override - public org.springframework.pulsar.listener.Proto.Person getDefaultInstanceForType() { - return org.springframework.pulsar.listener.Proto.Person.getDefaultInstance(); - } - - @java.lang.Override - public org.springframework.pulsar.listener.Proto.Person build() { - org.springframework.pulsar.listener.Proto.Person result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public org.springframework.pulsar.listener.Proto.Person buildPartial() { - org.springframework.pulsar.listener.Proto.Person result = new org.springframework.pulsar.listener.Proto.Person( - this); - if (bitField0_ != 0) { - buildPartial0(result); - } - onBuilt(); - return result; - } - - private void buildPartial0(org.springframework.pulsar.listener.Proto.Person result) { - int from_bitField0_ = bitField0_; - if (((from_bitField0_ & 0x00000001) != 0)) { - result.id_ = id_; - } - if (((from_bitField0_ & 0x00000002) != 0)) { - result.name_ = name_; - } - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - - @java.lang.Override - public Builder setField(com.google.protobuf.Descriptors.FieldDescriptor field, java.lang.Object value) { - return super.setField(field, value); - } - - @java.lang.Override - public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - - @java.lang.Override - public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - - @java.lang.Override - public Builder setRepeatedField(com.google.protobuf.Descriptors.FieldDescriptor field, int index, - java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - - @java.lang.Override - public Builder addRepeatedField(com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof org.springframework.pulsar.listener.Proto.Person) { - return mergeFrom((org.springframework.pulsar.listener.Proto.Person) other); - } - else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(org.springframework.pulsar.listener.Proto.Person other) { - if (other == org.springframework.pulsar.listener.Proto.Person.getDefaultInstance()) - return this; - if (other.getId() != 0) { - setId(other.getId()); - } - if (!other.getName().isEmpty()) { - name_ = other.name_; - bitField0_ |= 0x00000002; - onChanged(); - } - this.mergeUnknownFields(other.getUnknownFields()); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - case 10: { - name_ = input.readStringRequireUtf8(); - bitField0_ |= 0x00000002; - break; - } // case 10 - case 16: { - id_ = input.readInt32(); - bitField0_ |= 0x00000001; - break; - } // case 16 - default: { - if (!super.parseUnknownField(input, extensionRegistry, tag)) { - done = true; // was an endgroup tag - } - break; - } // default: - } // switch (tag) - } // while (!done) - } - catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.unwrapIOException(); - } - finally { - onChanged(); - } // finally - return this; - } - - private int bitField0_; - - private int id_; - - /** - * int32 id = 2; - * @return The id. - */ - @java.lang.Override - public int getId() { - return id_; - } - - /** - * int32 id = 2; - * @param value The id to set. - * @return This builder for chaining. - */ - public Builder setId(int value) { - - id_ = value; - bitField0_ |= 0x00000001; - onChanged(); - return this; - } - - /** - * int32 id = 2; - * @return This builder for chaining. - */ - public Builder clearId() { - bitField0_ = (bitField0_ & ~0x00000001); - id_ = 0; - onChanged(); - return this; - } - - private java.lang.Object name_ = ""; - - /** - * string name = 1; - * @return The name. - */ - public java.lang.String getName() { - java.lang.Object ref = name_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - name_ = s; - return s; - } - else { - return (java.lang.String) ref; - } - } - - /** - * string name = 1; - * @return The bytes for name. - */ - public com.google.protobuf.ByteString getNameBytes() { - java.lang.Object ref = name_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = com.google.protobuf.ByteString - .copyFromUtf8((java.lang.String) ref); - name_ = b; - return b; - } - else { - return (com.google.protobuf.ByteString) ref; - } - } - - /** - * string name = 1; - * @param value The name to set. - * @return This builder for chaining. - */ - public Builder setName(java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - name_ = value; - bitField0_ |= 0x00000002; - onChanged(); - return this; - } - - /** - * string name = 1; - * @return This builder for chaining. - */ - public Builder clearName() { - name_ = getDefaultInstance().getName(); - bitField0_ = (bitField0_ & ~0x00000002); - onChanged(); - return this; - } - - /** - * string name = 1; - * @param value The bytes for name to set. - * @return This builder for chaining. - */ - public Builder setNameBytes(com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - name_ = value; - bitField0_ |= 0x00000002; - onChanged(); - return this; - } - - @java.lang.Override - public final Builder setUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields(final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - // @@protoc_insertion_point(builder_scope:Person) - - } - - // @@protoc_insertion_point(class_scope:Person) - private static final org.springframework.pulsar.listener.Proto.Person DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new org.springframework.pulsar.listener.Proto.Person(); - } - - public static org.springframework.pulsar.listener.Proto.Person getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public Person parsePartialFrom(com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - Builder builder = newBuilder(); - try { - builder.mergeFrom(input, extensionRegistry); - } - catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(builder.buildPartial()); - } - catch (com.google.protobuf.UninitializedMessageException e) { - throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); - } - catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException(e) - .setUnfinishedMessage(builder.buildPartial()); - } - return builder.buildPartial(); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public org.springframework.pulsar.listener.Proto.Person getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - private static final com.google.protobuf.Descriptors.Descriptor internal_static_Person_descriptor; - - private static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable internal_static_Person_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\014person.proto\"\"\n\006Person\022\n\n\002id\030\002 \001(\005\022\014\n\004" - + "name\030\001 \001(\tB,\n#org.springframework.pulsar" + ".listenerB\005Protob\006proto3" }; - descriptor = com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom(descriptorData, - new com.google.protobuf.Descriptors.FileDescriptor[] {}); - internal_static_Person_descriptor = getDescriptor().getMessageTypes().get(0); - internal_static_Person_fieldAccessorTable = new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_Person_descriptor, new java.lang.String[] { "Id", "Name", }); - } - - // @@protoc_insertion_point(outer_class_scope) - -} diff --git a/spring-pulsar/src/test/proto/README.adoc b/spring-pulsar/src/test/proto/README.adoc deleted file mode 100644 index 017184de..00000000 --- a/spring-pulsar/src/test/proto/README.adoc +++ /dev/null @@ -1,60 +0,0 @@ -= How to regenerate the protos - -Every so often the generated Proto java POJO used for testing need to be updated. - -They are used in both `spring-pulsar` and `spring-pulsar-reactive`. - -== Make sure proper protoc installed - -Run the following command: ----- -protoc --version ----- - -If the command is not found or returns version below `25.6` then you will need to install as follows. - ----- -wget -O protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v25.6/protoc-25.6-osx-aarch_64.zip - -mkdir tmp -mv protoc.zip tmp -cd tmp -unzip protoc.zip -mv bin/protoc /usr/local/bin -cd .. -rm -rf tmp ----- - -Check the version again: ----- -protoc --version ----- -Should now return version `25.6`. If it does not, figure it out. - -TIP: If you are on Mac you may see “macOS cannot verify that this app is free from malware”. If so, navigate to the binary and hold down "CTRL" and right-click and select "Open". - -== Regenerate the protos - -From the project root directory run the following commands: - -.spring-pulsar ----- -pushd spring-pulsar/src/test/proto > /dev/null -protoc --java_out=. person.proto -cp -R org ../../../src/test/java -rm -rf org -popd > /dev/null -./gradlew format ----- - -.spring-pulsar-reactive ----- -pushd spring-pulsar-reactive/src/test/proto > /dev/null -protoc --java_out=. person.proto -cp -R org ../../../src/test/java -rm -rf org -popd > /dev/null -./gradlew format ----- - -Check in the modified generated POJOs