• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

devonfw / IDEasy / 19651727463

24 Nov 2025 10:43PM UTC coverage: 69.156% (+0.1%) from 69.024%
19651727463

push

github

web-flow
#1144: #1145: CVE warnings and suggestions (#1593)

Co-authored-by: KianRolf <kian.loroff@capgemini.com>
Co-authored-by: jan-vcapgemini <59438728+jan-vcapgemini@users.noreply.github.com>

3613 of 5721 branches covered (63.15%)

Branch coverage included in aggregate %.

9387 of 13077 relevant lines covered (71.78%)

3.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

53.03
cli/src/main/java/com/devonfw/tools/ide/step/Step.java
1
package com.devonfw.tools.ide.step;
2

3
import java.util.concurrent.Callable;
4
import java.util.function.Supplier;
5

6
import com.devonfw.tools.ide.log.IdeSubLogger;
7

8
/**
9
 * Interface for a {@link Step} of the process. Allows to split larger processes into smaller steps that are traced and measured. Also prevents that if one step
10
 * fails, the overall process can still continue so a sub-step (e.g. "plugin installation" or "git update") does not automatically block the entire process. At
11
 * the end you can get a report with the hierarchy of all steps and their success/failure status, duration in absolute and relative numbers to gain
12
 * transparency.<br> The typical use should follow this pattern:
13
 *
14
 * <pre>
15
 * Step step = context.{@link com.devonfw.tools.ide.context.IdeContext#newStep(String) newStep}("My step description");
16
 * step.run(() -> {
17
 *   // ... do something ...
18
 *   if (success) {
19
 *     step.{@link #success(String) success}("Did something successfully.");
20
 *   } else {
21
 *     step.{@link #error(String) error}("Failed to do something.");
22
 *   }
23
 * });
24
 * </pre>
25
 * No need to manually catch exceptions and report them as error. All this will happen automatically in {@link #run(Runnable)} method. You may pass a private
26
 * method as lambda to avoid multiline lambda syntax.
27
 */
28
public interface Step {
2!
29

30
  /**
31
   * Empty object array for no parameters.
32
   */
33
  Object[] NO_PARAMS = new Object[0];
4✔
34

35
  /**
36
   * @return the name of this {@link Step} as given to constructor.
37
   */
38
  String getName();
39

40
  /**
41
   * @return the duration of this {@link Step} from construction to {@link #success()} or {@link #close()}. Will be {@code 0} if not {@link #close() ended}.
42
   */
43
  long getDuration();
44

45
  /**
46
   * @return {@code Boolean#TRUE} if this {@link Step} has {@link #success() succeeded}, {@code Boolean#FALSE} if the {@link Step} has {@link #close() ended}
47
   *     without {@link #success() success} and {@code null} if the {@link Step} is still running.
48
   */
49
  Boolean getSuccess();
50

51
  /**
52
   * @return {@code true} if this step completed {@link #success() successfully}, {@code false} otherwise.
53
   */
54
  default boolean isSuccess() {
55

56
    return Boolean.TRUE.equals(getSuccess());
×
57
  }
58

59
  /**
60
   * @return {@code true} if this step {@link #close() ended} without {@link #success() success} e.g. with an {@link #error(String) error}, {@code false}
61
   *     otherwise.
62
   */
63
  default boolean isFailure() {
64

65
    return Boolean.FALSE.equals(getSuccess());
×
66
  }
67

68
  /**
69
   * @return {@code true} if this step is silent and not logged by default, {@code false} otherwise (default).
70
   */
71
  boolean isSilent();
72

73
  /**
74
   * Should be called to end this {@link Step} {@link #getSuccess() successfully}. May be called only once.
75
   */
76
  default void success() {
77

78
    success(null);
3✔
79
  }
1✔
80

81
  /**
82
   * Should be called to end this {@link Step} {@link #getSuccess() successfully}. May be called only once.
83
   *
84
   * @param message the explicit message to log as success.
85
   */
86
  default void success(String message) {
87

88
    success(message, (Object[]) null);
5✔
89
  }
1✔
90

91
  /**
92
   * Should be called to end this {@link Step} {@link #getSuccess() successfully}. May be called only once.
93
   *
94
   * @param message the explicit message to log as success.
95
   * @param args the optional arguments to fill as placeholder into the {@code message}.
96
   */
97
  void success(String message, Object... args);
98

99
  /**
100
   * @return the {@link IdeSubLogger} for success messages allowing generic code sharing logger fallback.
101
   */
102
  IdeSubLogger asSuccess();
103

104
  /**
105
   * Ensures this {@link Step} is properly ended. Has to be called from a finally block. Do not call manually but always use {@link #run(Runnable)} or
106
   * {@link #call(Callable)}.
107
   */
108
  void close();
109

110
  /**
111
   * Should be called to end this {@link Step} as {@link #isFailure() failure} with an explicit error message. May be called only once.
112
   *
113
   * @param message the explicit message to log as error.
114
   */
115
  default void error(String message) {
116

117
    error(null, message);
4✔
118
  }
1✔
119

120
  /**
121
   * Should be called to end this {@link Step} as {@link #isFailure() failure} with an explicit error message and/or {@link Throwable exception}. May be called
122
   * only once.
123
   *
124
   * @param message the explicit message to log as error.
125
   * @param args the optional arguments to fill as placeholder into the {@code message}.
126
   */
127
  default void error(String message, Object... args) {
128

129
    error(null, message, args);
5✔
130
  }
1✔
131

132
  /**
133
   * Should be called to end this {@link Step} as {@link #isFailure() failure} with an explicit error message and/or {@link Throwable exception}. May be called
134
   * only once.
135
   *
136
   * @param error the catched {@link Throwable}.
137
   */
138
  default void error(Throwable error) {
139

140
    error(error, false);
4✔
141
  }
1✔
142

143
  /**
144
   * Should be called to end this {@link Step} as {@link #isFailure() failure} with an explicit error message and/or {@link Throwable exception}. May be called
145
   * only once.
146
   *
147
   * @param error the catched {@link Throwable}.
148
   * @param suppress to suppress the error logging (if error will be rethrown and duplicated error messages shall be avoided).
149
   */
150
  default void error(Throwable error, boolean suppress) {
151

152
    assert (error != null);
4!
153
    error(error, suppress, null, (Object[]) null);
7✔
154
  }
1✔
155

156
  /**
157
   * Should be called to end this {@link Step} as {@link #isFailure() failure} with an explicit error message and/or {@link Throwable exception}. May be called
158
   * only once.
159
   *
160
   * @param error the catched {@link Throwable}. May be {@code null} if only a {@code message} is provided.
161
   * @param message the explicit message to log as error.
162
   */
163
  default void error(Throwable error, String message) {
164

165
    error(error, message, (Object[]) null);
6✔
166
  }
1✔
167

168
  /**
169
   * Should be called to end this {@link Step} as {@link #isFailure() failure} with an explicit error message and/or {@link Throwable exception}. May be called
170
   * only once.
171
   *
172
   * @param error the catched {@link Throwable}. May be {@code null} if only a {@code message} is provided.
173
   * @param message the explicit message to log as error.
174
   * @param args the optional arguments to fill as placeholder into the {@code message}.
175
   */
176
  default void error(Throwable error, String message, Object... args) {
177

178
    error(error, false, message, args);
6✔
179
  }
1✔
180

181
  /**
182
   * Should be called to end this {@link Step} as {@link #isFailure() failure} with an explicit error message and/or {@link Throwable exception}. May be called
183
   * only once.
184
   *
185
   * @param error the catched {@link Throwable}. May be {@code null} if only a {@code message} is provided.
186
   * @param suppress to suppress the error logging (if error will be rethrown and duplicated error messages shall be avoided).
187
   * @param message the explicit message to log as error.
188
   * @param args the optional arguments to fill as placeholder into the {@code message}.
189
   */
190
  void error(Throwable error, boolean suppress, String message, Object... args);
191

192
  /**
193
   * @return the {@link IdeSubLogger} for error messages allowing generic code sharing logger fallback.
194
   */
195
  IdeSubLogger asError();
196

197
  /**
198
   * @return the parent {@link Step} or {@code null} if there is no parent.
199
   */
200
  Step getParent();
201

202
  /**
203
   * @param i the index of the requested parameter. Should be in the range from {@code 0} to
204
   *     <code>{@link #getParameterCount()}-1</code>.
205
   * @return the parameter at the given index {@code i} or {@code null} if no such parameter exists.
206
   */
207
  Object getParameter(int i);
208

209
  /**
210
   * @return the number of {@link #getParameter(int) parameters}.
211
   */
212
  int getParameterCount();
213

214
  /**
215
   * @param stepCode the {@link Runnable} to {@link Runnable#run() execute} for this {@link Step}.
216
   * @return {@code true} on success, {@code false} on error.
217
   */
218
  default boolean run(Runnable stepCode) {
219

220
    return run(stepCode, false);
5✔
221
  }
222

223
  /**
224
   * @param stepCode the {@link Runnable} to {@link Runnable#run() execute} for this {@link Step}.
225
   * @param rethrow - {@code true} to rethrow a potential {@link Throwable error}.
226
   * @return {@code true} on success, {@code false} on error (if {@code rethrow} is {@code false}).
227
   */
228
  default boolean run(Runnable stepCode, boolean rethrow) {
229

230
    try {
231
      stepCode.run();
2✔
232
      if (getSuccess() == null) {
3✔
233
        success();
2✔
234
      }
235
      return true;
4✔
236
    } catch (RuntimeException | Error e) {
1✔
237
      error(e);
3✔
238
      if (rethrow) {
2!
239
        throw e;
×
240
      }
241
      return false;
4✔
242
    } finally {
243
      close();
2✔
244
    }
245
  }
246

247
  /**
248
   * @param stepCode the {@link Callable} to {@link Callable#call() execute} for this {@link Step}.
249
   * @param <R> type of the return value.
250
   * @return the value returned from {@link Callable#call()}.
251
   */
252
  default <R> R call(Callable<R> stepCode) {
253

254
    return call(stepCode, true, null);
×
255
  }
256

257
  /**
258
   * @param stepCode the {@link Callable} to {@link Callable#call() execute} for this {@link Step}.
259
   * @param resultOnErrorSupplier the {@link Supplier} {@link Supplier#get() providing} the result to be returned in case of a {@link Throwable error}.
260
   * @param <R> type of the return value.
261
   * @return the value returned from {@link Callable#call()}.
262
   */
263
  default <R> R call(Callable<R> stepCode, Supplier<R> resultOnErrorSupplier) {
264

265
    return call(stepCode, false, resultOnErrorSupplier);
×
266
  }
267

268
  /**
269
   * @param stepCode the {@link Callable} to {@link Callable#call() execute} for this {@link Step}.
270
   * @param rethrow - {@code true} to rethrow a potential {@link Throwable error}.
271
   * @param resultOnErrorSupplier the {@link Supplier} {@link Supplier#get() providing} the result to be returned in case of a {@link Throwable error}.
272
   * @param <R> type of the return value.
273
   * @return the value returned from {@link Callable#call()}.
274
   */
275
  default <R> R call(Callable<R> stepCode, boolean rethrow, Supplier<R> resultOnErrorSupplier) {
276

277
    try {
278
      R result = stepCode.call();
×
279
      if (getSuccess() == null) {
×
280
        success();
×
281
      }
282
      return result;
×
283
    } catch (Throwable e) {
×
284
      error(e);
×
285
      if (rethrow) {
×
286
        if (e instanceof RuntimeException re) {
×
287
          throw re;
×
288
        } else if (e instanceof Error error) {
×
289
          throw error;
×
290
        } else {
291
          throw new IllegalStateException(e);
×
292
        }
293
      }
294
      return resultOnErrorSupplier.get();
×
295
    } finally {
296
      close();
×
297
    }
298
  }
299

300
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc