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

devonfw / IDEasy / 7257029760

19 Dec 2023 03:34AM UTC coverage: 46.569%. First build
7257029760

Pull #150

github

web-flow
Merge c55c4a8c2 into 1d60d9c17
Pull Request #150: #102: implement update commandlet

1031 of 2451 branches covered (0.0%)

Branch coverage included in aggregate %.

2736 of 5638 relevant lines covered (48.53%)

2.0 hits per line

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

0.0
cli/src/main/java/com/devonfw/tools/ide/common/StepContainer.java
1
package com.devonfw.tools.ide.common;
2

3
import com.devonfw.tools.ide.cli.CliException;
4
import com.devonfw.tools.ide.context.IdeContext;
5

6
import java.util.ArrayList;
7
import java.util.List;
8

9
/**
10
 * A utility class to manage and log the progress of steps in a process.
11
 * Each step can be started, ended with success or failure, and the overall completion
12
 * status can be checked.
13
 * @throws CliException if one or more steps fail.
14
 */
15
public class StepContainer {
16

17
  private final IdeContext context;
18

19
  /** List of steps that ended successfully. */
20
  private List<String> successfulSteps;
21

22
  /** List of steps that failed. */
23
  private List<String> failedSteps;
24

25
  /**
26
   * The constructor.
27
   *
28
   * @param context the {@link IdeContext}.
29
   */
30
  public StepContainer(IdeContext context) {
×
31

32
    this.context = context;
×
33
    successfulSteps = new ArrayList<>();
×
34
    failedSteps = new ArrayList<>();
×
35
  }
×
36

37
  /**
38
   * Logs the start of a step.
39
   *
40
   * @param stepName the name of the step.
41
   */
42
  public void startStep(String stepName) {
43

44
    this.context.step("Starting step: {}", stepName);
×
45
  }
×
46

47
  /**
48
   * Logs the end of a step, indicating success or failure.
49
   *
50
   * @param stepName the name of the step.
51
   * @param success {@code true} if the step succeeded, {@code false} otherwise.
52
   * @param e the exception associated with the failure, or {@code null} if the step succeeded.
53
   */
54
  public void endStep(String stepName, boolean success, Throwable e) {
55

56
    if (success) {
×
57
      successfulSteps.add(stepName);
×
58
      this.context.success("Step '{}' succeeded.", stepName);
×
59
    } else {
60
      failedSteps.add(stepName);
×
61
      this.context.warning("Step '{}' failed.", stepName);
×
62
      if (e != null) {
×
63
        this.context.error(e);
×
64
      }
65
    }
66
  }
×
67

68
  /**
69
   * Checks the overall completion status of all steps.
70
   *
71
   * @throws CliException if one or more steps fail, providing a detailed summary.
72
   */
73
  public void complete() {
74

75
    if (failedSteps.isEmpty()) {
×
76
      this.context.success("All {} steps ended successfully!", successfulSteps.size());
×
77
    } else {
78
      throw new CliException(String.format("%d step(s) failed (%d%%) and %d step(s) succeeded (%d%%) out of %d step(s)!",
×
79
          failedSteps.size(), calculatePercentage(failedSteps.size()), successfulSteps.size(),
×
80
          100 - calculatePercentage(failedSteps.size()), successfulSteps.size() + failedSteps.size()));
×
81
    }
82
  }
×
83

84
  private int calculatePercentage(int count) {
85

86
    return (count * 100) / (successfulSteps.size() + failedSteps.size());
×
87
  }
88

89
}
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