将 "Add Java" 的行为更改为选择一个目录后, 在目录中递归搜索并添加所有 Java - #3494
Closed
ri-fumo wants to merge 16 commits into
Closed
Conversation
ri-fumo
force-pushed
the
add-java-by-search
branch
from
December 15, 2024 10:51
cea4e8b to
984761a
Compare
ri-fumo
force-pushed
the
add-java-by-search
branch
from
December 15, 2024 10:59
984761a to
cd9fe39
Compare
Member
|
新的代码请尽量使用 java.nio.Path 替换 java.io.File。 |
Member
|
我不是特别喜欢递归搜索,感觉改成支持多选就可以了 |
Member
|
递归搜索可以让玩家一次添加多个 Java / 不需要准确选中 java 可执行文件 |
Author
|
我刚刚发现 idea 添加 sdk 页面也是单个添加,但是选中的是 JavaHome 目录。 我参考的是我之前用的 eclipse,其中的 jre 是可以递归搜索来添加的,也可以选中单个 JavaHome 来添加。 |
Glavo
requested changes
Nov 3, 2025
| return new Task<List<JavaRuntime>>() { | ||
|
|
||
| private final Path dir = directory; | ||
| { setName("Search Java"); } |
Member
There was a problem hiding this comment.
要用 taskDialog 显示出来的 Task 请在 TaskListPane 中对名称实现本地化,而不是这样 setName。
| setResult(searchJava()); | ||
| } | ||
|
|
||
| private List<JavaRuntime> searchJava() throws IOException, InterruptedException { |
Member
There was a problem hiding this comment.
为什么不用 Files.walkFileTree 来遍历,或者直接递归实现?
| if (dir == null) return; | ||
|
|
||
| var file = dir.resolve(OperatingSystem.CURRENT_OS.getJavaExecutable()); | ||
| file = Files.exists(file) ? file |
|
|
||
| private void onSearchAndAddJavaBinary(Path directory) { | ||
| Controllers.taskDialog( | ||
| JavaManager.getSearchAndAddJavaTask(directory).thenAcceptAsync(Schedulers.javafx(), javaRuntimes -> { |
Member
There was a problem hiding this comment.
请用 whenComplete(Executor, FinalizedCallbackWithResult<T>) 来处理结果。
而且你这个 getSearchAndAddJavaTask 设计的过于诡异了。
“任务失败,但还是执行了有副作用的操作”这种事是需要避免的。如果一个任务可以部分成功部分失败,那么请将这种信息写到返回值里,而不是抛异常来解决。
| }).whenComplete(Schedulers.javafx(), exception -> { | ||
| if (exception instanceof UnsupportedPlatformException) { | ||
| LOG.warning("Failed to add java", exception); | ||
| Controllers.dialog(i18n("java.add.failed.some"), i18n("message.error"), MessageDialogPane.MessageType.ERROR); |
Member
There was a problem hiding this comment.
- 任务部分失败应当是 warning,而不是 error;
- 这样汇报错误过于粗糙,没有区分任务究竟是部分失败还是全部失败,也没有给出哪些 Java 添加失败了这样的信息。
- 我觉得只有在全部失败的情况下才有必要弹窗汇报给用户,部分成功的情况下不弹窗提示也是可以的。像这样弹一个非常粗糙的报错完全没有必要。
Member
|
我先关闭了吧。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#3492
如果选择的是某个 Java Home 或 bin 目录, 则认为选择了单个 Java
目录搜索递归层数限制为3层
由于增加按钮会导致过于拥挤, 所以直接更改了 "Add Java" 的行为
另外, i18n 中俄语 西班牙语 日语的翻译可能有误, 需要校正