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

devonfw / IDEasy / 22300285724

23 Feb 2026 09:32AM UTC coverage: 70.754% (+0.3%) from 70.474%
22300285724

Pull #1714

github

web-flow
Merge caa980897 into 379acdc9d
Pull Request #1714: #404: #1713: advanced logging

4064 of 6348 branches covered (64.02%)

Branch coverage included in aggregate %.

10640 of 14434 relevant lines covered (73.71%)

3.1 hits per line

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

51.61
cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java
1
package com.devonfw.tools.ide.process;
2

3
import java.util.Collections;
4
import java.util.List;
5
import java.util.Objects;
6

7
import org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
9

10
import com.devonfw.tools.ide.cli.CliProcessException;
11
import com.devonfw.tools.ide.log.IdeLogLevel;
12

13
/**
14
 * Implementation of {@link ProcessResult}.
15
 */
16
public class ProcessResultImpl implements ProcessResult {
17

18
  private static final Logger LOG = LoggerFactory.getLogger(ProcessResultImpl.class);
4✔
19

20
  private final String executable;
21

22
  private final String command;
23

24
  private final int exitCode;
25

26
  private final List<OutputMessage> outputMessages;
27

28
  private final boolean success;
29

30
  /**
31
   * The constructor.
32
   *
33
   * @param executable the {@link #getExecutable() executable}.
34
   * @param command the {@link #getCommand() command}.
35
   * @param exitCode the {@link #getExitCode() exit code}.
36
   * @param outputMessages {@link #getOutputMessages() output Messages}.
37
   */
38
  public ProcessResultImpl(String executable, String command, int exitCode, List<OutputMessage> outputMessages) {
39
    this(executable, command, exitCode, exitCode == SUCCESS, outputMessages);
11✔
40
  }
1✔
41

42
  /**
43
   * The constructor.
44
   *
45
   * @param executable the {@link #getExecutable() executable}.
46
   * @param command the {@link #getCommand() command}.
47
   * @param exitCode the {@link #getExitCode() exit code}.
48
   * @param success the {@link #isSuccessful() success} flag.
49
   * @param outputMessages {@link #getOutputMessages() output Messages}.
50
   */
51
  public ProcessResultImpl(String executable, String command, int exitCode, boolean success, List<OutputMessage> outputMessages) {
52

53
    super();
2✔
54
    this.executable = executable;
3✔
55
    this.command = command;
3✔
56
    this.exitCode = exitCode;
3✔
57
    this.success = success;
3✔
58
    this.outputMessages = Objects.requireNonNullElse(outputMessages, Collections.emptyList());
6✔
59
  }
1✔
60

61
  @Override
62
  public String getExecutable() {
63

64
    return this.executable;
×
65
  }
66

67
  @Override
68
  public String getCommand() {
69

70
    return this.command;
3✔
71
  }
72

73
  @Override
74
  public int getExitCode() {
75

76
    return this.exitCode;
3✔
77
  }
78

79
  @Override
80
  public String getSingleOutput(IdeLogLevel logLevel) throws IllegalStateException {
81
    String errorMessage;
82
    if (this.isSuccessful()) {
3!
83
      List<String> out = this.getOut();
3✔
84
      int size = out.size();
3✔
85
      if (size == 1) {
3!
86
        return out.getFirst();
4✔
87
      } else if (size == 0) {
×
88
        errorMessage = "No output received from " + this.getCommand();
×
89
      } else {
90
        StringBuilder sb = new StringBuilder();
×
91
        sb.append("Expected single line of output but received ");
×
92
        sb.append(size);
×
93
        sb.append(" lines from ");
×
94
        sb.append(this.getCommand());
×
95
        sb.append(":");
×
96
        for (String line : out) {
×
97
          sb.append("\n");
×
98
          sb.append(line);
×
99
        }
×
100
        errorMessage = sb.toString();
×
101
      }
102
    } else {
×
103
      errorMessage = "Command " + this.getCommand() + " failed with exit code " + this.getExitCode();
×
104
    }
105
    if (logLevel == null) {
×
106
      throw new IllegalStateException(errorMessage);
×
107
    } else {
108
      doLog(logLevel, errorMessage);
×
109
      return null;
×
110
    }
111
  }
112

113
  @Override
114
  public List<String> getOutput(IdeLogLevel logLevel) throws IllegalStateException {
115
    String errorMessage;
116
    if (this.isSuccessful()) {
×
117
      List<String> out = this.getOut();
×
118
      return out;
×
119
    } else {
120
      errorMessage = "Command " + this.getCommand() + " failed with exit code " + this.getExitCode();
×
121
    }
122
    if (logLevel == null) {
×
123
      throw new IllegalStateException(errorMessage);
×
124
    } else {
125
      doLog(logLevel, errorMessage);
×
126
      return null;
×
127
    }
128
  }
129

130
  @Override
131
  public List<String> getOut() {
132

133
    return this.outputMessages.stream().filter(outputMessage -> !outputMessage.error()).map(OutputMessage::message).toList();
16✔
134
  }
135

136
  @Override
137
  public List<String> getErr() {
138

139
    return this.outputMessages.stream().filter(OutputMessage::error).map(OutputMessage::message).toList();
9✔
140
  }
141

142
  @Override
143
  public List<OutputMessage> getOutputMessages() {
144

145
    return this.outputMessages;
×
146
  }
147

148
  @Override
149
  public boolean isSuccessful() {
150

151
    return this.success;
3✔
152
  }
153

154
  @Override
155
  public void log(IdeLogLevel level) {
156
    log(level, level);
4✔
157
  }
1✔
158

159
  @Override
160
  public void log(IdeLogLevel outLevel, IdeLogLevel errorLevel) {
161

162
    if (!this.outputMessages.isEmpty()) {
4✔
163
      for (OutputMessage outputMessage : this.outputMessages) {
11✔
164
        if (outputMessage.error()) {
3✔
165
          doLog(errorLevel, outputMessage.message());
6✔
166
        } else {
167
          doLog(outLevel, outputMessage.message());
5✔
168
        }
169
      }
1✔
170
    }
171
  }
1✔
172

173
  private void doLog(IdeLogLevel level, String message) {
174
    // remove !MESSAGE from log message
175
    if (message.startsWith("!MESSAGE ")) {
4!
176
      message = message.substring(9);
×
177
    }
178
    LOG.atLevel(level.getSlf4jLevel()).log(message);
6✔
179
  }
1✔
180

181
  @Override
182
  public void failOnError() throws CliProcessException {
183

184
    if (!isSuccessful()) {
3!
185
      throw new CliProcessException(this);
×
186
    }
187
  }
1✔
188
}
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