<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright © 2018-2025 Commonwealth Scientific and Industrial Research
  ~ Organisation (CSIRO) ABN 41 687 119 230.
  ~
  ~ 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>au.csiro.pathling</groupId>
    <artifactId>pathling</artifactId>
    <version>9.2.0</version>
  </parent>
  <artifactId>fhirpath</artifactId>
  <packaging>jar</packaging>

  <name>Pathling FHIRPath Engine</name>
  <description>A library that can translate FHIRPath expressions into Spark queries.</description>

  <dependencies>
    <dependency>
      <groupId>au.csiro.pathling</groupId>
      <artifactId>terminology</artifactId>
    </dependency>

    <!-- Apache Spark -->
    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-core_${pathling.scalaVersion}</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-sql_${pathling.scalaVersion}</artifactId>
      <scope>provided</scope>
      <exclusions>
        <exclusion>
          <groupId>org.apache.logging.log4j</groupId>
          <artifactId>log4j-slf4j2-impl</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>io.delta</groupId>
      <artifactId>delta-spark_${pathling.scalaVersion}</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>jakarta.servlet</groupId>
      <artifactId>jakarta.servlet-api</artifactId>
    </dependency>

    <!-- HAPI FHIR -->
    <dependency>
      <groupId>ca.uhn.hapi.fhir</groupId>
      <artifactId>hapi-fhir-base</artifactId>
    </dependency>
    <dependency>
      <groupId>ca.uhn.hapi.fhir</groupId>
      <artifactId>hapi-fhir-structures-r4</artifactId>
    </dependency>

    <!-- ANTLR -->
    <dependency>
      <groupId>org.antlr</groupId>
      <artifactId>antlr4</artifactId>
    </dependency>

    <!-- JSR 303 validation -->
    <dependency>
      <groupId>org.hibernate.validator</groupId>
      <artifactId>hibernate-validator</artifactId>
    </dependency>
    <dependency>
      <groupId>jakarta.validation</groupId>
      <artifactId>jakarta.validation-api</artifactId>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>com.google.code.findbugs</groupId>
      <artifactId>jsr305</artifactId>
    </dependency>
    <dependency>
      <groupId>commons-beanutils</groupId>
      <artifactId>commons-beanutils</artifactId>
    </dependency>
    <dependency>
      <groupId>org.json</groupId>
      <artifactId>json</artifactId>
    </dependency>
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
    </dependency>

    <!-- Testing -->
    <dependency>
      <groupId>au.csiro.pathling</groupId>
      <artifactId>utilities</artifactId>
      <type>test-jar</type>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>au.csiro.pathling</groupId>
      <artifactId>terminology</artifactId>
      <type>test-jar</type>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.github.tomakehurst</groupId>
      <artifactId>wiremock-jre8-standalone</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.awaitility</groupId>
      <artifactId>awaitility</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <configuration>
          <sourceFileExcludes>
            <sourceFileExclude>au/csiro/pathling/fhirpath/parser/generated/**</sourceFileExclude>
            <sourceFileExclude>au/csiro/pathling/views/ansi/generated/**</sourceFileExclude>
            <sourceFileExclude>au/csiro/pathling/terminology/mock/**</sourceFileExclude>
          </sourceFileExcludes>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.antlr</groupId>
        <artifactId>antlr4-maven-plugin</artifactId>
        <version>${pathling.antlrVersion}</version>
        <executions>
          <execution>
            <goals>
              <goal>antlr4</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <visitor>true</visitor>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-clean-plugin</artifactId>
        <configuration>
          <filesets>
            <fileset>
              <directory>${project.basedir}/src/test/resources/test-data/parquet</directory>
              <includes>
                <include>**/*</include>
              </includes>
            </fileset>
          </filesets>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <executions>
          <execution>
            <id>default-test</id>
            <goals>
              <goal>test</goal>
            </goals>
            <configuration>
              <excludes>
                <exclude>**/FhirViewShareableComplianceTest.java</exclude>
              </excludes>
              <systemPropertyVariables>
                <spring.profiles.active>unit-test</spring.profiles.active>
                <spark.logConf>true</spark.logConf>
              </systemPropertyVariables>
            </configuration>
          </execution>
          <execution>
            <id>sof-compliance-test</id>
            <goals>
              <goal>test</goal>
            </goals>
            <configuration>
              <includes>
                <include>**/FhirViewShareableComplianceTest.java</include>
              </includes>
              <!-- This test is run but it does not fail the build if it fails. -->
              <testFailureIgnore>true</testFailureIgnore>
              <systemPropertyVariables>
                <spring.profiles.active>unit-test</spring.profiles.active>
                <spark.logConf>true</spark.logConf>
              </systemPropertyVariables>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <configuration>
          <excludes>
            <exclude>au/csiro/pathling/fhirpath/parser/generated/*</exclude>
            <exclude>au/csiro/pathling/views/ansi/generated/*</exclude>
            <exclude>au/csiro/pathling/terminology/mock/*</exclude>
          </excludes>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>test-jar</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <excludes>
            <exclude>**/logback.xml</exclude>
          </excludes>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>skipFhirPathTests</id>
      <activation>
        <property>
          <name>skipFhirPathTests</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <skip>true</skip>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <configuration>
              <skip>true</skip>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>mavenRelease</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-gpg-plugin</artifactId>
          </plugin>
          <plugin>
            <groupId>org.sonatype.plugins</groupId>
            <artifactId>nexus-staging-maven-plugin</artifactId>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
            <configuration>
              <skip>false</skip>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>yaml-report</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <systemPropertyVariables>
                <au.csiro.pathling.test.yaml.exclusionsOnly>true</au.csiro.pathling.test.yaml.exclusionsOnly>
              </systemPropertyVariables>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>importTestData</id>
      <activation>
        <activeByDefault>false</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>import-test-data</id>
                <phase>process-test-classes</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration>
                  <executable>java</executable>
                  <arguments>
                    <argument>-classpath</argument>
                    <classpath/>
                    <argument>-Xmx4g</argument>
                    <argument>-Duser.timezone=UTC</argument>
                    <argument>--add-exports=java.base/sun.nio.ch=ALL-UNNAMED</argument>
                    <argument>--add-opens=java.base/java.net=ALL-UNNAMED</argument>
                    <argument>--add-opens=java.base/sun.nio.ch=ALL-UNNAMED</argument>
                    <argument>-Dpathling.version=${project.version}</argument>
                    <argument>-Dpathling.terminology.enabled=false</argument>
                    <argument>-Dspark.master=local[1]</argument>
                    <argument>au.csiro.pathling.test.TestDataImporter</argument>
                    <argument>${project.basedir}/src/test/resources/test-data/fhir</argument>
                    <argument>${project.basedir}/src/test/resources/test-data/parquet</argument>
                  </arguments>
                  <classpathScope>test</classpathScope>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
