From 930f4c019e3d8acc81376182c941ef887cc8a865 Mon Sep 17 00:00:00 2001 From: Jing Zhao Date: Tue, 28 Mar 2017 19:40:01 -0700 Subject: [PATCH] RATIS-49. Add a clean profile to remove shaded source. Contributed by Tsz Wo Nicholas Sze. --- BUILDING.md | 55 +++++++++++++++++++++++-------------- pom.xml | 2 +- ratis-hadoop-shaded/pom.xml | 42 ++++++++++++++++++++++------ ratis-proto-shaded/pom.xml | 54 ++++++++++++++++++++---------------- 4 files changed, 99 insertions(+), 54 deletions(-) diff --git a/BUILDING.md b/BUILDING.md index 4c634a459b..42a6f08f91 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -1,38 +1,54 @@ # Building -Ratis uses Apache Maven for the builds. A 3.0+ version of Maven is required as well as +Apache Ratis uses Apache Maven for the builds. A 3.2+ version of Maven is required as well as at least Java-1.8. -When Ratis is build for the first time, shaded protobuf files needs to be generated first -which happens only in the mvn package phase. That is why you should run: +When building Ratis the first time, shaded files need to be generated by the following command: ``` $ mvn package -DskipTests ``` -the first time the sources are checked out first. After doing that mvn compile or mvn test -can be used as normal. +After that, `mvn compile` or `mvn test` can be used as normal. +For example, we may run the basic tests by +``` +$ mvn test -Dtest=TestRaftWith\* +``` -# Raft Proto Shaded +# Shading -We shade protos, protobuf and other libraries such as Netty, gRPC and Hadoop so that -applications using Raft may use protobuf and other libraries with versions different -from the versions used here. +We shade protos, protobuf and other libraries such as Netty, gRPC, Guava and Hadoop +so that applications using Ratis may use protobuf and other libraries with versions +different from the versions used here. -The library requires the shaded sources for compilation. The generated sources are stored in -`ratis-proto-shaded/src/main/java/`. They are not checked-in git though. +Ratis requires the shaded sources for compilation. +The generated sources are stored in the following directories. +``` +ratis-proto-shaded/src/main/java/ +ratis-hadoop-shaded/src/main/java/ +``` +They are not checked-in to git though. -If you want to force-compile the proto files (for example after changing them), you should -run with +If you want to force compiling the proto files (for example after changing them), +you should run ``` $ mvn package -DskipTests -Dcompile-protobuf ``` +For removing the shaded sources, run +``` +$ mvn clean -Pclean-shade +``` + +Note that `mvn clean` alone does not remove the shaded sources. + ## What are shaded? -| Original packages | Shaded packages | -| ----------------------------------|----------------------------------------------------------| -| `com.google.protobuf` | `org.apache.ratis.shaded.com.google.protobuf` | -| `io.grpc` | `org.apache.ratis.shaded.io.grpc` | -| `io.netty.handler.codec.protobuf` | `org.apache.ratis.shaded.io.netty.handler.codec.protobuf` | -| `org.apache.hadoop.ipc.protobuf` | `org.apache.ratis.shaded.org.apache.hadoop.ipc.protobuf` | +| Original packages | Shaded packages | +| ------------------------------------|--------------------------------------------------------------| +| `com.google.common` | `org.apache.ratis.shaded.com.google.common` | +| `com.google.protobuf` | `org.apache.ratis.shaded.com.google.protobuf` | +| `com.google.thirdparty.publicsuffix`| `org.apache.ratis.shaded.com.google.thirdparty.publicsuffix` | +| `io.grpc` | `org.apache.ratis.shaded.io.grpc` | +| `io.netty` | `org.apache.ratis.shaded.io.netty` | +| `org.apache.hadoop.ipc.protobuf` | `org.apache.ratis.shaded.org.apache.hadoop.ipc.protobuf` | The protos defined in this project are stored in the `org.apache.ratis.shaded.proto` package. @@ -53,7 +69,6 @@ To publish, use the following settings.xml file ( placed in ~/.m2/settings.xml ) ratis_committer ******** - ``` diff --git a/pom.xml b/pom.xml index 7e0869f6e0..ea4f72b2af 100644 --- a/pom.xml +++ b/pom.xml @@ -134,7 +134,7 @@ 2.4 2.5.3 2.15 - 2.5 + 3.0.0 3.3.0 3.2 2.10 diff --git a/ratis-hadoop-shaded/pom.xml b/ratis-hadoop-shaded/pom.xml index cb74fa2957..0321a22caf 100644 --- a/ratis-hadoop-shaded/pom.xml +++ b/ratis-hadoop-shaded/pom.xml @@ -32,7 +32,7 @@ ${project.build.directory}/classes - src/main/java + src/main/java ${hadoop.version} @@ -41,7 +41,7 @@ - ${sources.dir} + ${shaded.sources.dir} ${classes.dir} @@ -72,17 +72,20 @@ com.google.protobuf protobuf-java ${shaded.protobuf.version} + true com.google.protobuf.nano protobuf-javanano ${shaded.protobuf.version} + true org.apache.hadoop hadoop-common ${shaded.hadoop.version} + true @@ -101,19 +104,41 @@ - skipShade + skipCompileProto - ${sources.dir} + ${shaded.sources.dir} - !shade-hadoop + !compile-protobuf - shade-hadoop + clean-shade + + false + + + + + maven-clean-plugin + + + + ${shaded.sources.dir} + false + + + + + + + + + + compile-protobuf @@ -121,7 +146,7 @@ true - shade-hadoop + compile-protobuf @@ -273,8 +298,7 @@ sources jar true - ${basedir}/src/main/java - + ${basedir}/${shaded.sources.dir} **/*.java diff --git a/ratis-proto-shaded/pom.xml b/ratis-proto-shaded/pom.xml index 76148c4b87..dc3240316d 100644 --- a/ratis-proto-shaded/pom.xml +++ b/ratis-proto-shaded/pom.xml @@ -32,8 +32,7 @@ ${project.build.directory}/classes - src/main/java - + src/main/java 1.0.1 @@ -44,7 +43,7 @@ - ${sources.dir} + ${shaded.sources.dir} ${classes.dir} @@ -372,10 +371,10 @@ - skip-proto-shaded-tests + skip-shaded-tests - skip-proto-shaded-tests + skip-shaded-tests @@ -387,7 +386,7 @@ skipCompileProto - ${sources.dir} + ${shaded.sources.dir} !compile-protobuf @@ -395,26 +394,34 @@ + + clean-shade + + false + + + + + maven-clean-plugin + + + + ${shaded.sources.dir} + false + + + + + + + + compile-protobuf true @@ -594,8 +601,7 @@ sources jar true - ${basedir}/src/main/java - + ${basedir}/${shaded.sources.dir} **/*.java