<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.apache.flink</groupId>
    <artifactId>flink-shaded</artifactId>
    <version>12.0</version>
    <relativePath>..</relativePath>
  </parent>
  <groupId>org.apache.flink</groupId>
  <artifactId>flink-shaded-netty-tcnative-dynamic</artifactId>
  <version>2.0.30.Final-12.0</version>
  <name>flink-shaded-netty-tcnative-dynamic</name>
  <licenses>
    <license>
      <name>The Apache Software License, Version 2.0</name>
      <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
      <distribution>repo</distribution>
    </license>
  </licenses>
  <properties>
    <netty.tcnative.version>2.0.30.Final</netty.tcnative.version>
  </properties>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-shade-plugin</artifactId>
        <executions>
          <execution>
            <id>shade-flink</id>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <createDependencyReducedPom>true</createDependencyReducedPom>
              <dependencyReducedPomLocation>${project.basedir}/target/dependency-reduced-pom.xml</dependencyReducedPomLocation>
              <artifactSet>
                <includes>
                  <include>io.netty:netty-tcnative</include>
                </includes>
              </artifactSet>
              <relocations>
                <relocation>
                  <pattern>io.netty</pattern>
                  <shadedPattern>${shading.prefix}.netty4.io.netty</shadedPattern>
                </relocation>
              </relocations>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.1.1</version>
        <executions>
          <execution>
            <id>copy</id>
            <phase>package</phase>
            <goals>
              <goal>copy</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <artifactItems>
            <artifactItem>
              <groupId>io.netty</groupId>
              <artifactId>netty-tcnative</artifactId>
              <version>${netty.tcnative.version}</version>
              <classifier>linux-x86_64</classifier>
              <type>jar</type>
              <overWrite>false</overWrite>
              <outputDirectory>${project.build.directory}/native_libs</outputDirectory>
            </artifactItem>
            <artifactItem>
              <groupId>io.netty</groupId>
              <artifactId>netty-tcnative</artifactId>
              <version>${netty.tcnative.version}</version>
              <classifier>linux-loongarch_64</classifier>
              <type>jar</type>
              <overWrite>false</overWrite>
              <outputDirectory>${project.build.directory}/native_libs</outputDirectory>
            </artifactItem>
            <artifactItem>
              <groupId>io.netty</groupId>
              <artifactId>netty-tcnative</artifactId>
              <version>${netty.tcnative.version}</version>
              <classifier>linux-x86_64-fedora</classifier>
              <type>jar</type>
              <overWrite>false</overWrite>
              <outputDirectory>${project.build.directory}/native_libs</outputDirectory>
            </artifactItem>
            <artifactItem>
              <groupId>io.netty</groupId>
              <artifactId>netty-tcnative</artifactId>
              <version>${netty.tcnative.version}</version>
              <classifier>osx-x86_64</classifier>
              <type>jar</type>
              <overWrite>false</overWrite>
              <outputDirectory>${project.build.directory}/native_libs</outputDirectory>
            </artifactItem>
            <artifactItem>
              <groupId>io.netty</groupId>
              <artifactId>netty-tcnative</artifactId>
              <version>${netty.tcnative.version}</version>
              <classifier>windows-x86_64</classifier>
              <type>jar</type>
              <overWrite>false</overWrite>
              <outputDirectory>${project.build.directory}/native_libs</outputDirectory>
            </artifactItem>
          </artifactItems>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.7</version>
        <executions>
          <execution>
            <id>rename-native-library</id>
            <phase>package</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <target>
                <echo message="unpacking netty jar" />
                <unzip src="${project.build.directory}/${artifactId}-${version}.jar" dest="${project.build.directory}/unpacked/" />
                <echo message="extracting netty_tcnative dynamically linked wrapper libraries" />
                <unzip src="${project.build.directory}/native_libs/netty-tcnative-${netty.tcnative.version}-linux-x86_64.jar" dest="${project.build.directory}/native_libs/unpacked/" />
                <move includeemptydirs="false" todir="${project.build.directory}/unpacked/META-INF/native">
                  <fileset dir="${project.build.directory}/native_libs/unpacked/META-INF/native" />
                  <mapper from="libnetty_tcnative.so" to="liborg_apache_flink_shaded_netty4_netty_tcnative_linux_x86_64.so" type="glob" />
                </move>
                <delete dir="${project.build.directory}/native_libs/unpacked/" />
                <unzip src="${project.build.directory}/native_libs/netty-tcnative-${netty.tcnative.version}-linux-loongarch_64.jar" dest="${project.build.directory}/native_libs/unpacked/" />
                <move includeemptydirs="false" todir="${project.build.directory}/unpacked/META-INF/native">
                  <fileset dir="${project.build.directory}/native_libs/unpacked/META-INF/native" />
                  <mapper from="libnetty_tcnative.so" to="liborg_apache_flink_shaded_netty4_netty_tcnative_linux_loongarch_64.so" type="glob" />
                </move>
                <delete dir="${project.build.directory}/native_libs/unpacked/" />
                <unzip src="${project.build.directory}/native_libs/netty-tcnative-${netty.tcnative.version}-linux-x86_64-fedora.jar" dest="${project.build.directory}/native_libs/unpacked/" />
                <move includeemptydirs="false" todir="${project.build.directory}/unpacked/META-INF/native">
                  <fileset dir="${project.build.directory}/native_libs/unpacked/META-INF/native" />
                  <mapper from="libnetty_tcnative.so" to="liborg_apache_flink_shaded_netty4_netty_tcnative_linux_x86_64_fedora.so" type="glob" />
                </move>
                <delete dir="${project.build.directory}/native_libs/unpacked/" />
                <unzip src="${project.build.directory}/native_libs/netty-tcnative-${netty.tcnative.version}-osx-x86_64.jar" dest="${project.build.directory}/native_libs/unpacked/" />
                <move includeemptydirs="false" todir="${project.build.directory}/unpacked/META-INF/native">
                  <fileset dir="${project.build.directory}/native_libs/unpacked/META-INF/native" />
                  <mapper from="libnetty_tcnative.jnilib" to="liborg_apache_flink_shaded_netty4_netty_tcnative_osx_x86_64.jnilib" type="glob" />
                </move>
                <delete dir="${project.build.directory}/native_libs/unpacked/" />
                <unzip src="${project.build.directory}/native_libs/netty-tcnative-${netty.tcnative.version}-windows-x86_64.jar" dest="${project.build.directory}/native_libs/unpacked/" />
                <move includeemptydirs="false" todir="${project.build.directory}/unpacked/META-INF/native">
                  <fileset dir="${project.build.directory}/native_libs/unpacked/META-INF/native" />
                  <mapper from="netty_tcnative.dll" to="org_apache_flink_shaded_netty4_netty_tcnative_windows_x86_64.dll" type="glob" />
                </move>
                <delete dir="${project.build.directory}/native_libs/unpacked/" />
                <echo message="repackaging netty jar" />
                <jar basedir="${project.build.directory}/unpacked" destfile="${project.build.directory}/${artifactId}-${version}.jar" />
              </target>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>flatten-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>
</project>
