<?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>ai.wanaku</groupId>
        <artifactId>apps</artifactId>
        <version>0.1.1-SNAPSHOT</version>
    </parent>

    <artifactId>wanaku-operator</artifactId>
    <name>Wanaku :: Apps :: Operator</name>

    <dependencies>
        <dependency>
            <groupId>io.quarkiverse.operatorsdk</groupId>
            <artifactId>quarkus-operator-sdk</artifactId>
            <version>${quarkus-operator-sdk.version}</version>
        </dependency>

        <dependency>
            <groupId>io.quarkiverse.operatorsdk</groupId>
            <artifactId>quarkus-operator-sdk-annotations</artifactId>
            <version>${quarkus-operator-sdk.version}</version>
        </dependency>

        <dependency>
            <groupId>ai.wanaku</groupId>
            <artifactId>core-util</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>ai.wanaku</groupId>
            <artifactId>core-services-api</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-rest</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-rest-client</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-rest-client-jackson</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-rest-jackson</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-arc</artifactId>
        </dependency>

        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-container-image-jib</artifactId>
        </dependency>

        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-openshift-client</artifactId>
        </dependency>

        <dependency>
            <groupId>io.quarkiverse.helm</groupId>
            <artifactId>quarkus-helm</artifactId>
            <version>${quarkus-helm.version}</version>
        </dependency>

        <dependency>
            <groupId>io.javaoperatorsdk</groupId>
            <artifactId>operator-framework-core</artifactId>
            <version>${operator-framework.version}</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-junit-mockito</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>${quarkus.platform.group-id}</groupId>
                <artifactId>quarkus-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
            <!-- Workaround: the quarkus-helm expressions engine cannot reach templates
                 generated by the Quarkus Operator SDK (JOSDK). Those files use a separate
                 AdditionalHelmTemplateBuildItem pipeline, so their roleRef values are not
                 updated when ClusterRole names are prefixed via quarkus.helm.expressions.
                 This plugin post-processes the generated Helm chart at package time to
                 align the roleRef names and remove duplicate RoleBindings. -->
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>fix-helm-roleref</id>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <property name="helm.templates"
                                          value="${project.build.directory}/helm/kubernetes/wanaku-operator/templates"/>
                                <!-- Prefix roleRef names to match namespace-prefixed ClusterRoles -->
                                <replace dir="${helm.templates}"
                                         includes="*-crd-role-binding.yaml"
                                         token="name: wanaku-capability-cluster-role"
                                         value="name: {{ $.Release.Namespace }}-wanaku-capability-cluster-role"/>
                                <replace dir="${helm.templates}"
                                         includes="*-crd-role-binding.yaml"
                                         token="name: wanaku-router-cluster-role"
                                         value="name: {{ $.Release.Namespace }}-wanaku-router-cluster-role"/>
                                <replace dir="${helm.templates}"
                                         includes="*-crd-role-binding.yaml"
                                         token="name: wanaku-service-catalog-cluster-role"
                                         value="name: {{ $.Release.Namespace }}-wanaku-service-catalog-cluster-role"/>
                                <replace dir="${helm.templates}"
                                         includes="validating-clusterrolebinding.yaml"
                                         token="name: josdk-crd-validating-cluster-role"
                                         value="name: {{ $.Release.Namespace }}-josdk-crd-validating-cluster-role"/>
                                <!-- Remove duplicate RoleBindings from rolebinding.yaml;
                                     the *-crd-role-binding.yaml files handle these conditionally -->
                                <echo file="${helm.templates}/rolebinding.yaml"><![CDATA[---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  labels:
    app.kubernetes.io/name: wanaku-operator
    app.kubernetes.io/version: ${project.version}
  name: wanaku-operator-view
roleRef:
  kind: ClusterRole
  apiGroup: rbac.authorization.k8s.io
  name: view
subjects:
  - kind: ServiceAccount
    name: wanaku-operator
    namespace: {{ .Release.Namespace }}
]]></echo>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven-surefire-plugin.version}</version>
                <configuration>
                    <excludes>
                        <exclude>**/*ManualTest.java</exclude>
                    </excludes>
                    <systemPropertyVariables>
                        <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                        <maven.home>${maven.home}</maven.home>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>${maven-failsafe-plugin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                        <configuration>
                            <excludes>
                                <exclude>**/*ManualTest.java</exclude>
                            </excludes>
                            <systemPropertyVariables>
                                <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
                                <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                                <maven.home>${maven.home}</maven.home>
                            </systemPropertyVariables>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>
