1
This commit is contained in:
1 parent
5efc778165
commit
59125d185c
64 files changed
+7912
-1393
No files matched your search
@@ -1,61 +1,59 @@
|
||||
import 'dart:io';
|
||||
import '../../models/run_task.dart';
|
||||
import '../distro_manager.dart';
|
||||
import '../run_task_storage_service.dart';
|
||||
|
||||
/// 传递给各项目探测模块的上下文环境
|
||||
class ProjectModuleContext {
|
||||
/// 工程根目录
|
||||
final Directory projectDir;
|
||||
import '../toolchain_service.dart';
|
||||
import 'project_probe.dart';
|
||||
|
||||
/// 当前在编辑器中激活的文件路径(宿主绝对路径,可能为 null)
|
||||
final String? currentFilePath;
|
||||
|
||||
/// 容器系统名称(默认为 'ubuntu' 或当前激活的容器)
|
||||
final String systemName;
|
||||
|
||||
/// 任务持久化存储服务
|
||||
final RunTaskStorageService storageService;
|
||||
|
||||
/// 容器管理器
|
||||
final DistroManager distroManager;
|
||||
|
||||
const ProjectModuleContext({
|
||||
required this.projectDir,
|
||||
this.currentFilePath,
|
||||
this.systemName = 'ubuntu',
|
||||
required this.storageService,
|
||||
required this.distroManager,
|
||||
});
|
||||
|
||||
/// 在容器后台静默执行命令并捕获输出
|
||||
Future<ProcessResult?> runHeadless(
|
||||
String command, {
|
||||
Duration timeout = const Duration(seconds: 120),
|
||||
}) {
|
||||
return distroManager.runHeadlessCommand(
|
||||
systemName: systemName,
|
||||
workspacePath: projectDir.path,
|
||||
command: command,
|
||||
timeout: timeout,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 项目探测模块接口(对标 VS Code TaskProvider)
|
||||
/// 项目探测模块接口(对标 VS Code TaskProvider / IDE 的 ProjectModel 提供者)
|
||||
///
|
||||
/// 总调度按**队列线性执行**驱动每个模块,每个模块依次做三个动作:
|
||||
/// 1. [prepare] + [checkDependencies]:环境准备与**依赖检测**(返回缺失的依赖 key);
|
||||
/// 2. [installDependencies]:**自动补全**缺失依赖(默认实现 = 复用容器内发行版安装命令);
|
||||
/// 3. [probe]:**执行探测**,返回结构化结果。
|
||||
///
|
||||
/// 约定:
|
||||
/// * 模块不得返回任何硬编码兜底任务;探测失败就如实返回 failed;
|
||||
/// * 模块不得自行猜测执行环境,一切执行都通过 [ProjectProbe] 提供的当前系统会话;
|
||||
/// * 依赖必须声明为 [requiredToolchainKeys](键取自 [ToolchainService.supportedTools]),
|
||||
/// 这样"自动补全"才能拿到对应发行版的安装命令。
|
||||
abstract class ProjectModule {
|
||||
/// 模块唯一标识(如 'gradle', 'cmake', 'cargo', 'npm' 等)
|
||||
String get id;
|
||||
|
||||
/// 模块友好展示名称
|
||||
/// 模块展示名(用于 UI 文案插值,如 'Gradle')
|
||||
String get displayName;
|
||||
|
||||
/// 该项目特有的特征标记文件(命中其中任意一个才激活本探测器)
|
||||
List<String> get triggerFiles;
|
||||
|
||||
/// 快速判断当前工程是否匹配本模块(毫秒级,只检测文件存在与否,不进行深层解析)
|
||||
/// 是否支持"重新同步真实任务"
|
||||
bool get supportsResync => false;
|
||||
|
||||
/// 需要的工具链依赖 key(对应 [ToolchainService.supportedTools] 的键)
|
||||
List<String> get requiredToolchainKeys => const [];
|
||||
|
||||
/// 快速判断当前工程是否匹配本模块(毫秒级,只检测文件存在与否)
|
||||
bool shouldActivate(Directory projectDir);
|
||||
|
||||
/// 探测项目任务(支持优先读取本地缓存;当 forceRefresh=true 时强制发起真实探测)
|
||||
Future<List<RunTask>> detect(ProjectModuleContext context, {bool forceRefresh = false});
|
||||
/// 环境准备(写探测脚本、准备临时目录等),在依赖检测前执行。默认无操作。
|
||||
Future<void> prepare(ProjectProbe probe) async {}
|
||||
|
||||
/// 依赖检测:返回缺失的依赖 key 列表。默认实现按 [requiredToolchainKeys] 逐个检查。
|
||||
Future<List<String>> checkDependencies(ProjectProbe probe) async {
|
||||
final missing = <String>[];
|
||||
for (final key in requiredToolchainKeys) {
|
||||
final requirement = ToolchainService.supportedTools[key];
|
||||
if (requirement == null) continue;
|
||||
final installed = await probe.isToolchainInstalled(requirement);
|
||||
if (!installed) missing.add(key);
|
||||
}
|
||||
return missing;
|
||||
}
|
||||
|
||||
/// 自动补全缺失依赖:默认实现调用容器内安装(按发行版家族合成命令)。
|
||||
Future<bool> installDependencies(ProjectProbe probe, List<String> missing) {
|
||||
return probe.installToolchains(missing);
|
||||
}
|
||||
|
||||
/// 执行探测(结构化结果)
|
||||
Future<ModuleProbeResult> probe(ProjectProbe probe);
|
||||
}
|
||||
Reference in new issue
Block a user