<?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>

    <parent>
        <groupId>dev.getelements.conductor</groupId>
        <artifactId>conductor</artifactId>
        <version>1.0.8</version>
    </parent>

    <artifactId>kubernetes</artifactId>
    <version>1.0.8</version>

    <name>Namazu Conductor Kubernetes Provider</name>

    <!--
        This includes a variety of dependencies which the Element uses. An Element may use some or all of these. Note
        that we do not specify version, nor wo we specify the scope. By including the bom in the parent project,
        you do not have to worry about scope. Our bom properly scopes all dependencies as to avoid runtime errors when
        deploying your Element.
    -->
    <dependencies>
        <!-- The Element's API artifact, required on the compile classpath for access to its interfaces. -->
        <dependency>
            <groupId>dev.getelements.conductor</groupId>
            <artifactId>api</artifactId>
        </dependency>
        <!-- The Element's API classifier artifact, copied into the api/ directory of the .elm archive. -->
        <dependency>
            <groupId>dev.getelements.conductor</groupId>
            <artifactId>api</artifactId>
            <classifier>${api.classifier}</classifier>
        </dependency>
        <!-- The SDK Artifact. This is the core SDK for Namazu Elements -->
        <dependency>
            <groupId>dev.getelements.elements</groupId>
            <artifactId>sdk</artifactId>
        </dependency>
        <!-- The Model Artifact. This contains all models used by the services and database objects. -->
        <dependency>
            <groupId>dev.getelements.elements</groupId>
            <artifactId>sdk-model</artifactId>
        </dependency>
        <!-- The Service artifact. Contains all business logic of Namazu Elements.-->
        <dependency>
            <groupId>dev.getelements.elements</groupId>
            <artifactId>sdk-service</artifactId>
        </dependency>
        <!-- The Guice loader SPI -->
        <dependency>
            <groupId>dev.getelements.elements</groupId>
            <artifactId>sdk-spi-guice</artifactId>
        </dependency>
        <!-- The Jakarta RS Support-->
        <dependency>
            <groupId>dev.getelements.elements</groupId>
            <artifactId>sdk-jakarta-rs</artifactId>
        </dependency>
        <!-- Guice. The version recommended and tested with Namazu Elements -->
        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
        </dependency>
        <!-- Jakarta RS. REST API Support. Only include if you want RESTFul APIs in your Element -->
        <dependency>
            <groupId>jakarta.ws.rs</groupId>
            <artifactId>jakarta.ws.rs-api</artifactId>
        </dependency>
        <!-- Jakarta WS. WebSocket Support. Only include if you want WebSockets in your Element -->
        <dependency>
            <groupId>jakarta.websocket</groupId>
            <artifactId>jakarta.websocket-api</artifactId>
        </dependency>
        <!-- Swagger Annotations for API Documentation. -->
        <dependency>
            <groupId>io.swagger.core.v3</groupId>
            <artifactId>swagger-annotations</artifactId>
        </dependency>
        <!-- Jakarta RS Supoport for you REST APIs -->
        <dependency>
            <groupId>io.swagger.core.v3</groupId>
            <artifactId>swagger-jaxrs2-jakarta</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib</artifactId>
        </dependency>
        <!-- Fabric8 Kubernetes client for PodTemplate discovery and Pod/Job/Service management -->
        <dependency>
            <groupId>io.fabric8</groupId>
            <artifactId>kubernetes-client</artifactId>
        </dependency>
        <!-- TestNG for integration tests -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.10.2</version>
            <scope>test</scope>
        </dependency>
        <!-- Logback as SLF4J implementation for test logging -->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>${logback.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <properties>
        <elm.builtin.spis>DEFAULT</elm.builtin.spis>
        <elm.staging.dir>${project.build.directory}/${project.groupId}.${project.artifactId}-${project.version}</elm.staging.dir>
        <elm.element.dir>${elm.staging.dir}/${project.groupId}.${project.artifactId}</elm.element.dir>
    </properties>

    <build>
        <plugins>

            <plugin>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>compile</id>
                        <goals><goal>compile</goal></goals>
                        <configuration>
                            <sourceDirs>
                                <sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
                                <sourceDir>${project.basedir}/src/main/java</sourceDir>
                            </sourceDirs>
                        </configuration>
                    </execution>
                    <execution>
                        <id>test-compile</id>
                        <goals><goal>test-compile</goal></goals>
                        <configuration>
                            <sourceDirs>
                                <sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
                            </sourceDirs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!--
                Compiles Java sources (e.g. package-info.java) after Kotlin compilation.
                package-info.java is required for package-level annotations such as @ElementDefinition,
                which use ElementType.PACKAGE — a target that Kotlin does not natively support.
            -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-compile</id>
                        <phase>none</phase>
                    </execution>
                    <execution>
                        <id>java-compile</id>
                        <phase>compile</phase>
                        <goals><goal>compile</goal></goals>
                        <configuration>
                            <sourceDirs>
                                <sourceDir>${project.basedir}/src/main/java</sourceDir>
                            </sourceDirs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>


            <!--
                This run of the maven-dependency-plugin builds the ELM file containing the Element formatted in
                the specific layout the loader understands.
            -->

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.6.0</version>
                <executions>
                    <!--
                        Copies dependent artifacts carrying the "element-api" classifier that belong to this
                        project's groupId into the "api" directory of the staging area. These are the API jars
                        exported to other Elements.
                    -->
                    <execution>
                        <id>elm-copy-api-deps</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${elm.element.dir}/api</outputDirectory>
                            <includeGroupIds>${project.groupId}</includeGroupIds>
                            <includeClassifiers>${api.classifier}</includeClassifiers>
                            <prependGroupId>true</prependGroupId>
                        </configuration>
                    </execution>
                    <!--
                        Copies all non-provided dependencies into the "lib" directory of the staging area.
                        These are the runtime libraries bundled with the Element.
                    -->
                    <execution>
                        <id>elm-copy-lib-deps</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${elm.element.dir}/lib</outputDirectory>
                            <excludeScope>provided</excludeScope>
                            <prependGroupId>true</prependGroupId>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <!--
                        Stages compiled classes and src/main/resources contents into the "classpath" directory.
                        Runs in prepare-package so the staging area is complete before the archive is created.
                    -->
                    <execution>
                        <id>elm-stage-classpath</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <copy todir="${elm.element.dir}/classpath" failonerror="false">
                                    <fileset dir="${project.build.outputDirectory}" erroronmissingdir="false" includes="**/*" />
                                </copy>
                                <copy todir="${elm.element.dir}/classpath" failonerror="false">
                                    <fileset dir="${basedir}/src/main/resources" erroronmissingdir="false" includes="**/*" />
                                </copy>
                            </target>
                        </configuration>
                    </execution>
                    <!--
                        Writes the element manifest properties file into the root of the element directory.
                        The loader reads this file to obtain version metadata and required builtin SPIs.
                    -->
                    <execution>
                        <id>elm-write-manifest</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <mkdir dir="${elm.element.dir}" />
                                <exec executable="git" outputproperty="git.revision" failifexecutionfails="false" errorproperty="git.error">
                                    <arg value="rev-parse" />
                                    <arg value="HEAD" />
                                </exec>
                                <property name="git.revision" value="unknown" />
                                <echo file="${elm.element.dir}/dev.getelements.element.manifest.properties" append="false">
Element-Version=${project.version}
Element-Build-Time=${maven.build.timestamp}
Element-Revision=${git.revision}
Element-Builtin-Spis=${elm.builtin.spis}
                                </echo>
                            </target>
                        </configuration>
                    </execution>

                    <!--
                        Creates the .elm archive from the fully staged directory. Ensures all three top-level
                        directories exist so the archive structure is always consistent.
                    -->
                    <execution>
                        <id>elm-create-archive</id>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <mkdir dir="${elm.element.dir}/api" />
                                <mkdir dir="${elm.element.dir}/lib" />
                                <mkdir dir="${elm.element.dir}/classpath" />
                                <zip destfile="${elm.staging.dir}.elm" basedir="${elm.staging.dir}" />
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!--
                Runs integration tests (*IT classes) during mvn verify. Always runs — there is no
                skip switch; the test fails (rather than skips) when no cluster is reachable. CI
                provisions minikube before the build.
            -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>3.2.5</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <includes>
                        <include>**/*IT.class</include>
                    </includes>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.6.0</version>
                <executions>
                    <execution>
                        <id>attach-elm</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${elm.staging.dir}.elm</file>
                                    <type>elm</type>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

</project>