From 1c20a31a1c31f9eff166fba4624d891ddf578b04 Mon Sep 17 00:00:00 2001 From: jan-vcapgemini Date: Thu, 12 Dec 2024 13:24:39 +0100 Subject: [PATCH] #877: improved process error message added static getLogLevelFromErrorHandling method to IdeLogLevel removed Internal error message replaced check of ProcessErrorHandling with getLogLevelFromErrorHandling --- .../com/devonfw/tools/ide/log/IdeLogLevel.java | 15 +++++++++++++++ .../tools/ide/process/ProcessContextImpl.java | 12 ++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/cli/src/main/java/com/devonfw/tools/ide/log/IdeLogLevel.java b/cli/src/main/java/com/devonfw/tools/ide/log/IdeLogLevel.java index a6edec6b9..9c6a536b9 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/log/IdeLogLevel.java +++ b/cli/src/main/java/com/devonfw/tools/ide/log/IdeLogLevel.java @@ -1,6 +1,9 @@ package com.devonfw.tools.ide.log; +import java.util.Objects; + import com.devonfw.tools.ide.context.IdeContext; +import com.devonfw.tools.ide.process.ProcessErrorHandling; /** * {@link Enum} with the available log-levels. @@ -74,4 +77,16 @@ public boolean isCustom() { return (this == STEP) || (this == INTERACTION) || (this == SUCCESS) || (this == PROCESSABLE); } + /** + * @param errorHandling the given {@link ProcessErrorHandling}. + * @return matching {@link IdeLogLevel}. + */ + public static IdeLogLevel getLogLevelFromErrorHandling(ProcessErrorHandling errorHandling) { + + if (Objects.requireNonNull(errorHandling) == ProcessErrorHandling.LOG_WARNING) { + return IdeLogLevel.WARNING; + } + return IdeLogLevel.ERROR; + } + } 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 bdd0199c4..155ae08ab 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 @@ -332,18 +332,10 @@ private String addExecutable(String exec, List args) { private void performLogging(ProcessResult result, int exitCode, String interpreter) { if (!result.isSuccessful() && (this.errorHandling != ProcessErrorHandling.NONE)) { - IdeLogLevel ideLogLevel; + IdeLogLevel ideLogLevel = IdeLogLevel.getLogLevelFromErrorHandling(this.errorHandling); + ; String message = createCommandMessage(interpreter, "\nfailed with exit code " + exitCode + "!"); - if (this.errorHandling == ProcessErrorHandling.LOG_ERROR) { - ideLogLevel = IdeLogLevel.ERROR; - } else if (this.errorHandling == ProcessErrorHandling.LOG_WARNING) { - ideLogLevel = IdeLogLevel.WARNING; - } else { - ideLogLevel = IdeLogLevel.ERROR; - this.context.error("Internal error: Undefined error handling {}", this.errorHandling); - } - context.level(ideLogLevel).log(message); result.log(ideLogLevel, context);