[Bugfix] 使用 tomlj 代替 toml4j 以适配 TOML 标准#5863
Conversation
|
toml4j 和 tomlj 最后一次 commit 均在两年以前,不应使用一个无人维护的库替代另一个无人维护的库 |
看了一眼 gradle 读取 toml 的库,用的就是这个,甚至是这玩意的老版本。这证明 tomlj 是得到了认可的。 同时,toml4j 的最后一个 release 是在 2016,而 tomlj 在 2024,差了八年;前者只支持 toml 0.4.0,而后者支持 1.0.0。个人认为这些使得这两个库对于 HMCL 的意义有本质区别。 |
|
哦我知道了,https://github.com/mwanji/toml4j TOML4j 自 2017 年以来的维护都不涉及代码变更,被他骗了…… |
# Conflicts: # HMCL/src/main/resources/assets/about/deps.json # HMCLCore/src/main/java/org/jackhuang/hmcl/mod/modinfo/ForgeNewModMetadata.java # gradle/libs.versions.toml
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request replaces the toml4j library with tomlj. Key changes include updating dependency configurations in libs.versions.toml and build.gradle.kts, adding license information to deps.json, and refactoring ForgeNewModMetadata.java to use the tomlj API. The refactoring improves error handling during TOML parsing and updates the metadata extraction logic. A review comment suggests extracting repeated logic for converting TomlArray objects into dependency lists into a private helper method to improve code maintainability.
| private static ModLoaderType analyzeLoader(TomlParseResult toml, String modID, ModLoaderType loader) { | ||
| List<Map<String, Object>> dependencies = null; | ||
| try { | ||
| dependencies = toml.getList("dependencies." + modID); | ||
| TomlArray tomlArray = toml.getArray("dependencies." + modID); | ||
| if (tomlArray != null) { | ||
| dependencies = tomlArray.toList().stream().map( o -> ((TomlTable) o).toMap()).toList(); | ||
| } | ||
| } catch (ClassCastException ignored) { // https://github.com/HMCL-dev/HMCL/issues/5068 | ||
| } | ||
|
|
||
| if (dependencies == null) { | ||
| try { | ||
| dependencies = toml.getList("dependencies"); // ??? I have no idea why some of the Forge mods use [[dependencies]] | ||
| TomlArray tomlArray = toml.getArray("dependencies"); // ??? I have no idea why some of the Forge mods use [[dependencies]] | ||
| if (tomlArray != null) { | ||
| dependencies = tomlArray.toList().stream().map( o -> ((TomlTable) o).toMap()).toList(); | ||
| } | ||
| } catch (ClassCastException e) { | ||
| try { | ||
| Toml table = toml.getTable("dependencies"); | ||
| TomlTable table = toml.getTable("dependencies"); | ||
| if (table == null) | ||
| return loader; | ||
|
|
||
| dependencies = table.getList(modID); | ||
| TomlArray tomlArray = table.getArray(modID); | ||
| if (tomlArray != null) { | ||
| dependencies = tomlArray.toList().stream().map( o -> ((TomlTable) o).toMap()).toList(); | ||
| } | ||
| } catch (Throwable ignored) { | ||
| } | ||
| } |
There was a problem hiding this comment.
Resolves #5544
https://github.com/tomlj/tomlj