<?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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.jitsi</groupId>
    <artifactId>jitsi-srtp</artifactId>
    <version>1.1-5-g70395c7</version>
    <packaging>bundle</packaging>

    <name>Jitsi Secure RTP implementation</name>
    <description>Jitsi SRTP contains classes for encrypting and decrypting SRTP and SRTCP packets</description>
    <url>https://github.com/jitsi/jitsi-srtp</url>

    <organization>
        <name>jitsi.org</name>
        <url>https://jitsi.org</url>
    </organization>

    <developers>
        <developer>
            <id>org.jitsi</id>
            <name>Jitsi Team</name>
            <email>dev@jitsi.org</email>
        </developer>
    </developers>

    <scm>
        <url>https://github.com/jitsi/jitsi-srtp</url>
        <connection>scm:git:https://github.com/jitsi/jitsi-srtp.git</connection>
        <developerConnection>scm:git:https://github.com/jitsi/jitsi-srtp.git</developerConnection>
        <tag>HEAD</tag>
    </scm>

    <licenses>
        <license>
            <name>Apache-2.0</name>
            <url>https://github.com/jitsi/jitsi-srtp/blob/master/LICENSE</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <junit.version>5.8.1</junit.version>
        <bouncycastle.version>1.69</bouncycastle.version>
    </properties>

    <profiles>
        <profile>
            <!-- for reasons I don't understand, depending on the JDK version,
             sometimes ${java.home} ends in ../jre, and sometimes it doesn't.
             Because the default jdkIncludePath is ${java.home}/../include,
             we need to override its value in cases where it doesn't end in jre. -->
            <id>set-custom-jdkIncludePath</id>
            <activation>
                <property>
                    <name>buildNativeLib</name>
                </property>
                <file>
                    <missing>${java.home}/../include</missing>
                    <exists>${java.home}/include</exists>
                </file>
            </activation>
            <properties>
                <jdkIncludePath>${java.home}/include</jdkIncludePath>
            </properties>
        </profile>

        <profile>
            <id>build-native-lib-mac</id>
            <activation>
                <os>
                    <family>mac</family>
                </os>
                <property>
                    <name>buildNativeLib</name>
                </property>
            </activation>
            <properties>
                <ssldir>/usr/local/opt/openssl@1.1</ssldir>
                <libextension>jnilib</libextension>
                <compilerStartOpts>
                    -I${ssldir}/include
                </compilerStartOpts>
                <linkStartOpts>
                    -shared
                    -L${ssldir}/lib
                    -lcrypto
                </linkStartOpts>
                <linkEndOpts></linkEndOpts>
                <os>darwin</os>
                <nativeLibDir>${os}</nativeLibDir>
            </properties>
        </profile>

        <profile>
            <id>build-native-lib-linux</id>
            <activation>
                <os>
                    <family>unix</family>
                    <name>Linux</name>
                </os>
                <property>
                    <name>buildNativeLib</name>
                </property>
            </activation>
            <properties>
                <libextension>so</libextension>
                <linkStartOpts>
                    -shared
                </linkStartOpts>
                <linkEndOpts>
                    -lcrypto
                </linkEndOpts>
                <os>linux</os>
                <nativeLibDir>${os}-${canonArch}</nativeLibDir>
            </properties>

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                        <version>3.0.0</version>
                        <executions>
                            <execution>
                                <id>set-canon-arch</id>
                                <goals>
                                    <goal>regex-property</goal>
                                </goals>
                                <configuration>
                                    <name>canonArch</name>
                                    <value>${os.arch}</value>
                                    <regex>amd64|x86_64</regex>
                                    <replacement>x86-64</replacement>
                                    <failIfNoMatch>false</failIfNoMatch>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>build-native-lib</id>
            <activation>
                <property>
                    <name>buildNativeLib</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>native-maven-plugin</artifactId>
                        <version>1.0-alpha-11</version>
                        <extensions>true</extensions>
                        <executions>
                            <execution>
                                <id>native-compile</id>
                                <phase>compile</phase>
                                <goals>
                                    <goal>compile</goal>
                                    <goal>link</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <compilerProvider>generic</compilerProvider>
                            <compilerStartOptions>
                                <compilerStartOption>
                                    -g -fPIC -std=c99 -O2 -Wall
                                </compilerStartOption>
                                <compilerStartOption>
                                    -I ${project.build.directory}/native/javah
                                </compilerStartOption>
                                <compilerStartOption>${compilerStartOpts}
                                </compilerStartOption>
                            </compilerStartOptions>

                            <jdkIncludePath>${jdkIncludePath}</jdkIncludePath>
                            <javahOS>${os}</javahOS>

                            <sources>
                                <source>
                                    <directory>src/main/native</directory>
                                    <fileNames>
                                        <fileName>JitsiHmacOpenSsl.c</fileName>
                                        <fileName>JitsiOpenSslProvider.c
                                        </fileName>
                                        <fileName>JitsiCipherOpenSsl.c
                                        </fileName>
                                        <fileName>SrtpCipherGcmAuthOnlyOpenSsl.c
                                        </fileName>
                                    </fileNames>
                                </source>
                            </sources>

                            <linkerStartOptions>
                                <linkerStartOption>${linkStartOpts}
                                </linkerStartOption>
                            </linkerStartOptions>
                            <linkerEndOptions>
                                <linkerEndOption>${linkEndOpts}
                                </linkerEndOption>
                            </linkerEndOptions>
                            <linkerFinalName>libjitsisrtp</linkerFinalName>
                            <linkerFinalNameExt>${libextension}
                            </linkerFinalNameExt>
                        </configuration>
                    </plugin>
                    <plugin>
                        <artifactId>maven-resources-plugin</artifactId>
                        <version>3.1.0</version>
                        <executions>
                            <execution>
                                <id>deploy-jnilib</id>
                                <!-- "process-classes" doesn't make sense as a name for this step's phase, but the phase's
                                     description - "post-process the generated files from compilation" - kind of does.
                                     The natural phase for this would be either "process-resources" or "prepare-package", but we need it to be
                                     after "compile" and before "test". -->
                                <phase>process-classes</phase>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>
                                        ${project.basedir}/src/main/resources/${nativeLibDir}/
                                    </outputDirectory>
                                    <resources>
                                        <resource>
                                            <directory>
                                                ${project.build.directory}
                                            </directory>
                                            <include>
                                                libjitsisrtp.${libextension}
                                            </include>
                                        </resource>
                                    </resources>
                                </configuration>
                            </execution>
                            <!-- If we built the jnilib, we need to make sure the newly-built version is deployed to the target dir also -->
                            <execution>
                                <id>update-jnilib</id>
                                <phase>process-classes</phase>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>
                                        ${project.basedir}/target/classes/${nativeLibDir}/
                                    </outputDirectory>
                                    <resources>
                                        <resource>
                                            <directory>
                                                ${project.build.directory}
                                            </directory>
                                            <include>
                                                libjitsisrtp.${libextension}
                                            </include>
                                        </resource>
                                    </resources>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>release</id>
            <activation>
                <property>
                    <name>release</name>
                    <value>true</value>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>1.6</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <gpgArguments>
                                <arg>--pinentry-mode</arg>
                                <arg>loopback</arg>
                            </gpgArguments>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>coverage</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <version>0.8.7</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                            </execution>
                            <!-- attached to Maven test phase -->
                            <execution>
                                <id>report</id>
                                <phase>test</phase>
                                <goals>
                                    <goal>report</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <dependencies>
        <dependency>
            <groupId>org.jitsi</groupId>
            <artifactId>jitsi-utils</artifactId>
            <version>1.0-108-g480acf0</version>
        </dependency>
        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcprov-jdk15on</artifactId>
            <version>${bouncycastle.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jetbrains</groupId>
            <artifactId>annotations</artifactId>
            <version>22.0.0</version>
            <optional>true</optional>
        </dependency>
        <!-- test -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>gnu.getopt</groupId>
            <artifactId>java-getopt</artifactId>
            <version>1.0.13</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.xml.bind</groupId>
            <artifactId>jakarta.xml.bind-api</artifactId>
            <version>3.0.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <id>attach-native-sources</id>
                        <phase>package</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>src/main/native</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.2.1</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <executions>
                    <!-- Replacing default-compile as it is treated specially by maven -->
                    <execution>
                        <id>default-compile</id>
                        <phase>none</phase>
                    </execution>
                    <!-- Replacing default-testCompile as it is treated specially by maven -->
                    <execution>
                        <id>default-testCompile</id>
                        <phase>none</phase>
                    </execution>
                    <execution>
                        <id>java-compile</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>java-test-compile</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <compilerArgs combine.children="append">
                        <arg>-h</arg>
                        <arg>${project.build.directory}/native/javah/</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.22.2</version>
            </plugin>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>5.1.2</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <_noclassforname>true</_noclassforname>
                        <_removeheaders>Bnd-*, Tool, Require-Capability
                        </_removeheaders>
                        <Bundle-NativeCode>
                            linux-x86-64/libjitsisrtp.so;osname=Linux;processor=x86-64,
                            linux-aarch64/libjitsisrtp.so;osname=Linux;processor=AArch64,
                            *
                        </Bundle-NativeCode>
                        <!-- Prevent importing a specific version. -->
                        <Import-Package>
                            *;version=!,
                            sun.security.pkcs11;resolution:=optional
                        </Import-Package>
                    </instructions>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>3.1.2</version>
                <configuration>
                    <configLocation>checkstyle.xml</configLocation>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>com.puppycrawl.tools</groupId>
                        <artifactId>checkstyle</artifactId>
                        <version>9.1</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.3.1</version>
                <configuration>
                    <doclint>-missing</doclint>
                    <source>8</source>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
            </plugin>
            <plugin>
                <groupId>org.sonatype.plugins</groupId>
                <artifactId>nexus-staging-maven-plugin</artifactId>
                <version>1.6.8</version>
                <extensions>true</extensions>
                <configuration>
                    <serverId>ossrh</serverId>
                    <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                    <autoReleaseAfterClose>true</autoReleaseAfterClose>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <distributionManagement>
        <snapshotRepository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
        <repository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
        </repository>
    </distributionManagement>
</project>
