diff --git a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessContextImpl.java b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessContextImpl.java index c2e1dc62f..4de098bc5 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessContextImpl.java +++ b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessContextImpl.java @@ -20,7 +20,6 @@ import com.devonfw.tools.ide.context.IdeContext; import com.devonfw.tools.ide.environment.VariableLine; import com.devonfw.tools.ide.log.IdeLogLevel; -import com.devonfw.tools.ide.log.IdeSubLogger; import com.devonfw.tools.ide.os.SystemInfoImpl; import com.devonfw.tools.ide.os.WindowsPathSyntax; import com.devonfw.tools.ide.util.FilenameUtil; @@ -316,34 +315,25 @@ private String addExecutable(String exec, List args) { private void performLogOnError(ProcessResult result, int exitCode, String interpreter) { if (!result.isSuccessful() && (this.errorHandling != ProcessErrorHandling.NONE)) { - IdeSubLogger subLogger = this.context.error(); IdeLogLevel ideLogLevel; String message = createCommandMessage(interpreter, "\nfailed with exit code " + exitCode + "!"); - if (this.errorHandling == ProcessErrorHandling.THROW_CLI) { - subLogger.log(message); - result.log(IdeLogLevel.ERROR, context); - throw new CliProcessException(message, result); - } else if (this.errorHandling == ProcessErrorHandling.THROW_ERR) { - subLogger.log(message); - result.log(IdeLogLevel.ERROR, context); - throw new IllegalStateException(message); - } - if (this.errorHandling == ProcessErrorHandling.LOG_ERROR) { ideLogLevel = IdeLogLevel.ERROR; - subLogger = this.context.error(); } else if (this.errorHandling == ProcessErrorHandling.LOG_WARNING) { ideLogLevel = IdeLogLevel.WARNING; - subLogger = this.context.warning(); } else { ideLogLevel = IdeLogLevel.ERROR; - subLogger = this.context.error(); this.context.error("Internal error: Undefined error handling {}", this.errorHandling); } - subLogger.log(message); result.log(ideLogLevel, context); + + if (this.errorHandling == ProcessErrorHandling.THROW_CLI) { + throw new CliProcessException(message, result); + } else if (this.errorHandling == ProcessErrorHandling.THROW_ERR) { + throw new IllegalStateException(message); + } } } diff --git a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java index 5f758d117..857a07dcd 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java +++ b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessResultImpl.java @@ -2,6 +2,7 @@ import java.util.Collections; import java.util.List; +import java.util.Objects; import com.devonfw.tools.ide.context.IdeContext; import com.devonfw.tools.ide.log.IdeLogLevel; @@ -28,16 +29,8 @@ public ProcessResultImpl(int exitCode, List out, List err) { super(); this.exitCode = exitCode; - if (out == null) { - this.out = Collections.emptyList(); - } else { - this.out = out; - } - if (err == null) { - this.err = Collections.emptyList(); - } else { - this.err = err; - } + this.out = Objects.requireNonNullElse(out, Collections.emptyList()); + this.err = Objects.requireNonNullElse(err, Collections.emptyList()); } @Override @@ -61,10 +54,10 @@ public List getErr() { @Override public void log(IdeLogLevel level, IdeContext context) { - if (this.out != null && !this.out.isEmpty() && level == IdeLogLevel.INFO) { + if (!this.out.isEmpty()) { doLog(level, this.out, context); } - if (this.err != null && !this.err.isEmpty() && level == IdeLogLevel.ERROR) { + if (!this.err.isEmpty()) { doLog(level, this.err, context); } }