NihalJain commented on code in PR #105:
URL: https://github.com/apache/hbase-thirdparty/pull/105#discussion_r1332255317


##########
hbase-shaded-netty-tcnative/pom.xml:
##########
@@ -0,0 +1,145 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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/maven-v4_0_0.xsd";>
+  <!--
+/**
+ * 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.
+ */
+
+
+  ON MVN COMPILE NOT WORKING
+
+  If you wondering why 'mvn compile' does not work building HBase
+  (in particular, if you are doing it for the first time), instead do
+  'mvn package'.  If you are interested in the full story, see
+  https://issues.apache.org/jira/browse/HBASE-6795.
+
+-->
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.hbase.thirdparty</groupId>
+    <artifactId>hbase-thirdparty</artifactId>
+    <version>${revision}</version>
+    <relativePath>..</relativePath>
+  </parent>
+  <artifactId>hbase-shaded-netty-tcnative</artifactId>
+  <name>Apache HBase Relocated (Shaded) netty-tcnative Libs</name>
+  <dependencies>
+    <dependency>
+      <groupId>io.netty</groupId>
+      <artifactId>netty-tcnative-boringssl-static</artifactId>
+      <version>${netty.tcnative.version}</version>
+      <classifier>linux-x86_64</classifier>
+    </dependency>
+    <dependency>
+      <groupId>io.netty</groupId>
+      <artifactId>netty-tcnative-boringssl-static</artifactId>
+      <version>${netty.tcnative.version}</version>
+      <classifier>linux-aarch_64</classifier>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-clean-plugin</artifactId>
+        <configuration>
+          <filesets>
+            <fileset>
+              <directory>${basedir}</directory>
+              <includes>
+                <include>dependency-reduced-pom.xml</include>
+              </includes>
+            </fileset>
+          </filesets>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-shade-plugin</artifactId>
+        <executions>
+          <execution>
+            <phase>package</phase>
+            <goals>
+              <goal>shade</goal>
+            </goals>
+            <configuration>
+              <shadeSourcesContent>true</shadeSourcesContent>
+              <createSourcesJar>true</createSourcesJar>
+              <relocations>
+                <relocation>
+                  <pattern>io.netty</pattern>
+                  <shadedPattern>${rename.offset}.io.netty</shadedPattern>
+                </relocation>
+              </relocations>
+              <artifactSet>
+                <includes>
+                  <include>io.netty:*</include>
+                </includes>
+              </artifactSet>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <!--This trick from
+             
https://stackoverflow.com/questions/33825743/rename-files-inside-a-jar-using-some-maven-plugin
+
+            The netty jar has a .so in it. Shading requires rename of the .so 
and then passing a system
+            property so netty finds the renamed .so and associates it w/ the 
relocated netty files.
+
+            Add this define when running unit tests:
+
+               mvn test 
-Dorg.apache.hbase.thirdparty.io.netty.packagePrefix=org.apache.hbase.thirdparty.
 -Dtest=TestNettyIPC
+
+            See toward the end of this issue for how to pass config:
+
+              https://github.com/netty/netty/issues/6665
+
+            TODO: Ensure native works.
+            NOTE: The 'tofile' in the move command below has the relocation 
hard-coded
+            with '-' instead of '.' separators. If change the relocation, need 
to change here too.
+          -->
+        <groupId>org.apache.maven.plugins</groupId>

Review Comment:
   Was trying to see if could figure out a way to work around META-INF/LICENSE, 
 META-INF/license case insensitive name issue on Mac.
   
   Finally thought of an alternate way where instead of unzipping the whole 
jar, we do the following:
   
   1. just extract what we need, 
   2. rename/delete them locally, 
   3. delete original files in jar and 
   4. add back renamed files inside jar. 
   
   A working code based on above idea:
   ```
          <executions>
             <execution>
               <id>unpack</id>
               <phase>package</phase>
                 <configuration>
                     <target>
                         <echo message="Extract files inside 
META-INF/native/*"/>
                         <unzip 
src="${project.build.directory}/${project.artifactId}-${project.version}.jar"
                                dest="${project.build.directory}/unpacked/">
                             <patternset>
                                 <include name="META-INF/native/*"/>
                             </patternset>
                         </unzip>
   
                         <echo message="Rename netty .so in META-INF"/>
                         <move 
file="${project.build.directory}/unpacked/META-INF/native/libnetty_tcnative_linux_x86_64.so"
                               
tofile="${project.build.directory}/unpacked/META-INF/native/liborg_apache_hbase_thirdparty_netty_tcnative_linux_x86_64.so"/>
                         <move 
file="${project.build.directory}/unpacked/META-INF/native/libnetty_tcnative_linux_aarch_64.so"
                               
tofile="${project.build.directory}/unpacked/META-INF/native/liborg_apache_hbase_thirdparty_netty_tcnative_linux_aarch_64.so"/>
   
                         <echo message="Delete original netty .so in META-INF"/>
                         <exec executable="zip">
                             <arg value="-d"/>
                             <arg 
value="${project.build.directory}/${project.artifactId}-${project.version}.jar"/>
                             <arg 
value="META-INF/native/libnetty_tcnative_linux_x86_64.so"/>
                         </exec>
                         <exec executable="zip">
                             <arg value="-d"/>
                             <arg 
value="${project.build.directory}/${project.artifactId}-${project.version}.jar"/>
                             <arg 
value="META-INF/native/libnetty_tcnative_linux_aarch_64.so"/>
                         </exec>
   
                         <echo message="Rename netty .jnilib in META-INF"/>
                         <move 
file="${project.build.directory}/unpacked/META-INF/native/libnetty_tcnative_osx_x86_64.jnilib"
                               
tofile="${project.build.directory}/unpacked/META-INF/native/liborg_apache_hbase_thirdparty_netty_tcnative_osx_x86_64.jnilib"/>
                         <move 
file="${project.build.directory}/unpacked/META-INF/native/libnetty_tcnative_osx_aarch_64.jnilib"
                               
tofile="${project.build.directory}/unpacked/META-INF/native/liborg_apache_hbase_thirdparty_netty_tcnative_osx_aarch_64.jnilib"/>
   
                         <echo message="Delete original netty .jnilib in 
META-INF"/>
                         <exec executable="zip">
                             <arg value="-d"/>
                             <arg 
value="${project.build.directory}/${project.artifactId}-${project.version}.jar"/>
                             <arg 
value="META-INF/native/libnetty_tcnative_osx_x86_64.jnilib"/>
                         </exec>
                         <exec executable="zip">
                             <arg value="-d"/>
                             <arg 
value="${project.build.directory}/${project.artifactId}-${project.version}.jar"/>
                             <arg 
value="META-INF/native/libnetty_tcnative_osx_aarch_64.jnilib"/>
                         </exec>
   
                         <echo message="Remove netty .dll file in META-INF"/>
                         <delete 
file="${project.build.directory}/unpacked/META-INF/native/netty_tcnative_windows_x86_64.dll"/>
                         <echo message="Delete original netty .dll file in 
META-INF"/>
                         <exec executable="zip">
                             <arg value="-d"/>
                             <arg 
value="${project.build.directory}/${project.artifactId}-${project.version}.jar"/>
                             <arg 
value="META-INF/native/netty_tcnative_windows_x86_64.dll"/>
                         </exec>
   
                         <echo message="Add renamed files back to jar"/>
                         <zip 
destfile="${project.build.directory}/${project.artifactId}-${project.version}.jar"
                              update="true">
                             <zipfileset 
dir="${project.build.directory}/unpacked/" includes="**/*"/>
                         </zip>
                     </target>
                 </configuration>
               <goals>
                 <goal>run</goal>
               </goals>
             </execution>
           </executions>
   ```
   This works on Mac and saves us from extracting the whole zip.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to