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

    <artifactId>n2o-boot-platform-parent</artifactId>
    <packaging>pom</packaging>
    <name>n2o-boot-platform-parent</name>

    <parent>
        <groupId>net.n2oapp.platform</groupId>
        <artifactId>n2o-boot-dependencies</artifactId>
        <version>7.0.1</version>
        <relativePath>../n2o-platform-dependencies</relativePath>
    </parent>

    <properties>
        <argLine /><!--required for mockito agent enable in maven-surefire-plugin https://javadoc.io/doc/org.mockito/mockito-core/latest/org.mockito/org/mockito/Mockito.html#0.3-->

        <java.version>21</java.version>

        <maven.compiler.source>${java.version}</maven.compiler.source>
        <maven.compiler.target>${java.version}</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <maven.source.version>3.3.0</maven.source.version>
        <maven.javadoc.version>3.11.2</maven.javadoc.version>
        <maven.javadoc.failOnError>false</maven.javadoc.failOnError>
        <maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
        <versions-maven-plugin.version>2.15.0</versions-maven-plugin.version>
        <maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>

        <jacoco-maven-plugin.version>0.8.11</jacoco-maven-plugin.version>
        <jacoco.skip>true</jacoco.skip> <!-- Skip all by default for project's root and aggregator pom modules. Disable skip in jar modules. -->
        <jacoco.aggregate.report.path>${project.basedir}/../target/site/jacoco-aggregate</jacoco.aggregate.report.path> <!-- By default use parent directory of module for multimodule projects. -->

        <sonar.sources>.</sonar.sources>
        <sonar.inclusions>
            src/main/resources/db/**,
            src/main/resources/**/*.yml,
            src/main/java/**
        </sonar.inclusions>
        <sonar.test.exclusions>src/test/**</sonar.test.exclusions>

        <docker-compose.config.folder>.docker-compose</docker-compose.config.folder>
        <k8s.config.folder>.k8s</k8s.config.folder>
        <maven.build.timestamp.format>yyyyMMdd.HHmmss</maven.build.timestamp.format>
        <docker.image.tag>${project.version}-${maven.build.timestamp}</docker.image.tag>
        <helm.chart.version>${docker.image.tag}</helm.chart.version>
    </properties>

    <dependencies>
        <!-- Do not add here other dependencies! This parent should be as small as possible -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
        </dependency>
        <!-- Do not add here other dependencies! This parent should be as small as possible -->
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.yaml</include>
                    <include>**/*.yml</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
                <excludes>
                    <exclude>**/*.properties</exclude>
                    <exclude>**/*.yaml</exclude>
                    <exclude>**/*.yml</exclude>
                </excludes>
            </resource>
        </resources>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <goals>
                                <goal>repackage</goal>
                                <goal>build-info</goal>
                            </goals>
                            <configuration>
                                <additionalProperties>
                                    <java.source>${maven.compiler.source}</java.source>
                                    <java.target>${maven.compiler.target}</java.target>
                                </additionalProperties>
                            </configuration>
                        </execution>
                    </executions>
                    <configuration>
                        <executable>true</executable>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>  <!-- See info about jacoco.skip property. -->
                    <version>${jacoco-maven-plugin.version}</version>
                    <executions>
                        <execution>
                            <id>prepare</id>
                            <goals>
                                <goal>prepare-agent</goal>
                                <goal>report</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>jacoco-site</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>report-aggregate</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${jacoco.aggregate.report.path}</outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>${maven.source.version}</version>
                    <executions>
                        <execution>
                            <id>attach-sources</id>
                            <goals>
                                <goal>jar-no-fork</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>${maven.javadoc.version}</version>
                    <executions>
                        <execution>
                            <id>attach-javadocs</id>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                            <configuration>
                                <detectOfflineLinks>false</detectOfflineLinks>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>${maven-resources-plugin.version}</version>
                    <executions>
                        <execution>
                            <id>process-docker-config</id>
                            <phase>none</phase>
                            <goals>
                                <goal>copy-resources</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${project.basedir}</outputDirectory>
                                <resources>
                                    <resource>
                                        <directory>${project.basedir}/${docker-compose.config.folder}</directory>
                                        <targetPath>${project.basedir}/${docker-compose.config.folder}/target</targetPath>
                                        <filtering>true</filtering>
                                        <excludes>
                                            <exclude>**/target/**</exclude>
                                        </excludes>
                                    </resource>
                                    <resource>
                                        <directory>${project.basedir}/${k8s.config.folder}</directory>
                                        <targetPath>${project.basedir}/${k8s.config.folder}/target</targetPath>
                                        <filtering>true</filtering>
                                        <excludes>
                                            <exclude>**/target/**</exclude>
                                        </excludes>
                                    </resource>
                                </resources>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>${maven-clean-plugin.version}</version>
                    <executions>
                        <execution>
                            <id>process-docker-config</id>
                            <phase>none</phase>
                            <goals>
                                <goal>clean</goal>
                            </goals>
                            <configuration>
                                <filesets>
                                    <fileset>
                                        <directory>${project.basedir}/${docker-compose.config.folder}/target</directory>
                                    </fileset>
                                    <fileset>
                                        <directory>${project.basedir}/${k8s.config.folder}/target</directory>
                                    </fileset>
                                </filesets>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
            </plugin>

<!--        required for mockito agent enable in maven-surefire-plugin https://javadoc.io/doc/org.mockito/mockito-core/latest/org.mockito/org/mockito/Mockito.html#0.3-->
            <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-surefire-plugin</artifactId>
                <configuration>
                    <includes>
                        <include>**/*Test.java</include>
                        <include>**/*Tests.java</include>
                    </includes>
                    <argLine>@{argLine} -javaagent:${org.mockito:mockito-core:jar}</argLine>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>versions-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>jacoco</id> <!-- See info about jacoco.skip property. -->
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>ci-build</id>
            <activation>
                <property>
                    <name>ci.commit.sha</name>
                </property>
            </activation>
            <properties>
                <docker.env.name><!--do not delete, property overrides at ci-build--></docker.env.name>
                <docker.image.tag>${project.version}${ci.commit.sha}${docker.env.name}</docker.image.tag>
            </properties>
        </profile>
    </profiles>

</project>
