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

devonfw / IDEasy / 14975564558

12 May 2025 02:56PM UTC coverage: 67.679% (+0.03%) from 67.649%
14975564558

push

github

web-flow
#1058: fixed missing JAVA_HOME env var (#1100)

3101 of 4990 branches covered (62.14%)

Branch coverage included in aggregate %.

7974 of 11374 relevant lines covered (70.11%)

3.07 hits per line

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

51.35
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> getOut() {
96

97
    return this.outputMessages.stream().filter(outputMessage -> !outputMessage.error()).map(OutputMessage::message).toList();
16✔
98
  }
99

100
  @Override
101
  public List<String> getErr() {
102

103
    return this.outputMessages.stream().filter(OutputMessage::error).map(OutputMessage::message).toList();
9✔
104
  }
105

106
  @Override
107
  public List<OutputMessage> getOutputMessages() {
108

109
    return this.outputMessages;
×
110

111
  }
112

113
  @Override
114
  public void log(IdeLogLevel level, IdeContext context) {
115
    log(level, context, level);
5✔
116
  }
1✔
117

118
  @Override
119
  public void log(IdeLogLevel outLevel, IdeContext context, IdeLogLevel errorLevel) {
120

121
    if (!this.outputMessages.isEmpty()) {
4✔
122
      for (OutputMessage outputMessage : this.outputMessages) {
11✔
123
        if (outputMessage.error()) {
3✔
124
          doLog(errorLevel, outputMessage.message(), context);
7✔
125
        } else {
126
          doLog(outLevel, outputMessage.message(), context);
6✔
127
        }
128
      }
1✔
129
    }
130
  }
1✔
131

132
  private void doLog(IdeLogLevel level, String message, IdeContext context) {
133
    // remove !MESSAGE from log message
134
    if (message.startsWith("!MESSAGE ")) {
4!
135
      message = message.substring(9);
×
136
    }
137
    context.level(level).log(message);
5✔
138
  }
1✔
139

140
  @Override
141
  public void failOnError() throws CliProcessException {
142

143
    if (!isSuccessful()) {
×
144
      throw new CliProcessException(this);
×
145
    }
146
  }
×
147
}
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

© 2025 Coveralls, Inc