Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,28 @@ jobs:
if-no-files-found: error
retention-days: 14

- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '17'
- uses: actions/download-artifact@v4
with:
name: maven-build-windows
path: .artifacts/profile-host-package
- name: Test Maven Profile switching in the desktop host
run: |
compatible="$(node -p '
const {requires} = require("./io.github.lithe-idea.maven-build/plugin.json");
require("./e2e/host/lithe-host.json").suites.profiles.hostBuildProviders.includes(requires.buildProviders)
')"
if [[ "$compatible" == "false" ]]; then
echo "::notice::The pinned Profile-tree host cannot install this buildProviders version. The Maven integration matrix still tests Profile activation."
exit 0
fi
version="$(node -p 'require("./io.github.lithe-idea.maven-build/plugin.json").version')"
export LITHE_TEST_MAVEN_PLUGIN_ARCHIVE="$PWD/.artifacts/profile-host-package/maven-build-$version-windows.zip"
node scripts/e2e-host.mjs --suite profiles

# The Windows archive built above, unpacked the way Lithe installs it (under
# a path with a space), runs the declared commands through mvn.cmd.
windows:
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ node scripts/verify-scripts.mjs --host-bundle /Applications/Lithe.app
打开一个真实的两模块 Spring Boot 3.5 项目(`spring-boot-starter-web`),确认运行配置下拉只列出 `ShopApplication`(服务),
用运行配置编辑器保存 JVM 参数、程序参数和环境变量,运行后检查控制台里的 Maven 构建日志和 Spring Boot 启动日志,
请求 `/hello` 确认三项设置都传到了进程;停止后确认服务不再响应、端口已释放,插件安装目录没有被写入。
- `TestOfficialMavenPluginSwitchesActiveProfilesInBuildTree`(`desktop/internal/workbench` 包):在构建树切换 Profile,
编译后检查模块产物,重开项目确认保存的选择仍然有效。
- `TestMavenPluginProjectGeneratesABuildableMavenProject`、`TestMavenPluginArchetypeRunsRealMaven`(`desktop/internal/projectgen` 包):
用清单里的两个新建项目条目生成项目。

Expand All @@ -219,14 +221,17 @@ LITHE_TEST_JAVA_PLUGIN_ARCHIVE="$PWD/.artifacts/java-plugin/Lithe-Java-Support-<
node scripts/e2e-host.mjs
```

- `LITHE_TEST_MAVEN_PLUGIN_ARCHIVE` 和 `LITHE_TEST_JAVA_PLUGIN_ARCHIVE` 都必须设置,脚本不会因为缺少插件包而跳过测试。
- 全量宿主端到端测试需要 `LITHE_TEST_MAVEN_PLUGIN_ARCHIVE` 和 `LITHE_TEST_JAVA_PLUGIN_ARCHIVE`。
运行计划用 `java` 工具启动应用,这个工具由 Java Support 插件定义,所以运行测试要装上它。
- 运行测试使用本机 `~/.m2` 和 Maven 设置,第一次运行会下载 Spring Boot 3.5 的依赖,项目需要 JDK 17 及以上。
- 新建项目测试读取 `LITHE_PLUGIN_MAVEN_DIR` 里的 `plugin.json` 和模板,默认是本仓库的 `io.github.lithe-idea.maven-build/`。
- 原型测试要从 Maven Central 下载原型插件,只在设置了 `LITHE_INTEGRATION_NETWORK=1` 和 `JAVA_HOME` 时运行,否则跳过。

脚本把固定版本的宿主(只取 `desktop/` 和 `scripts/`)检出到 `.artifacts/lithe-host`,复制 `e2e/host/desktop/` 下的测试,
再在那里运行宿主的 `scripts/desktop/desktop-go.sh test`;第一次运行会克隆并构建 Rust Core,`LITHE_CORE_RUST_DIR`
`node scripts/e2e-host.mjs --suite profiles` 只运行 Profile 用例,只需设置 `LITHE_TEST_MAVEN_PLUGIN_ARCHIVE`。
CI 在固定宿主支持插件所需的 `buildProviders` 版本时,用打包作业的插件包运行此用例。

脚本把固定版本的宿主(只取 `desktop/` 和 `scripts/`)检出到 `.artifacts/lithe-host`,
通过 Go overlay 加载本仓库的测试,再运行宿主的 `scripts/desktop/desktop-go.sh test`。第一次运行会克隆并构建 Rust Core,`LITHE_CORE_RUST_DIR`
可以指向本地的 Core 检出。`--ref <分支或 commit>` 换一个宿主版本试跑,`--run <正则>` 只跑部分测试。
测试用的是宿主内部的测试工具,升级 `lithe-host.json` 的 `revision` 时可能要同步修改测试。

Expand Down
9 changes: 6 additions & 3 deletions docs/feature-matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,17 @@ JDT 侧的项目导入归 Java Support 插件维护。
## java-maven-profiles-dependencies

**能力**:构建选项 Profiles 传 `-P <profile>`,候选值从反应堆、父 POM 和 `settings.xml` 读取,也可以手动补充;
随包 Maven 扩展用 Maven 自身的 `ProfileSelector` 计算应用 Lithe 覆盖前的默认 Profile(含 `.mvn/maven.config` 中的启用和禁用、`settings.xml`、条件激活以及 Maven 3.9 的 `packaging` 条件)写入 `optionDefaults.profiles`。当前反应堆实际激活的 Profile 由 Maven 项目模型提供,写入 `optionActiveChoices.profiles`,包括 `settings.xml` 和命令行同时激活的选项。扩展还输出 `optionExcludePrefixes.profiles = "-"`,支持在 Build 工具窗口树、构建选项和运行配置里勾选启用或以 `-<profile>` 显式取消默认激活 Profile;
依赖树显示整个反应堆或单个模块的依赖(含作用域和传递依赖),反应堆内未安装的兄弟模块也能解析。

**证据**:`plugin.json` 的 `buildSystems[0].options`(`profiles`)和 `buildSystems[0].dependencies`、`extension/`、
**证据**:`plugin.json` 的 `buildSystems[0].options`(`profiles`)和 `buildSystems[0].dependencies`、`extension/`(`ModelExport.java`)、
`scripts/test.mjs`、宿主端到端测试里 `app` 模块依赖 `core` 的检查。

**依赖的宿主能力**:`buildSystems` 的构建选项、依赖命令和 `litheDependencies` 解码。
**自动化**:`node scripts/test.mjs` 在 Maven 3.6.3 和运行器版本验证原生 Profile 语义。宿主能力版本匹配时,CI 另用 `node scripts/e2e-host.mjs --suite profiles` 验证构建树、编译和重开。

**最近验证**:2026-11-14,macOS arm64,插件 0.0.1 发布包,宿主 `059d878d4`,`node scripts/e2e-host.mjs`:`TestOfficialMavenPluginBuildsAReactor` 检查了 `app` 对反应堆兄弟模块 `core` 的依赖。Profiles 切换、作用域、传递依赖和大依赖树没有自动化覆盖。
**依赖的宿主能力**:`buildSystems` 的构建选项(含 `optionDefaults`、`optionActiveChoices`、`optionExcludePrefixes` 与 `presentation: "tree"` 勾选树节点)、依赖命令和 `litheDependencies` 解码。

**最近验证**:2026-11-18,macOS arm64,插件 1.0.0 打包产物,`node scripts/test.mjs` 验证了反应堆 `optionValues.profiles`、`optionDefaults.profiles`(`<activeByDefault>`)与 `optionExcludePrefixes.profiles = "-"` 的导出,以及通过 `-P -dev,prod` 切换激活模块和 `-P -dev` 取消全部默认 Profile 后模型按新 Profile 重读且 `optionDefaults` 保持不变。Maven 3.6.3 和 3.9.16 验证了项目配置与打包类型激活基线。Maven 3.9.16 还验证了当前激活集合随这两次切换分别变为 `["prod"]` 和 `[]`,以及 `settings.xml` 激活 `dev` 与命令行选择 `prod` 可以同时生效。固定宿主 `6f31984` 上的 `TestOfficialMavenPluginSwitchesActiveProfilesInBuildTree` 验证项目 Maven 配置的勾选、切换、编译、重开及已安装插件包内容校验;2026-11-14 宿主端到端测试 `TestOfficialMavenPluginBuildsAReactor` 检查了 `app` 对反应堆兄弟模块 `core` 的依赖。完整原生 UI 手工验收与大依赖树仍待执行。

**验证方法**(macOS):

Expand Down
109 changes: 108 additions & 1 deletion e2e/host/desktop/internal/workbench/official_maven_plugin_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"time"

"github.com/1lck/Lithe-IDEA/desktop/internal/core"
"github.com/1lck/Lithe-IDEA/desktop/internal/i18n"
"github.com/1lck/Lithe-IDEA/desktop/internal/plugininstall"
"github.com/1lck/Lithe-IDEA/desktop/internal/pluginservice"
"github.com/1lck/Lithe-IDEA/desktop/internal/pluginsettings"
Expand Down Expand Up @@ -174,7 +175,7 @@ func runBuildTaskToEnd(t *testing.T, h *harness, p *project, projectID, taskID s
}
awaitStateWithin(t, h, limit, "the "+taskID+" task", func() bool { return p.build.operation == nil })
output := op.session.output.all()
if p.build.status != h.app.text.Build.Succeeded {
if op.session.outcome != runSucceeded {
t.Fatalf("%s did not succeed: status=%q output=%q", taskID, p.build.status, output)
}
return output
Expand Down Expand Up @@ -332,3 +333,109 @@ func TestOfficialMavenPluginBuildsAReactor(t *testing.T) {
h.settle()
assertPackageUnchanged(t, installed, before)
}

// TestOfficialMavenPluginSwitchesActiveProfilesInBuildTree installs the Maven Build archive,
// verifies a Profile enabled by .mvn/maven.config appears checked in the Build tool window,
// toggles from dev to prod through the real checkbox UI, and checks that model reload,
// compile and project reopen all honor -P -dev,prod.
func TestOfficialMavenPluginSwitchesActiveProfilesInBuildTree(t *testing.T) {
archive := os.Getenv("LITHE_TEST_MAVEN_PLUGIN_ARCHIVE")
if archive == "" {
t.Skip("set LITHE_TEST_MAVEN_PLUGIN_ARCHIVE to a maven-build-<version>-darwin.zip")
}
if _, err := exec.LookPath("mvn"); err != nil {
t.Fatalf("mvn is not on PATH: %v", err)
}
h := newHarness(t, &testKernel{Client: core.NewClient()})
installed := installOfficialPluginArchive(t, h, archive, "io.github.lithe-idea.maven-build")
before := packageDigest(t, installed)
root := t.TempDir()
modulePom := func(name string) string {
return "<project xmlns=\"http://maven.apache.org/POM/4.0.0\">\n <modelVersion>4.0.0</modelVersion>\n" +
" <parent><groupId>demo</groupId><artifactId>reactor</artifactId><version>1.0.0-SNAPSHOT</version></parent>\n" +
" <artifactId>" + name + "</artifactId>\n</project>\n"
}
writePluginFixture(t, root, map[string]string{
"pom.xml": "<project xmlns=\"http://maven.apache.org/POM/4.0.0\">\n <modelVersion>4.0.0</modelVersion>\n" +
" <groupId>demo</groupId><artifactId>reactor</artifactId><version>1.0.0-SNAPSHOT</version><packaging>pom</packaging>\n" +
" <properties><maven.compiler.release>11</maven.compiler.release><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties>\n" +
" <profiles>\n" +
" <profile><id>dev</id><modules><module>dev-mod</module></modules></profile>\n" +
" <profile><id>prod</id><modules><module>prod-mod</module></modules></profile>\n" +
" </profiles>\n</project>\n",
".mvn/maven.config": "-Pdev\n",
"dev-mod/pom.xml": modulePom("dev-mod"),
"dev-mod/src/main/java/demo/dev/DevOnly.java": "package demo.dev;\npublic final class DevOnly {}\n",
"prod-mod/pom.xml": modulePom("prod-mod"),
"prod-mod/src/main/java/demo/prod/ProdOk.java": "package demo.prod;\npublic final class ProdOk {}\n",
})
h.open(root)
p := h.app.project
if p == nil {
t.Fatal("the reactor did not open")
}
h.app.reduceChrome(core.ToggleChrome(itemBuild))
instance := awaitBuildModel(t, h, p, "maven", 3*time.Minute)
if modelProjectNamed(instance.Model, "dev-mod") == nil || modelProjectNamed(instance.Model, "prod-mod") != nil {
t.Fatalf("initial projects = %+v, want the project config to activate dev-mod", instance.Model.Projects)
}

awaitStateWithin(t, h, 30*time.Second, "the Build tree layout", func() bool {
return p.build.instances[0].trees.whole != nil && !p.build.instances[0].trees.wholeOut
})
h.settle()
h.click(center(h.labelBounds("Profiles")))
h.settle()

language := h.app.language()
toggle := func(choice string) {
t.Helper()
awaitStateWithin(t, h, 30*time.Second, "tree ready before toggling "+choice, func() bool {
return !p.build.optionSaving && !p.build.loading && len(p.build.instances) == 1 &&
p.build.instances[0].modelLoaded && !p.build.instances[0].trees.wholeOut
})
h.settle()
label := i18n.SharedFormat(language, "desktop.build.toggleOptionChoice", map[string]string{
"option": "Profiles",
"choice": choice,
})
h.clickNamed(label)
awaitStateWithin(t, h, 3*time.Minute, "reload after toggling "+choice, func() bool {
return !p.build.optionSaving && p.build.loaded && !p.build.loading && !p.build.reloadPending &&
len(p.build.instances) == 1 && p.build.instances[0].modelLoaded && !p.build.instances[0].modelLoading
})
}

toggle("prod")
toggle("dev")
instance = &p.build.instances[0]
if modelProjectNamed(instance.Model, "prod-mod") == nil || modelProjectNamed(instance.Model, "dev-mod") != nil {
t.Fatalf("projects after switching to prod = %+v, want prod-mod only", instance.Model.Projects)
}

output := runBuildTaskToEnd(t, h, p, "", "compile", 5*time.Minute)
if !strings.Contains(output, "BUILD SUCCESS") {
t.Fatalf("mvn compile printed no success: %q", output)
}
if _, err := os.Stat(filepath.Join(root, "prod-mod/target/classes/demo/prod/ProdOk.class")); err != nil {
t.Fatalf("prod-mod did not compile: %v", err)
}
if _, err := os.Stat(filepath.Join(root, "dev-mod/target/classes/demo/dev/DevOnly.class")); !os.IsNotExist(err) {
t.Fatalf("inactive dev-mod was compiled: %v", err)
}

// Reopening the workspace keeps -P -dev,prod on cold start before decodeModel runs.
h.app.closeProject()
awaitStateWithin(t, h, 30*time.Second, "the closed project", func() bool { return h.app.project == nil })
h.open(root)
p = h.app.project
h.app.loadBuildSystems(p)
reopened := awaitBuildModel(t, h, p, "maven", 3*time.Minute)
if modelProjectNamed(reopened.Model, "prod-mod") == nil || modelProjectNamed(reopened.Model, "dev-mod") != nil {
t.Fatalf("projects after reopen = %+v, want prod-mod only", reopened.Model.Projects)
}
h.app.closeProject()
awaitStateWithin(t, h, 30*time.Second, "the closed project", func() bool { return h.app.project == nil })
h.settle()
assertPackageUnchanged(t, installed, before)
}
13 changes: 11 additions & 2 deletions e2e/host/lithe-host.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
{
"repository": "https://github.com/1lck/Lithe-IDEA.git",
"revision": "1ce4085e7012a8b9e887c5bab734ef3fd561a7f8",
"revision": "6f319840219a5788ca897ec01a378184efea3471",
"packages": {
"./internal/workbench": "^TestOfficialMavenPlugin(BuildsAReactor|RunsASpringBootApplication|DebugsASpringBootApplication)$",
"./internal/workbench": "^TestOfficialMavenPlugin(BuildsAReactor|RunsASpringBootApplication|DebugsASpringBootApplication|SwitchesActiveProfilesInBuildTree)$",
"./internal/projectgen": "^TestMavenPlugin"
},
"suites": {
"profiles": {
"hostBuildProviders": [0],
"packages": {
"./internal/workbench": "^TestOfficialMavenPluginSwitchesActiveProfilesInBuildTree$"
},
"requiredEnvironment": ["LITHE_TEST_MAVEN_PLUGIN_ARCHIVE"]
}
},
"requiredEnvironment": {
"LITHE_TEST_MAVEN_PLUGIN_ARCHIVE": "maven-build-<version>-darwin.zip to install, for example dist/maven-build-0.0.1-darwin.zip",
"LITHE_PLUGIN_MAVEN_DIR": "directory holding the plugin.json and templates; defaults to this repository's",
Expand Down
6 changes: 6 additions & 0 deletions extension/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-embedder</artifactId>
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
import org.apache.maven.AbstractMavenLifecycleParticipant;
import org.apache.maven.MavenExecutionException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.profile.ProfileSelector;
import org.apache.maven.plugin.MavenPluginManager;
import org.apache.maven.plugin.version.PluginVersionResolver;
import org.apache.maven.project.ProjectDependenciesResolver;
import org.apache.maven.rtinfo.RuntimeInformation;
import org.apache.maven.settings.building.SettingsBuilder;

/**
* Writes what Lithe asked for once Maven has read the reactor, before any
Expand Down Expand Up @@ -42,22 +45,32 @@ public final class LitheLifecycleParticipant extends AbstractMavenLifecycleParti
private final MavenPluginManager pluginManager;
private final PluginVersionResolver versionResolver;
private final ProjectDependenciesResolver dependenciesResolver;
private final ProfileSelector profileSelector;
private final SettingsBuilder settingsBuilder;
private final RuntimeInformation runtime;

@Inject
public LitheLifecycleParticipant(
MavenPluginManager pluginManager,
PluginVersionResolver versionResolver,
ProjectDependenciesResolver dependenciesResolver) {
ProjectDependenciesResolver dependenciesResolver,
ProfileSelector profileSelector,
SettingsBuilder settingsBuilder,
RuntimeInformation runtime) {
this.pluginManager = pluginManager;
this.versionResolver = versionResolver;
this.dependenciesResolver = dependenciesResolver;
this.profileSelector = profileSelector;
this.settingsBuilder = settingsBuilder;
this.runtime = runtime;
}

@Override
public void afterProjectsRead(MavenSession session) throws MavenExecutionException {
String modelOutput = property(session, MODEL_OUTPUT);
if (modelOutput != null) {
write(modelOutput, Json.write(new ModelExport(session, pluginManager, versionResolver).document()));
write(modelOutput, Json.write(new ModelExport(session, pluginManager, versionResolver,
profileSelector, settingsBuilder, runtime.isMavenVersion("[3.9.0,)")).document()));
}
String dependenciesOutput = property(session, DEPENDENCIES_OUTPUT);
if (dependenciesOutput != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package io.github.litheidea.maven;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Stream;
import org.apache.commons.cli.ParseException;
import org.apache.maven.cli.CLIManager;

/** Restores the project-side profile switches Maven merges with the invocation's arguments. */
final class MavenConfigProfiles {
private MavenConfigProfiles() {}

static void read(File root, boolean maven39OrLater, List<String> active, List<String> inactive)
throws IOException, ParseException {
if (root == null) {
return;
}
Path config = root.toPath().resolve(".mvn").resolve("maven.config");
if (!Files.isRegularFile(config)) {
return;
}
String[] arguments;
// Maven 3.9 changed from whitespace tokens to one UTF-8 argument per line.
if (maven39OrLater) {
try (Stream<String> lines = Files.lines(config, StandardCharsets.UTF_8)) {
arguments = lines.filter(line -> !line.isEmpty() && !line.startsWith("#")).toArray(String[]::new);
}
} else {
arguments = new String(Files.readAllBytes(config), Charset.defaultCharset()).trim().split("\\s+");
}
String[] groups = new CLIManager().parse(arguments).getOptionValues(CLIManager.ACTIVATE_PROFILES);
if (groups == null) {
return;
}
for (String group : groups) {
for (String value : group.split(",")) {
String profile = value.trim();
if (profile.startsWith("-") || profile.startsWith("!")) {
inactive.add(profile.substring(1));
} else if (!profile.isEmpty()) {
active.add(profile.startsWith("+") ? profile.substring(1) : profile);
}
}
}
}
}
Loading
Loading