Skip to content

搜索 Java 时缓存 Java 信息#4716

Merged
Glavo merged 24 commits intoHMCL-dev:mainfrom
Glavo:java-cache
Apr 4, 2026
Merged

搜索 Java 时缓存 Java 信息#4716
Glavo merged 24 commits intoHMCL-dev:mainfrom
Glavo:java-cache

Conversation

@Glavo
Copy link
Copy Markdown
Member

@Glavo Glavo commented Oct 25, 2025

之前我们依靠读取 release 文件加速读取 Java 信息。但是 release 文件包含的信息较少,而且我们无法从 release 文件中得知该 Java 是否能正常工作,所以可能会造成游戏无法启动的问题。

本 PR 调整了读取 Java 信息的机制,现在 HMCL 总是通过运行 Java 来获取信息。为了降低开销,我们现在使用一个缓存文件来缓存读取到的 Java 信息。

Copilot AI review requested due to automatic review settings October 25, 2025 08:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors Java detection and information retrieval to improve reliability by always running Java executables to obtain version information, rather than relying on potentially incomplete release files. To minimize performance overhead, a caching mechanism is introduced that stores Java information in a cache file (javaCache.json).

Key changes:

  • Introduced caching system for Java information with version-aware cache file management
  • Refactored Java search logic into a dedicated Searcher class
  • Modified JavaRepository interface to return Collection<Path> instead of Collection<JavaRuntime>

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
HMCLCore/src/main/java/org/jackhuang/hmcl/java/JavaRepository.java Changed return type of getAllJava() from Collection<JavaRuntime> to Collection<Path>
HMCLCore/src/main/java/org/jackhuang/hmcl/java/JavaInfo.java Added Builder pattern, removed release file parsing, modernized vendor normalization switch statement
HMCL/src/main/java/org/jackhuang/hmcl/java/JavaManager.java Implemented cache-based Java search with dedicated Searcher class, added cache key generation and validation logic
HMCL/src/main/java/org/jackhuang/hmcl/java/JavaInfoUtils.java Removed release file parsing, simplified to always execute Java for information retrieval
HMCL/src/main/java/org/jackhuang/hmcl/java/HMCLJavaRepository.java Updated to return paths instead of runtime objects, simplified platform-specific logic

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Glavo
Copy link
Copy Markdown
Member Author

Glavo commented Apr 4, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1fe1623c9d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Glavo
Copy link
Copy Markdown
Member Author

Glavo commented Apr 4, 2026

/gemini review

@Glavo Glavo requested a review from Copilot April 4, 2026 13:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the Java runtime discovery and management logic, primarily by introducing a caching mechanism to improve performance. A new Searcher inner class in JavaManager handles the search process and persists results to javaCache.json. Additionally, the JavaInfo class was updated to use a builder pattern and switch expressions, and several internal APIs were simplified to return Path collections instead of JavaRuntime objects during the discovery phase. My feedback focuses on optimizing the cache loading and key generation logic to avoid redundant operations and potential performance bottlenecks during I/O-heavy tasks.


Path releaseFile = javaHome.resolve("release");
if (Files.exists(releaseFile)) {
releaseHash = DigestUtils.digestToString("SHA-1", releaseFile);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using DigestUtils.digestToString("SHA-1", releaseFile) to hash the entire release file every time the cache key is generated might be inefficient if there are many Java installations. While release files are generally small, reading and hashing the file content on every search adds unnecessary I/O overhead. Since you are already including the executable's size and last modified time in the cache key (lines 642-643), you could consider using only the release file's attributes (size and last modified time) instead of its full content hash to improve performance.

@Glavo Glavo merged commit 84c4943 into HMCL-dev:main Apr 4, 2026
2 checks passed
@Glavo Glavo deleted the java-cache branch April 4, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants