44import com .fasterxml .jackson .databind .ObjectMapper ;
55import com .fasterxml .jackson .dataformat .yaml .YAMLFactory ;
66import com .flowci .common .validator .ValidName ;
7- import com .flowci .yaml .business .ParseYamlV2 ;
7+ import com .flowci .yaml .business .ParseYaml ;
88import com .flowci .yaml .exception .InvalidYamlException ;
9- import com .flowci .yaml .model .FlowV2 ;
10- import com .flowci .yaml .model .StepV2 ;
9+ import com .flowci .yaml .model .Step ;
10+ import com .flowci .yaml .model .v2 .FlowV2 ;
11+ import com .flowci .yaml .model .v2 .StepV2 ;
1112import lombok .extern .slf4j .Slf4j ;
1213import org .springframework .stereotype .Component ;
13- import org .springframework .util .CollectionUtils ;
1414
15- import java .util .*;
15+ import java .util .HashMap ;
16+ import java .util .HashSet ;
17+ import java .util .List ;
1618
1719import static java .lang .String .format ;
1820import static org .springframework .util .CollectionUtils .isEmpty ;
1921import static org .springframework .util .StringUtils .hasText ;
2022
2123@ Slf4j
2224@ Component
23- public class ParseYamlV2Impl implements ParseYamlV2 {
25+ public class ParseYamlV2Impl implements ParseYaml {
2426
2527 private static final ObjectMapper objectMapper = new ObjectMapper (new YAMLFactory ());
2628 private static final ValidName .NameValidator nameValidator = new ValidName .NameValidator ();
@@ -34,7 +36,9 @@ public FlowV2 invoke(String yaml) {
3436 try {
3537 var flowV2 = objectMapper .readValue (yaml , FlowV2 .class );
3638 for (var step : flowV2 .getSteps ()) {
37- step .setParent (flowV2 );
39+ if (step instanceof StepV2 v2 ) {
40+ v2 .setParent (flowV2 );
41+ }
3842 }
3943
4044 validateSteps (flowV2 );
@@ -48,7 +52,7 @@ public FlowV2 invoke(String yaml) {
4852
4953 private void validateSteps (FlowV2 flow ) {
5054 var steps = flow .getSteps ();
51- if (CollectionUtils . isEmpty (steps )) {
55+ if (isEmpty (steps )) {
5256 throw new InvalidYamlException ("at least one step is required" );
5357 }
5458
@@ -78,7 +82,7 @@ private void validateSteps(FlowV2 flow) {
7882
7983 private void validateCommands (StepV2 step ) {
8084 var commands = step .getCommands ();
81- if (CollectionUtils . isEmpty (commands )) {
85+ if (isEmpty (commands )) {
8286 throw new InvalidYamlException (format ("at least one command under step '%s' is required" , step .getName ()));
8387 }
8488
@@ -101,7 +105,7 @@ private void buildGraph(FlowV2 flow) {
101105 }
102106
103107 for (var step : steps ) {
104- if (CollectionUtils . isEmpty (step .getDependsOn ())) {
108+ if (isEmpty (step .getDependsOn ())) {
105109 continue ;
106110 }
107111
@@ -118,7 +122,7 @@ private void buildGraph(FlowV2 flow) {
118122 }
119123 }
120124
121- private void checkCircularDependencies (List <StepV2 > steps , HashMap <StepV2 , Integer > traversed ) {
125+ private void checkCircularDependencies (List <Step > steps , HashMap <Step , Integer > traversed ) {
122126 for (var step : steps ) {
123127 Integer numEncountered = traversed .get (step );
124128
@@ -137,13 +141,4 @@ private void checkCircularDependencies(List<StepV2> steps, HashMap<StepV2, Integ
137141 checkCircularDependencies (step .getNext (), traversed );
138142 }
139143 }
140-
141- /**
142- * Ex:
143- * A <-- B <-- C
144- * A <-- C
145- */
146- private void checkDuplicatedDependsOn (List <StepV2 > steps ) {
147-
148- }
149144}
0 commit comments