Implement maxSeverity tracking on log handler
MODIFY
asciidoctorj-core/src/main/java/org/asciidoctor/jruby/cli/AsciidoctorInvoker.java
asciidoctorj-core/src/main/java/org/asciidoctor/jruby/cli/AsciidoctorInvoker.java
@@ -58,6 +58,9 @@ public class AsciidoctorInvoker {
+ "' missing or cannot be read");
}
+ MaxSeverityLogHandler maxSeverityLogHandler = new MaxSeverityLogHandler();
+ asciidoctor.registerLogHandler(maxSeverityLogHandler);
+
Options options = asciidoctorCliOptions.parse();
if (asciidoctorCliOptions.isRequire()) {
@@ -72,7 +75,7 @@ public class AsciidoctorInvoker {
convertInput(asciidoctor, options, inputFiles);
- if (asciidoctorCliOptions.getFailureLevel().compareTo(asciidoctor.getMaxSeverity()) <= 0) {
+ if (asciidoctorCliOptions.getFailureLevel().compareTo(maxSeverityLogHandler.getMaxSeverity()) <= 0) {
return 1;
}

ADD
asciidoctorj-core/src/main/java/org/asciidoctor/jruby/cli/MaxSeverityLogHandler.java
+package org.asciidoctor.jruby.cli;
+
+import org.asciidoctor.log.LogHandler;
+import org.asciidoctor.log.LogRecord;
+import org.asciidoctor.log.Severity;
+
+public class MaxSeverityLogHandler implements LogHandler {
+ private Severity maxSeverity = Severity.DEBUG;
+
+ @Override
+ public void log(LogRecord logRecord) {
+ if (this.maxSeverity.compareTo(logRecord.getSeverity()) < 0) {
+ this.maxSeverity = logRecord.getSeverity();
+ }
+ }
+
+ public Severity getMaxSeverity() {
+ return this.maxSeverity;
+ }
+}

MODIFY
asciidoctorj-core/src/main/java/org/asciidoctor/jruby/internal/JRubyAsciidoctor.java
asciidoctorj-core/src/main/java/org/asciidoctor/jruby/internal/JRubyAsciidoctor.java
@@ -22,7 +22,6 @@ import org.asciidoctor.jruby.log.internal.LogHandlerRegistryExecutor;
import org.asciidoctor.jruby.syntaxhighlighter.internal.SyntaxHighlighterRegistryExecutor;
import org.asciidoctor.log.LogHandler;
import org.asciidoctor.log.LogRecord;
-import org.asciidoctor.log.Severity;
import org.asciidoctor.syntaxhighlighter.SyntaxHighlighterRegistry;
import org.jruby.*;
import org.jruby.exceptions.RaiseException;
@@ -47,8 +46,6 @@ public class JRubyAsciidoctor implements AsciidoctorJRuby, LogHandler {
private List<LogHandler> logHandlers = new ArrayList<>();
- private Severity maxSeverity = Severity.DEBUG;
-
public JRubyAsciidoctor() {
this(createRubyRuntime(Collections.singletonMap(GEM_PATH, null), new ArrayList<>(), null));
processRegistrations(this);
@@ -510,15 +507,8 @@ public class JRubyAsciidoctor implements AsciidoctorJRuby, LogHandler {
@Override
public void log(LogRecord logRecord) {
- if (this.maxSeverity.compareTo(logRecord.getSeverity()) < 0) {
- this.maxSeverity = logRecord.getSeverity();
- }
for (LogHandler logHandler : logHandlers) {
logHandler.log(logRecord);
}
}
-
- public Severity getMaxSeverity() {
- return this.maxSeverity;
- }
}

Implement maxSeverity tracking on log handler