code refactoring
This commit is contained in:
parent
8100c782ce
commit
8480cebe4b
5 changed files with 143 additions and 135 deletions
|
|
@ -19,7 +19,7 @@ pipeline:
|
|||
#일반적인 if문과 동일
|
||||
- if:
|
||||
#property의 내용은 기본 dynamic(Object)형으로써, 비교시 정확한 캐스팅 필요, 적지 않을시 기본 string
|
||||
condition-int: <!property:test> == <!property:result>
|
||||
condition-string: <!property:git-rev> == <!property:old-git-rev>
|
||||
on-false:
|
||||
- exe: zip
|
||||
|
||||
|
|
|
|||
|
|
@ -26,41 +26,11 @@ class Application {
|
|||
BuildType.file: () => DataComposerFile()
|
||||
};
|
||||
|
||||
final Map<String, PipelineExecutor Function()> exeMap = {
|
||||
'exe': () => PipelineExe(),
|
||||
'async': () => PipelineAsync(),
|
||||
'if': () => PipelineIf(),
|
||||
/*'while': () => PipelineWhile(),
|
||||
'wait-until': () => PipelineWaitUntil(),
|
||||
'switch': () => PipelineSwitch(),*/
|
||||
};
|
||||
|
||||
DataJenkins? jenkinsData;
|
||||
Map<String, dynamic> property = {};
|
||||
Map<String, DataCommand> dataCommandMap = {};
|
||||
late Pipeline pipeline;
|
||||
|
||||
//pipeline validate & initialize
|
||||
PipelineValidateResult pipelineInitialize(List<dynamic> list) {
|
||||
var result = PipelineValidateResult();
|
||||
for (Map<String, dynamic> item in list) {
|
||||
var key = item.keys.first;
|
||||
if (!exeMap.containsKey(key)) {
|
||||
result.enable = false;
|
||||
result.message = 'Validate Error - "$key" is not a supported task';
|
||||
return result;
|
||||
}
|
||||
|
||||
var exe = exeMap[key]!();
|
||||
var childResult = exe.initialize(item);
|
||||
if (!childResult.enable) {
|
||||
return childResult;
|
||||
}
|
||||
result.exeList.add(exe);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<void> build(BuildType buildType, {String? yamlContent}) async {
|
||||
setUTF8();
|
||||
|
||||
|
|
@ -99,7 +69,8 @@ class Application {
|
|||
}
|
||||
|
||||
//Parse pipeline & validate
|
||||
var validateResult = pipelineInitialize(build.pipeline!.workflow);
|
||||
var validateResult =
|
||||
Pipeline.pipelineInitialize(build.pipeline!.workflow);
|
||||
if (!validateResult.enable) {
|
||||
var ex = ExceptionData();
|
||||
ex.phase = 'Validate Pipeline';
|
||||
|
|
|
|||
|
|
@ -1,11 +1,38 @@
|
|||
import 'package:dart_framework/utils/system_util.dart';
|
||||
import 'package:oto_cli/cli/cli.dart';
|
||||
import 'package:oto_cli/oto/application.dart';
|
||||
import 'package:oto_cli/oto/commands/command.dart';
|
||||
import 'package:oto_cli/oto/data/command_data.dart';
|
||||
import 'package:oto_cli/oto/data/pipeline_data.dart';
|
||||
import 'package:oto_cli/oto/pipeline/pipeline_exe.dart';
|
||||
import 'package:oto_cli/oto/pipeline/pipeline_if.dart';
|
||||
|
||||
class Pipeline {
|
||||
static Map<String, PipelineExecutor Function()> exeMap = {
|
||||
'exe': () => PipelineExe(),
|
||||
'async': () => PipelineAsync(),
|
||||
'if': () => PipelineIf(),
|
||||
/*'while': () => PipelineWhile(),
|
||||
'wait-until': () => PipelineWaitUntil(),
|
||||
'switch': () => PipelineSwitch(),*/
|
||||
};
|
||||
|
||||
//pipeline validate & initialize
|
||||
static PipelineValidateResult pipelineInitialize(List<dynamic> list) {
|
||||
var result = PipelineValidateResult();
|
||||
for (Map<String, dynamic> item in list) {
|
||||
var key = item.keys.first;
|
||||
if (!exeMap.containsKey(key)) {
|
||||
result.enable = false;
|
||||
result.message = 'Validate Error - "$key" is not a supported task';
|
||||
return result;
|
||||
}
|
||||
|
||||
var exe = exeMap[key]!();
|
||||
var childResult = exe.initialize(item);
|
||||
if (!childResult.enable) {
|
||||
return childResult;
|
||||
}
|
||||
result.exeList.add(exe);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
final List<PipelineExecutor> _exeList;
|
||||
|
||||
Pipeline(this._exeList);
|
||||
|
|
@ -30,101 +57,3 @@ class PipelineValidateResult {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract class PipelineExecutor {
|
||||
//set & validate data
|
||||
PipelineValidateResult initialize(Map<String, dynamic> set);
|
||||
Future execute();
|
||||
|
||||
PipelineValidateResult validateTasks(List<dynamic>? list) {
|
||||
var result = PipelineValidateResult();
|
||||
if (list != null) {
|
||||
return Application.instance.pipelineInitialize(list);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
class PipelineExe extends PipelineExecutor {
|
||||
late String targetCommandID;
|
||||
@override
|
||||
PipelineValidateResult initialize(Map<String, dynamic> set) {
|
||||
var result = PipelineValidateResult();
|
||||
targetCommandID = set.values.first as String;
|
||||
if (!Application.instance.dataCommandMap.containsKey(targetCommandID)) {
|
||||
result.enable = false;
|
||||
result.message =
|
||||
'The "$targetCommandID" command does not exist in the command list.';
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<DataCommand> get commandData async {
|
||||
var commandData = Application.instance.dataCommandMap[targetCommandID]!;
|
||||
await Application.instance
|
||||
.printBuildStep('Phase Start: ${commandData.name}', Color.green);
|
||||
return dataFutrue(commandData);
|
||||
}
|
||||
|
||||
@override
|
||||
Future execute() async {
|
||||
// var now = DateTime.now();
|
||||
// var time =
|
||||
// '${now.minute.toString().padLeft(2)}:${now.second.toString().padLeft(2)}:${now.millisecond.toString().padLeft(2)}';
|
||||
// print('==================> [$time] Execute: $targetCommandID');
|
||||
var data = await commandData;
|
||||
await Command.byType(data.command).execute(data);
|
||||
return simpleFuture;
|
||||
}
|
||||
}
|
||||
|
||||
class PipelineAsync extends PipelineExe {
|
||||
@override
|
||||
Future execute() async {
|
||||
executeAsync(await commandData);
|
||||
return simpleFuture;
|
||||
}
|
||||
|
||||
void executeAsync(DataCommand data) async {
|
||||
await Command.byType(data.command).execute(data);
|
||||
}
|
||||
}
|
||||
|
||||
class PipelineIf extends PipelineExecutor {
|
||||
late DataIf _data;
|
||||
late Pipeline? _pipelineTrue;
|
||||
late Pipeline? _pipelineFalse;
|
||||
|
||||
@override
|
||||
PipelineValidateResult initialize(Map<String, dynamic> set) {
|
||||
var result = PipelineValidateResult();
|
||||
_data = DataIf.fromJson(set.values.first);
|
||||
var dataValidateResult = _data.validate();
|
||||
if (!dataValidateResult.enable) {
|
||||
return dataValidateResult;
|
||||
}
|
||||
//set true task
|
||||
var validateResult = validateTasks(_data.on_true);
|
||||
if (!validateResult.enable) {
|
||||
return validateResult;
|
||||
}
|
||||
_pipelineTrue = validateResult.pipeline;
|
||||
|
||||
//set false task
|
||||
validateResult = validateTasks(_data.on_false);
|
||||
if (!validateResult.enable) {
|
||||
return validateResult;
|
||||
}
|
||||
_pipelineFalse = validateResult.pipeline;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future execute() async {
|
||||
//To-do: check true or false
|
||||
await _pipelineTrue?.execute();
|
||||
await _pipelineFalse?.execute();
|
||||
return simpleFuture;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
65
lib/oto/pipeline/pipeline_exe.dart
Normal file
65
lib/oto/pipeline/pipeline_exe.dart
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
import 'package:dart_framework/utils/system_util.dart';
|
||||
import 'package:oto_cli/cli/cli.dart';
|
||||
import 'package:oto_cli/oto/application.dart';
|
||||
import 'package:oto_cli/oto/commands/command.dart';
|
||||
import 'package:oto_cli/oto/data/command_data.dart';
|
||||
import 'package:oto_cli/oto/pipeline/pipeline.dart';
|
||||
|
||||
abstract class PipelineExecutor {
|
||||
//set & validate data
|
||||
PipelineValidateResult initialize(Map<String, dynamic> set);
|
||||
Future execute();
|
||||
|
||||
PipelineValidateResult validateTasks(List<dynamic>? list) {
|
||||
var result = PipelineValidateResult();
|
||||
if (list != null) {
|
||||
return Pipeline.pipelineInitialize(list);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
class PipelineExe extends PipelineExecutor {
|
||||
late String targetCommandID;
|
||||
@override
|
||||
PipelineValidateResult initialize(Map<String, dynamic> set) {
|
||||
var result = PipelineValidateResult();
|
||||
targetCommandID = set.values.first as String;
|
||||
if (!Application.instance.dataCommandMap.containsKey(targetCommandID)) {
|
||||
result.enable = false;
|
||||
result.message =
|
||||
'The "$targetCommandID" command does not exist in the command list.';
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<DataCommand> get commandData async {
|
||||
var commandData = Application.instance.dataCommandMap[targetCommandID]!;
|
||||
await Application.instance
|
||||
.printBuildStep('Phase Start: ${commandData.name}', Color.green);
|
||||
return dataFutrue(commandData);
|
||||
}
|
||||
|
||||
@override
|
||||
Future execute() async {
|
||||
// var now = DateTime.now();
|
||||
// var time =
|
||||
// '${now.minute.toString().padLeft(2)}:${now.second.toString().padLeft(2)}:${now.millisecond.toString().padLeft(2)}';
|
||||
// print('==================> [$time] Execute: $targetCommandID');
|
||||
var data = await commandData;
|
||||
await Command.byType(data.command).execute(data);
|
||||
return simpleFuture;
|
||||
}
|
||||
}
|
||||
|
||||
class PipelineAsync extends PipelineExe {
|
||||
@override
|
||||
Future execute() async {
|
||||
executeAsync(await commandData);
|
||||
return simpleFuture;
|
||||
}
|
||||
|
||||
void executeAsync(DataCommand data) async {
|
||||
await Command.byType(data.command).execute(data);
|
||||
}
|
||||
}
|
||||
43
lib/oto/pipeline/pipeline_if.dart
Normal file
43
lib/oto/pipeline/pipeline_if.dart
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import 'package:dart_framework/utils/system_util.dart';
|
||||
import 'package:oto_cli/oto/data/pipeline_data.dart';
|
||||
import 'package:oto_cli/oto/pipeline/pipeline.dart';
|
||||
import 'package:oto_cli/oto/pipeline/pipeline_exe.dart';
|
||||
|
||||
class PipelineIf extends PipelineExecutor {
|
||||
late DataIf _data;
|
||||
late Pipeline? _pipelineTrue;
|
||||
late Pipeline? _pipelineFalse;
|
||||
|
||||
@override
|
||||
PipelineValidateResult initialize(Map<String, dynamic> set) {
|
||||
var result = PipelineValidateResult();
|
||||
_data = DataIf.fromJson(set.values.first);
|
||||
var dataValidateResult = _data.validate();
|
||||
if (!dataValidateResult.enable) {
|
||||
return dataValidateResult;
|
||||
}
|
||||
//set true task
|
||||
var validateResult = validateTasks(_data.on_true);
|
||||
if (!validateResult.enable) {
|
||||
return validateResult;
|
||||
}
|
||||
_pipelineTrue = validateResult.pipeline;
|
||||
|
||||
//set false task
|
||||
validateResult = validateTasks(_data.on_false);
|
||||
if (!validateResult.enable) {
|
||||
return validateResult;
|
||||
}
|
||||
_pipelineFalse = validateResult.pipeline;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future execute() async {
|
||||
//To-do: check true or false
|
||||
await _pipelineTrue?.execute();
|
||||
await _pipelineFalse?.execute();
|
||||
return simpleFuture;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue