<?xml version="1.0" encoding="UTF-8"?>
<!--

    Copyright © 2024 CuriosityStack (curiosity.stack@gmail.com)

    Licensed 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.

-->
<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>com.curiositystack</groupId>
    <artifactId>linux-socket-probe</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>

    <name>linux-socket-probe</name>
    <url>https://github.com/CuriosityStack/linux-socket-probe</url>
    <description>Java tool for socket metric collection on Linux.</description>

    <licenses>
        <license>
            <name>The Apache License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
        </license>
    </licenses>

    <developers>
        <developer>
            <name>CuriosityStack</name>
            <email>curiosity.stack@gmail.com</email>
            <organization>CuriosityStack</organization>
            <organizationUrl>https://github.com/CuriosityStack</organizationUrl>
        </developer>
    </developers>

    <scm>
        <connection>scm:git:git://github.com/CuriosityStack/linux-socket-probe.git</connection>
        <developerConnection>scm:git:ssh://github.com/CuriosityStack/linux-socket-probe.git</developerConnection>
        <url>https://github.com/CuriosityStack/linux-socket-probe/tree/main</url>
    </scm>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <jni.lib.name>linux_socket_probe</jni.lib.name>
        <jni.compiler.args.cflags>CFLAGS=-O2 -pipe -fno-omit-frame-pointer -Wunused-variable -fvisibility=hidden -D_FORTIFY_SOURCE=2 -ffunction-sections -fdata-sections</jni.compiler.args.cflags>
        <jni.compiler.args.ldflags>LDFLAGS=-Wl,-z,relro -Wl,-z,now -Wl,--as-needed -Wl,--gc-sections </jni.compiler.args.ldflags>
        <nativeSourceDirectory>${project.basedir}/src/main/c</nativeSourceDirectory>
        <skipTests>true</skipTests>
        <gpg.skip>true</gpg.skip>
        <gpg.keyname>CE015AE00816F08B</gpg.keyname>
    </properties>

    <profiles>
        <profile>
            <id>linux</id>
            <activation>
                <os>
                    <family>linux</family>
                </os>
            </activation>
            <properties>
                <skipTests>false</skipTests>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.fusesource.hawtjni</groupId>
                        <artifactId>hawtjni-maven-plugin</artifactId>
                        <version>1.17</version>
                        <executions>
                            <execution>
                                <id>build-native-lib</id>
                                <configuration>
                                    <name>${jni.lib.name}_${os.detected.arch}</name>
                                    <nativeSourceDirectory>${nativeSourceDirectory}</nativeSourceDirectory>
                                    <libDirectory>${project.build.outputDirectory}</libDirectory>
                                    <!-- We use Maven's artifact classifier instead.
                                         This hack will make the hawtjni plugin to put the native library
                                         under 'META-INF/native' rather than 'META-INF/native/${platform}'. -->
                                    <platform>.</platform>
                                    <configureArgs>
                                        <arg>${jni.compiler.args.ldflags}</arg>
                                        <arg>${jni.compiler.args.cflags}</arg>
                                        <configureArg>--libdir=${project.build.directory}/native-build/target/lib</configureArg>
                                    </configureArgs>
                                </configuration>
                                <goals>
                                    <goal>generate</goal>
                                    <goal>build</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <artifactId>maven-jar-plugin</artifactId>
                        <version>3.3.0</version>
                        <executions>
                            <!-- Generate the JAR that contains the native library in it. -->
                            <execution>
                                <id>native-jar</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                                <configuration>
                                    <archive>
                                        <manifest>
                                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                                        </manifest>
                                        <index>true</index>
                                    </archive>
                                    <classifier>${os.detected.arch}</classifier>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.24</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.8.2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.36</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-core</artifactId>
            <version>1.12.1</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <!-- Workaround for the docker build issue: /bin/sh: bad interpreter: Permission denied. -->
        <directory>/tmp/target</directory>
        <plugins>
            <!-- Also include c files in source jar -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.3.0</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${nativeSourceDirectory}</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.3.0</version>
                <executions>
                    <!-- Generate the fallback JAR that does not contain the native library. -->
                    <execution>
                        <id>default-jar</id>
                        <configuration>
                            <excludes>
                                <exclude>META-INF/native/**</exclude>
                            </excludes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-gpg-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>sign-artifacts</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                        <configuration>
                            <keyname>${gpg.keyname}</keyname>
                            <passphraseServerId>${gpg.keyname}</passphraseServerId>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.sonatype.central</groupId>
                <artifactId>central-publishing-maven-plugin</artifactId>
                <version>0.4.0</version>
                <extensions>true</extensions>
                <configuration>
                    <publishingServerId>central</publishingServerId>
                    <tokenAuth>true</tokenAuth>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.mycila</groupId>
                <artifactId>license-maven-plugin</artifactId>
                <version>4.3</version>
                <configuration>
                    <properties>
                        <year>2024</year>
                        <owner>CuriosityStack</owner>
                        <email>curiosity.stack@gmail.com</email>
                    </properties>
                    <licenseSets>
                        <licenseSet>
                            <header>com/mycila/maven/plugin/license/templates/APACHE-2.txt</header>
                            <excludes>
                                <exclude>**/README</exclude>
                                <exclude>src/test/resources/**</exclude>
                                <exclude>src/main/resources/**</exclude>
                                <exclude>src/main/java/com/curiositystack/linux/socket/probe/utils/**</exclude>
                            </excludes>
                        </licenseSet>
                    </licenseSets>
                </configuration>
            </plugin>
        </plugins>

        <extensions>
            <extension>
                <groupId>kr.motd.maven</groupId>
                <artifactId>os-maven-plugin</artifactId>
                <version>1.7.1</version>
            </extension>
        </extensions>

    </build>

</project>