Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Conditional Metadata instead of Standard Metadata #567

Merged
merged 3 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
cache: 'maven'
- name: Build Spring Boot Starter 3 test with Maven
run: |
./mvnw -am -pl dynamic-datasource-spring-boot3-starter -PnativeTestInSpringBoot -T1C -B clean test
./mvnw -am -pl dynamic-datasource-spring-boot3-starter -PnativeTestInSpringBoot -T1C -B -e clean test
test-hotspot-jdk-ci:
name: Test CI - JDK ${{ matrix.java-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand All @@ -63,7 +63,7 @@ jobs:
cache: 'maven'
- name: Build test with Maven
run: |
./mvnw -T1C -B clean test
./mvnw -T1C -B -e clean test
test-minimum-jdk-ci:
name: Test CI - JDK ${{ matrix.java-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand All @@ -82,7 +82,7 @@ jobs:
cache: 'maven'
- name: Build test with Maven
run: |
./mvnw -am -pl dynamic-datasource-creator -T1C -B clean test
./mvnw -am -pl dynamic-datasource-spring -T1C -B clean test
./mvnw -am -pl dynamic-datasource-spring-boot-common -T1C -B clean test
./mvnw -am -pl dynamic-datasource-spring-boot-starter -T1C -B clean test
./mvnw -am -pl dynamic-datasource-creator -T1C -B -e clean test
./mvnw -am -pl dynamic-datasource-spring -T1C -B -e clean test
./mvnw -am -pl dynamic-datasource-spring-boot-common -T1C -B -e clean test
./mvnw -am -pl dynamic-datasource-spring-boot-starter -T1C -B -e clean test
6 changes: 3 additions & 3 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
# 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.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.3/apache-maven-3.9.3-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.4/apache-maven-3.9.4-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
35 changes: 29 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ cd ./dynamic-datasource/
./mvnw -am -pl dynamic-datasource-spring-boot3-starter -PnativeTestInSpringBoot -T1C -B clean test
```

贡献者在提交 PR 后,位于 Github Actions 的 CI 将进行此验证。如果 nativeTest 执行失败,请跳转到[本文的 2.2一节](./CONTRIBUTING.md)。
贡献者在提交 PR 后,位于 Github Actions 的 CI 将进行此验证。如果 nativeTest 执行失败,请跳转到[本文的 2.2 一节](./CONTRIBUTING.md)。

当贡献者发现缺少与 `dynamic-datasource` 无关的第三方库的 GraalVM Reachability Metadata 时,应当在
https://github.com/oracle/graalvm-reachability-metadata 打开新的 issue, 并提交包含依赖的第三方库缺失的 GraalVM Reachability
Expand All @@ -59,20 +59,43 @@ Metadata 的 PR。
## 2.2 Generate or merge GraalVM Reachability Metadata for unit tests

如果 nativeTest 执行失败, 应为单元测试生成初步的 GraalVM Reachability Metadata,并手动调整以修复 nativeTest。
如有需要,请使用 `org.junit.jupiter.api.condition.DisabledInNativeImage` 注解屏蔽部分单元测试。
如有需要,请使用 `org.junit.jupiter.api.condition.DisabledInNativeImage` 注解或 `org.graalvm.nativeimage.imagecode` 的
System Property 屏蔽部分单元测试在 GraalVM Native Image 下运行。

请不要为 SpEL 功能编写可能的 nativeTest,参考 https://github.com/spring-projects/spring-framework/issues/29548 。如有需要,
请使用 `org.graalvm.nativeimage.imagecode` 的 System Property 屏蔽相关测试在 GraalVM Native Image 下运行。
请不要为 SpEL 功能编写可能的 nativeTest,参考尚未关闭的 https://github.com/spring-projects/spring-framework/issues/29548 。

项目定义了 `generateMetadata` 的 Maven Profile 用于在普通 JVM 下携带 GraalVM Tracing Agent 执行单元测试,并在特定目录下生成或合并
已有的 GraalVM Reachability Metadata 文件。可通过如下 bash 命令简单处理此流程。贡献者仍可能需要手动调整具体的 JSON 条目,并在适当的时候
调整 Maven Profile 和 GraalVM Tracing Agent 的 Filter 链。

以下命令仅为 `dynamic-datasource-spring-boot3-starter` 生成 Conditioanl 形态的 GraalVM Reachability Metadata 的一个举例。
在 https://github.com/graalvm/native-build-tools/issues/500 关闭之前,你都需要手动调整 `native-image-configure` 的 `input-dir`
为 `./mvnw -PgenerateMetadata -DskipNativeTests -e clean test` 真实的输出目录。

对于测试类和测试文件独立使用的 GraalVM Reachability Metadata,贡献者应该放置到相关子模块对应的
`${project.basedir}/src/test/resources/META-INF/native-image/${project.artifactId}-test-metadata/` 文件夹下。`${}` 内为
POM 4.0 的常规系统变量,自行替换。

```bash
./mvnw -T1C -B -PgenerateMetadata -DskipNativeTests clean test
./mvnw -am -pl dynamic-datasource-spring-boot3-starter -PnativeTestInSpringBoot -T1C -B clean test
git clone git@github.com:baomidou/dynamic-datasource.git

cd ./dynamic-datasource/

./mvnw -PgenerateMetadata -DskipNativeTests -e clean test

mkdir -p "./dynamic-datasource-spring-boot3-starter/src/test/resources/META-INF/native-image/com.baomidou/dynamic-datasource-spring-boot3-starter/"

native-image-configure generate-conditional\
--user-code-filter="./native-image/user-code-filter.json"\
--class-name-filter="./native-image/extra-filter.json"\
--input-dir="./dynamic-datasource-spring-boot3-starter/target/native/agent-output/test/session-45270-20230907T013541Z/"\
--output-dir="./dynamic-datasource-spring-boot3-starter/src/main/resources/META-INF/native-image/com.baomidou/dynamic-datasource-spring-boot3-starter/"

./mvnw -am -pl dynamic-datasource-spring-boot3-starter -PnativeTestInSpringBoot -T1C -B -e clean test
```

请手动删除无任何具体条目的 JSON 文件。

# 3. PR

PR 应提交到位于 Github 的 Git Mirror,即 https://github.com/baomidou/dynamic-datasource 。
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[
{
"condition":{"typeReachable":"com.baomidou.dynamic.datasource.provider.AbstractJdbcDataSourceProvider"},
"name":"[Lcom.sun.management.internal.DiagnosticCommandArgumentInfo;"
},
{
"condition":{"typeReachable":"com.baomidou.dynamic.datasource.provider.AbstractJdbcDataSourceProvider"},
"name":"[Lcom.sun.management.internal.DiagnosticCommandInfo;"
},
{
"condition":{"typeReachable":"com.baomidou.dynamic.datasource.provider.AbstractJdbcDataSourceProvider"},
"name":"java.util.Arrays",
"methods":[{"name":"asList","parameterTypes":["java.lang.Object[]"] }]
}
]
Loading