jerrypeng closed pull request #2168: fixing protobuf schema shading issue URL: https://github.com/apache/incubator-pulsar/pull/2168
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/pom.xml b/pom.xml index 8a0da985ee..881b628883 100644 --- a/pom.xml +++ b/pom.xml @@ -82,6 +82,7 @@ flexible messaging model and an intuitive client API.</description> <module>pulsar-broker-shaded</module> <module>pulsar-client</module> <module>pulsar-client-shaded</module> + <module>pulsar-client-schema</module> <module>pulsar-client-admin</module> <module>pulsar-client-admin-shaded</module> <module>pulsar-client-tools</module> diff --git a/pulsar-broker/pom.xml b/pulsar-broker/pom.xml index ccee189a9c..d505c7a881 100644 --- a/pulsar-broker/pom.xml +++ b/pulsar-broker/pom.xml @@ -180,6 +180,11 @@ <artifactId>jackson-jaxrs-json-provider</artifactId> </dependency> + <dependency> + <groupId>com.fasterxml.jackson.module</groupId> + <artifactId>jackson-module-jsonSchema</artifactId> + </dependency> + <dependency> <groupId>org.slf4j</groupId> <artifactId>jul-to-slf4j</artifactId> diff --git a/pulsar-client-admin-shaded/pom.xml b/pulsar-client-admin-shaded/pom.xml index 2edc7cf971..0c9fb93130 100644 --- a/pulsar-client-admin-shaded/pom.xml +++ b/pulsar-client-admin-shaded/pom.xml @@ -98,15 +98,6 @@ <include>io.opencensus:*</include> <include>org.objenesis:*</include> <include>org.yaml:snakeyaml</include> - - <include>org.apache.avro:*</include> - <!-- Avro transitive dependencies--> - <include>org.codehaus.jackson:jackson-core-asl</include> - <include>org.codehaus.jackson:jackson-mapper-asl</include> - <include>com.thoughtworks.paranamer:paranamer</include> - <include>org.xerial.snappy:snappy-java</include> - <include>org.apache.commons:commons-compress</include> - <include>org.tukaani:xz</include> </includes> </artifactSet> <filters> @@ -210,27 +201,6 @@ <pattern>org.reactivestreams</pattern> <shadedPattern>org.apache.pulsar.shade.org.reactivestreams</shadedPattern> </relocation> - <relocation> - <pattern>org.apache.avro</pattern> - <shadedPattern>org.apache.pulsar.shade.org.apache.avro</shadedPattern> - </relocation> - <!-- Avro transitive dependencies--> - <relocation> - <pattern>org.codehaus.jackson</pattern> - <shadedPattern>org.apache.pulsar.shade.org.codehaus.jackson</shadedPattern> - </relocation> - <relocation> - <pattern>com.thoughtworks.paranamer</pattern> - <shadedPattern>org.apache.pulsar.shade.com.thoughtworks.paranamer</shadedPattern> - </relocation> - <relocation> - <pattern>org.xerial.snappy</pattern> - <shadedPattern>org.apache.pulsar.shade.org.xerial.snappy</shadedPattern> - </relocation> - <relocation> - <pattern>org.tukaani</pattern> - <shadedPattern>org.apache.pulsar.shade.org.tukaani</shadedPattern> - </relocation> <relocation> <pattern>io.grpc</pattern> <shadedPattern>org.apache.pulsar.shade.io.grpc</shadedPattern> diff --git a/pulsar-client-kafka-compat/pulsar-client-kafka-shaded/pom.xml b/pulsar-client-kafka-compat/pulsar-client-kafka-shaded/pom.xml index 5d474ba66e..3ba94e9aaf 100644 --- a/pulsar-client-kafka-compat/pulsar-client-kafka-shaded/pom.xml +++ b/pulsar-client-kafka-compat/pulsar-client-kafka-shaded/pom.xml @@ -68,6 +68,7 @@ <include>org.apache.kafka:kafka-clients</include> <include>org.apache.pulsar:pulsar-client-kafka-original</include> <include>org.apache.pulsar:pulsar-client-original</include> + <include>org.apache.pulsar:pulsar-client-schema</include> <include>org.apache.commons:commons-lang3</include> <include>commons-codec:commons-codec</include> <include>commons-collections:commons-collections</include> @@ -97,15 +98,6 @@ <include>commons-*:*</include> <include>org.yaml:snakeyaml</include> <include>org.objenesis:*</include> - - <include>org.apache.avro:*</include> - <!-- Avro transitive dependencies--> - <include>org.codehaus.jackson:jackson-core-asl</include> - <include>org.codehaus.jackson:jackson-mapper-asl</include> - <include>com.thoughtworks.paranamer:paranamer</include> - <include>org.xerial.snappy:snappy-java</include> - <include>org.apache.commons:commons-compress</include> - <include>org.tukaani:xz</include> </includes> </artifactSet> <filters> @@ -188,27 +180,6 @@ <pattern>org.apache.http</pattern> <shadedPattern>org.apache.pulsar.shade.org.apache.http</shadedPattern> </relocation> - <relocation> - <pattern>org.apache.avro</pattern> - <shadedPattern>org.apache.pulsar.shade.org.apache.avro</shadedPattern> - </relocation> - <!-- Avro transitive dependencies--> - <relocation> - <pattern>org.codehaus.jackson</pattern> - <shadedPattern>org.apache.pulsar.shade.org.codehaus.jackson</shadedPattern> - </relocation> - <relocation> - <pattern>com.thoughtworks.paranamer</pattern> - <shadedPattern>org.apache.pulsar.shade.com.thoughtworks.paranamer</shadedPattern> - </relocation> - <relocation> - <pattern>org.xerial.snappy</pattern> - <shadedPattern>org.apache.pulsar.shade.org.xerial.snappy</shadedPattern> - </relocation> - <relocation> - <pattern>org.tukaani</pattern> - <shadedPattern>org.apache.pulsar.shade.org.tukaani</shadedPattern> - </relocation> <relocation> <pattern>org.eclipse.jetty</pattern> <shadedPattern>org.apache.pulsar.shade.org.eclipse</shadedPattern> diff --git a/pulsar-client-schema/pom.xml b/pulsar-client-schema/pom.xml new file mode 100644 index 0000000000..a7d9f470d5 --- /dev/null +++ b/pulsar-client-schema/pom.xml @@ -0,0 +1,349 @@ +<!-- + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you 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. + +--> +<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/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.pulsar</groupId> + <artifactId>pulsar</artifactId> + <version>2.2.0-incubating-SNAPSHOT</version> + <relativePath>..</relativePath> + </parent> + + <artifactId>pulsar-client-schema</artifactId> + <name>Pulsar Client Schema</name> + + <dependencies> + + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>pulsar-common</artifactId> + <version>${project.parent.version}</version> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.avro</groupId> + <artifactId>avro</artifactId> + <version>${avro.version}</version> + </dependency> + + <dependency> + <groupId>org.apache.avro</groupId> + <artifactId>avro-protobuf</artifactId> + <version>${avro.version}</version> + </dependency> + + <dependency> + <groupId>com.google.protobuf</groupId> + <artifactId>protobuf-java</artifactId> + <version>${protobuf3.version}</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>com.fasterxml.jackson.module</groupId> + <artifactId>jackson-module-jsonSchema</artifactId> + </dependency> + + <!-- Testing dependencies --> + <dependency> + <groupId>org.apache.pulsar</groupId> + <artifactId>pulsar-functions-proto</artifactId> + <version>${project.parent.version}</version> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <resources> + <resource> + <directory>src/main/resources</directory> + <filtering>true</filtering> + </resource> + </resources> + <extensions> + <extension> + <groupId>kr.motd.maven</groupId> + <artifactId>os-maven-plugin</artifactId> + <version>1.4.1.Final</version> + </extension> + </extensions> + <!-- Generate protobuf for testing purposes --> + <plugins> + <plugin> + <groupId>org.xolstice.maven.plugins</groupId> + <artifactId>protobuf-maven-plugin</artifactId> + <version>${protobuf-maven-plugin.version}</version> + <configuration> + <protocArtifact>com.google.protobuf:protoc:${protoc3.version}:exe:${os.detected.classifier}</protocArtifact> + <checkStaleness>true</checkStaleness> + <pluginId>grpc-java</pluginId> + <pluginArtifact>io.grpc:protoc-gen-grpc-java:${protoc-gen-grpc-java.version}:exe:${os.detected.classifier}</pluginArtifact> + </configuration> + <executions> + <execution> + <goals> + <goal>test-compile</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <createDependencyReducedPom>true</createDependencyReducedPom> + <promoteTransitiveDependencies>true</promoteTransitiveDependencies> + + <artifactSet> + <includes> + <include>org.apache.commons:commons-lang3</include> + <include>commons-codec:commons-codec</include> + <include>commons-collections:commons-collections</include> + <include>org.asynchttpclient:*</include> + <include>io.netty:netty-codec-http</include> + <include>io.netty:netty-transport-native-epoll</include> + <include>org.reactivestreams:reactive-streams</include> + <include>com.typesafe.netty:netty-reactive-streams</include> + <include>org.javassist:javassist</include> + <include>com.google.guava:guava</include> + <include>com.google.code.gson:gson</include> + <include>com.fasterxml.jackson.core</include> + <include>io.netty:netty</include> + <include>io.netty:netty-all</include> + <include>org.apache.bookkeeper:circe-checksum</include> + <include>net.jpountz.lz4:lz4</include> + <include>com.yahoo.datasketches:sketches-core</include> + <include>org.glassfish.jersey*:*</include> + <include>javax.ws.rs:*</include> + <include>javax.annotation:*</include> + <include>org.glassfish.hk2*:*</include> + <include>com.fasterxml.jackson.*:*</include> + <include>io.grpc:*</include> + <include>com.yahoo.datasketches:*</include> + <include>io.netty:*</include> + <include>com.squareup.*:*</include> + <include>commons-*:*</include> + <include>org.apache.httpcomponents:*</include> + <include>org.eclipse.jetty:*</include> + <include>com.google.auth:*</include> + <include>org.jvnet.mimepull:*</include> + <include>io.opencensus:*</include> + <include>org.objenesis:*</include> + <include>org.yaml:snakeyaml</include> + + <include>org.apache.avro:*</include> + <!-- Avro transitive dependencies--> + <include>org.codehaus.jackson:jackson-core-asl</include> + <include>org.codehaus.jackson:jackson-mapper-asl</include> + <include>com.thoughtworks.paranamer:paranamer</include> + <include>org.xerial.snappy:snappy-java</include> + <include>org.apache.commons:commons-compress</include> + <include>org.tukaani:xz</include> + </includes> + </artifactSet> + <filters> + <filter> + <artifact>net.jpountz.lz4:lz4</artifact> + <includes> + <include>**</include> + </includes> + </filter> + <filter> + <artifact>org.apache.pulsar:pulsar-io-core</artifact> + <includes> + <include>**</include> + </includes> + </filter> + <filter> + <artifact>org.apache.pulsar:pulsar-client-original</artifact> + <includes> + <include>**</include> + </includes> + </filter> + </filters> + <relocations> + <relocation> + <pattern>org.asynchttpclient</pattern> + <shadedPattern>org.apache.pulsar.shade.org.asynchttpclient</shadedPattern> + </relocation> + <relocation> + <pattern>org.apache.commons</pattern> + <shadedPattern>org.apache.pulsar.shade.org.apache.commons</shadedPattern> + </relocation> + <relocation> + <pattern>com.google.guava</pattern> + <shadedPattern>org.apache.pulsar.shade.com.google.guava</shadedPattern> + </relocation> + <relocation> + <pattern>com.google.code</pattern> + <shadedPattern>org.apache.pulsar.shade.com.google.code</shadedPattern> + </relocation> + <relocation> + <pattern>com.google.auth</pattern> + <shadedPattern>org.apache.pulsar.shade.com.google.auth</shadedPattern> + </relocation> + <relocation> + <pattern>com.fasterxml.jackson</pattern> + <shadedPattern>org.apache.pulsar.shade.com.fasterxml.jackson</shadedPattern> + </relocation> + <relocation> + <pattern>io.netty</pattern> + <shadedPattern>org.apache.pulsar.shade.io.netty</shadedPattern> + </relocation> + <relocation> + <pattern>org.apache.pulsar.policies</pattern> + <shadedPattern>org.apache.pulsar.shade.org.apache.pulsar.policies</shadedPattern> + </relocation> + <relocation> + <pattern>org.apache.pulsar.checksum</pattern> + <shadedPattern>org.apache.pulsar.shade.org.apache.pulsar.checksum</shadedPattern> + </relocation> + <relocation> + <pattern>com.scurrilous.circe</pattern> + <shadedPattern>org.apache.pulsar.shade.com.scurrilous.circe</shadedPattern> + </relocation> + <relocation> + <pattern>net.jpountz</pattern> + <shadedPattern>org.apache.pulsar.shade.net.jpountz</shadedPattern> + </relocation> + <relocation> + <pattern>com.yahoo</pattern> + <shadedPattern>org.apache.pulsar.shade.com.yahoo</shadedPattern> + </relocation> + <relocation> + <pattern>com.typesafe</pattern> + <shadedPattern>org.apache.pulsar.shade.com.typesafe</shadedPattern> + </relocation> + <relocation> + <pattern>org.glassfish</pattern> + <shadedPattern>org.apache.pulsar.shade.org.glassfish</shadedPattern> + </relocation> + <relocation> + <pattern>javax.ws</pattern> + <shadedPattern>org.apache.pulsar.shade.javax.ws</shadedPattern> + </relocation> + <relocation> + <pattern>javax.annotation</pattern> + <shadedPattern>org.apache.pulsar.shade.javax.annotation</shadedPattern> + </relocation> + <relocation> + <pattern>jersey</pattern> + <shadedPattern>org.apache.pulsar.shade.jersey</shadedPattern> + </relocation> + <relocation> + <pattern>org.jvnet</pattern> + <shadedPattern>org.apache.pulsar.shade.org.jvnet</shadedPattern> + </relocation> + <relocation> + <pattern>org.aopalliance</pattern> + <shadedPattern>org.apache.pulsar.shade.org.aopalliance</shadedPattern> + </relocation> + <relocation> + <pattern>javassist</pattern> + <shadedPattern>org.apache.pulsar.shade.javassist</shadedPattern> + </relocation> + <relocation> + <pattern>javax.inject</pattern> + <shadedPattern>org.apache.pulsar.shade.javax.inject</shadedPattern> + </relocation> + <relocation> + <pattern>org.reactivestreams</pattern> + <shadedPattern>org.apache.pulsar.shade.org.reactivestreams</shadedPattern> + </relocation> + <relocation> + <pattern>org.apache.avro</pattern> + <shadedPattern>org.apache.pulsar.shade.org.apache.avro</shadedPattern> + </relocation> + <!-- Avro transitive dependencies--> + <relocation> + <pattern>org.codehaus.jackson</pattern> + <shadedPattern>org.apache.pulsar.shade.org.codehaus.jackson</shadedPattern> + </relocation> + <relocation> + <pattern>com.thoughtworks.paranamer</pattern> + <shadedPattern>org.apache.pulsar.shade.com.thoughtworks.paranamer</shadedPattern> + </relocation> + <relocation> + <pattern>org.xerial.snappy</pattern> + <shadedPattern>org.apache.pulsar.shade.org.xerial.snappy</shadedPattern> + </relocation> + <relocation> + <pattern>org.tukaani</pattern> + <shadedPattern>org.apache.pulsar.shade.org.tukaani</shadedPattern> + </relocation> + <relocation> + <pattern>io.grpc</pattern> + <shadedPattern>org.apache.pulsar.shade.io.grpc</shadedPattern> + </relocation> + <relocation> + <pattern>okio</pattern> + <shadedPattern>org.apache.pulsar.shade.okio</shadedPattern> + </relocation> + <relocation> + <pattern>com.squareup</pattern> + <shadedPattern>org.apache.pulsar.shade.com.squareup</shadedPattern> + </relocation> + <relocation> + <pattern>io.opencensus</pattern> + <shadedPattern>org.apache.pulsar.shade.io.opencensus</shadedPattern> + </relocation> + <relocation> + <pattern>org.eclipse.jetty</pattern> + <shadedPattern>org.apache.pulsar.shade.org.eclipse.jetty</shadedPattern> + </relocation> + <relocation> + <pattern>org.apache.http</pattern> + <shadedPattern>org.apache.pulsar.shade.org.apache.http</shadedPattern> + </relocation> + <relocation> + <pattern>org.objenesis</pattern> + <shadedPattern>org.apache.pulsar.shade.org.objenesis</shadedPattern> + </relocation> + <relocation> + <pattern>org.yaml</pattern> + <shadedPattern>org.apache.pulsar.shade.org.yaml</shadedPattern> + </relocation> + </relocations> + <transformers> + <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> + <transformer implementation="org.apache.maven.plugins.shade.resource.PluginXmlResourceTransformer" /> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/api/Schema.java b/pulsar-client-schema/src/main/java/org/apache/pulsar/client/api/Schema.java similarity index 81% rename from pulsar-client/src/main/java/org/apache/pulsar/client/api/Schema.java rename to pulsar-client-schema/src/main/java/org/apache/pulsar/client/api/Schema.java index 12c35c66a0..3088a4de21 100644 --- a/pulsar-client/src/main/java/org/apache/pulsar/client/api/Schema.java +++ b/pulsar-client-schema/src/main/java/org/apache/pulsar/client/api/Schema.java @@ -18,7 +18,10 @@ */ package org.apache.pulsar.client.api; +import org.apache.pulsar.client.impl.schema.AvroSchema; import org.apache.pulsar.client.impl.schema.BytesSchema; +import org.apache.pulsar.client.impl.schema.JSONSchema; +import org.apache.pulsar.client.impl.schema.ProtobufSchema; import org.apache.pulsar.client.impl.schema.StringSchema; import org.apache.pulsar.common.schema.SchemaInfo; @@ -61,4 +64,17 @@ * Schema that can be used to encode/decode messages whose values are String. The payload is encoded with UTF-8. */ Schema<String> STRING = new StringSchema(); + + + static <T extends com.google.protobuf.GeneratedMessageV3> Schema<T> PROTOBUF(Class<T> clazz) { + return ProtobufSchema.of(clazz); + } + + static <T> Schema<T> AVRO(Class<T> clazz) { + return AvroSchema.of(clazz); + } + + static <T> Schema<T> JSON(Class<T> clazz) { + return JSONSchema.of(clazz); + } } diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/api/SchemaSerializationException.java b/pulsar-client-schema/src/main/java/org/apache/pulsar/client/api/SchemaSerializationException.java similarity index 100% rename from pulsar-client/src/main/java/org/apache/pulsar/client/api/SchemaSerializationException.java rename to pulsar-client-schema/src/main/java/org/apache/pulsar/client/api/SchemaSerializationException.java diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AvroSchema.java b/pulsar-client-schema/src/main/java/org/apache/pulsar/client/impl/schema/AvroSchema.java similarity index 100% rename from pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AvroSchema.java rename to pulsar-client-schema/src/main/java/org/apache/pulsar/client/impl/schema/AvroSchema.java diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/BytesSchema.java b/pulsar-client-schema/src/main/java/org/apache/pulsar/client/impl/schema/BytesSchema.java similarity index 100% rename from pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/BytesSchema.java rename to pulsar-client-schema/src/main/java/org/apache/pulsar/client/impl/schema/BytesSchema.java diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/JSONSchema.java b/pulsar-client-schema/src/main/java/org/apache/pulsar/client/impl/schema/JSONSchema.java similarity index 100% rename from pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/JSONSchema.java rename to pulsar-client-schema/src/main/java/org/apache/pulsar/client/impl/schema/JSONSchema.java diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/ProtobufSchema.java b/pulsar-client-schema/src/main/java/org/apache/pulsar/client/impl/schema/ProtobufSchema.java similarity index 100% rename from pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/ProtobufSchema.java rename to pulsar-client-schema/src/main/java/org/apache/pulsar/client/impl/schema/ProtobufSchema.java diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/StringSchema.java b/pulsar-client-schema/src/main/java/org/apache/pulsar/client/impl/schema/StringSchema.java similarity index 100% rename from pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/StringSchema.java rename to pulsar-client-schema/src/main/java/org/apache/pulsar/client/impl/schema/StringSchema.java diff --git a/pulsar-client/src/test/java/org/apache/pulsar/client/schemas/AvroSchemaTest.java b/pulsar-client-schema/src/test/java/org/apache/pulsar/client/schema/AvroSchemaTest.java similarity index 95% rename from pulsar-client/src/test/java/org/apache/pulsar/client/schemas/AvroSchemaTest.java rename to pulsar-client-schema/src/test/java/org/apache/pulsar/client/schema/AvroSchemaTest.java index a8b94deca1..84c060e80d 100644 --- a/pulsar-client/src/test/java/org/apache/pulsar/client/schemas/AvroSchemaTest.java +++ b/pulsar-client-schema/src/test/java/org/apache/pulsar/client/schema/AvroSchemaTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.pulsar.client.schemas; +package org.apache.pulsar.client.schema; import lombok.Data; import lombok.EqualsAndHashCode; @@ -50,7 +50,7 @@ private static final String SCHEMA_JSON = "{\"type\":\"record\",\"name\":\"Foo\",\"namespace\":\"org.apache" + ".pulsar.client" + - ".schemas.AvroSchemaTest$\",\"fields\":[{\"name\":\"field1\",\"type\":[\"null\",\"string\"]," + + ".schema.AvroSchemaTest$\",\"fields\":[{\"name\":\"field1\",\"type\":[\"null\",\"string\"]," + "\"default\":null},{\"name\":\"field2\",\"type\":[\"null\",\"string\"],\"default\":null}," + "{\"name\":\"field3\",\"type\":\"int\"},{\"name\":\"field4\",\"type\":[\"null\",{\"type\":\"record\"," + "\"name\":\"Bar\",\"fields\":[{\"name\":\"field1\",\"type\":\"boolean\"}]}],\"default\":null}]}"; diff --git a/pulsar-client/src/test/java/org/apache/pulsar/client/schemas/JSONSchemaTest.java b/pulsar-client-schema/src/test/java/org/apache/pulsar/client/schema/JSONSchemaTest.java similarity index 95% rename from pulsar-client/src/test/java/org/apache/pulsar/client/schemas/JSONSchemaTest.java rename to pulsar-client-schema/src/test/java/org/apache/pulsar/client/schema/JSONSchemaTest.java index 0605f2de27..2add60f27a 100644 --- a/pulsar-client/src/test/java/org/apache/pulsar/client/schemas/JSONSchemaTest.java +++ b/pulsar-client-schema/src/test/java/org/apache/pulsar/client/schema/JSONSchemaTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.pulsar.client.schemas; +package org.apache.pulsar.client.schema; import lombok.Data; import lombok.EqualsAndHashCode; @@ -47,7 +47,7 @@ private static final String SCHEMA_JSON = "{\"type\":\"record\",\"name\":\"Foo\",\"namespace\":\"org.apache" + ".pulsar.client" + - ".schemas.JSONSchemaTest$\",\"fields\":[{\"name\":\"field1\",\"type\":[\"null\",\"string\"]," + + ".schema.JSONSchemaTest$\",\"fields\":[{\"name\":\"field1\",\"type\":[\"null\",\"string\"]," + "\"default\":null},{\"name\":\"field2\",\"type\":[\"null\",\"string\"],\"default\":null}," + "{\"name\":\"field3\",\"type\":\"int\"},{\"name\":\"field4\",\"type\":[\"null\",{\"type\":\"record\"," + "\"name\":\"Bar\",\"fields\":[{\"name\":\"field1\",\"type\":\"boolean\"}]}],\"default\":null}]}"; diff --git a/pulsar-client/src/test/java/org/apache/pulsar/client/schemas/ProtobufSchemaTest.java b/pulsar-client-schema/src/test/java/org/apache/pulsar/client/schema/ProtobufSchemaTest.java similarity index 91% rename from pulsar-client/src/test/java/org/apache/pulsar/client/schemas/ProtobufSchemaTest.java rename to pulsar-client-schema/src/test/java/org/apache/pulsar/client/schema/ProtobufSchemaTest.java index f099eb2281..7ed575a5d1 100644 --- a/pulsar-client/src/test/java/org/apache/pulsar/client/schemas/ProtobufSchemaTest.java +++ b/pulsar-client-schema/src/test/java/org/apache/pulsar/client/schema/ProtobufSchemaTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.pulsar.client.schemas; +package org.apache.pulsar.client.schema; import lombok.extern.slf4j.Slf4j; import org.apache.avro.Schema; @@ -32,7 +32,7 @@ private static final String NAME = "foo"; private static final String EXPECTED_SCHEMA_JSON = "{\"type\":\"record\",\"name\":\"TestMessage\"," + - "\"namespace\":\"org.apache.pulsar.client.schemas.proto.Test$\",\"fields\":[{\"name\":\"stringField\"," + + "\"namespace\":\"org.apache.pulsar.client.schema.proto.Test$\",\"fields\":[{\"name\":\"stringField\"," + "\"type\":{\"type\":\"string\",\"avro.java.string\":\"String\"},\"default\":\"\"}," + "{\"name\":\"doubleField\",\"type\":\"double\",\"default\":0},{\"name\":\"intField\",\"type\":\"int\"," + "\"default\":0},{\"name\":\"testEnum\",\"type\":{\"type\":\"enum\",\"name\":\"TestEnum\"," + @@ -56,8 +56,8 @@ public void testEncodeAndDecode() { @Test public void testSchema() { - ProtobufSchema<org.apache.pulsar.client.schemas.proto.Test.TestMessage> protobufSchema - = ProtobufSchema.of(org.apache.pulsar.client.schemas.proto.Test.TestMessage.class); + ProtobufSchema<org.apache.pulsar.client.schema.proto.Test.TestMessage> protobufSchema + = ProtobufSchema.of(org.apache.pulsar.client.schema.proto.Test.TestMessage.class); Assert.assertEquals(protobufSchema.getSchemaInfo().getType(), SchemaType.PROTOBUF); diff --git a/pulsar-client/src/test/proto/Test.proto b/pulsar-client-schema/src/test/proto/Test.proto similarity index 94% rename from pulsar-client/src/test/proto/Test.proto rename to pulsar-client-schema/src/test/proto/Test.proto index d1400516d2..d640d2c499 100644 --- a/pulsar-client/src/test/proto/Test.proto +++ b/pulsar-client-schema/src/test/proto/Test.proto @@ -19,7 +19,7 @@ syntax = "proto3"; package proto; -option java_package = "org.apache.pulsar.client.schemas.proto"; +option java_package = "org.apache.pulsar.client.schema.proto"; option java_outer_classname = "Test"; enum TestEnum { diff --git a/pulsar-client-shaded/pom.xml b/pulsar-client-shaded/pom.xml index 3f66080641..8e7eb98ee3 100644 --- a/pulsar-client-shaded/pom.xml +++ b/pulsar-client-shaded/pom.xml @@ -58,6 +58,9 @@ <minimizeJar>false</minimizeJar> <artifactSet> + <excludes> + <exclude>org.apache.pulsar:pulsar-client-schema</exclude> + </excludes> <includes> <include>org.apache.pulsar:pulsar-io-core</include> <include>org.apache.pulsar:pulsar-client-original</include> @@ -94,14 +97,6 @@ <include>org.objenesis:*</include> <include>org.yaml:snakeyaml</include> - <include>org.apache.avro:*</include> - <!-- Avro transitive dependencies--> - <include>org.codehaus.jackson:jackson-core-asl</include> - <include>org.codehaus.jackson:jackson-mapper-asl</include> - <include>com.thoughtworks.paranamer:paranamer</include> - <include>org.xerial.snappy:snappy-java</include> - <include>org.apache.commons:commons-compress</include> - <include>org.tukaani:xz</include> </includes> </artifactSet> <filters> @@ -179,27 +174,6 @@ <pattern>org.apache.http</pattern> <shadedPattern>org.apache.pulsar.shade.org.apache.http</shadedPattern> </relocation> - <relocation> - <pattern>org.apache.avro</pattern> - <shadedPattern>org.apache.pulsar.shade.org.apache.avro</shadedPattern> - </relocation> - <!-- Avro transitive dependencies--> - <relocation> - <pattern>org.codehaus.jackson</pattern> - <shadedPattern>org.apache.pulsar.shade.org.codehaus.jackson</shadedPattern> - </relocation> - <relocation> - <pattern>com.thoughtworks.paranamer</pattern> - <shadedPattern>org.apache.pulsar.shade.com.thoughtworks.paranamer</shadedPattern> - </relocation> - <relocation> - <pattern>org.xerial.snappy</pattern> - <shadedPattern>org.apache.pulsar.shade.org.xerial.snappy</shadedPattern> - </relocation> - <relocation> - <pattern>org.tukaani</pattern> - <shadedPattern>org.apache.pulsar.shade.org.tukaani</shadedPattern> - </relocation> <relocation> <pattern>org.eclipse.jetty</pattern> <shadedPattern>org.apache.pulsar.shade.org.eclipse</shadedPattern> diff --git a/pulsar-client/pom.xml b/pulsar-client/pom.xml index 848cfef25f..2f624cd5f2 100644 --- a/pulsar-client/pom.xml +++ b/pulsar-client/pom.xml @@ -39,6 +39,18 @@ <version>${project.parent.version}</version> </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>pulsar-client-schema</artifactId> + <version>${project.parent.version}</version> + <exclusions> + <exclusion> + <groupId>org.apache.avro</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> <groupId>${project.groupId}</groupId> <artifactId>pulsar-io-core</artifactId> @@ -90,31 +102,6 @@ </exclusion> </exclusions> </dependency> - - <dependency> - <groupId>org.apache.avro</groupId> - <artifactId>avro</artifactId> - <version>${avro.version}</version> - </dependency> - - <dependency> - <groupId>org.apache.avro</groupId> - <artifactId>avro-protobuf</artifactId> - <version>${avro.version}</version> - <exclusions> - <exclusion> - <groupId>*</groupId> - <artifactId>*</artifactId> - </exclusion> - </exclusions> - </dependency> - - <dependency> - <groupId>com.google.protobuf</groupId> - <artifactId>protobuf-java</artifactId> - <version>${protobuf3.version}</version> - <scope>provided</scope> - </dependency> <!-- httpclient-hostname-verification depends on below dependencies --> <dependency> @@ -128,11 +115,6 @@ <version>4.4.9</version> </dependency> - <dependency> - <groupId>com.fasterxml.jackson.module</groupId> - <artifactId>jackson-module-jsonSchema</artifactId> - </dependency> - <!-- Testing dependencies --> <dependency> <groupId>org.apache.pulsar</groupId> @@ -149,26 +131,5 @@ <filtering>true</filtering> </resource> </resources> - <!-- Generate protobuf for testing purposes --> - <plugins> - <plugin> - <groupId>org.xolstice.maven.plugins</groupId> - <artifactId>protobuf-maven-plugin</artifactId> - <version>${protobuf-maven-plugin.version}</version> - <configuration> - <protocArtifact>com.google.protobuf:protoc:${protoc3.version}:exe:${os.detected.classifier}</protocArtifact> - <checkStaleness>true</checkStaleness> - <pluginId>grpc-java</pluginId> - <pluginArtifact>io.grpc:protoc-gen-grpc-java:${protoc-gen-grpc-java.version}:exe:${os.detected.classifier}</pluginArtifact> - </configuration> - <executions> - <execution> - <goals> - <goal>test-compile</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> </build> </project> diff --git a/pulsar-client/src/test/java/org/apache/pulsar/client/schemas/DefaultSchemasTest.java b/pulsar-client/src/test/java/org/apache/pulsar/client/schema/DefaultSchemasTest.java similarity index 88% rename from pulsar-client/src/test/java/org/apache/pulsar/client/schemas/DefaultSchemasTest.java rename to pulsar-client/src/test/java/org/apache/pulsar/client/schema/DefaultSchemasTest.java index b9386fcd4f..8ab034914a 100644 --- a/pulsar-client/src/test/java/org/apache/pulsar/client/schemas/DefaultSchemasTest.java +++ b/pulsar-client/src/test/java/org/apache/pulsar/client/schema/DefaultSchemasTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.pulsar.client.schemas; +package org.apache.pulsar.client.schema; import org.apache.pulsar.client.api.ConsumerBuilder; import org.apache.pulsar.client.api.Message; @@ -26,16 +26,14 @@ import org.apache.pulsar.client.api.PulsarClientException; import org.apache.pulsar.client.api.ReaderBuilder; import org.apache.pulsar.client.impl.schema.StringSchema; +import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; public class DefaultSchemasTest { private PulsarClient client; @@ -53,21 +51,21 @@ public void setup() throws PulsarClientException { public void testConsumerInstantiation() { ConsumerBuilder<String> stringConsumerBuilder = client.newConsumer(new StringSchema()) .topic(TEST_TOPIC); - assertNotNull(stringConsumerBuilder); + Assert.assertNotNull(stringConsumerBuilder); } @Test public void testProducerInstantiation() { ProducerBuilder<String> stringProducerBuilder = client.newProducer(new StringSchema()) .topic(TEST_TOPIC); - assertNotNull(stringProducerBuilder); + Assert.assertNotNull(stringProducerBuilder); } @Test public void testReaderInstantiation() { ReaderBuilder<String> stringReaderBuilder = client.newReader(new StringSchema()) .topic(TEST_TOPIC); - assertNotNull(stringReaderBuilder); + Assert.assertNotNull(stringReaderBuilder); } @Test @@ -75,7 +73,7 @@ public void testStringSchema() throws Exception { String testString = "hello world"; byte[] testBytes = testString.getBytes(StandardCharsets.UTF_8); StringSchema stringSchema = new StringSchema(); - assertTrue(stringSchema.decode(testBytes).equals(testString)); + Assert.assertTrue(stringSchema.decode(testBytes).equals(testString)); assertEquals(stringSchema.encode(testString), testBytes); Message<String> msg1 = MessageBuilder.create(stringSchema) @@ -90,7 +88,7 @@ public void testStringSchema() throws Exception { byte[] bytes2 = testString.getBytes(StandardCharsets.UTF_16); StringSchema stringSchemaUtf16 = new StringSchema(StandardCharsets.UTF_16); - assertTrue(stringSchemaUtf16.decode(bytes2).equals(testString)); + Assert.assertTrue(stringSchemaUtf16.decode(bytes2).equals(testString)); assertEquals(stringSchemaUtf16.encode(testString), bytes2); } ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services