<!--

    Copyright © 2015 The Gravitee team (http://gravitee.io)

    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>

    <parent>
        <groupId>io.gravitee</groupId>
        <artifactId>gravitee-parent</artifactId>
        <version>23.5.0</version>
    </parent>

    <groupId>io.gravitee.llama.cpp</groupId>
    <artifactId>llamaj.cpp</artifactId>
    <version>0.8.14</version>
    <packaging>jar</packaging>

    <name>Gravitee.io - llamaj.cpp</name>
    <url>https://github.com/gravitee-io/llamaj.cpp</url>
    <description>Llamaj.cpp (contraction of llama.cpp and java/jextract) is a port of llama.cpp in the JVM using jextract.</description>

    <scm>
        <url>https://github.com/gravitee-io/llamaj.cpp</url>
        <connection>scm:git:git://github.com/gravitee-io/llamaj.cpp</connection>
        <developerConnection>scm:git:git@github.com:gravitee-io/llamaj.cpp</developerConnection>
    </scm>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <junit-jupiter-api.version>6.0.1</junit-jupiter-api.version>
        <assertj-core.version>3.27.6</assertj-core.version>
        <llama.cpp.version>b7126</llama.cpp.version>
        <llama.cpp.dir>${project.basedir}/../llama.cpp</llama.cpp.dir>
        <jextract.dir>${project.basedir}/../jextract/bin</jextract.dir>
    </properties>

    <profiles>
        <profile>
            <id>linux-x86_64</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>3.6.2</version>
                        <executions>
                            <execution>
                                <id>download-llama.cpp-shared-objects</id>
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>scripts/download-native-libraries.sh</executable>
                                    <arguments>
                                        <argument>-o</argument>
                                        <argument>linux</argument>
                                        <argument>-p</argument>
                                        <argument>x86_64</argument>
                                        <argument>-v</argument>
                                        <argument>${llama.cpp.version}</argument>
                                        <argument>-d</argument>
                                        <argument>${project.basedir}/src/main/resources</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                            <execution>
                                <id>generate-llama.cpp-sources-linux</id>
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>${jextract.dir}/jextract</executable>
                                    <arguments>
                                        <argument>-t</argument>
                                        <argument>io.gravitee.llama.cpp.linux.x86_64</argument>
                                        <argument>--source</argument>
                                        <argument>--include-dir</argument>
                                        <argument>${llama.cpp.dir}/ggml/include</argument>
                                        <argument>--output</argument>
                                        <argument>${project.build.directory}/generated-sources</argument>
                                        <argument>${llama.cpp.dir}/include/llama.h</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>macosx-aarch64</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>3.6.2</version>
                        <executions>
                            <execution>
                                <id>download-llama.cpp-dylibs</id>
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>scripts/download-native-libraries.sh</executable>
                                    <arguments>
                                        <argument>-o</argument>
                                        <argument>macosx</argument>
                                        <argument>-p</argument>
                                        <argument>aarch64</argument>
                                        <argument>-v</argument>
                                        <argument>${llama.cpp.version}</argument>mv
                                        <argument>-d</argument>
                                        <argument>${project.basedir}/src/main/resources</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                            <execution>
                                <id>generate-llama.cpp-sources-macosx</id>
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>${jextract.dir}/jextract</executable>
                                    <arguments>
                                        <argument>-t</argument>
                                        <argument>io.gravitee.llama.cpp.macosx.aarch64</argument>
                                        <argument>--source</argument>
                                        <argument>--include-dir</argument>
                                        <argument>${llama.cpp.dir}/ggml/include</argument>
                                        <argument>--output</argument>
                                        <argument>${project.build.directory}/generated-sources</argument>
                                        <argument>${llama.cpp.dir}/include/llama.h</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit-jupiter-api.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit-jupiter-api.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-params</artifactId>
            <version>${junit-jupiter-api.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <version>${assertj-core.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>com.mycila</groupId>
                <artifactId>license-maven-plugin</artifactId>
                <configuration>
                    <properties>
                        <owner>The Gravitee team</owner>
                        <email>http://gravitee.io</email>
                    </properties>
                    <licenseSets>
                        <licenseSet>
                            <header>com/mycila/maven/plugin/license/templates/APACHE-2.txt</header>
                            <excludes>
                                <exclude>CONTRIBUTING.adoc</exclude>
                                <exclude>LICENSE.txt</exclude>
                                <exclude>.circleci/config.yml</exclude>
                                <exclude>README.md</exclude>
                                <exclude>SECURITY.md</exclude>
                                <exclude>.gravitee.settings.xml</exclude>
                            </excludes>
                        </licenseSet>
                    </licenseSets>
                    <mapping>
                        <ts>SLASHSTAR_STYLE</ts>
                        <js>SLASHSTAR_STYLE</js>
                    </mapping>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>21</source>
                    <target>21</target>
                    <compilerArgs>
                        <arg>--enable-preview</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>io.gravitee.llama.cpp.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.6.1</version>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${project.build.directory}/generated-sources</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.hubspot.maven.plugins</groupId>
                <artifactId>prettier-maven-plugin</artifactId>
                <version>0.22</version>
                <configuration>
                    <prettierJavaVersion>2.0.0</prettierJavaVersion>
                    <printWidth>125</printWidth>
                    <inputGlobs>
                        <inputGlob>src/{main,test}/**/*.java</inputGlob>
                        <inputGlob>.github/*.json</inputGlob>
                    </inputGlobs>
                </configuration>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.5.4</version>
                <configuration>
                    <argLine>--enable-preview</argLine>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <configuration>
                    <source>21</source>
                    <additionalOptions>--enable-preview</additionalOptions>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
