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

devonfw / IDEasy / 17731386810

15 Sep 2025 11:24AM UTC coverage: 68.556% (-0.07%) from 68.627%
17731386810

Pull #1463

github

web-flow
Merge c92f0398c into 2efad3d2e
Pull Request #1463: #1454: Add ng commandlet

3414 of 5447 branches covered (62.68%)

Branch coverage included in aggregate %.

8902 of 12518 relevant lines covered (71.11%)

3.12 hits per line

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

44.19
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
  /**
26
   * The constructor.
27
   *
28
   * @param executable the {@link #getExecutable() executable}.
29
   * @param command the {@link #getCommand() command}.
30
   * @param exitCode the {@link #getExitCode() exit code}.
31
   * @param outputMessages {@link #getOutputMessages() output Messages}.
32
   */
33
  public ProcessResultImpl(String executable, String command, int exitCode, List<OutputMessage> outputMessages) {
34

35
    super();
2✔
36
    this.executable = executable;
3✔
37
    this.command = command;
3✔
38
    this.exitCode = exitCode;
3✔
39
    this.outputMessages = Objects.requireNonNullElse(outputMessages, Collections.emptyList());
6✔
40
  }
1✔
41

42
  @Override
43
  public String getExecutable() {
44

45
    return this.executable;
×
46
  }
47

48
  @Override
49
  public String getCommand() {
50

51
    return this.command;
3✔
52
  }
53

54
  @Override
55
  public int getExitCode() {
56

57
    return this.exitCode;
3✔
58
  }
59

60
  @Override
61
  public String getSingleOutput(IdeSubLogger logger) throws IllegalStateException {
62
    String errorMessage;
63
    if (this.isSuccessful()) {
3!
64
      List<String> out = this.getOut();
3✔
65
      int size = out.size();
3✔
66
      if (size == 1) {
3!
67
        return out.getFirst();
4✔
68
      } else if (size == 0) {
×
69
        errorMessage = "No output received from " + this.getCommand();
×
70
      } else {
71
        StringBuilder sb = new StringBuilder();
×
72
        sb.append("Expected single line of output but received ");
×
73
        sb.append(size);
×
74
        sb.append(" lines from ");
×
75
        sb.append(this.getCommand());
×
76
        sb.append(":");
×
77
        for (String line : out) {
×
78
          sb.append("\n");
×
79
          sb.append(line);
×
80
        }
×
81
        errorMessage = sb.toString();
×
82
      }
83
    } else {
×
84
      errorMessage = "Command " + this.getCommand() + " failed with exit code " + this.getExitCode();
×
85
    }
86
    if (logger == null) {
×
87
      throw new IllegalStateException(errorMessage);
×
88
    } else {
89
      logger.log(errorMessage);
×
90
      return null;
×
91
    }
92
  }
93

94
  @Override
95
  public List<String> getOutput(IdeSubLogger logger) throws IllegalStateException {
96
    String errorMessage;
97
    if (this.isSuccessful()) {
×
98
      List<String> out = this.getOut();
×
99
      return out;
×
100
    } else {
101
      errorMessage = "Command " + this.getCommand() + " failed with exit code " + this.getExitCode();
×
102
    }
103
    if (logger == null) {
×
104
      throw new IllegalStateException(errorMessage);
×
105
    } else {
106
      logger.log(errorMessage);
×
107
      return null;
×
108
    }
109
  }
110

111
  @Override
112
  public List<String> getOut() {
113

114
    return this.outputMessages.stream().filter(outputMessage -> !outputMessage.error()).map(OutputMessage::message).toList();
16✔
115
  }
116

117
  @Override
118
  public List<String> getErr() {
119

120
    return this.outputMessages.stream().filter(OutputMessage::error).map(OutputMessage::message).toList();
9✔
121
  }
122

123
  @Override
124
  public List<OutputMessage> getOutputMessages() {
125

126
    return this.outputMessages;
×
127

128
  }
129

130
  @Override
131
  public void log(IdeLogLevel level, IdeContext context) {
132
    log(level, context, level);
5✔
133
  }
1✔
134

135
  @Override
136
  public void log(IdeLogLevel outLevel, IdeContext context, IdeLogLevel errorLevel) {
137

138
    if (!this.outputMessages.isEmpty()) {
4✔
139
      for (OutputMessage outputMessage : this.outputMessages) {
11✔
140
        if (outputMessage.error()) {
3✔
141
          doLog(errorLevel, outputMessage.message(), context);
7✔
142
        } else {
143
          doLog(outLevel, outputMessage.message(), context);
6✔
144
        }
145
      }
1✔
146
    }
147
  }
1✔
148

149
  private void doLog(IdeLogLevel level, String message, IdeContext context) {
150
    // remove !MESSAGE from log message
151
    if (message.startsWith("!MESSAGE ")) {
4!
152
      message = message.substring(9);
×
153
    }
154
    context.level(level).log(message);
5✔
155
  }
1✔
156

157
  @Override
158
  public void failOnError() throws CliProcessException {
159

160
    if (!isSuccessful()) {
×
161
      throw new CliProcessException(this);
×
162
    }
163
  }
×
164
}
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