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

devonfw / IDEasy / 21174240071

20 Jan 2026 02:00PM UTC coverage: 70.447% (-0.02%) from 70.471%
21174240071

Pull #1681

github

web-flow
Merge a3e58d5e7 into 365b39a49
Pull Request #1681: #1679: fix determine version if npm list has exit code 1

4031 of 6308 branches covered (63.9%)

Branch coverage included in aggregate %.

10479 of 14289 relevant lines covered (73.34%)

3.18 hits per line

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

51.09
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 com.devonfw.tools.ide.cli.CliProcessException;
8
import com.devonfw.tools.ide.context.IdeContext;
9
import com.devonfw.tools.ide.log.IdeLogLevel;
10
import com.devonfw.tools.ide.log.IdeSubLogger;
11

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

17
  private final String executable;
18

19
  private final String command;
20

21
  private final int exitCode;
22

23
  private final List<OutputMessage> outputMessages;
24

25
  private final boolean success;
26

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

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

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

58
  @Override
59
  public String getExecutable() {
60

61
    return this.executable;
×
62
  }
63

64
  @Override
65
  public String getCommand() {
66

67
    return this.command;
3✔
68
  }
69

70
  @Override
71
  public int getExitCode() {
72

73
    return this.exitCode;
3✔
74
  }
75

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

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

127
  @Override
128
  public List<String> getOut() {
129

130
    return this.outputMessages.stream().filter(outputMessage -> !outputMessage.error()).map(OutputMessage::message).toList();
16✔
131
  }
132

133
  @Override
134
  public List<String> getErr() {
135

136
    return this.outputMessages.stream().filter(OutputMessage::error).map(OutputMessage::message).toList();
9✔
137
  }
138

139
  @Override
140
  public List<OutputMessage> getOutputMessages() {
141

142
    return this.outputMessages;
×
143
  }
144

145
  @Override
146
  public boolean isSuccessful() {
147

148
    return this.success;
3✔
149
  }
150

151
  @Override
152
  public void log(IdeLogLevel level, IdeContext context) {
153
    log(level, context, level);
5✔
154
  }
1✔
155

156
  @Override
157
  public void log(IdeLogLevel outLevel, IdeContext context, IdeLogLevel errorLevel) {
158

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

170
  private void doLog(IdeLogLevel level, String message, IdeContext context) {
171
    // remove !MESSAGE from log message
172
    if (message.startsWith("!MESSAGE ")) {
4!
173
      message = message.substring(9);
×
174
    }
175
    context.level(level).log(message);
5✔
176
  }
1✔
177

178
  @Override
179
  public void failOnError() throws CliProcessException {
180

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