From 9e4f29d70b107c8fd9326a1610a0203fd96bc769 Mon Sep 17 00:00:00 2001 From: lick <2188718831@qq.com> Date: Thu, 19 Nov 2026 04:42:26 -0800 Subject: [PATCH] =?UTF-8?q?feat(maven):=20=E6=A8=A1=E5=9E=8B=E6=8A=A5?= =?UTF-8?q?=E5=91=8A=20Settings=20File=20=E4=B8=8E=20Local=20Repository=20?= =?UTF-8?q?=E7=9A=84=E5=AE=9E=E9=99=85=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 扩展在 litheBuildModel 的 optionDefaults 中报告不传参数时 Maven 实际使用的 用户设置文件(~/.m2/settings.xml)和本地仓库(本次读取的设置中的 ,没有时为 ~/.m2/repository),对应 IntelliJ IDEA Maven 设置里 PathOverrider 灰显的默认值。宿主据此显示“覆盖”复选框;旧宿主忽略 这两项,所以清单不变、兼容所有已发布的桌面版本。 Refs 1lck/Lithe-IDEA#2152 Co-Authored-By: Claude Opus 5.5 --- docs/feature-matrix.md | 2 ++ .../github/litheidea/maven/ModelExport.java | 33 +++++++++++++++++-- scripts/test.mjs | 25 +++++++++++--- 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/docs/feature-matrix.md b/docs/feature-matrix.md index fe53589..f2451f9 100644 --- a/docs/feature-matrix.md +++ b/docs/feature-matrix.md @@ -100,6 +100,8 @@ Local Repository、Offline、Skip Tests,按工作区保存,加到构建、 **依赖的宿主能力**:`settings`(插件设置页和 `reload` 生效方式)、`settingRegions`(设置侧栏搜索关键词定位)、`buildSystems` 的构建选项和可执行文件候选顺序。 +**实际值**:模型的 `optionDefaults` 报告 Settings File 和 Local Repository 在不传参数时 Maven 实际使用的值(用户设置文件为 `~/.m2/settings.xml`;本地仓库取本次读取的设置中的 ``,没有时为 `~/.m2/repository`)。宿主(Core `Lithe-core-rust#120`、`#121` 及以后、桌面 [1lck/Lithe-IDEA#2210](https://github.com/1lck/Lithe-IDEA/pull/2210))据此显示 IDEA 式的“覆盖”复选框;旧宿主忽略这两项。2026-11-19 `scripts/test.mjs` 的 `the model reports the settings file and local repository Maven uses` 通过(macOS arm64)。 + **最近验证**:2026-11-18,`plugin.json` 与 `l10n/zh-Hans.json` 经 Core `9dea6aa6eaaf830c3568b647aa7daae5018b9727` schema 与 `plugins.settings.catalog` / `plugins.declarative.settingsState` 校验,`scripts/test.mjs` 断言全部通过,并在宿主 Viva 无头设置窗口验证中文分组名与关键词检索。2026-11-14,macOS arm64,插件 0.0.1 发布包,宿主 `059d878d4`,`node scripts/e2e-host.mjs`:`TestOfficialMavenPluginBuildsAReactor` 设置 Maven executable 为一个包装脚本后,确认模型重新读取和 `compile` 都运行了它。六个构建选项、按工作区保存和 `mvnw` / `MAVEN_HOME` 的候选顺序没有自动化覆盖。 **验证方法**(macOS): diff --git a/extension/src/main/java/io/github/litheidea/maven/ModelExport.java b/extension/src/main/java/io/github/litheidea/maven/ModelExport.java index 6b047d3..d1ec81d 100644 --- a/extension/src/main/java/io/github/litheidea/maven/ModelExport.java +++ b/extension/src/main/java/io/github/litheidea/maven/ModelExport.java @@ -128,11 +128,12 @@ Map document() { document.put("tasks", tasks); document.put("contentRoots", contentRoots); document.put("optionValues", optionValues); + Map optionDefaults = new LinkedHashMap<>(); if (!defaultProfiles.isEmpty()) { - Map optionDefaults = new LinkedHashMap<>(); optionDefaults.put("profiles", new ArrayList<>(defaultProfiles)); - document.put("optionDefaults", optionDefaults); } + pathDefaults(optionDefaults); + document.put("optionDefaults", optionDefaults); document.put("optionExcludePrefixes", optionExcludePrefixes); document.put("optionActiveChoices", Collections.singletonMap("profiles", new ArrayList<>(activeProfileIds(profiles)))); @@ -433,6 +434,34 @@ private Settings effectiveSettings(Properties userProperties) { } } + /** + * What Maven uses for the Settings File and Local Repository options when + * Lithe passes neither, which Lithe shows greyed until the user checks + * Override, as IntelliJ IDEA's Maven settings do + * ({@code MavenUtil.resolveUserSettingsPath} and + * {@code resolveLocalRepository}): the user settings file is + * {@code ~/.m2/settings.xml}, and the local repository is the one the + * settings this run read name (the user settings file, then the global + * one), else {@code ~/.m2/repository}. The settings read are the + * overridden file when the user set one, so the repository follows it + * as in IDEA. Hosts without this support ignore both entries. + */ + private void pathDefaults(Map optionDefaults) { + File m2 = new File(System.getProperty("user.home"), ".m2"); + optionDefaults.put("settingsFile", + Collections.singletonList(new File(m2, "settings.xml").getAbsolutePath())); + String repository = null; + Settings settings = effectiveSettings(cleanUserProperties()); + if (settings != null && settings.getLocalRepository() != null + && !settings.getLocalRepository().trim().isEmpty()) { + repository = new File(settings.getLocalRepository().trim()).getAbsolutePath(); + } + if (repository == null) { + repository = new File(m2, "repository").getAbsolutePath(); + } + optionDefaults.put("localRepository", Collections.singletonList(repository)); + } + private Properties cleanUserProperties() { Properties cleaned = new Properties(); if (session.getUserProperties() == null) { diff --git a/scripts/test.mjs b/scripts/test.mjs index 5f43ae0..ef39e8f 100644 --- a/scripts/test.mjs +++ b/scripts/test.mjs @@ -24,7 +24,7 @@ import { createReport } from "./report.mjs"; import { BackendClient } from "./compiler/backend-client.mjs"; import { execFileSync } from "node:child_process"; import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs"; -import { tmpdir } from "node:os"; +import { homedir, tmpdir } from "node:os"; import { delimiter, join, resolve } from "node:path"; const PACKAGE_DIR = "io.github.lithe-idea.maven-build"; @@ -241,7 +241,7 @@ async function test(signal) { await check("profiles become choices of the Profiles option", () => { assert.deepEqual(model.optionValues.profiles, ["ci", "release"]); - assert.equal(model.optionDefaults, undefined); + assert.equal(model.optionDefaults.profiles, undefined); assert.deepEqual(model.optionActiveChoices, { profiles: [] }); assert.deepEqual(model.optionExcludePrefixes, { profiles: "-" }); }); @@ -301,18 +301,18 @@ async function test(signal) { } const initial = await readProfileModel("default", ""); assert.deepEqual(initial.optionValues.profiles, ["dev", "prod"]); - assert.deepEqual(initial.optionDefaults, { profiles: ["dev"] }); + assert.deepEqual(initial.optionDefaults.profiles, ["dev"]); assert.deepEqual(initial.optionActiveChoices, { profiles: ["dev"] }); assert.deepEqual(initial.optionExcludePrefixes, { profiles: "-" }); assert.deepEqual(initial.projects.map((project) => project.name), ["profiles-reactor", "dev-module"]); const switched = await readProfileModel("switched", "-dev,prod"); - assert.deepEqual(switched.optionDefaults, { profiles: ["dev"] }); + assert.deepEqual(switched.optionDefaults.profiles, ["dev"]); assert.deepEqual(switched.optionActiveChoices, { profiles: ["prod"] }); assert.deepEqual(switched.projects.map((project) => project.name), ["profiles-reactor", "prod-module"]); const cleared = await readProfileModel("cleared", "-dev"); - assert.deepEqual(cleared.optionDefaults, { profiles: ["dev"] }); + assert.deepEqual(cleared.optionDefaults.profiles, ["dev"]); assert.deepEqual(cleared.optionActiveChoices, { profiles: [] }); assert.deepEqual(cleared.projects.map((project) => project.name), ["profiles-reactor"]); @@ -324,6 +324,21 @@ async function test(signal) { ["profiles-reactor", "dev-module", "prod-module"]); }); + await check("the model reports the settings file and local repository Maven uses", async () => { + // Shown greyed until Override, as IDEA's Maven settings: the user settings file is always + // ~/.m2/settings.xml, and the repository is the one the settings read name, else ~/.m2/repository. + const m2 = join(homedir(), ".m2"); + const plain = await readProfileModel("paths-default", ""); + assert.deepEqual(plain.optionDefaults.settingsFile, [join(m2, "settings.xml")]); + assert.deepEqual(plain.optionDefaults.localRepository, [join(m2, "repository")]); + const repository = join(scratch, "settings-repository"); + const settings = join(scratch, "paths-settings.xml"); + writeFileSync(settings, `${repository}`); + const named = await readProfileModel("paths-settings", "", settings); + assert.deepEqual(named.optionDefaults.settingsFile, [join(m2, "settings.xml")]); + assert.deepEqual(named.optionDefaults.localRepository, [repository]); + }); + await check("packaging activation is reflected in baseline defaults and can be disabled", async () => { const pom = join(profileRoot, "pom.xml"); const original = readFileSync(pom, "utf8");