1 | package com.github.dakusui.actionunit.core; | |
2 | ||
3 | import com.github.dakusui.actionunit.actions.*; | |
4 | import com.github.dakusui.actionunit.actions.cmd.CommanderConfig; | |
5 | import com.github.dakusui.actionunit.actions.cmd.UnixCommanderFactory; | |
6 | import com.github.dakusui.actionunit.actions.cmd.unix.Cmd; | |
7 | ||
8 | import java.util.List; | |
9 | import java.util.function.Consumer; | |
10 | import java.util.function.Function; | |
11 | import java.util.function.Predicate; | |
12 | import java.util.stream.Stream; | |
13 | ||
14 | import static com.github.dakusui.actionunit.core.context.ContextConsumer.NOP_CONSUMER; | |
15 | import static com.github.dakusui.actionunit.utils.InternalUtils.toStringIfOverriddenOrNoname; | |
16 | import static com.github.dakusui.printables.PrintableFunctionals.printableConsumer; | |
17 | import static java.util.Arrays.asList; | |
18 | import static java.util.Objects.requireNonNull; | |
19 | ||
20 | /** | |
21 | * A utility class to build various actions. | |
22 | */ | |
23 | public enum ActionSupport { | |
24 | ; | |
25 | ||
26 | /** | |
27 | * Creates an action that does nothing. | |
28 | * | |
29 | * @return A nop action. | |
30 | */ | |
31 | public static Action nop() { | |
32 | // Needs to be instantiated each time this method is called. | |
33 | // Otherwise, multiple nops cannot be identified in an action tree. | |
34 |
1
1. nop : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::nop → KILLED |
return Leaf.of(NOP_CONSUMER); |
35 | } | |
36 | ||
37 | public static Action leaf(Consumer<Context> consumer) { | |
38 |
1
1. leaf : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::leaf → KILLED |
return Leaf.of(consumer); |
39 | } | |
40 | ||
41 | /** | |
42 | * Returns an action named with a given string `name`. | |
43 | * | |
44 | * @param name A name given to `action`. | |
45 | * @param action An action to be named. | |
46 | * @return A named action. | |
47 | */ | |
48 | public static Action named(String name, Action action) { | |
49 |
1
1. named : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::named → KILLED |
return Named.of(name, action); |
50 | } | |
51 | ||
52 | public static Attempt.Builder attempt(Action action) { | |
53 |
1
1. attempt : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::attempt → KILLED |
return new Attempt.Builder(action); |
54 | } | |
55 | ||
56 | public static <E> ForEach.Builder<E> forEach(Function<Context, Stream<E>> streamGenerator) { | |
57 |
1
1. forEach : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::forEach → KILLED |
return forEach("i", streamGenerator); |
58 | } | |
59 | ||
60 | /** | |
61 | * Note that the `variableName` is only used for printing the variable in an action tree. | |
62 | * Not used for identifying a corresponding entry in the context. | |
63 | * | |
64 | * @param variableName A name of variable. | |
65 | * @param streamGenerator A function to return stream. | |
66 | * @param <E> The type of the loop variable. | |
67 | * @return A builder for `ForEach2` action | |
68 | */ | |
69 | public static <E> ForEach.Builder<E> forEach(String variableName, Function<Context, Stream<E>> streamGenerator) { | |
70 |
1
1. forEach : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::forEach → KILLED |
return new ForEach.Builder<>(variableName, streamGenerator); |
71 | } | |
72 | ||
73 | /** | |
74 | * Returns a builder to create an action repeated while `condition` is satisfied. | |
75 | * | |
76 | * @param condition A condition to make an action repeated. | |
77 | * @return A builder for `While` action. | |
78 | * @see While | |
79 | * @see While.Builder | |
80 | */ | |
81 | public static While.Builder repeatWhile(Predicate<Context> condition) { | |
82 |
1
1. repeatWhile : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::repeatWhile → KILLED |
return new While.Builder(condition); |
83 | } | |
84 | ||
85 | /** | |
86 | * Returns a builder to create an action performed when `condition` is satisfied. | |
87 | * | |
88 | * @param cond A condition to make an actiono performed. | |
89 | * @return A builder for `When` action | |
90 | * @see When | |
91 | * @see When.Builder | |
92 | */ | |
93 | public static When.Builder when(Predicate<Context> cond) { | |
94 |
1
1. when : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::when → KILLED |
return new When.Builder(cond); |
95 | } | |
96 | ||
97 | public static <T> With.Builder<T> with(Function<Context, T> value) { | |
98 |
1
1. with : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::with → KILLED |
return with("i", value); |
99 | } | |
100 | ||
101 | /** | |
102 | * Note that `variableName` won't be used to resolve a value of a variable, it is | |
103 | * merely intended to be printed in an action-tree or logs. | |
104 | * | |
105 | * @param variableName human-readable variable name. | |
106 | * @param value A function to give a value to be used a context under the returned action. | |
107 | * @param <T> The type of the variable | |
108 | * @return A builder for a `with` action. | |
109 | */ | |
110 | public static <T> With.Builder<T> with(String variableName, Function<Context, T> value) { | |
111 |
1
1. with : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::with → KILLED |
return new With.Builder<>(variableName, value); |
112 | } | |
113 | ||
114 | public static Retry.Builder retry(Action action) { | |
115 |
1
1. retry : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::retry → KILLED |
return new Retry.Builder(action); |
116 | } | |
117 | ||
118 | public static TimeOut.Builder timeout(Action action) { | |
119 |
1
1. timeout : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::timeout → KILLED |
return new TimeOut.Builder(action); |
120 | } | |
121 | ||
122 | public static Action sequential(List<Action> actions) { | |
123 |
1
1. sequential : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::sequential → KILLED |
return new Composite.Builder(actions).build(); |
124 | } | |
125 | ||
126 | public static Action parallel(List<Action> actions) { | |
127 |
1
1. parallel : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::parallel → KILLED |
return new Composite.Builder(actions).parallel().build(); |
128 | } | |
129 | ||
130 | public static Cmd cmd(String program, ContextVariable... knownVariables) { | |
131 |
1
1. cmd : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::cmd → KILLED |
return cmd(program, CommanderConfig.DEFAULT, knownVariables); |
132 | } | |
133 | ||
134 | public static Cmd cmd(String program, CommanderConfig config, ContextVariable... knownVariables) { | |
135 | Cmd ret = new Cmd(config).commandName(requireNonNull(program).trim()); | |
136 | for (ContextVariable each : knownVariables) | |
137 | ret = ret.declareVariable(each); | |
138 |
1
1. cmd : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::cmd → KILLED |
return ret.append(" "); |
139 | } | |
140 | ||
141 | public static UnixCommanderFactory unix() { | |
142 |
1
1. unix : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::unix → KILLED |
return unix(CommanderConfig.DEFAULT); |
143 | } | |
144 | ||
145 | public static UnixCommanderFactory unix(CommanderConfig config) { | |
146 |
1
1. unix : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::unix → KILLED |
return UnixCommanderFactory.create(config); |
147 | } | |
148 | ||
149 | public static Action simple(String name, Consumer<Context> consumer) { | |
150 |
1
1. simple : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::simple → KILLED |
return leaf(printableConsumer(consumer).describe(name + ":" + toStringIfOverriddenOrNoname(consumer))); |
151 | } | |
152 | ||
153 | /** | |
154 | * Creates an action that performs given actions one by one sequentially. | |
155 | * | |
156 | * @param actions Actions to be performed. | |
157 | * @return An action that performs `actions`. | |
158 | */ | |
159 | public static Action sequential(Action... actions) { | |
160 |
1
1. sequential : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::sequential → KILLED |
return sequential(asList(actions)); |
161 | } | |
162 | ||
163 | /** | |
164 | * Creates an action that performs given actions one by one sequentially. | |
165 | * | |
166 | * @param actions Actions to be performed. | |
167 | * @return An action that performs `actions`. | |
168 | */ | |
169 | public static Action parallel(Action... actions) { | |
170 |
1
1. parallel : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::parallel → KILLED |
return parallel(asList(actions)); |
171 | } | |
172 | ||
173 | /** | |
174 | * Returns an action to build `Ensured` action. | |
175 | * By adding actions to the returned builder's methods, you can construct an `Ensured` action, whose | |
176 | * target action's success is ensured by those added actions. | |
177 | * | |
178 | * @param target An action ensured to be successful. | |
179 | * @return A builder for an `Ensured` action. | |
180 | * @see Ensured | |
181 | */ | |
182 | public static Ensured.Builder ensure(Action target) { | |
183 | Ensured.Builder b = new Ensured.Builder(); | |
184 | b.target(target); | |
185 |
1
1. ensure : replaced return value with null for com/github/dakusui/actionunit/core/ActionSupport::ensure → KILLED |
return b; |
186 | } | |
187 | } | |
188 | ||
Mutations | ||
34 |
1.1 |
|
38 |
1.1 |
|
49 |
1.1 |
|
53 |
1.1 |
|
57 |
1.1 |
|
70 |
1.1 |
|
82 |
1.1 |
|
94 |
1.1 |
|
98 |
1.1 |
|
111 |
1.1 |
|
115 |
1.1 |
|
119 |
1.1 |
|
123 |
1.1 |
|
127 |
1.1 |
|
131 |
1.1 |
|
138 |
1.1 |
|
142 |
1.1 |
|
146 |
1.1 |
|
150 |
1.1 |
|
160 |
1.1 |
|
170 |
1.1 |
|
185 |
1.1 |