Skip to content

Commit

Permalink
devonfw#877: implemented requested changes
Browse files Browse the repository at this point in the history
replaced getLogLevelFromErrorHandling with getLogLevel
  • Loading branch information
jan-vcapgemini committed Dec 12, 2024
1 parent 1c20a31 commit 38a60bc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
15 changes: 0 additions & 15 deletions cli/src/main/java/com/devonfw/tools/ide/log/IdeLogLevel.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,7 @@ private String addExecutable(String exec, List<String> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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}.
*/
Expand All @@ -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;
}
}

0 comments on commit 38a60bc

Please sign in to comment.