This is an automated email from the ASF dual-hosted git repository.
zhangduo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/master by this push:
new 6452396 HBASE-24119 Polish the protobuf usage in hbase-examples
(#1438)
6452396 is described below
commit 64523961879715ff7d8bad843883b494ae4a8017
Author: Duo Zhang <[email protected]>
AuthorDate: Mon Apr 6 22:14:55 2020 +0800
HBASE-24119 Polish the protobuf usage in hbase-examples (#1438)
Move the proto files only used by hbase-examples to hbase-examples, to show
users how to make use of shaded hbase protos when implementing coprocessor.
Signed-off-by: Jan Hentschel <[email protected]>
Signed-off-by: Viraj Jasani <[email protected]>
---
hbase-examples/pom.xml | 52 +++++++++++++++++++++-
.../java/org/apache/hadoop/hbase/types/PBCell.java | 5 ++-
.../java/org/apache/hadoop/hbase/types/PBType.java | 12 +++--
.../src/main/protobuf}/BulkDelete.proto | 0
.../src/main/protobuf}/RefreshHFiles.proto | 0
.../src/main/protobuf}/RowCount.proto | 0
.../org/apache/hadoop/hbase/types/TestPBCell.java | 3 +-
hbase-protocol-shaded/pom.xml | 15 +------
8 files changed, 67 insertions(+), 20 deletions(-)
diff --git a/hbase-examples/pom.xml b/hbase-examples/pom.xml
index e95d6a2..08bff98 100644
--- a/hbase-examples/pom.xml
+++ b/hbase-examples/pom.xml
@@ -29,7 +29,12 @@
<artifactId>hbase-examples</artifactId>
<name>Apache HBase - Examples</name>
<description>Examples of HBase usage</description>
- <!--REMOVE-->
+ <properties>
+ <!--Version of protobuf that hbase uses internally (we shade our pb)
+ Must match what is out in hbase-thirdparty include.
+ -->
+ <internal.protobuf.version>3.11.4</internal.protobuf.version>
+ </properties>
<build>
<plugins>
<plugin>
@@ -62,10 +67,51 @@
<goals>
<goal>compile</goal>
</goals>
+ <configuration>
+
<protocArtifact>com.google.protobuf:protoc:${internal.protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
+ <checkStaleness>true</checkStaleness>
+ </configuration>
</execution>
</executions>
</plugin>
<plugin>
+ <groupId>com.google.code.maven-replacer-plugin</groupId>
+ <artifactId>replacer</artifactId>
+ <version>1.5.3</version>
+ <executions>
+ <execution>
+ <phase>process-sources</phase>
+ <goals>
+ <goal>replace</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <basedir>${basedir}/target/generated-sources/</basedir>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ <!-- Ignore errors when missing files, because it means this build
+ was run with -Dprotoc.skip and there is no -Dreplacer.skip -->
+ <ignoreErrors>true</ignoreErrors>
+ <replacements>
+ <replacement>
+ <token>([^\.])com.google.protobuf</token>
+
<value>$1org.apache.hbase.thirdparty.com.google.protobuf</value>
+ </replacement>
+ <replacement>
+ <token>(public)(\W+static)?(\W+final)?(\W+class)</token>
+ <value>@javax.annotation.Generated("proto") $1$2$3$4</value>
+ </replacement>
+ <!-- replacer doesn't support anchoring or negative lookbehind
-->
+ <replacement>
+ <token>(@javax.annotation.Generated\("proto"\) ){2}</token>
+ <value>$1</value>
+ </replacement>
+ </replacements>
+ </configuration>
+ </plugin>
+ <plugin>
<groupId>net.revelc.code</groupId>
<artifactId>warbucks-maven-plugin</artifactId>
</plugin>
@@ -89,6 +135,10 @@
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
+ <artifactId>hbase-protocol-shaded</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hbase</groupId>
<artifactId>hbase-common</artifactId>
</dependency>
<dependency>
diff --git
a/hbase-examples/src/main/java/org/apache/hadoop/hbase/types/PBCell.java
b/hbase-examples/src/main/java/org/apache/hadoop/hbase/types/PBCell.java
index 9962797..9946b02 100644
--- a/hbase-examples/src/main/java/org/apache/hadoop/hbase/types/PBCell.java
+++ b/hbase-examples/src/main/java/org/apache/hadoop/hbase/types/PBCell.java
@@ -17,13 +17,14 @@
*/
package org.apache.hadoop.hbase.types;
-import com.google.protobuf.CodedInputStream;
-import com.google.protobuf.CodedOutputStream;
import java.io.IOException;
import org.apache.hadoop.hbase.example.protobuf.generated.CellMessage;
import org.apache.hadoop.hbase.util.PositionedByteRange;
import org.apache.yetus.audience.InterfaceAudience;
+import org.apache.hbase.thirdparty.com.google.protobuf.CodedInputStream;
+import org.apache.hbase.thirdparty.com.google.protobuf.CodedOutputStream;
+
/**
* An example for using protobuf objects with {@link DataType} API.
*/
diff --git
a/hbase-examples/src/main/java/org/apache/hadoop/hbase/types/PBType.java
b/hbase-examples/src/main/java/org/apache/hadoop/hbase/types/PBType.java
index 8c6a1d9..c9dc382 100644
--- a/hbase-examples/src/main/java/org/apache/hadoop/hbase/types/PBType.java
+++ b/hbase-examples/src/main/java/org/apache/hadoop/hbase/types/PBType.java
@@ -17,15 +17,19 @@
*/
package org.apache.hadoop.hbase.types;
-import com.google.protobuf.CodedInputStream;
-import com.google.protobuf.CodedOutputStream;
-import com.google.protobuf.Message;
import org.apache.hadoop.hbase.util.Order;
import org.apache.hadoop.hbase.util.PositionedByteRange;
import org.apache.yetus.audience.InterfaceAudience;
+import org.apache.hbase.thirdparty.com.google.protobuf.CodedInputStream;
+import org.apache.hbase.thirdparty.com.google.protobuf.CodedOutputStream;
+import org.apache.hbase.thirdparty.com.google.protobuf.Message;
+
/**
* A base-class for {@link DataType} implementations backed by protobuf. See
{@link PBCell}.
+ * <p/>
+ * Notice that, in hbase we always uses our own shaded version of protobuf,
but you are free to use
+ * the original version of protobuf in your own project.
*/
@InterfaceAudience.Private
public abstract class PBType<T extends Message> implements DataType<T> {
@@ -59,6 +63,7 @@ public abstract class PBType<T extends Message> implements
DataType<T> {
* {@code src}'s position after consuming from the stream.
* <p/>
* For example:
+ *
* <pre>
* Foo.Builder builder = ...
* CodedInputStream is = inputStreamFromByteRange(src);
@@ -76,6 +81,7 @@ public abstract class PBType<T extends Message> implements
DataType<T> {
* {@code dst}'s position after writing to the stream.
* <p/>
* For example:
+ *
* <pre>
* CodedOutputStream os = outputStreamFromByteRange(dst);
* int before = os.spaceLeft(), after, written;
diff --git
a/hbase-protocol-shaded/src/main/protobuf/server/coprocessor/examples/BulkDelete.proto
b/hbase-examples/src/main/protobuf/BulkDelete.proto
similarity index 100%
rename from
hbase-protocol-shaded/src/main/protobuf/server/coprocessor/examples/BulkDelete.proto
rename to hbase-examples/src/main/protobuf/BulkDelete.proto
diff --git
a/hbase-protocol-shaded/src/main/protobuf/server/coprocessor/examples/RefreshHFiles.proto
b/hbase-examples/src/main/protobuf/RefreshHFiles.proto
similarity index 100%
rename from
hbase-protocol-shaded/src/main/protobuf/server/coprocessor/examples/RefreshHFiles.proto
rename to hbase-examples/src/main/protobuf/RefreshHFiles.proto
diff --git
a/hbase-protocol-shaded/src/main/protobuf/server/coprocessor/examples/RowCount.proto
b/hbase-examples/src/main/protobuf/RowCount.proto
similarity index 100%
rename from
hbase-protocol-shaded/src/main/protobuf/server/coprocessor/examples/RowCount.proto
rename to hbase-examples/src/main/protobuf/RowCount.proto
diff --git
a/hbase-examples/src/test/java/org/apache/hadoop/hbase/types/TestPBCell.java
b/hbase-examples/src/test/java/org/apache/hadoop/hbase/types/TestPBCell.java
index 5ca3cf4..7c193d3 100644
--- a/hbase-examples/src/test/java/org/apache/hadoop/hbase/types/TestPBCell.java
+++ b/hbase-examples/src/test/java/org/apache/hadoop/hbase/types/TestPBCell.java
@@ -19,7 +19,6 @@ package org.apache.hadoop.hbase.types;
import static org.junit.Assert.assertEquals;
-import com.google.protobuf.ByteString;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.example.protobuf.generated.CellMessage;
import org.apache.hadoop.hbase.testclassification.MiscTests;
@@ -30,6 +29,8 @@ import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import org.apache.hbase.thirdparty.com.google.protobuf.ByteString;
+
@Category({ SmallTests.class, MiscTests.class })
public class TestPBCell {
diff --git a/hbase-protocol-shaded/pom.xml b/hbase-protocol-shaded/pom.xml
index 2b3c7fe..6d8b0ab 100644
--- a/hbase-protocol-shaded/pom.xml
+++ b/hbase-protocol-shaded/pom.xml
@@ -33,20 +33,10 @@
<maven.javadoc.skip>true</maven.javadoc.skip>
<!--Version of protobuf that hbase uses internally (we shade our pb)
Must match what is out in hbase-thirdparty include.
- 3.5.1-1 is the same as 3.5.1 except includes corrected binaries for
el6
- to work around https://github.com/google/protobuf/issues/4109
- -->
- <internal.protobuf.version>3.5.1-1</internal.protobuf.version>
+ -->
+ <internal.protobuf.version>3.11.4</internal.protobuf.version>
</properties>
<build>
- <resources>
- <resource>
- <directory>src/main/</directory>
- <includes>
- <include>**/*.proto</include>
- </includes>
- </resource>
- </resources>
<plugins>
<!-- Make a jar and put the sources in the jar -->
<plugin>
@@ -88,7 +78,6 @@
</goals>
<configuration>
<protocArtifact>com.google.protobuf:protoc:${internal.protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
- <attachProtoSources>false</attachProtoSources>
<checkStaleness>true</checkStaleness>
</configuration>
</execution>