Skip to content

Commit

Permalink
devonfw#608: implemented requested changes
Browse files Browse the repository at this point in the history
removed SubLogger
moved throw of exceptions after logger
optimized out and err creation
removed level checks for logger
  • Loading branch information
jan-vcapgemini committed Oct 21, 2024
1 parent e516604 commit 42f59f5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -316,34 +315,25 @@ private String addExecutable(String exec, List<String> 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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,16 +29,8 @@ public ProcessResultImpl(int exitCode, List<String> out, List<String> 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
Expand All @@ -61,10 +54,10 @@ public List<String> 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);
}
}
Expand Down

0 comments on commit 42f59f5

Please sign in to comment.