<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>be.nspire.vaadincommon</groupId>
        <artifactId>vaadin-common</artifactId>
        <version>4.4.1-SNAPSHOT</version>
    </parent>

    <artifactId>common-lib</artifactId>

    <properties>
        <!-- Enable deployment for this module - this is the library artifact -->
        <maven.deploy.skip>false</maven.deploy.skip>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.vaadin</groupId>
            <!-- Replace artifactId with vaadin-core to use only free components -->
            <artifactId>vaadin</artifactId>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.parttio</groupId>
            <artifactId>line-awesome</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-cache</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>nl.martijndwars</groupId>
            <artifactId>web-push</artifactId>
        </dependency>
        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcprov-jdk18on</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.appreciated</groupId>
            <artifactId>apexcharts</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-testbench-junit5</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.ben-manes.caffeine</groupId>
            <artifactId>caffeine</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
        </dependency>
        <dependency>
            <groupId>org.reflections</groupId>
            <artifactId>reflections</artifactId>
            <version>0.10.2</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
        </dependency>
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <!-- Aggregated coverage gate for common-lib.
                     Most of common-lib's production code is exercised by the integration tests in
                     common-lib-h2, which JaCoCo records in a separate jacoco.exec. These executions are
                     UNBOUND (no <phase>): they do not run during this module's own build (common-lib is
                     built before common-lib-h2 in the reactor, so h2's exec would not exist yet). Instead
                     CI invokes them explicitly AFTER `mvn verify`, when both exec files are present:
                       mvn -pl common-lib jacoco:merge@merge-coverage \
                                          jacoco:report@aggregate-report \
                                          jacoco:check@aggregate-check
                     The check analyzes common-lib's own classes (this module) against the merged data. -->
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco.version}</version>
                <executions>
                    <execution>
                        <!-- Merge common-lib's own unit-test exec with common-lib-h2's integration-test exec. -->
                        <id>merge-coverage</id>
                        <goals>
                            <goal>merge</goal>
                        </goals>
                        <configuration>
                            <fileSets>
                                <fileSet>
                                    <directory>${project.basedir}/target</directory>
                                    <includes>
                                        <include>jacoco.exec</include>
                                    </includes>
                                </fileSet>
                                <fileSet>
                                    <directory>${project.basedir}/../common-lib-h2/target</directory>
                                    <includes>
                                        <include>jacoco.exec</include>
                                    </includes>
                                </fileSet>
                            </fileSets>
                            <destFile>${project.basedir}/target/jacoco-aggregate.exec</destFile>
                        </configuration>
                    </execution>
                    <execution>
                        <!-- Human-readable aggregated report (html + xml) over common-lib's classes. -->
                        <id>aggregate-report</id>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <configuration>
                            <dataFile>${project.basedir}/target/jacoco-aggregate.exec</dataFile>
                            <outputDirectory>${project.basedir}/target/site/jacoco-aggregate</outputDirectory>
                        </configuration>
                    </execution>
                    <execution>
                        <!-- CI coverage gate: fails the build if testable code regresses below the floor.
                             Framework-bound code (Vaadin views/UI, config) is excluded from the gate. -->
                        <id>aggregate-check</id>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <configuration>
                            <dataFile>${project.basedir}/target/jacoco-aggregate.exec</dataFile>
                            <excludes>
                                <exclude>**/*Application.*</exclude>
                                <exclude>**/config/**</exclude>
                                <exclude>**/db/migration/**</exclude>
                                <exclude>**/ui/**</exclude>
                                <exclude>**/views/**</exclude>
                            </excludes>
                            <rules>
                                <rule>
                                    <element>BUNDLE</element>
                                    <limits>
                                        <!-- Floor sits just below the current ~0.16 aggregate so the gate
                                             catches regressions; raise it as the test suite grows. -->
                                        <limit>
                                            <counter>LINE</counter>
                                            <value>COVEREDRATIO</value>
                                            <minimum>0.14</minimum>
                                        </limit>
                                    </limits>
                                </rule>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>