<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2018 The Netty Project
  ~
  ~ The Netty Project 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:
  ~
  ~   https://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.
  -->
<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 https://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>io.netty</groupId>
    <artifactId>netty-parent</artifactId>
    <version>4.1.133.Final</version>
  </parent>

  <artifactId>netty-testsuite-shading</artifactId>
  <packaging>jar</packaging>

  <name>Netty/Testsuite/Shading</name>

  <properties>
    <generatedSourceDir>${project.build.directory}/src</generatedSourceDir>
    <dependencyVersionsDir>${project.build.directory}/versions</dependencyVersionsDir>
    <classesShadedDir>${project.build.directory}/classes-shaded</classesShadedDir>
    <classesShadedNativeDir>${classesShadedDir}/META-INF/native</classesShadedNativeDir>
    <shadingPrefix>shaded</shadingPrefix>
    <shadingPrefix2>shaded_2</shadingPrefix2>
    <mangledShadingPrefix>shaded</mangledShadingPrefix>
    <mangledShadingPrefix2>shaded_12</mangledShadingPrefix2>
    <skipShadingTestsuite>true</skipShadingTestsuite>
    <shadedPackagePrefix>io.netty.</shadedPackagePrefix>
    <japicmp.skip>true</japicmp.skip>
    <revapi.skip>true</revapi.skip>
    <!-- Do not deploy this module -->
    <skipDeploy>true</skipDeploy>
    <javaModuleName>io.netty.testsuite_shading</javaModuleName>
  </properties>

  <build>
    <extensions>
      <extension>
        <groupId>kr.motd.maven</groupId>
        <artifactId>os-maven-plugin</artifactId>
        <version>${osmaven.version}</version>
      </extension>
    </extensions>
    <plugins>
      <!-- Do not deploy this module -->
      <plugin>
        <artifactId>maven-deploy-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>

      <plugin>
        <artifactId>maven-shade-plugin</artifactId>
        <executions>
          <execution>
            <id>shade</id>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <artifactSet>
                <includes>
                  <include>${project.groupId}</include>
                </includes>
              </artifactSet>
              <relocations>
                <relocation>
                  <pattern>${shadedPackagePrefix}</pattern>
                  <shadedPattern>${shadingPrefix}.${shadedPackagePrefix}</shadedPattern>
                </relocation>
              </relocations>
              <finalName>shaded1</finalName>
            </configuration>
          </execution>
          <execution>
            <id>shade-1</id>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <artifactSet>
                <includes>
                  <include>${project.groupId}</include>
                </includes>
              </artifactSet>
              <relocations>
                <relocation>
                  <pattern>${shadedPackagePrefix}</pattern>
                  <shadedPattern>${shadingPrefix2}.${shadedPackagePrefix}</shadedPattern>
                </relocation>
              </relocations>
              <finalName>shaded2</finalName>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>unpack-jar-features</id>
            <phase>package</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <skip>${skipShadingTestsuite}</skip>
              <target>
                <unzip dest="${classesShadedDir}/">
                  <fileset dir="${project.build.directory}/">
                    <include name="shaded1.jar" />
                    <include name="shaded2.jar" />
                  </fileset>
                </unzip>
                <copy file="${classesShadedNativeDir}/lib${nativeTransportLib}" tofile="${classesShadedNativeDir}/lib${mangledShadingPrefix}_${nativeTransportLib}" />
                <copy file="${classesShadedNativeDir}/lib${nativeTransportLib}" tofile="${classesShadedNativeDir}/lib${mangledShadingPrefix2}_${nativeTransportLib}" />
                <delete file="${classesShadedNativeDir}/lib${nativeTransportLib}" />

                <copy file="${classesShadedNativeDir}/lib${nativeTcnativeLib}" tofile="${classesShadedNativeDir}/lib${mangledShadingPrefix}_${nativeTcnativeLib}" />
                <copy file="${classesShadedNativeDir}/lib${nativeTcnativeLib}" tofile="${classesShadedNativeDir}/lib${mangledShadingPrefix2}_${nativeTcnativeLib}" />
                <delete file="${classesShadedNativeDir}/lib${nativeTcnativeLib}" />

                <delete file="${project.build.directory}/shaded1.jar" />
                <delete file="${project.build.directory}/shaded2.jar" />
              </target>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <configuration>
          <skip>${skipShadingTestsuite}</skip>
          <!--
            Use a fork count of 0 as otherwise the build will just pass when a forked VM dies during JNI loading.
          -->
          <forkCount>0</forkCount>
          <systemPropertyVariables>
            <shadingPrefix>${shadingPrefix}</shadingPrefix>
            <shadingPrefix2>${shadingPrefix2}</shadingPrefix2>
          </systemPropertyVariables>
          <additionalClasspathElements>
            <additionalClasspathElement>${classesShadedDir}</additionalClasspathElement>
          </additionalClasspathElements>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>integration-test</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <!-- We must generate a -javadoc JAR file to publish on Maven Central -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>
          <execution>
            <id>empty-javadoc-jar</id>
            <phase>package</phase>
            <goals>
              <goal>jar</goal>
            </goals>
            <configuration>
              <classifier>javadoc</classifier>
              <classesDirectory>${basedir}/javadoc</classesDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
    </dependency>
  </dependencies>
  <profiles>
    <profile>
      <id>skipTests</id>
      <activation>
        <property>
          <name>skipTests</name>
        </property>
      </activation>
      <properties>
        <skipShadingTestsuite>true</skipShadingTestsuite>
      </properties>
    </profile>

    <profile>
      <id>windows</id>
      <activation>
        <os>
          <family>windows</family>
        </os>
      </activation>
      <properties>
        <skipShadingTestsuite>true</skipShadingTestsuite>
      </properties>
      <dependencies>
        <dependency>
          <groupId>${project.groupId}</groupId>
          <artifactId>netty-common</artifactId>
          <version>${project.version}</version>
          <scope>compile</scope>
        </dependency>
        <dependency>
          <groupId>${project.groupId}</groupId>
          <artifactId>netty-handler</artifactId>
          <version>${project.version}</version>
          <scope>compile</scope>
        </dependency>
        <dependency>
          <groupId>${project.groupId}</groupId>
          <artifactId>${tcnative.artifactId}</artifactId>
          <version>${tcnative.version}</version>
          <classifier>${tcnative.classifier}</classifier>
          <scope>compile</scope>
        </dependency>
      </dependencies>
    </profile>

    <profile>
      <id>mac</id>
      <activation>
        <os>
          <family>mac</family>
        </os>
      </activation>
      <properties>
        <nativeTransportLib>netty_transport_native_kqueue_${os.detected.arch}.jnilib</nativeTransportLib>
        <nativeTcnativeLib>netty_tcnative_osx_${os.detected.arch}.jnilib</nativeTcnativeLib>
        <skipShadingTestsuite>false</skipShadingTestsuite>
      </properties>
      <dependencies>
        <dependency>
          <groupId>${project.groupId}</groupId>
          <artifactId>netty-common</artifactId>
          <version>${project.version}</version>
          <scope>compile</scope>
        </dependency>
        <dependency>
          <groupId>${project.groupId}</groupId>
          <artifactId>netty-transport-native-kqueue</artifactId>
          <version>${project.version}</version>
          <classifier>${jni.classifier}</classifier>
          <scope>compile</scope>
        </dependency>
        <!-- Needed to test shading of netty-tcnative -->
        <dependency>
          <groupId>${project.groupId}</groupId>
          <artifactId>netty-handler</artifactId>
          <version>${project.version}</version>
          <scope>compile</scope>
        </dependency>
        <dependency>
          <groupId>${project.groupId}</groupId>
          <artifactId>${tcnative.artifactId}</artifactId>
          <version>${tcnative.version}</version>
          <classifier>${tcnative.classifier}</classifier>
          <scope>compile</scope>
        </dependency>
      </dependencies>
    </profile>

    <profile>
      <id>linux</id>
      <activation>
        <os>
          <family>linux</family>
        </os>
      </activation>
      <properties>
        <nativeTransportLib>netty_transport_native_epoll_${os.detected.arch}.so</nativeTransportLib>
        <nativeTcnativeLib>netty_tcnative_linux_${os.detected.arch}.so</nativeTcnativeLib>
        <skipShadingTestsuite>false</skipShadingTestsuite>
      </properties>
      <dependencies>
        <dependency>
          <groupId>${project.groupId}</groupId>
          <artifactId>netty-common</artifactId>
          <version>${project.version}</version>
          <scope>compile</scope>
        </dependency>
        <dependency>
          <groupId>${project.groupId}</groupId>
          <artifactId>netty-transport-native-epoll</artifactId>
          <version>${project.version}</version>
          <classifier>${jni.classifier}</classifier>
          <scope>compile</scope>
        </dependency>
        <!-- Needed to test shading of netty-tcnative -->
        <dependency>
          <groupId>${project.groupId}</groupId>
          <artifactId>netty-handler</artifactId>
          <version>${project.version}</version>
          <scope>compile</scope>
        </dependency>
        <dependency>
          <groupId>${project.groupId}</groupId>
          <artifactId>${tcnative.artifactId}</artifactId>
          <version>${tcnative.version}</version>
          <classifier>${tcnative.classifier}</classifier>
          <scope>compile</scope>
        </dependency>
      </dependencies>
    </profile>
  </profiles>
</project>

