diff --git a/src/features/settings/languages/LanguagePages.tsx b/src/features/settings/languages/LanguagePages.tsx index f463c8daf2..cd7441657c 100644 --- a/src/features/settings/languages/LanguagePages.tsx +++ b/src/features/settings/languages/LanguagePages.tsx @@ -14,6 +14,7 @@ import { GlobListEditor, Row, Section, Select, Toggle } from "../components/Form import { choosePath } from "@/platform/choosePath"; import { usePageContext, useSetting } from "../components/context"; import { SdkField, tildify, useDetected, useJdtlsJdk } from "./components"; +import { isMavenThreadCount } from "./mavenThreads"; import styles from "./Sdk.module.css"; function PathInput({ @@ -566,6 +567,7 @@ export function MavenPage() { const [downloadSources, setDownloadSources] = useSetting("languages.java.maven.downloadSources"); const [updateSnapshots, setUpdateSnapshots] = useSetting("languages.java.maven.updateSnapshots"); const [threads, setThreads] = useSetting("languages.java.maven.threads"); + const threadsInvalid = !!threads?.trim() && !isMavenThreadCount(threads); const [activeProfiles, setActiveProfiles] = useSetting("languages.java.maven.activeProfiles"); const id = useId(); return ( @@ -651,12 +653,24 @@ export function MavenPage() { + + Not a thread count Maven accepts, so builds run serially. Use a number (4) or a core multiplier (2C, + 2.5C). + + + ) : ( + "Passed as -T to Maven builds and run configurations: a thread count (4) or a core multiplier (2C, 2.5C) for parallel builds of multi-module projects. Empty runs Maven serially." + ) + } > { + for (const ok of ["4", "1C", "2.5C", "0.5C", " 8 "]) expect(isMavenThreadCount(ok), ok).toBe(true); + for (const bad of ["0", "0C", "-2", "2c", "2.C", ".5C", "2.5.1C", "four", "4 threads", "C"]) + expect(isMavenThreadCount(bad), bad).toBe(false); +}); diff --git a/src/features/settings/languages/mavenThreads.ts b/src/features/settings/languages/mavenThreads.ts new file mode 100644 index 0000000000..0bed6da705 --- /dev/null +++ b/src/features/settings/languages/mavenThreads.ts @@ -0,0 +1,8 @@ +/** + * Whether Maven accepts `value` as `-T`: a thread count (`4`) or a core multiplier with an + * optional decimal fraction (`1C`, `2.5C`). Mirrors `MavenSettings::thread_count`, which + * leaves any other value out of the command line. + */ +export function isMavenThreadCount(value: string): boolean { + return /^(?:\d+(?:\.\d+)?)C?$/.test(value.trim()) && parseFloat(value) > 0; +} diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index e69b760b02..0c3a78f802 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -2789,5 +2789,6 @@ "Download to {folder} finished with errors": "Download to {folder} finished with errors", "Cannot download to {folder}": "Cannot download to {folder}", "Copy the selected files and folders of a remote project to a folder on this computer": "Copy the selected files and folders of a remote project to a folder on this computer", - "{modifier}+Click to only see \"{name}\"": "{modifier}+Click to only see \"{name}\"" + "{modifier}+Click to only see \"{name}\"": "{modifier}+Click to only see \"{name}\"", + "Not a thread count Maven accepts, so builds run serially. Use a number (4) or a core multiplier (2C, 2.5C).": "Not a thread count Maven accepts, so builds run serially. Use a number (4) or a core multiplier (2C, 2.5C)." } diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index 908b396641..3d700db84b 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -9152,5 +9152,6 @@ "Download to {folder} finished with errors": "下载到 {folder} 完成,但有错误", "Cannot download to {folder}": "无法下载到 {folder}", "Copy the selected files and folders of a remote project to a folder on this computer": "把远程项目中选中的文件和文件夹复制到本机的文件夹", - "{modifier}+Click to only see \"{name}\"": "{modifier}+点击仅显示“{name}”" + "{modifier}+Click to only see \"{name}\"": "{modifier}+点击仅显示“{name}”", + "Not a thread count Maven accepts, so builds run serially. Use a number (4) or a core multiplier (2C, 2.5C).": "Maven 不接受这个线程数,构建将串行执行。请填写数字(4)或核数倍数(2C、2.5C)。" }