From 38a60bc28dff61ce267561178a79322e271dce26 Mon Sep 17 00:00:00 2001 From: jan-vcapgemini Date: Thu, 12 Dec 2024 14:12:03 +0100 Subject: [PATCH] #877: implemented requested changes replaced getLogLevelFromErrorHandling with getLogLevel --- .../com/devonfw/tools/ide/log/IdeLogLevel.java | 15 --------------- .../tools/ide/process/ProcessContextImpl.java | 3 +-- .../tools/ide/process/ProcessErrorHandling.java | 13 ++++++++++++- 3 files changed, 13 insertions(+), 18 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 9c6a536b9..a6edec6b9 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,9 +1,6 @@ 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. @@ -77,16 +74,4 @@ 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 155ae08ab..3290b8cf0 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,8 +332,7 @@ 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.getLogLevelFromErrorHandling(this.errorHandling); - ; + IdeLogLevel ideLogLevel = this.errorHandling.getLogLevel(); String message = createCommandMessage(interpreter, "\nfailed with exit code " + exitCode + "!"); context.level(ideLogLevel).log(message); diff --git a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessErrorHandling.java b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessErrorHandling.java index 640082b82..a46e7f6c0 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessErrorHandling.java +++ b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessErrorHandling.java @@ -1,5 +1,7 @@ package com.devonfw.tools.ide.process; +import com.devonfw.tools.ide.log.IdeLogLevel; + /** * {@link Enum} with the available handling if a {@link Process#exitValue() status code} was not {@link ProcessResult#SUCCESS successful}. */ @@ -26,6 +28,15 @@ public enum ProcessErrorHandling { * Throw an exception if the status code was not successful. In this case the {@link ProcessContext#run() run} method will never return an exit code other * than {@link ProcessResult#SUCCESS} as otherwise an exception is thrown preventing the method to return. */ - THROW_ERR + THROW_ERR; + /** + * @return the matching {@link IdeLogLevel}. + */ + public IdeLogLevel getLogLevel() { + if (this.equals(LOG_WARNING)) { + return IdeLogLevel.WARNING; + } + return IdeLogLevel.ERROR; + } }