<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2011-2026 Lime Mojito Pty Ltd
  ~
  ~    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>
    <name>${project.artifactId}</name>

    <parent>
        <groupId>com.limemojito.oss.standards</groupId>
        <artifactId>oss-maven-standards</artifactId>
        <version>17.0.7</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <artifactId>java-development</artifactId>
    <packaging>pom</packaging>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.limemojito.oss.standards</groupId>
                <artifactId>library</artifactId>
                <version>17.0.7</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <properties>
        <coverage.line.ratio>0.95</coverage.line.ratio>
        <coverage.exclude.pattern.1/>
        <coverage.exclude.pattern.2/>
        <coverage.exclude.pattern.3/>
        <coverage.exclude.pattern.4/>
        <coverage.exclude.pattern.5/>

        <!-- docker test configuration defaults -->
        <docker.build.log.dir>${project.build.directory}/docker-logs</docker.build.log.dir>
        <docker.unit.test>false</docker.unit.test>
        <docker.test.compose.dir>${project.basedir}/src/test/docker</docker.test.compose.dir>
        <docker.test.compose.file>${docker.test.compose.dir}/docker-compose.yml</docker.test.compose.file>
        <docker.test.properties>${project.basedir}/target/docker.properties</docker.test.properties>

        <!-- Compiler configuration assuming JDK 11 or higher -->
        <maven.compiler.source>${java.version}</maven.compiler.source>
        <maven.compiler.target>${java.version}</maven.compiler.target>
        <maven.compiler.release.version>${java.version}</maven.compiler.release.version>

        <!--suppress HttpUrlsUsage -->
        <maven-checkstyle-plugin.configLocation>http://standards.limemojito.com/oss-checkstyle.xml
        </maven-checkstyle-plugin.configLocation>

        <!-- For internal build use only -->
        <!-- Excluded from unit test coverage by default as Spring configurations -->
        <coverage.exclude.build.pattern.1>**.*Config</coverage.exclude.build.pattern.1>
        <coverage.exclude.build.pattern.2>**.*Configuration</coverage.exclude.build.pattern.2>
        <coverage.exclude.build.pattern.3/>
        <coverage.exclude.build.pattern.4/>
        <coverage.exclude.build.pattern.5/>

        <lombok.outputDirectory>${project.build.directory}/generated-sources/delombok</lombok.outputDirectory>

        <!-- This can be disabled by profile - suggest fast-build -->
        <skipTests>false</skipTests>
        <skipITs>false</skipITs>
        <lime.fast-build>false</lime.fast-build>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </dependency>

        <!-- Test Dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <!-- We define common CONFIGURATIONS here.  The poms representing a deliverable type have this one as a parent, and their build
        invokes the plugins -->
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>properties-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>import-test-docker-properties</id>
                            <!-- This import occurs AFTER identify-docker-compose, so that we know the docker state -->
                            <phase>initialize</phase>
                            <goals>
                                <goal>read-project-properties</goal>
                            </goals>
                            <configuration>
                                <files>
                                    <file>${docker.test.properties}</file>
                                </files>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>identify-docker-compose</id>
                            <phase>validate</phase>
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <configuration>
                                <target>
                                    <!-- writes to a property file to avoid warnings from ant export properties
                                         configuration -->
                                    <condition property="docker.test.compose.skip" else="false">
                                        <or>
                                            <equals arg1="${lime.fast-build}" arg2="true"/>
                                            <not>
                                                <available file="${docker.test.compose.file}"/>
                                            </not>
                                        </or>
                                    </condition>
                                    <!--suppress UnresolvedMavenProperty -->
                                    <echo level="info"
                                          message="docker.test.compose.skip is ${docker.test.compose.skip}"/>
                                    <!--suppress UnresolvedMavenProperty -->
                                    <echo file="${docker.test.properties}"
                                          message="docker.test.compose.skip=${docker.test.compose.skip}"/>
                                </target>
                            </configuration>
                        </execution>
                        <execution>
                            <id>docker-up-unit-test</id>
                            <!--
                             NOTE THAT LIFECYCLE CHECKS IN DOCKER COMPOSE FILES ARE REQUIRED
                             AS NO WAIT AFTER STARTUP BEFORE TESTING BEGINS.
                             -->
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <phase>test-compile</phase>
                            <configuration>
                                <!--suppress MavenModelInspection -->
                                <skip>${docker.test.compose.skip}</skip>
                                <target if="${docker.unit.test}">
                                    <exec executable="docker"
                                          dir="${docker.test.compose.dir}"
                                          failifexecutionfails="true"
                                          failonerror="true">
                                        <arg value="compose"/>
                                        <arg value="up"/>
                                        <arg value="--wait"/>
                                        <arg value="--detach"/>
                                    </exec>
                                </target>
                            </configuration>
                        </execution>
                        <execution>
                            <id>docker-up-integration-test</id>
                            <!--
                             NOTE THAT LIFECYCLE CHECKS IN DOCKER COMPOSE FILES ARE REQUIRED
                             AS NO WAIT AFTER STARTUP BEFORE TESTING BEGINS.
                             -->
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <phase>pre-integration-test</phase>
                            <configuration>
                                <!--suppress MavenModelInspection -->
                                <skip>${docker.test.compose.skip}</skip>
                                <target unless="${docker.unit.test}">
                                    <exec executable="docker"
                                          dir="${docker.test.compose.dir}"
                                          failifexecutionfails="true"
                                          failonerror="true">
                                        <arg value="compose"/>
                                        <arg value="up"/>
                                        <arg value="--wait"/>
                                        <arg value="--detach"/>
                                    </exec>
                                </target>
                            </configuration>
                        </execution>
                        <execution>
                            <id>docker-save-logs</id>
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <phase>post-integration-test</phase>
                            <configuration>
                                <!--suppress MavenModelInspection -->
                                <skip>${docker.test.compose.skip}</skip>
                                <target xmlns:ac="antlib:net.sf.antcontrib">
                                    <echo level="info"
                                          message="Saving Docker logs for all running containers"/>
                                    <exec executable="docker"
                                          failonerror="true"
                                          outputProperty="docker.container.list.raw">
                                        <arg value="ps"/>
                                        <arg value="-aq"/>
                                    </exec>
                                    <exec executable="/bin/bash"
                                          failonerror="true"
                                          outputProperty="docker.container.list">
                                        <arg value="-c"/>
                                        <!-- Quoting in XML entities so it gets passed through to the bash command line -->
                                        <!--suppress UnresolvedMavenProperty -->
                                        <arg line='"echo &apos;${docker.container.list.raw}&apos; | tr &apos;\n&apos; &apos; &apos;"'/>
                                    </exec>
                                    <ac:if>
                                        <not>
                                            <!--suppress UnresolvedMavenProperty -->
                                            <equals arg1="" arg2="${docker.container.list}"/>
                                        </not>
                                        <then><!--suppress UnresolvedMavenProperty -->
                                            <echo level="info"
                                                  message="Docker container list: ${docker.container.list}"/>
                                            <echo level="info"
                                                  message="Output docker logs to ${docker.build.log.dir}"/>
                                            <mkdir dir="${docker.build.log.dir}"/>
                                            <exec executable="/bin/bash"
                                                  dir="${docker.build.log.dir}"
                                                  failonerror="true">
                                                <arg value="-c"/>
                                                <!--suppress UnresolvedMavenProperty -->
                                                <arg line='"for container in ${docker.container.list}; do name=$(docker ps --format &quot;{{.Names}}&quot; --filter &quot;id=$container&quot;); docker logs ${container} > ${container}-$name.log; echo Wrote ${container}-$name.log; done"'/>
                                            </exec>
                                        </then>
                                    </ac:if>
                                </target>
                            </configuration>
                        </execution>
                        <execution>
                            <id>docker-down</id>
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <!--
                                Docker down in install phase to cover unit test only modules - these may not have
                                an integration-test phase
                            -->
                            <phase>install</phase>
                            <configuration>
                                <!--suppress MavenModelInspection -->
                                <skip>${docker.test.compose.skip}</skip>
                                <target>
                                    <exec executable="docker"
                                          dir="${docker.test.compose.dir}"
                                          failifexecutionfails="true"
                                          failonerror="true">
                                        <arg value="compose"/>
                                        <arg value="down"/>
                                        <arg value="--remove-orphans"/>
                                        <arg value="--volumes"/>
                                    </exec>
                                </target>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-checkstyle-plugin</artifactId>
                    <dependencies>
                        <dependency>
                            <groupId>com.puppycrawl.tools</groupId>
                            <artifactId>checkstyle</artifactId>
                            <version>${checkstyle.version}</version>
                            <exclusions>
                                <!--  MCHECKSTYLE-156  -->
                                <exclusion>
                                    <groupId>com.sun</groupId>
                                    <artifactId>tools</artifactId>
                                </exclusion>
                            </exclusions>
                        </dependency>
                    </dependencies>
                    <executions>
                        <execution>
                            <id>validate</id>
                            <phase>process-classes</phase>
                            <goals>
                                <goal>check</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <configLocation>${maven-checkstyle-plugin.configLocation}</configLocation>
                        <consoleOutput>true</consoleOutput>
                        <failsOnError>true</failsOnError>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <!-- note using release option on JDK 9+ -->
                        <release>${java.version}</release>
                        <compilerArgs>
                            <compilerArg>-Xlint:all</compilerArg>
                            <!-- Due to spurious warnings with Lombok -->
                            <compilerArg>-Xlint:-processing</compilerArg>
                            <!-- Serialization is rare now.  IDE assistance covers most situations -->
                            <compilerArg>-Xlint:-serial</compilerArg>
                            <compilerArg>-Werror</compilerArg>
                        </compilerArgs>
                        <showWarnings>true</showWarnings>
                        <showDeprecation>true</showDeprecation>
                        <failOnError>true</failOnError>
                        <annotationProcessorPaths>
                            <annotationProcessorPath>
                                <groupId>org.projectlombok</groupId>
                                <artifactId>lombok</artifactId>
                                <version>${lombok.version}</version>
                            </annotationProcessorPath>
                        </annotationProcessorPaths>
                        <parameters>true</parameters>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <executions>
                        <execution>
                            <goals>
                                <goal>properties</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <configuration>
                        <!-- Setup for mockito as per https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html -->
                        <argLine>-XX:+EnableDynamicAgentLoading</argLine>
                        <!-- as Lombok generated classes are NOT seen by boot -->
                        <classesDirectory>${project.build.outputDirectory}</classesDirectory>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>integration-test</goal>
                                <goal>verify</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <configuration>
                        <archive>
                            <manifest>
                                <addDefaultEntries>true</addDefaultEntries>
                                <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                                <addBuildEnvironmentEntries>true</addBuildEnvironmentEntries>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <configuration>
                        <!--suppress MavenModelInspection -->
                        <skip>${javadoc.skip}</skip>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                            <phase>prepare-package</phase>
                            <configuration>
                                <sourcepath>${lombok.outputDirectory}:${project.build.sourceDirectory}</sourcepath>
                                <doclint>-missing</doclint>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <configuration>
                        <propertiesEncoding>ISO-8859-1</propertiesEncoding>
                        <nonFilteredFileExtensions>
                            <nonFilteredFileExtension>bi5</nonFilteredFileExtension>
                            <nonFilteredFileExtension>dll</nonFilteredFileExtension>
                            <nonFilteredFileExtension>doc</nonFilteredFileExtension>
                            <nonFilteredFileExtension>exe</nonFilteredFileExtension>
                            <nonFilteredFileExtension>so</nonFilteredFileExtension>
                            <nonFilteredFileExtension>xls</nonFilteredFileExtension>
                            <nonFilteredFileExtension>zip</nonFilteredFileExtension>
                        </nonFilteredFileExtensions>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                    <configuration>
                        <!--suppress MavenModelInspection -->
                        <skipSource>${source.skip}</skipSource>
                    </configuration>
                    <executions>
                        <execution>
                            <id>attach-sources</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <!-- Include set argLine such as jacoco.-->
                        <!--suppress UnresolvedMavenProperty -->
                        <!-- Setup for mockito as per https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html#0.3 -->
                        <argLine>@{argLine} -XX:+EnableDynamicAgentLoading</argLine>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>default-prepare-agent</id>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>default-report</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>default-check</id>
                            <goals>
                                <goal>check</goal>
                            </goals>
                            <!-- We don't care about integration tests -->
                            <phase>package</phase>
                            <!-- Configuration is here to make it easier to override though use the properties first. -->
                            <configuration>
                                <rules>
                                    <rule implementation="org.jacoco.maven.RuleConfiguration">
                                        <element>CLASS</element>
                                        <excludes>
                                            <!-- Exclude for Spring configuration package as these are too hard to unit test -->
                                            <exclude>*.config.*</exclude>
                                            <exclude>*.Config</exclude>
                                            <exclude>*.Configuration</exclude>
                                            <!-- Exclude for *.1 classes produced by the compiler for things like switch statements -->
                                            <exclude>*.?</exclude>
                                            <!-- General exclude patterns from other projects -->
                                            <exclude>${coverage.exclude.pattern.1}</exclude>
                                            <exclude>${coverage.exclude.pattern.2}</exclude>
                                            <exclude>${coverage.exclude.pattern.3}</exclude>
                                            <exclude>${coverage.exclude.pattern.4}</exclude>
                                            <exclude>${coverage.exclude.pattern.5}</exclude>

                                            <!-- Build exclude patterns -->
                                            <exclude>${coverage.exclude.build.pattern.1}</exclude>
                                            <exclude>${coverage.exclude.build.pattern.2}</exclude>
                                            <exclude>${coverage.exclude.build.pattern.3}</exclude>
                                            <exclude>${coverage.exclude.build.pattern.4}</exclude>
                                            <exclude>${coverage.exclude.build.pattern.5}</exclude>
                                        </excludes>
                                        <limits>
                                            <limit implementation="org.jacoco.report.check.Limit">
                                                <counter>LINE</counter>
                                                <value>COVEREDRATIO</value>
                                                <minimum>${coverage.line.ratio}</minimum>
                                            </limit>
                                        </limits>
                                    </rule>
                                </rules>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <!-- declared late so that signing is before install -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-gpg-plugin</artifactId>
                    <configuration>
                        <!--suppress MavenModelInspection -->
                        <skip>${sign.skip}</skip>
                    </configuration>
                    <executions>
                        <execution>
                            <id>sign-artifacts</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>sign</goal>
                            </goals>
                            <!--
                              Supply key name with gpg.keyname property on command line if not default
                              https://maven.apache.org/plugins/maven-gpg-plugin/sign-mojo.html#keyname
                             -->
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-install-plugin</artifactId>
                </plugin>
            </plugins>
        </pluginManagement>

        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>

        <!-- We define common PROCESS here.  The CONFIGURATIONS are in the plugin management section -->
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>properties-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-compile</id>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                        <phase>compile</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
            </plugin>
            <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>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>fast-build</id>
            <properties>
                <checkstyle.skip>true</checkstyle.skip>
                <codenarc.skip>true</codenarc.skip>
                <enforcer.skip>true</enforcer.skip>
                <jacoco.skip>true</jacoco.skip>
                <javadoc.skip>true</javadoc.skip>
                <sign.skip>true</sign.skip>
                <skipTests>true</skipTests>
                <skipITs>true</skipITs>
                <source.skip>true</source.skip>
                <lime.fast-build>true</lime.fast-build>
            </properties>
        </profile>
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok-maven-plugin</artifactId>
                        <dependencies>
                            <dependency>
                                <groupId>org.projectlombok</groupId>
                                <artifactId>lombok</artifactId>
                                <version>${lombok.version}</version>
                            </dependency>
                        </dependencies>
                        <executions>
                            <execution>
                                <phase>verify</phase>
                                <goals>
                                    <goal>delombok</goal>
                                </goals>
                                <configuration>
                                    <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
                                    <outputDirectory>${lombok.outputDirectory}</outputDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
