Skip to content

Commit 98a8767

Browse files
pasieronenrobertpanzer
authored andcommitted
Implement maxSeverity tracking on log handler
1 parent 4d5128e commit 98a8767

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

asciidoctorj-core/src/main/java/org/asciidoctor/jruby/cli/AsciidoctorInvoker.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public int invoke(String... parameters) {
5858
+ "' missing or cannot be read");
5959
}
6060

61+
MaxSeverityLogHandler maxSeverityLogHandler = new MaxSeverityLogHandler();
62+
asciidoctor.registerLogHandler(maxSeverityLogHandler);
63+
6164
Options options = asciidoctorCliOptions.parse();
6265

6366
if (asciidoctorCliOptions.isRequire()) {
@@ -72,7 +75,7 @@ public int invoke(String... parameters) {
7275

7376
convertInput(asciidoctor, options, inputFiles);
7477

75-
if (asciidoctorCliOptions.getFailureLevel().compareTo(asciidoctor.getMaxSeverity()) <= 0) {
78+
if (asciidoctorCliOptions.getFailureLevel().compareTo(maxSeverityLogHandler.getMaxSeverity()) <= 0) {
7679
return 1;
7780
}
7881

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.asciidoctor.jruby.cli;
2+
3+
import org.asciidoctor.log.LogHandler;
4+
import org.asciidoctor.log.LogRecord;
5+
import org.asciidoctor.log.Severity;
6+
7+
public class MaxSeverityLogHandler implements LogHandler {
8+
private Severity maxSeverity = Severity.DEBUG;
9+
10+
@Override
11+
public void log(LogRecord logRecord) {
12+
if (this.maxSeverity.compareTo(logRecord.getSeverity()) < 0) {
13+
this.maxSeverity = logRecord.getSeverity();
14+
}
15+
}
16+
17+
public Severity getMaxSeverity() {
18+
return this.maxSeverity;
19+
}
20+
}

asciidoctorj-core/src/main/java/org/asciidoctor/jruby/internal/JRubyAsciidoctor.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.asciidoctor.jruby.syntaxhighlighter.internal.SyntaxHighlighterRegistryExecutor;
2323
import org.asciidoctor.log.LogHandler;
2424
import org.asciidoctor.log.LogRecord;
25-
import org.asciidoctor.log.Severity;
2625
import org.asciidoctor.syntaxhighlighter.SyntaxHighlighterRegistry;
2726
import org.jruby.*;
2827
import org.jruby.exceptions.RaiseException;
@@ -47,8 +46,6 @@ public class JRubyAsciidoctor implements AsciidoctorJRuby, LogHandler {
4746

4847
private List<LogHandler> logHandlers = new ArrayList<>();
4948

50-
private Severity maxSeverity = Severity.DEBUG;
51-
5249
public JRubyAsciidoctor() {
5350
this(createRubyRuntime(Collections.singletonMap(GEM_PATH, null), new ArrayList<>(), null));
5451
processRegistrations(this);
@@ -510,15 +507,8 @@ private RubyClass getExtensionGroupClass() {
510507

511508
@Override
512509
public void log(LogRecord logRecord) {
513-
if (this.maxSeverity.compareTo(logRecord.getSeverity()) < 0) {
514-
this.maxSeverity = logRecord.getSeverity();
515-
}
516510
for (LogHandler logHandler : logHandlers) {
517511
logHandler.log(logRecord);
518512
}
519513
}
520-
521-
public Severity getMaxSeverity() {
522-
return this.maxSeverity;
523-
}
524514
}

0 commit comments

Comments
 (0)