2
This commit is contained in:
1 parent
5ac164b407
commit
f93f6095af
94 files changed
+7877
-4018
No files matched your search
@@ -0,0 +1,76 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
import '../../models/run_task.dart';
|
||||
import 'project_module.dart';
|
||||
import 'project_probe.dart';
|
||||
|
||||
/// Maven (Java) 工程模块:识别 pom.xml 或 mvnw 包装脚本
|
||||
class MavenProjectModule extends ProjectModule {
|
||||
@override
|
||||
String get id => 'maven';
|
||||
|
||||
@override
|
||||
String get displayName => 'Maven';
|
||||
|
||||
@override
|
||||
List<String> get triggerFiles => const ['pom.xml', 'mvnw'];
|
||||
|
||||
@override
|
||||
bool shouldActivate(Directory projectDir) {
|
||||
return triggerFiles.any((f) => File(p.join(projectDir.path, f)).existsSync());
|
||||
}
|
||||
|
||||
@override
|
||||
List<String> get requiredToolchainKeys => const ['maven'];
|
||||
|
||||
@override
|
||||
Future<ModuleProbeResult> probe(ProjectProbe probe) async {
|
||||
if (probe.isCancelled) return ModuleProbeResult.cancelled(id);
|
||||
|
||||
final root = probe.projectDir;
|
||||
final hasWrapper = File(p.join(root.path, 'mvnw')).existsSync();
|
||||
final cmdPrefix = hasWrapper ? './mvnw' : 'mvn';
|
||||
|
||||
return ModuleProbeResult.ok(id, [
|
||||
RunTask(
|
||||
id: 'detected_maven_package',
|
||||
name: 'Maven: Package',
|
||||
command: '$cmdPrefix package',
|
||||
source: TaskSource.detected,
|
||||
group: 'build',
|
||||
moduleId: id,
|
||||
icon: Icons.inventory_2_outlined,
|
||||
),
|
||||
RunTask(
|
||||
id: 'detected_maven_compile',
|
||||
name: 'Maven: Compile',
|
||||
command: '$cmdPrefix compile',
|
||||
source: TaskSource.detected,
|
||||
group: 'build',
|
||||
moduleId: id,
|
||||
icon: Icons.build_outlined,
|
||||
),
|
||||
RunTask(
|
||||
id: 'detected_maven_test',
|
||||
name: 'Maven: Test',
|
||||
command: '$cmdPrefix test',
|
||||
source: TaskSource.detected,
|
||||
group: 'verification',
|
||||
moduleId: id,
|
||||
icon: Icons.fact_check_outlined,
|
||||
),
|
||||
RunTask(
|
||||
id: 'detected_maven_clean',
|
||||
name: 'Maven: Clean',
|
||||
command: '$cmdPrefix clean',
|
||||
source: TaskSource.detected,
|
||||
group: 'build',
|
||||
moduleId: id,
|
||||
icon: Icons.cleaning_services_outlined,
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,9 @@ import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../../models/notice_item.dart';
|
||||
import '../../models/run_task.dart';
|
||||
import '../background_task/background_task.dart';
|
||||
import '../background_task/background_task_scheduler.dart';
|
||||
import '../background_task/generic_background_task.dart';
|
||||
import '../distro_manager.dart';
|
||||
import '../toolchain_service.dart';
|
||||
|
||||
@@ -297,15 +300,34 @@ class ProjectProbe {
|
||||
if (commands.isEmpty) return false;
|
||||
|
||||
final script = commands.join(' && ');
|
||||
final result = await runHeadless(
|
||||
script,
|
||||
timeout: const Duration(minutes: 10),
|
||||
onStdout: (chunk) {
|
||||
final line = chunk.trim();
|
||||
if (line.isNotEmpty) setInstallLine(line);
|
||||
|
||||
// 接入统一调度器:通过 TaskExecutionScope.packageManager 保证独占排他锁,
|
||||
// 不与用户同时触发的 LSP 组件安装/卸载冲突
|
||||
final task = GenericBackgroundTask<bool>(
|
||||
id: 'probe:toolchains:${toolchainKeys.join('+')}',
|
||||
scope: TaskExecutionScope.packageManager,
|
||||
priority: TaskPriority.projectLifecycle,
|
||||
showNotice: false, // 模块探测自身已有专用的 ModulePhaseText 弹窗显示
|
||||
runner: (taskContext) async {
|
||||
if (isCancelled || _disposed) return false;
|
||||
|
||||
final result = await runHeadless(
|
||||
script,
|
||||
timeout: const Duration(minutes: 10),
|
||||
onStdout: (chunk) {
|
||||
final line = chunk.trim();
|
||||
if (line.isNotEmpty) setInstallLine(line);
|
||||
},
|
||||
);
|
||||
return result != null && result.exitCode == 0;
|
||||
},
|
||||
);
|
||||
return result != null && result.exitCode == 0;
|
||||
|
||||
try {
|
||||
return await BackgroundTaskScheduler.instance.submit(task);
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// 更新安装进度行(带释放保护,避免取消/释放后写入已 dispose 的 notifier)
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
import '../../models/run_task.dart';
|
||||
import 'project_module.dart';
|
||||
import 'project_probe.dart';
|
||||
|
||||
/// Python 工程模块:识别 requirements.txt、pyproject.toml 等特征
|
||||
class PythonProjectModule extends ProjectModule {
|
||||
@override
|
||||
String get id => 'python';
|
||||
|
||||
@override
|
||||
String get displayName => 'Python';
|
||||
|
||||
@override
|
||||
List<String> get triggerFiles => const [
|
||||
'requirements.txt',
|
||||
'pyproject.toml',
|
||||
'setup.py',
|
||||
'Pipfile',
|
||||
];
|
||||
|
||||
@override
|
||||
bool shouldActivate(Directory projectDir) {
|
||||
return triggerFiles.any((f) => File(p.join(projectDir.path, f)).existsSync());
|
||||
}
|
||||
|
||||
@override
|
||||
List<String> get requiredToolchainKeys => const ['python3'];
|
||||
|
||||
@override
|
||||
Future<ModuleProbeResult> probe(ProjectProbe probe) async {
|
||||
if (probe.isCancelled) return ModuleProbeResult.cancelled(id);
|
||||
|
||||
final tasks = <RunTask>[];
|
||||
final root = probe.projectDir;
|
||||
|
||||
// 1. 依赖安装任务
|
||||
if (File(p.join(root.path, 'requirements.txt')).existsSync()) {
|
||||
tasks.add(
|
||||
RunTask(
|
||||
id: 'detected_python_pip_install',
|
||||
name: 'Pip: Install Requirements',
|
||||
command: 'pip3 install -r requirements.txt',
|
||||
source: TaskSource.detected,
|
||||
group: 'build',
|
||||
moduleId: id,
|
||||
icon: Icons.download_outlined,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 2. 主入口任务
|
||||
if (File(p.join(root.path, 'main.py')).existsSync()) {
|
||||
tasks.add(
|
||||
RunTask(
|
||||
id: 'detected_python_run_main',
|
||||
name: 'Python: Run main.py',
|
||||
command: 'python3 main.py',
|
||||
source: TaskSource.detected,
|
||||
group: 'application',
|
||||
moduleId: id,
|
||||
icon: Icons.play_circle_outline,
|
||||
),
|
||||
);
|
||||
} else if (File(p.join(root.path, 'app.py')).existsSync()) {
|
||||
tasks.add(
|
||||
RunTask(
|
||||
id: 'detected_python_run_app',
|
||||
name: 'Python: Run app.py',
|
||||
command: 'python3 app.py',
|
||||
source: TaskSource.detected,
|
||||
group: 'application',
|
||||
moduleId: id,
|
||||
icon: Icons.play_circle_outline,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 3. 测试任务
|
||||
final hasTestsDir = Directory(p.join(root.path, 'tests')).existsSync() ||
|
||||
Directory(p.join(root.path, 'test')).existsSync();
|
||||
final hasPytestIni = File(p.join(root.path, 'pytest.ini')).existsSync();
|
||||
if (hasTestsDir || hasPytestIni) {
|
||||
tasks.add(
|
||||
RunTask(
|
||||
id: 'detected_python_pytest',
|
||||
name: 'Pytest: Run Tests',
|
||||
command: 'pytest',
|
||||
source: TaskSource.detected,
|
||||
group: 'verification',
|
||||
moduleId: id,
|
||||
icon: Icons.fact_check_outlined,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return ModuleProbeResult.ok(id, tasks);
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,12 @@ class SingleFileTaskDetector {
|
||||
'.go',
|
||||
'.rs',
|
||||
'.js',
|
||||
'.java',
|
||||
'.ts',
|
||||
'.mts',
|
||||
'.lua',
|
||||
'.pl',
|
||||
'.php',
|
||||
};
|
||||
|
||||
/// 检查给定文件路径是否属于支持的单文件任务类型
|
||||
@@ -135,6 +141,52 @@ class SingleFileTaskDetector {
|
||||
group: 'single_file',
|
||||
icon: Icons.javascript,
|
||||
);
|
||||
case '.java':
|
||||
return RunTask(
|
||||
id: 'detected_single_java',
|
||||
name: 'Java: $fileName',
|
||||
command: 'java $escapedRelPath',
|
||||
source: TaskSource.detected,
|
||||
group: 'single_file',
|
||||
icon: Icons.code,
|
||||
);
|
||||
case '.ts':
|
||||
case '.mts':
|
||||
return RunTask(
|
||||
id: 'detected_single_ts',
|
||||
name: 'TypeScript: $fileName',
|
||||
command: 'npx -y tsx $escapedRelPath',
|
||||
source: TaskSource.detected,
|
||||
group: 'single_file',
|
||||
icon: Icons.javascript,
|
||||
);
|
||||
case '.lua':
|
||||
return RunTask(
|
||||
id: 'detected_single_lua',
|
||||
name: 'Lua: $fileName',
|
||||
command: 'lua $escapedRelPath',
|
||||
source: TaskSource.detected,
|
||||
group: 'single_file',
|
||||
icon: Icons.code,
|
||||
);
|
||||
case '.pl':
|
||||
return RunTask(
|
||||
id: 'detected_single_perl',
|
||||
name: 'Perl: $fileName',
|
||||
command: 'perl $escapedRelPath',
|
||||
source: TaskSource.detected,
|
||||
group: 'single_file',
|
||||
icon: Icons.terminal,
|
||||
);
|
||||
case '.php':
|
||||
return RunTask(
|
||||
id: 'detected_single_php',
|
||||
name: 'PHP: $fileName',
|
||||
command: 'php $escapedRelPath',
|
||||
source: TaskSource.detected,
|
||||
group: 'single_file',
|
||||
icon: Icons.code,
|
||||
);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ library;
|
||||
export 'cargo_project_module.dart';
|
||||
export 'cmake_project_module.dart';
|
||||
export 'dart_project_module.dart';
|
||||
export 'gradle_project_module.dart';
|
||||
export 'make_project_module.dart';
|
||||
export 'maven_project_module.dart';
|
||||
export 'npm_project_module.dart';
|
||||
export 'python_project_module.dart';
|
||||
export 'single_file_task_detector.dart';
|
||||
Reference in new issue
Block a user