From 73000ea619308a18340d82026221b71e8e010593 Mon Sep 17 00:00:00 2001 From: leedongmyung Date: Thu, 28 Nov 2024 18:59:42 +0900 Subject: [PATCH] =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20ignore=20=ED=8C=A8?= =?UTF-8?q?=ED=84=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 7 ++++++ lib/oto/commands/command.dart | 17 ++++++-------- lib/oto/commands/file/file.dart | 39 ++++++++++++++++++++++++++++++-- lib/oto/data/command_data.dart | 16 +++++++++++++ lib/oto/data/command_data.g.dart | 25 ++++++++++++++++++++ pubspec.yaml | 2 +- 6 files changed, 93 insertions(+), 13 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index e1fa066..292a4c5 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -53,6 +53,13 @@ "program": "./bin/main.dart", "args": ["exe", "-f", "./assets/pipeline-test2.yaml"] }, + { + "name": "exe aos build", + "request": "launch", + "type": "dart", + "program": "./bin/main.dart", + "args": ["exe", "-f", "/Users/toki/works/lgup-mcs-aos/app/buildScript/build-lt.yaml"] + }, { "name": "exe slack", "request": "launch", diff --git a/lib/oto/commands/command.dart b/lib/oto/commands/command.dart index 51c06fa..db771f3 100644 --- a/lib/oto/commands/command.dart +++ b/lib/oto/commands/command.dart @@ -66,6 +66,7 @@ enum CommandType { FileDiffCheck, FileRead, FileWrite, + Files, DirectoryCreate, Slack, SlackBuild, @@ -124,6 +125,7 @@ abstract class Command { CommandType.FileDiffCheck: () => FileDiffCheck(), CommandType.FileRead: () => FileRead(), CommandType.FileWrite: () => FileWrite(), + CommandType.Files: () => Files(), CommandType.DirectoryCreate: () => DirectoryCreate(), CommandType.Slack: () => Slack(), CommandType.SlackBuild: () => SlackBuild(), @@ -363,7 +365,7 @@ abstract class Command { Map getParam(DataCommand command) { Map map; - if(command.param == null) { + if (command.param == null) { map = {}; } else { map = Command.replaceAllTagsMap(command.param); @@ -378,11 +380,9 @@ abstract class Command { Future executeHandle(DataCommand command, ExeHandleData handleData) async { exeHandle = handleData; - try - { + try { return await execute(command); - } - on Exception { + } on Exception { return await exeHandle!.pipelineFail!.execute(); } } @@ -434,8 +434,7 @@ abstract class Command { await setProperty(data.setResult!, resultMessage); } } - if(exeHandle == null) - { + if (exeHandle == null) { if (passExitCodesMerge.contains(exitCode)) { return simpleFuture; } else { @@ -445,9 +444,7 @@ abstract class Command { data.message = errorMessage; throw Exception(data); } - } - else - { + } else { if (passExitCodesMerge.contains(exitCode)) { return await exeHandle!.pipelineSuccess!.execute(); } else { diff --git a/lib/oto/commands/file/file.dart b/lib/oto/commands/file/file.dart index 0a7c307..ad44019 100644 --- a/lib/oto/commands/file/file.dart +++ b/lib/oto/commands/file/file.dart @@ -11,7 +11,7 @@ class FileRead extends Command { var data = DataFileRead.fromJson(getParam(command)); var file = File(data.path); var content = ''; - if(file.existsSync()) { + if (file.existsSync()) { content = file.readAsStringSync(); } else { throw Exception('File not exist - ${data.path}'); @@ -26,9 +26,44 @@ class FileWrite extends Command { Future execute(DataCommand command) async { var data = DataFileWrite.fromJson(getParam(command)); var file = File(data.path); - if(file.existsSync()) file.deleteSync(); + if (file.existsSync()) file.deleteSync(); await file.writeAsString(data.content); return complete(0, command); } } + +class Files extends Command { + @override + Future execute(DataCommand command) async { + var data = DataFiles.fromJson(getParam(command)); + var target = Directory(data.path); + var list = []; + var recursive = data.recursive ?? false; + var regExs = data.ignoreRegExs ?? []; + + if (target.existsSync()) { + var files = target.listSync(recursive: recursive); + for (var file in files) { + var path = file.path; + var matched = false; + for (var regEx in regExs) { + var pattern = RegExp(regEx); + if (pattern.hasMatch(path)) { + matched = true; + break; + } + } + if (!matched) { + if (FileSystemEntity.typeSync(path) == FileSystemEntityType.file) { + list.add(path); + print('====================$path'); + } + } + } + } + + await setProperty(data.setFiles, list); + return complete(0, command); + } +} diff --git a/lib/oto/data/command_data.dart b/lib/oto/data/command_data.dart index a49d3f0..b315b7a 100644 --- a/lib/oto/data/command_data.dart +++ b/lib/oto/data/command_data.dart @@ -434,6 +434,22 @@ class DataFileWrite extends DataParam { Map toJson() => _$DataFileWriteToJson(this); } +//Files +@JsonSerializable() +class DataFiles extends DataParam { + DataFiles(); + + late String path; + late bool? recursive = false; + late List? ignoreRegExs = []; + late String setFiles; + + factory DataFiles.fromJson(Map json) => + _$DataFilesFromJson(json); + @override + Map toJson() => _$DataFilesToJson(this); +} + //Directory Create @JsonSerializable() class DataDirectoryCreate extends DataParam { diff --git a/lib/oto/data/command_data.g.dart b/lib/oto/data/command_data.g.dart index 500b5c3..728d624 100644 --- a/lib/oto/data/command_data.g.dart +++ b/lib/oto/data/command_data.g.dart @@ -58,6 +58,7 @@ const _$CommandTypeEnumMap = { CommandType.FileDiffCheck: 'FileDiffCheck', CommandType.FileRead: 'FileRead', CommandType.FileWrite: 'FileWrite', + CommandType.Files: 'Files', CommandType.DirectoryCreate: 'DirectoryCreate', CommandType.Slack: 'Slack', CommandType.SlackBuild: 'SlackBuild', @@ -708,6 +709,30 @@ Map _$DataFileWriteToJson(DataFileWrite instance) => 'content': instance.content, }; +DataFiles _$DataFilesFromJson(Map json) => DataFiles() + ..workspace = json['workspace'] as String? + ..passExitCodes = (json['passExitCodes'] as List?) + ?.map((e) => (e as num).toInt()) + .toList() + ..setResult = json['setResult'] as String? + ..setExitCode = json['setExitCode'] as String? + ..path = json['path'] as String + ..recursive = json['recursive'] as bool? + ..ignoreRegExs = + (json['ignoreRegExs'] as List?)?.map((e) => e as String).toList() + ..setFiles = json['setFiles'] as String; + +Map _$DataFilesToJson(DataFiles instance) => { + 'workspace': instance.workspace, + 'passExitCodes': instance.passExitCodes, + 'setResult': instance.setResult, + 'setExitCode': instance.setExitCode, + 'path': instance.path, + 'recursive': instance.recursive, + 'ignoreRegExs': instance.ignoreRegExs, + 'setFiles': instance.setFiles, + }; + DataDirectoryCreate _$DataDirectoryCreateFromJson(Map json) => DataDirectoryCreate() ..workspace = json['workspace'] as String? diff --git a/pubspec.yaml b/pubspec.yaml index b8bb106..4da8a55 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -21,7 +21,7 @@ dependencies: file_hasher: ^0.1.0+0 dev_dependencies: - lints: ^4.0.0 + lints: ^5.0.0 test: ^1.24.9 build_runner: ^2.1.4 json_serializable: ^6.0.1