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

    <parent>
        <groupId>cloud.opencode.base</groupId>
        <artifactId>opencode-base-parent</artifactId>
        <version>1.0.4</version>
    </parent>

    <artifactId>opencode-base-classloader</artifactId>
    <name>OpenCode Base ClassLoader</name>
    <description>ClassLoader component for class loading, scanning, resource management and metadata reading for JDK 25+</description>

    <dependencies>
        <!-- 内部依赖 -->
        <dependency>
            <groupId>cloud.opencode.base</groupId>
            <artifactId>opencode-base-core</artifactId>
        </dependency>

        <!-- 测试依赖 -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <properties>
        <!-- LeakCleaner 测试需要访问 java.lang 内部（ThreadLocal/ShutdownHooks 反射清理） -->
        <!-- JaCoCo agent 在模块路径上无法 instrument，需降回类路径运行测试 -->
        <surefire.useModulePath>false</surefire.useModulePath>
    </properties>

    <build>
        <plugins>
            <!-- LeakCleaner 需要 add-opens java.base/java.lang（ThreadLocal/ShutdownHooks 反射） -->
            <!-- JaCoCo on-the-fly instrumentation 不兼容 JPMS 模块路径，需关闭 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <useModulePath>false</useModulePath>
                    <argLine>@{argLine} --enable-native-access=ALL-UNNAMED --sun-misc-unsafe-memory-access=allow -XX:+EnableDynamicAgentLoading --add-opens java.base/java.lang=ALL-UNNAMED</argLine>
                </configuration>
            </plugin>
            <!-- 覆盖率阈值临时降低，后续逐步提升至 80% / Coverage threshold temporarily lowered -->
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>check</id>
                        <goals><goal>check</goal></goals>
                        <configuration>
                            <rules>
                                <rule>
                                    <element>BUNDLE</element>
                                    <limits>
                                        <limit>
                                            <counter>INSTRUCTION</counter>
                                            <value>COVEREDRATIO</value>
                                            <minimum>0.75</minimum>
                                        </limit>
                                    </limits>
                                </rule>
                                <!-- 安全包要求更高覆盖率 / Higher threshold for security package -->
                                <rule>
                                    <element>PACKAGE</element>
                                    <includes>
                                        <include>cloud.opencode.base.classloader.security</include>
                                    </includes>
                                    <limits>
                                        <limit>
                                            <counter>INSTRUCTION</counter>
                                            <value>COVEREDRATIO</value>
                                            <minimum>0.85</minimum>
                                        </limit>
                                    </limits>
                                </rule>
                                <!-- 泄漏包包含反射清理代码，部分路径受模块系统限制无法在测试中覆盖 -->
                                <rule>
                                    <element>PACKAGE</element>
                                    <includes>
                                        <include>cloud.opencode.base.classloader.leak</include>
                                    </includes>
                                    <limits>
                                        <limit>
                                            <counter>INSTRUCTION</counter>
                                            <value>COVEREDRATIO</value>
                                            <minimum>0.75</minimum>
                                        </limit>
                                    </limits>
                                </rule>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
