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

    <groupId>io.github.entropy-cloud</groupId>
    <artifactId>nop-entropy</artifactId>
    <version>2.0.0-SNAPSHOT</version>

    <packaging>pom</packaging>

    <licenses>
        <license>
            <name>Apache License 2.0</name>
            <url>https://www.apache.org/licenses/LICENSE-2.0.html</url>
        </license>
    </licenses>


    <properties>
        <revision>2.0.0-SNAPSHOT</revision>

        <java.version>17</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <maven.compiler.release>11</maven.compiler.release>

        <main.basedir>${basedir}</main.basedir>
        <docs.main>${project.artifactId}</docs.main>

        <!-- Sonar: 使用 mvn sonar:sonar 主动触发,不参与日常构建 -->
        <sonar.coverage.jacoco.xmlReportPaths>
            ${maven.multiModuleProjectDirectory}/tests/target/site/jacoco-aggregate/jacoco.xml
        </sonar.coverage.jacoco.xmlReportPaths>
        <sonar.language>java</sonar.language>
        <sonar.sourceEncoding>UTF-8</sonar.sourceEncoding>

        <!-- 排除自动生成文件:_gen 目录、_ 前缀文件、Errors/Configs/Constants -->
        <sonar.exclusions>
            **/_gen/**,**/_*.java,**/_*.xml,**/*Errors.java,**/*Configs.java,**/*Constants.java
        </sonar.exclusions>
        <sonar.coverage.exclusions>
            **/_gen/**,**/_*.java,**/*Errors.java,**/*Configs.java,**/*Constants.java,**/parse/antlr/**
        </sonar.coverage.exclusions>
        <sonar.cpd.exclusions>
            **/_gen/**,**/_*.java,**/*Errors.java,**/*Configs.java,**/*Constants.java
        </sonar.cpd.exclusions>

        <!-- Plugins -->
        <maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
        <maven-failsafe-plugin.version>3.0.0-M4</maven-failsafe-plugin.version>
        <maven-javadoc-plugin.version>3.1.0</maven-javadoc-plugin.version>
        <maven-source-plugin.version>3.3.0</maven-source-plugin.version>
        <maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>
        <maven-install-plugin.version>3.1.1</maven-install-plugin.version>
        <maven-antrun-plugin.version>1.8</maven-antrun-plugin.version>
        <maven-surefire-plugin.version>3.0.0-M4</maven-surefire-plugin.version>
        <exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
        <maven-resources-plugin.version>3.1.0</maven-resources-plugin.version>
        <git-commit-id-plugin.version>3.0.0</git-commit-id-plugin.version>
        <maven-shade-plugin.version>3.1.1</maven-shade-plugin.version>
        <maven-enforcer-plugin.version>3.0.0-M2</maven-enforcer-plugin.version>
        <maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
        <maven-dependency-plugin.version>3.1.1</maven-dependency-plugin.version>
        <asciidoctor-maven-plugin.version>1.5.8</asciidoctor-maven-plugin.version>
        <build-helper-maven-plugin.version>3.0.0</build-helper-maven-plugin.version>
        <artifactory-maven-plugin.version>2.2.1</artifactory-maven-plugin.version>
        <license-maven-plugin.version>1.16</license-maven-plugin.version>
        <maven-checkstyle-plugin.version>3.1.0</maven-checkstyle-plugin.version>
        <disable.checks>false</disable.checks>
        <maven-checkstyle-plugin.failsOnError>true</maven-checkstyle-plugin.failsOnError>
        <maven-checkstyle-plugin.failOnViolation>true</maven-checkstyle-plugin.failOnViolation>
        <maven-checkstyle-plugin.includeTestSourceDirectory>true</maven-checkstyle-plugin.includeTestSourceDirectory>
        <spring-cloud-build-checkstyle.branch>master</spring-cloud-build-checkstyle.branch>

        <antelopetasks.version>3.2.10</antelopetasks.version>
        <ant-nodeps.version>1.8.1</ant-nodeps.version>

        <nop-entropy.version>2.0.0-SNAPSHOT</nop-entropy.version>

        <quarkus.platform.version>3.35.1</quarkus.platform.version>

        <surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencyManagement>

        <dependencies>
            <dependency>
                <groupId>io.github.entropy-cloud</groupId>
                <artifactId>nop-bom</artifactId>
                <version>${nop-entropy.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin.version}</version>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.3.1</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>${maven-source-plugin.version}</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!-- Checkstyle 代码质量检查 -->
<!--            <plugin>-->
<!--                <groupId>org.apache.maven.plugins</groupId>-->
<!--                <artifactId>maven-checkstyle-plugin</artifactId>-->
<!--                <version>${maven-checkstyle-plugin.version}</version>-->
<!--                <dependencies>-->
<!--                    <dependency>-->
<!--                        <groupId>com.puppycrawl.tools</groupId>-->
<!--                        <artifactId>checkstyle</artifactId>-->
<!--                        <version>8.45.1</version>-->
<!--                    </dependency>-->
<!--                </dependencies>-->
<!--                <executions>-->
<!--                    <execution>-->
<!--                        <id>validate</id>-->
<!--                        <phase>validate</phase>-->
<!--                        <goals>-->
<!--                            <goal>check</goal>-->
<!--                        </goals>-->
<!--                    </execution>-->
<!--                </executions>-->
<!--                <configuration>-->
<!--                    <configLocation>${main.basedir}/checkstyle.xml</configLocation>-->
<!--                    <encoding>UTF-8</encoding>-->
<!--                    <consoleOutput>true</consoleOutput>-->
<!--                    <failsOnError>${maven-checkstyle-plugin.failsOnError}</failsOnError>-->
<!--                    <failOnViolation>${maven-checkstyle-plugin.failOnViolation}</failOnViolation>-->
<!--                    <includeTestSourceDirectory>${maven-checkstyle-plugin.includeTestSourceDirectory}</includeTestSourceDirectory>-->
<!--                    <excludes>**/_gen/**,**/*Errors.java,**/*Configs.java,**/*Constants.java,**/target/**</excludes>-->
<!--                </configuration>-->
<!--            </plugin>-->

            <!-- mvn site指令生成报告 -->
            <!--            <plugin>-->
            <!--                <groupId>org.apache.maven.plugins</groupId>-->
            <!--                <artifactId>maven-site-plugin</artifactId>-->
            <!--                <version>4.0.0-M2</version>-->
            <!--            </plugin>-->

            <!--            <plugin>-->
            <!--                <groupId>org.apache.maven.plugins</groupId>-->
            <!--                <artifactId>maven-project-info-reports-plugin</artifactId>-->
            <!--                <version>3.3.0</version>-->
            <!--            </plugin>-->


            <!-- mvn surefire-report:report指令生成测试报告 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.2.2</version>

                <configuration>
                    <argLine>
                        ${jacocoArgLine}
                        -Xmx1G
                        -Xms256m
                        -XX:MaxMetaspaceSize=256m
                        -XX:+UseG1GC
                        -XX:+UseStringDeduplication
                    </argLine>
                    <testFailureIgnore>false</testFailureIgnore>
                    <!--                    <forkCount>4</forkCount>-->
                    <!--                    <reuseForks>true</reuseForks>-->
                    <!--                    <forkedProcessExitTimeoutInSeconds>60</forkedProcessExitTimeoutInSeconds>-->

                    <!--
                       forkCount: 这是关键!它定义了要启动多少个JVM进程来运行测试。
                       你可以使用一个固定的数字,比如 '4'。
                       或者,更灵活的方式是使用类似 '2C' 的表达式,表示“每个CPU核心启动2个JVM进程”。
                       这里我们用 '2C' 作为示例,它会根据你机器的CPU核心数动态调整。
                   -->
                    <forkCount>1C</forkCount>

                    <!--
                        reuseForks: 设置为 'true'。
                        这意味着Maven会重用已经启动的JVM进程来运行多个测试类,而不是为每个测试类都创建一个新的JVM。
                        这可以显著减少测试的总体时间,因为JVM的启动和销毁是昂贵的操作。
                    -->
                    <reuseForks>true</reuseForks>

                    <!--
                        parallel: 设置为 'classes'。
                        这个设置告诉Surefire将“测试类”作为并行的基本单位。
                        它会将所有的测试类分发到由 forkCount 创建的多个JVM中去执行。
                    -->
                    <parallel>classes</parallel>

                    <!--
                        threadCount: 这是实现“JVM内串行”的关键!
                        将其设置为 '1'。
                        它限制了在每一个独立的JVM进程内部,只有一个执行线程。
                        因此,被分配到同一个JVM的测试类会一个接一个地串行执行。
                    -->
                    <threadCount>1</threadCount>
                </configuration>

            </plugin>


            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>3.0.0-M2</version>
                <executions>
                    <execution>
                        <id>enforce-no-duplicate-dependencies</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <!-- 检查pom中没有添加重复的依赖项 -->
                                <banDuplicatePomDependencyVersions/>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!--            <plugin>-->
            <!--                <groupId>org.codehaus.mojo</groupId>-->
            <!--                <artifactId>flatten-maven-plugin</artifactId>-->
            <!--                <version>1.5.0</version>-->
            <!--                <configuration>-->
            <!--                    <updatePomFile>true</updatePomFile>-->
            <!--                    <flattenMode>oss</flattenMode>-->
            <!--                </configuration>-->
            <!--                <executions>-->
            <!--                    <execution>-->
            <!--                        <id>flatten</id>-->
            <!--                        <phase>process-resources</phase>-->
            <!--                        <goals>-->
            <!--                            <goal>flatten</goal>-->
            <!--                        </goals>-->
            <!--                    </execution>-->
            <!--                    <execution>-->
            <!--                        <id>flatten.clean</id>-->
            <!--                        <phase>clean</phase>-->
            <!--                        <goals>-->
            <!--                            <goal>clean</goal>-->
            <!--                        </goals>-->
            <!--                    </execution>-->
            <!--                </executions>-->
            <!--            </plugin>-->

        </plugins>

        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>3.4.0</version>
                    <configuration>
                        <failOnError>false</failOnError>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>${maven-jar-plugin.version}</version>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>${maven-install-plugin.version}</version>
                </plugin>


                <plugin>
                    <groupId>io.smallrye</groupId>
                    <artifactId>jandex-maven-plugin</artifactId>
                    <version>3.5.2</version>
                    <executions>
                        <execution>
                            <id>make-index</id>
                            <goals>
                                <goal>jandex</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>3.0.0</version>
                    <executions>
                        <execution>
                            <id>precompile</id>
                            <phase>generate-sources</phase>
                            <goals>
                                <goal>java</goal>
                            </goals>
                            <configuration>
                                <arguments>
                                    <argument>${project.basedir}</argument>
                                    <argument>precompile</argument>
                                </arguments>

                                <!--
                                避免包含META-INF目录导致加载尚未编译的ICoreInitializer
                                -->
                                <addResourcesToClasspath>false</addResourcesToClasspath>
                                <addOutputToClasspath>false</addOutputToClasspath>
                            </configuration>
                        </execution>

                        <execution>
                            <id>precompile2</id>
                            <phase>generate-sources</phase>
                            <goals>
                                <goal>java</goal>
                            </goals>
                            <configuration>
                                <arguments>
                                    <argument>${project.basedir}</argument>
                                    <argument>precompile2</argument>
                                </arguments>

                                <addResourcesToClasspath>true</addResourcesToClasspath>
                                <addOutputToClasspath>true</addOutputToClasspath>
                            </configuration>
                        </execution>

                        <execution>
                            <id>aop</id>
                            <phase>compile</phase>
                            <goals>
                                <goal>java</goal>
                            </goals>
                            <configuration>
                                <classpathScope>test</classpathScope>
                                <arguments>
                                    <argument>${project.basedir}</argument>
                                    <argument>aop</argument>
                                </arguments>
                            </configuration>
                        </execution>

                        <execution>
                            <id>postcompile</id>
                            <phase>generate-test-resources</phase>
                            <goals>
                                <goal>java</goal>
                            </goals>
                            <configuration>
                                <addResourcesToClasspath>true</addResourcesToClasspath>
                                <addOutputToClasspath>true</addOutputToClasspath>
                                <arguments>
                                    <argument>${project.basedir}</argument>
                                    <argument>postcompile</argument>
                                </arguments>
                            </configuration>
                        </execution>
                    </executions>
                    <configuration>
                        <classpathScope>compile</classpathScope>
                        <includePluginDependencies>true</includePluginDependencies>
                        <includeProjectDependencies>true</includeProjectDependencies>
                        <addResourcesToClasspath>true</addResourcesToClasspath>
                        <mainClass>io.nop.codegen.task.CodeGenTask</mainClass>
                        <cleanupDaemonThreads>false</cleanupDaemonThreads>
                    </configuration>

                    <dependencies>
                        <dependency>
                            <groupId>io.github.entropy-cloud</groupId>
                            <artifactId>nop-codegen</artifactId>
                            <version>${nop-entropy.version}</version>
                        </dependency>
                    </dependencies>
                </plugin>

                <plugin>
                    <groupId>org.sonarsource.scanner.maven</groupId>
                    <artifactId>sonar-maven-plugin</artifactId>
                    <version>3.10.0.2594</version>
                </plugin>

                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>0.8.14</version>
                </plugin>
            </plugins>

        </pluginManagement>

    </build>

    <profiles>
        <profile>
            <id>coverage</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>default-prepare-agent</id>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                                <!-- 与surefire共用时需要重命名argLine -->
                                <configuration>
                                    <propertyName>jacocoArgLine</propertyName>
                                </configuration>
                            </execution>
                        </executions>
                        <configuration>
                            <excludes>
                                <exclude>**/_gen/**</exclude>
                                <exclude>**/_*.java</exclude>
                                <exclude>**/_*.xml</exclude>
                                <exclude>**/*Errors.*</exclude>
                                <exclude>**/*Configs.*</exclude>
                                <exclude>**/*Constants*</exclude>
                                <exclude>**/parse/antlr/**</exclude>
                            </excludes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <!-- QA Profile: spotbugs + checkstyle + PMD 本地代码质量审计,仅主动调用 -->
        <!-- 使用方式: ./mvnw checkstyle:check -Pqa  或  ./mvnw pmd:check -Pqa -->
        <profile>
            <id>qa</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-checkstyle-plugin</artifactId>
                        <version>3.6.0</version>
                        <dependencies>
                            <dependency>
                                <groupId>com.puppycrawl.tools</groupId>
                                <artifactId>checkstyle</artifactId>
                                <version>10.21.1</version>
                            </dependency>
                        </dependencies>
                        <configuration>
                            <failOnViolation>false</failOnViolation>
                            <configLocation>${maven.multiModuleProjectDirectory}/checkstyle.xml</configLocation>
                            <consoleOutput>true</consoleOutput>
                            <excludes>**/_gen/**,**/_*.java</excludes>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-pmd-plugin</artifactId>
                        <version>3.28.0</version>
                        <configuration>
                            <failOnViolation>false</failOnViolation>
                            <printFailingErrors>true</printFailingErrors>
                            <excludes>
                                <exclude>**/_gen/**</exclude>
                                <exclude>**/_*.java</exclude>
                            </excludes>
                            <rulesets>
                                <ruleset>${maven.multiModuleProjectDirectory}/pmd-ruleset.xml</ruleset>
                            </rulesets>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>com.github.spotbugs</groupId>
                        <artifactId>spotbugs-maven-plugin</artifactId>
                        <version>4.9.8.3</version>
                        <configuration>
                            <failOnError>false</failOnError>
                            <excludeFilterFile>${maven.multiModuleProjectDirectory}/spotbugs-exclude.xml</excludeFilterFile>
                            <threshold>low</threshold>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <modules>
        <module>nop-kernel</module>
        <module>nop-bom</module>
        <module>nop-tcc</module>
        <module>nop-cluster</module>
        <module>nop-wf</module>
        <module>nop-auth</module>
        <module>nop-benchmark</module>
        <module>nop-message</module>
        <module>nop-spring</module>
        <module>nop-rule</module>
        <module>nop-job</module>
        <module>nop-batch</module>
        <module>nop-task</module>
        <module>nop-autotest</module>
        <module>nop-demo</module>
        <module>nop-quarkus</module>
        <module>nop-sys</module>
        <module>nop-report</module>
        <module>nop-integration</module>
        <module>nop-stream</module>
        <module>nop-file</module>
        <module>nop-datav</module>
        <!-- <module>tests</module> -->
        <module>nop-dyn</module>
        <module>nop-ai</module>
        <module>nop-search</module>
        <module>nop-persistence</module>
        <module>nop-dev-tools</module>
        <module>nop-format</module>
        <module>nop-utils</module>
        <module>nop-network</module>
        <module>nop-frontend-support</module>
        <module>nop-core-framework</module>
        <module>nop-migration</module>
        <module>nop-runner</module>
        <module>nop-service-framework</module>
        <module>nop-retry</module>
        <module>nop-code</module>
        <!--        <module>nop-commons-java21</module>-->
    </modules>
</project>