This is an automated email from the ASF dual-hosted git repository.

lhotari pushed a commit to branch branch-3.2
in repository https://gitbox.apache.org/repos/asf/pulsar.git

commit 9466eb32f6c8d6b3363fae84c7493d1d820d1a93
Author: Lari Hotari <lhot...@users.noreply.github.com>
AuthorDate: Mon Jun 24 19:54:27 2024 +0300

    [improve][misc] Replace rename-netty-native-libs.sh script with renaming 
with maven-shade-plugin (#22957)
    
    (cherry picked from commit f728b2ebb9bfe2dfe1f64643640700f762524c40)
---
 README.md                          |  2 -
 pom.xml                            |  7 ---
 pulsar-client-admin-shaded/pom.xml | 31 +++---------
 pulsar-client-all/pom.xml          | 31 +++---------
 pulsar-client-shaded/pom.xml       | 31 +++---------
 src/rename-netty-native-libs.cmd   | 98 --------------------------------------
 src/rename-netty-native-libs.sh    | 70 ---------------------------
 7 files changed, 18 insertions(+), 252 deletions(-)

diff --git a/README.md b/README.md
index e84265f91a7..0a85a91cc68 100644
--- a/README.md
+++ b/README.md
@@ -141,8 +141,6 @@ components in the Pulsar ecosystem, including connectors, 
adapters, and other la
 >
 > This project includes a [Maven Wrapper](https://maven.apache.org/wrapper/) 
 > that can be used instead of a system-installed Maven.
 > Use it by replacing `mvn` by `./mvnw` on Linux and `mvnw.cmd` on Windows in 
 > the commands below.    
->
-> It's better to use CMD rather than Powershell on Windows. Because maven will 
activate the `windows` profile which runs `rename-netty-native-libs.cmd`.
 
 ### Build
 
diff --git a/pom.xml b/pom.xml
index f9091b20e2f..15dac34c182 100644
--- a/pom.xml
+++ b/pom.xml
@@ -310,9 +310,6 @@ flexible messaging model and an intuitive client 
API.</description>
     <extra-enforcer-rules.version>1.6.1</extra-enforcer-rules.version>
     <oshi.version>6.4.0</oshi.version>
     <checkerframework.version>3.33.0</checkerframework.version>
-
-    <!-- Used to configure rename.netty.native. Libs -->
-    
<rename.netty.native.libs>rename-netty-native-libs.sh</rename.netty.native.libs>
   </properties>
 
   <dependencyManagement>
@@ -2270,10 +2267,6 @@ flexible messaging model and an intuitive client 
API.</description>
           <family>Windows</family>
         </os>
       </activation>
-      <properties>
-        
<rename.netty.native.libs>rename-netty-native-libs.cmd</rename.netty.native.libs>
-      </properties>
-
     </profile>
     <!-- Primary Module profile -->
     <profile>
diff --git a/pulsar-client-admin-shaded/pom.xml 
b/pulsar-client-admin-shaded/pom.xml
index 2b29f9f783e..d019c8d7a45 100644
--- a/pulsar-client-admin-shaded/pom.xml
+++ b/pulsar-client-admin-shaded/pom.xml
@@ -295,6 +295,12 @@
                     <pattern>org.apache.bookkeeper</pattern>
                     
<shadedPattern>org.apache.pulsar.shade.org.apache.bookkeeper</shadedPattern>
                   </relocation>
+                  <!-- Rename Netty native libraries to include the shaded 
prefix -->
+                  <relocation>
+                    
<pattern>(META-INF/native/(lib)?)(netty.+\.(so|jnilib|dll))$</pattern>
+                    <shadedPattern>$1org_apache_pulsar_shade_$3</shadedPattern>
+                    <rawString>true</rawString>
+                  </relocation>
               </relocations>
               <transformers>
                 <transformer 
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"
 />
@@ -304,31 +310,6 @@
           </execution>
         </executions>
       </plugin>
-
-      <plugin>
-        <!-- This plugin is used to run a script after the package phase in 
order to rename
-            libnetty_transport_native_epoll_x86_64.so from Netty into
-            liborg_apache_pulsar_shade_netty_transport_native_epoll_x86_64.so
-            to reflect the shade that is being applied.
-         -->
-        <artifactId>exec-maven-plugin</artifactId>
-        <groupId>org.codehaus.mojo</groupId>
-        <executions>
-          <execution>
-            <id>rename-epoll-library</id>
-            <phase>package</phase>
-            <goals>
-              <goal>exec</goal>
-            </goals>
-            <configuration>
-              
<executable>${project.parent.basedir}/src/${rename.netty.native.libs}</executable>
-              <arguments>
-                <argument>${project.artifactId}</argument>
-              </arguments>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
     </plugins>
   </build>
 </project>
diff --git a/pulsar-client-all/pom.xml b/pulsar-client-all/pom.xml
index f805ff0de4a..3c8eb745946 100644
--- a/pulsar-client-all/pom.xml
+++ b/pulsar-client-all/pom.xml
@@ -387,6 +387,12 @@
                   <pattern>org.tukaani</pattern>
                   
<shadedPattern>org.apache.pulsar.shade.org.tukaani</shadedPattern>
                 </relocation>
+                <!-- Rename Netty native libraries to include the shaded 
prefix -->
+                <relocation>
+                  
<pattern>(META-INF/native/(lib)?)(netty.+\.(so|jnilib|dll))$</pattern>
+                  <shadedPattern>$1org_apache_pulsar_shade_$3</shadedPattern>
+                  <rawString>true</rawString>
+                </relocation>
               </relocations>
               <transformers>
                 <transformer 
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"
 />
@@ -396,31 +402,6 @@
           </execution>
         </executions>
       </plugin>
-
-      <plugin>
-        <!-- This plugin is used to run a script after the package phase in 
order to rename
-            libnetty_transport_native_epoll_x86_64.so from Netty into
-            liborg_apache_pulsar_shade_netty_transport_native_epoll_x86_64.so
-            to reflect the shade that is being applied.
-         -->
-        <artifactId>exec-maven-plugin</artifactId>
-        <groupId>org.codehaus.mojo</groupId>
-        <executions>
-          <execution>
-            <id>rename-epoll-library</id>
-            <phase>package</phase>
-            <goals>
-              <goal>exec</goal>
-            </goals>
-            <configuration>
-              
<executable>${project.parent.basedir}/src/${rename.netty.native.libs}</executable>
-              <arguments>
-                <argument>${project.artifactId}</argument>
-              </arguments>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-enforcer-plugin</artifactId>
diff --git a/pulsar-client-shaded/pom.xml b/pulsar-client-shaded/pom.xml
index cac0b1e74da..d6af1183dbf 100644
--- a/pulsar-client-shaded/pom.xml
+++ b/pulsar-client-shaded/pom.xml
@@ -300,6 +300,12 @@
                   <pattern>org.apache.bookkeeper</pattern>
                   
<shadedPattern>org.apache.pulsar.shade.org.apache.bookkeeper</shadedPattern>
                 </relocation>
+                <!-- Rename Netty native libraries to include the shaded 
prefix -->
+                <relocation>
+                  
<pattern>(META-INF/native/(lib)?)(netty.+\.(so|jnilib|dll))$</pattern>
+                  <shadedPattern>$1org_apache_pulsar_shade_$3</shadedPattern>
+                  <rawString>true</rawString>
+                </relocation>
               </relocations>
               <transformers>
                 <transformer 
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"
 />
@@ -323,31 +329,6 @@
           </execution>
         </executions>
       </plugin>
-
-      <plugin>
-        <!-- This plugin is used to run a script after the package phase in 
order to rename
-            libnetty_transport_native_epoll_x86_64.so from Netty into
-            liborg_apache_pulsar_shade_netty_transport_native_epoll_x86_64.so
-            to reflect the shade that is being applied.
-         -->
-        <artifactId>exec-maven-plugin</artifactId>
-        <groupId>org.codehaus.mojo</groupId>
-        <executions>
-          <execution>
-            <id>rename-epoll-library</id>
-            <phase>package</phase>
-            <goals>
-              <goal>exec</goal>
-            </goals>
-            <configuration>
-              
<executable>${project.parent.basedir}/src/${rename.netty.native.libs}</executable>
-              <arguments>
-                <argument>${project.artifactId}</argument>
-              </arguments>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
     </plugins>
   </build>
 </project>
diff --git a/src/rename-netty-native-libs.cmd b/src/rename-netty-native-libs.cmd
deleted file mode 100644
index bfaa16de081..00000000000
--- a/src/rename-netty-native-libs.cmd
+++ /dev/null
@@ -1,98 +0,0 @@
-@REM
-@REM Licensed to the Apache Software Foundation (ASF) under one
-@REM or more contributor license agreements.  See the NOTICE file
-@REM distributed with this work for additional information
-@REM regarding copyright ownership.  The ASF licenses this file
-@REM to you under the Apache License, Version 2.0 (the
-@REM "License"); you may not use this file except in compliance
-@REM with the License.  You may obtain a copy of the License at
-@REM
-@REM   http://www.apache.org/licenses/LICENSE-2.0
-@REM
-@REM Unless required by applicable law or agreed to in writing,
-@REM software distributed under the License is distributed on an
-@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-@REM KIND, either express or implied.  See the License for the
-@REM specific language governing permissions and limitations
-@REM under the License.
-@REM
-
-@echo off
-
-set ARTIFACT_ID=%1
-set JAR_PATH=%cd%/target/%ARTIFACT_ID%.jar
-set FILE_PREFIX=META-INF/native
-
-:: echo %JAR_PATH%
-:: echo %FILE_PREFIX%
-
-ECHO.
-echo ----- Renaming epoll lib in %JAR_PATH% ------
-set TMP_DIR=%temp%\tmp_pulsar
-
-rd %TMP_DIR% /s /q
-mkdir %TMP_DIR%
-
-set UNZIP_CMD=unzip -q %JAR_PATH% -d %TMP_DIR%
-call %UNZIP_CMD%
-
-:: echo %UNZIP_CMD%
-:: echo %TMP_DIR%
-
-cd /d %TMP_DIR%/%FILE_PREFIX%
-
-:: Loop through the number of groups
-SET Obj_Length=10
-SET Obj[0].FROM=libnetty_transport_native_epoll_x86_64.so
-SET Obj[0].TO=liborg_apache_pulsar_shade_netty_transport_native_epoll_x86_64.so
-SET Obj[1].FROM=libnetty_transport_native_epoll_aarch_64.so
-SET 
Obj[1].TO=liborg_apache_pulsar_shade_netty_transport_native_epoll_aarch_64.so
-SET Obj[2].FROM=libnetty_tcnative_linux_x86_64.so
-SET Obj[2].TO=liborg_apache_pulsar_shade_netty_tcnative_linux_x86_64.so
-SET Obj[3].FROM=libnetty_tcnative_linux_aarch_64.so
-SET Obj[3].TO=liborg_apache_pulsar_shade_netty_tcnative_linux_aarch_64.so
-SET Obj[4].FROM=libnetty_tcnative_osx_x86_64.jnilib
-SET Obj[4].TO=liborg_apache_pulsar_shade_netty_tcnative_osx_x86_64.jnilib
-SET Obj[5].FROM=libnetty_tcnative_osx_aarch_64.jnilib
-SET Obj[5].TO=liborg_apache_pulsar_shade_netty_tcnative_osx_aarch_64.jnilib
-SET Obj[6].FROM=libnetty_transport_native_io_uring_x86_64.so
-SET 
Obj[6].TO=liborg_apache_pulsar_shade_netty_transport_native_io_uring_x86_64.so
-SET Obj[7].FROM=libnetty_transport_native_io_uring_aarch_64.so
-SET 
Obj[7].TO=liborg_apache_pulsar_shade_netty_transport_native_io_uring_aarch_64.so
-SET Obj[8].FROM=libnetty_resolver_dns_native_macos_aarch_64.jnilib
-SET 
Obj[8].TO=liborg_apache_pulsar_shade_netty_resolver_dns_native_macos_aarch_64.jnilib
-SET Obj[9].FROM=libnetty_resolver_dns_native_macos_x86_64.jnilib
-SET 
Obj[9].TO=liborg_apache_pulsar_shade_netty_resolver_dns_native_macos_x86_64.jnilib
-SET Obj_Index=0
-
-:LoopStart
-IF %Obj_Index% EQU %Obj_Length% GOTO END
-
-SET Obj_Current.FROM=0
-SET Obj_Current.TO=0
-
-FOR /F "usebackq delims==. tokens=1-3" %%I IN (`SET Obj[%Obj_Index%]`) DO (
-  SET Obj_Current.%%J=%%K.so
-)
-
-echo "Renaming %Obj_Current.FROM% -> %Obj_Current.TO%"
-call ren %Obj_Current.FROM% %Obj_Current.TO%
-
-SET /A Obj_Index=%Obj_Index% + 1
-
-GOTO LoopStart
-:: Loop end
-
-:END
-cd /d %TMP_DIR%
-
-:: Overwrite the original ZIP archive
-rd %JAR_PATH% /s /q
-set ZIP_CMD=zip -q -r %JAR_PATH% .
-:: echo %ZIP_CMD%
-call %ZIP_CMD%
-:: echo %TMP_DIR%
-rd %TMP_DIR% /s /q
-
-exit /b 0
-:: echo.&pause&goto:eof
\ No newline at end of file
diff --git a/src/rename-netty-native-libs.sh b/src/rename-netty-native-libs.sh
deleted file mode 100755
index ea2a4c0e242..00000000000
--- a/src/rename-netty-native-libs.sh
+++ /dev/null
@@ -1,70 +0,0 @@
-#!/usr/bin/env bash
-#
-# 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.
-#
-
-set -e
-
-ARTIFACT_ID=$1
-JAR_PATH="$PWD/target/$ARTIFACT_ID.jar"
-
-FILE_PREFIX='META-INF/native'
-
-FILES_TO_RENAME=(
-    'libnetty_transport_native_epoll_x86_64.so 
liborg_apache_pulsar_shade_netty_transport_native_epoll_x86_64.so'
-    'libnetty_transport_native_epoll_aarch_64.so 
liborg_apache_pulsar_shade_netty_transport_native_epoll_aarch_64.so'
-    'libnetty_tcnative_linux_x86_64.so 
liborg_apache_pulsar_shade_netty_tcnative_linux_x86_64.so'
-    'libnetty_tcnative_linux_aarch_64.so 
liborg_apache_pulsar_shade_netty_tcnative_linux_aarch_64.so'
-    'libnetty_tcnative_osx_x86_64.jnilib 
liborg_apache_pulsar_shade_netty_tcnative_osx_x86_64.jnilib'
-    'libnetty_tcnative_osx_aarch_64.jnilib 
liborg_apache_pulsar_shade_netty_tcnative_osx_aarch_64.jnilib'
-    'libnetty_transport_native_io_uring_x86_64.so 
liborg_apache_pulsar_shade_netty_transport_native_io_uring_x86_64.so'
-    'libnetty_transport_native_io_uring_aarch_64.so 
liborg_apache_pulsar_shade_netty_transport_native_io_uring_aarch_64.so'
-    'libnetty_resolver_dns_native_macos_aarch_64.jnilib 
liborg_apache_pulsar_shade_netty_resolver_dns_native_macos_aarch_64.jnilib'
-    'libnetty_resolver_dns_native_macos_x86_64.jnilib 
liborg_apache_pulsar_shade_netty_resolver_dns_native_macos_x86_64.jnilib'
-)
-
-echo "----- Renaming epoll lib in $JAR_PATH ------"
-TMP_DIR=`mktemp -d`
-CUR_DIR=$(pwd)
-cd ${TMP_DIR}
-# exclude `META-INF/LICENSE`
-unzip -q $JAR_PATH -x "META-INF/LICENSE"
-# include `META-INF/LICENSE` as LICENSE.netty.
-# This approach is to get around the issue that MacOS is not able to recognize 
the difference between `META-INF/LICENSE` and `META-INF/license/`.
-unzip -p $JAR_PATH META-INF/LICENSE > META-INF/LICENSE.netty
-cd ${CUR_DIR}
-
-pushd $TMP_DIR
-
-for line in "${FILES_TO_RENAME[@]}"; do
-    read -r -a A <<< "$line"
-    FROM=${A[0]}
-    TO=${A[1]}
-
-    if [ -f $FILE_PREFIX/$FROM ]; then
-        echo "Renaming $FROM -> $TO"
-        mv $FILE_PREFIX/$FROM $FILE_PREFIX/$TO
-    fi
-done
-
-# Overwrite the original ZIP archive
-rm $JAR_PATH
-zip -q -r $JAR_PATH .
-popd
-
-rm -rf $TMP_DIR

Reply via email to