org.asciidoctor.log.LogRecord Java Examples

The following examples show how to use org.asciidoctor.log.LogRecord. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WhenAsciidoctorLogsToConsole.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
@Test
public void a_extension_should_be_able_to_log() throws Exception {

    final List<LogRecord> logRecords = new ArrayList<>();

    asciidoctor.registerLogHandler(logRecords::add);
    asciidoctor.javaExtensionRegistry().block(LoggingProcessor.class);

    String renderContent = asciidoctor.convert("= Test\n\n== Something different\n\n[big]\nHello World",
            options().option("sourcemap", "true").asMap());

    assertEquals(1, logRecords.size());
    assertThat(logRecords.get(0).getMessage(), is("Hello Log"));
    final Cursor cursor = logRecords.get(0).getCursor();
    assertThat(cursor.getLineNumber(), is(3));

    assertThat(renderContent, containsString("HELLO WORLD"));
}
 
Example #2
Source File: WhenAsciidoctorLogsToConsole.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldLogInvalidRefs() throws Exception {

    final List<LogRecord> logRecords = new ArrayList<>();

    asciidoctor.registerLogHandler(logRecords::add);

    File inputFile = classpath.getResource("documentwithinvalidrefs.adoc");
    String renderContent = asciidoctor.convertFile(inputFile,
            options()
                    .inPlace(true)
                    .safe(SafeMode.SERVER)
                    .toFile(false)
                    .attributes(
                            AttributesBuilder.attributes().allowUriRead(true))
                    .asMap());

    assertThat(logRecords, hasSize(1));
    assertThat(logRecords.get(0).getMessage(), containsString("invalid reference: invalidref"));
    final Cursor cursor = logRecords.get(0).getCursor();
    assertThat(cursor, is(nullValue()));
}
 
Example #3
Source File: LogRecordHelper.java    From asciidoctor-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Formats the logRecord in a similar manner to original Asciidoctor.
 * Note: prints the relative path of the file to `sourceDirectory`.
 *
 * @param logRecord       Asciidoctor logRecord to format
 * @param sourceDirectory source directory of the converted AsciiDoc document
 * @return Asciidoctor-like formatted string
 */
public static String format(LogRecord logRecord, File sourceDirectory) {
    final Cursor cursor = logRecord.getCursor();
    final String relativePath = calculateFileRelativePath(cursor, sourceDirectory);

    final List<String> messageParts = new ArrayList<>();
    messageParts.add(MESSAGE_HEADER);
    messageParts.add(logRecord.getSeverity().toString());

    if (relativePath != null)
        messageParts.add(relativePath);

    if (cursor != null && cursor.getLineNumber() > 0)
        messageParts.add("line " + cursor.getLineNumber());

    messageParts.add(logRecord.getMessage());

    return messageParts.stream().collect(Collectors.joining(": "));
}
 
Example #4
Source File: WhenJavaExtensionGroupIsRegistered.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
@Test
public void an_inline_macro_as_instance_extension_should_be_executed_when_an_inline_macro_is_detected() {

    Map<String, Object> options = new HashMap<String, Object>();

    ManpageMacro inlineMacroProcessor = new ManpageMacro("man", options);
    this.asciidoctor.createGroup()
        .inlineMacro(inlineMacroProcessor)
        .register();

    String content = asciidoctor.convertFile(
            classpath.getResource("sample-with-man-link.ad"),
            options().toFile(false).get());

    org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8");
    Element link = doc.getElementsByTag("a").first();
    assertNotNull(link);
    assertThat(link.attr("href"), is("gittutorial.html"));

    final List<LogRecord> logRecords = TestLogHandlerService.getLogRecords();
    assertThat(logRecords, hasSize(0));
}
 
Example #5
Source File: JavaLogger.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
/**
 * @param threadContext
 * @param args
 */
@JRubyMethod(name = "add", required = 1, optional = 2)
public IRubyObject add(final ThreadContext threadContext, final IRubyObject[] args, Block block) {
  final IRubyObject rubyMessage;
  if (args.length >= 2 && !args[1].isNil()) {
    rubyMessage = args[1];
  } else if (block.isGiven()) {
    rubyMessage = block.yield(threadContext, getRuntime().getNil());
  } else {
    rubyMessage = args[2];
  }
  final Cursor cursor = getSourceLocation(rubyMessage);
  final String message = formatMessage(rubyMessage);
  final Severity severity = mapRubyLogLevel(args[0]);

  final LogRecord record = createLogRecord(threadContext, severity, cursor, message);

  rootLogHandler.log(record);
  return getRuntime().getNil();
}
 
Example #6
Source File: WhenJavaExtensionGroupIsRegistered.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
@Test
public void an_inline_macro_as_instance_extension_should_not_be_executed_when_regexp_is_set_and_does_not_match() {

    Map<String, Object> options = new HashMap<String, Object>();
    options.put(InlineMacroProcessor.REGEXP, "man(?:page)?:(ThisDoesNotMatch)\\[(.*?)\\]");

    ManpageMacro inlineMacroProcessor = new ManpageMacro("man", options);
    this.asciidoctor.createGroup()
        .inlineMacro(inlineMacroProcessor)
        .register();

    String content = asciidoctor.convertFile(
            classpath.getResource("sample-with-man-link.ad"),
            options().toFile(false).get());

    org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8");
    Element link = doc.getElementsByTag("a").first();
    assertNull(link);

    final List<LogRecord> logRecords = TestLogHandlerService.getLogRecords();
    assertThat(logRecords, hasSize(0));
}
 
Example #7
Source File: WhenJavaExtensionGroupIsRegistered.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
@Test
public void an_inline_macro_as_instance_extension_should_be_executed_when_regexp_is_set_as_option_inline_macro_is_detected() {

    Map<String, Object> options = new HashMap<String, Object>();
    options.put(InlineMacroProcessor.REGEXP, "man(?:page)?:(\\S+?)\\[(.*?)\\]");

    ManpageMacro inlineMacroProcessor = new ManpageMacro("man", options);
    this.asciidoctor.createGroup()
        .inlineMacro(inlineMacroProcessor)
        .register();

    String content = asciidoctor.convertFile(
            classpath.getResource("sample-with-man-link.ad"),
            options().toFile(false).get());

    org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8");
    Element link = doc.getElementsByTag("a").first();
    assertNotNull(link);
    assertThat(link.attr("href"), is("gittutorial.html"));

    final List<LogRecord> logRecords = TestLogHandlerService.getLogRecords();
    assertThat(logRecords, hasSize(0));
}
 
Example #8
Source File: WhenJavaExtensionGroupIsRegistered.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
@Test
public void an_inline_macro_extension_should_be_executed_when_an_inline_macro_is_detected() {

    this.asciidoctor.createGroup()
        .inlineMacro("man", ManpageMacro.class)
        .register();

    String content = asciidoctor.convertFile(
            classpath.getResource("sample-with-man-link.ad"),
            options().toFile(false).get());

    org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8");
    Element link = doc.getElementsByTag("a").first();
    assertThat(link.attr("href"), is("gittutorial.html"));

    final List<LogRecord> logRecords = TestLogHandlerService.getLogRecords();
    assertThat(logRecords, hasSize(0));
}
 
Example #9
Source File: WhenJavaExtensionIsRegistered.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
@Test
public void an_inline_macro_as_string_extension_should_be_executed_when_an_inline_macro_is_detected() {

    JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry();

    javaExtensionRegistry.inlineMacro("man", "org.asciidoctor.extension.ManpageMacro");

    String content = asciidoctor.convertFile(
            classpath.getResource("sample-with-man-link.ad"),
            options().toFile(false).get());

    org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8");
    Element link = doc.getElementsByTag("a").first();
    assertThat(link.attr("href"), is("gittutorial.html"));

    final List<LogRecord> logRecords = TestLogHandlerService.getLogRecords();
    assertThat(logRecords, hasSize(0));
}
 
Example #10
Source File: WhenJavaExtensionIsRegistered.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
@Test
public void an_inline_macro_extension_should_be_executed_when_an_inline_macro_is_detected() {

    JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry();

    javaExtensionRegistry.inlineMacro("man", ManpageMacro.class);

    String content = asciidoctor.convertFile(
            classpath.getResource("sample-with-man-link.ad"),
            options().toFile(false).get());

    org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8");
    Element link = doc.getElementsByTag("a").first();
    assertThat(link.attr("href"), is("gittutorial.html"));

    final List<LogRecord> logRecords = TestLogHandlerService.getLogRecords();
    assertThat(logRecords, hasSize(0));
}
 
Example #11
Source File: WhenJavaExtensionIsRegistered.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
@Test
public void an_inline_macro_as_instance_extension_should_be_executed_when_regexp_is_set_as_option_inline_macro_is_detected() {

    JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry();

    Map<String, Object> options = new HashMap<>();
    options.put(InlineMacroProcessor.REGEXP, "man(?:page)?:(\\S+?)\\[(.*?)\\]");

    ManpageMacro inlineMacroProcessor = new ManpageMacro("man", options);
    javaExtensionRegistry.inlineMacro(inlineMacroProcessor);

    String content = asciidoctor.convertFile(
            classpath.getResource("sample-with-man-link.ad"),
            options().toFile(false).get());

    org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8");
    Element link = doc.getElementsByTag("a").first();
    assertNotNull(link);
    assertThat(link.attr("href"), is("gittutorial.html"));

    final List<LogRecord> logRecords = TestLogHandlerService.getLogRecords();
    assertThat(logRecords, hasSize(0));
}
 
Example #12
Source File: WhenJavaExtensionIsRegistered.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
@Test
public void an_inline_macro_as_instance_extension_should_not_be_executed_when_regexp_is_set_and_does_not_match() {

    JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry();

    Map<String, Object> options = new HashMap<>();
    options.put(InlineMacroProcessor.REGEXP, "man(?:page)?:(ThisDoesNotMatch)\\[(.*?)\\]");

    ManpageMacro inlineMacroProcessor = new ManpageMacro("man", options);
    javaExtensionRegistry.inlineMacro(inlineMacroProcessor);

    String content = asciidoctor.convertFile(
            classpath.getResource("sample-with-man-link.ad"),
            options().toFile(false).get());

    org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8");
    Element link = doc.getElementsByTag("a").first();
    assertNull(link);

    final List<LogRecord> logRecords = TestLogHandlerService.getLogRecords();
    assertThat(logRecords, hasSize(0));
}
 
Example #13
Source File: WhenJavaExtensionIsRegistered.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
@Test
public void an_inline_macro_as_instance_extension_should_be_executed_when_an_inline_macro_is_detected() {

    JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry();

    Map<String, Object> options = new HashMap<>();

    ManpageMacro inlineMacroProcessor = new ManpageMacro("man", options);
    javaExtensionRegistry.inlineMacro(inlineMacroProcessor);

    String content = asciidoctor.convertFile(
            classpath.getResource("sample-with-man-link.ad"),
            options().toFile(false).get());

    org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8");
    Element link = doc.getElementsByTag("a").first();
    assertNotNull(link);
    assertThat(link.attr("href"), is("gittutorial.html"));

    final List<LogRecord> logRecords = TestLogHandlerService.getLogRecords();
    assertThat(logRecords, hasSize(0));
}
 
Example #14
Source File: WhenJavaExtensionGroupIsRegistered.java    From asciidoctorj with Apache License 2.0 6 votes vote down vote up
@Test
public void an_inline_macro_as_string_extension_should_be_executed_when_an_inline_macro_is_detected() {

    this.asciidoctor.createGroup()
        .inlineMacro("man", "org.asciidoctor.extension.ManpageMacro")
        .register();

    String content = asciidoctor.convertFile(
            classpath.getResource("sample-with-man-link.ad"),
            options().toFile(false).get());

    org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8");
    Element link = doc.getElementsByTag("a").first();
    assertThat(link.attr("href"), is("gittutorial.html"));

    final List<LogRecord> logRecords = TestLogHandlerService.getLogRecords();
    assertThat(logRecords, hasSize(0));
}
 
Example #15
Source File: WhenAsciidoctorLogsToConsole.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@Override
public Object process(StructuralNode parent, Reader reader, Map<String, Object> attributes) {
    log(new LogRecord(Severity.INFO, parent.getSourceLocation(), "Hello Log"));
    final List<String> strings = reader.readLines().stream()
            .map(String::toUpperCase)
            .collect(Collectors.toList());

    return createBlock(parent, "paragraph", strings);
}
 
Example #16
Source File: WhenAsciidoctorLogsToConsole.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotifyLogHandler() throws Exception {

    final List<LogRecord> logRecords = new ArrayList<>();

    asciidoctor.registerLogHandler(logRecords::add);

    File inputFile = classpath.getResource("documentwithnotexistingfile.adoc");
    String renderContent = asciidoctor.convertFile(inputFile,
            options()
                    .inPlace(true)
                    .safe(SafeMode.SERVER)
                    .attributes(
                            AttributesBuilder.attributes().allowUriRead(true))
                    .asMap());

    File expectedFile = new File(inputFile.getParent(), "documentwithnotexistingfile.html");
    expectedFile.delete();

    assertEquals(4, logRecords.size());
    assertThat(logRecords.get(0).getMessage(), containsString("include file not found"));
    final Cursor cursor = logRecords.get(0).getCursor();
    assertThat(cursor.getDir().replace('\\', '/'), is(inputFile.getParent().replace('\\', '/')));
    assertThat(cursor.getFile(), is(inputFile.getName()));
    assertThat(cursor.getLineNumber(), is(3));

    for (LogRecord logRecord : logRecords) {
        assertThat(logRecord.getCursor(), not(nullValue()));
        assertThat(logRecord.getCursor().getFile(), not(nullValue()));
        assertThat(logRecord.getCursor().getDir(), not(nullValue()));
    }

}
 
Example #17
Source File: MemoryLogHandler.java    From asciidoctor-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Returns LogRecords that are equal or above the severity level.
 *
 * @param severity Asciidoctor severity level
 * @return list of filtered logRecords
 */
public List<LogRecord> filter(Severity severity) {
    // FIXME: find better name or replace with stream
    final List<LogRecord> records = new ArrayList<>();
    for (LogRecord record : this.records) {
        if (record.getSeverity().ordinal() >= severity.ordinal())
            records.add(record);
    }
    return records;
}
 
Example #18
Source File: MemoryLogHandler.java    From asciidoctor-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Returns LogRecords whose message contains text.
 *
 * @param text text to search for in the LogRecords
 * @return list of filtered logRecords
 */
public List<LogRecord> filter(String text) {
    final List<LogRecord> records = new ArrayList<>();
    for (LogRecord record : this.records) {
        if (record.getMessage().contains(text))
            records.add(record);
    }
    return records;
}
 
Example #19
Source File: MemoryLogHandler.java    From asciidoctor-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Returns LogRecords that are equal or above the severity level and whose message contains text.
 *
 * @param severity Asciidoctor severity level
 * @param text     text to search for in the LogRecords
 * @return list of filtered logRecords
 */
public List<LogRecord> filter(Severity severity, String text) {
    final List<LogRecord> records = new ArrayList<>();
    for (LogRecord record : this.records) {
        if (record.getSeverity().ordinal() >= severity.ordinal() && record.getMessage().contains(text))
            records.add(record);
    }
    return records;
}
 
Example #20
Source File: LogRecordHelperTest.java    From asciidoctor-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void should_apply_full_format_logRecord_with_all_data() {
    // given
    final Cursor cursor = new TestCursor(new File("file.adoc").getAbsolutePath(), 3, "path", "dir");
    final LogRecord logRecord = new LogRecord(Severity.INFO, cursor, "a message");
    final File sourceDir = getParentFile();
    // when
    String formattedLogRecord = LogRecordHelper.format(logRecord, sourceDir);
    // then
    assertThat(normalizePath(formattedLogRecord)).isEqualTo("asciidoctor: INFO: asciidoctor-maven-plugin/file.adoc: line 3: a message");
}
 
Example #21
Source File: LogRecordHelperTest.java    From asciidoctor-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void should_apply_simple_format_when_cursor_is_null() {
    // given
    final LogRecord logRecord = new LogRecord(Severity.INFO, null, "a message");
    // when
    String formattedLogRecord = LogRecordHelper.format(logRecord, null);
    // then
    assertThat(normalizePath(formattedLogRecord)).isEqualTo("asciidoctor: INFO: a message");
}
 
Example #22
Source File: LogRecordHelperTest.java    From asciidoctor-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void should_apply_simple_format_when_cursor_is_empty() {
    // given
    final Cursor cursor = new TestCursor(null, 0, null, null);
    final LogRecord logRecord = new LogRecord(Severity.INFO, cursor, "a message");
    // when
    String formattedLogRecord = LogRecordHelper.format(logRecord, null);
    // then
    assertThat(normalizePath(formattedLogRecord)).isEqualTo("asciidoctor: INFO: a message");
}
 
Example #23
Source File: LogRecordHelperTest.java    From asciidoctor-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void should_format_full_logRecord_with_file_absolute_path_when_sourceDir_is_not_valid() throws IOException {
    // given
    final Cursor cursor = new TestCursor(new File("file.adoc").getAbsolutePath(), 3, "path", "dir");
    final LogRecord logRecord = new LogRecord(Severity.INFO, cursor, "a message");
    final File sourceDir = Mockito.mock(File.class);
    Mockito.when(sourceDir.getCanonicalPath()).thenThrow(new IOException());

    // when
    String formattedLogRecord = LogRecordHelper.format(logRecord, sourceDir);
    // then
    assertThat(normalizePath(formattedLogRecord)).matches("asciidoctor: INFO: .*/asciidoctor-maven-plugin/file.adoc: line 3: a message");
}
 
Example #24
Source File: LogRecordHelperTest.java    From asciidoctor-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void should_format_logRecords_with_empty_lineNumber_absolute_path_when_sourceDir_is_not_valid2() throws IOException {
    // given
    final Cursor cursor = new TestCursor(new File("file.adoc").getAbsolutePath(), 0, "path", "dir");
    final LogRecord logRecord = new LogRecord(Severity.INFO, cursor, "a message");
    final File sourceDir = Mockito.mock(File.class);
    Mockito.when(sourceDir.getCanonicalPath()).thenThrow(new IOException());

    // when
    String formattedLogRecord = LogRecordHelper.format(logRecord, sourceDir);
    // then
    assertThat(normalizePath(formattedLogRecord)).matches("asciidoctor: INFO: .*/asciidoctor-maven-plugin/file.adoc: a message");
}
 
Example #25
Source File: WhenAsciidoctorLogsToConsole.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNoLongerNotifyAfterUnregisterOnlyNotifyFromRegisteredAsciidoctor() throws Exception {

    final List<LogRecord> logRecords = new ArrayList<>();

    final LogHandler logHandler = logRecords::add;
    asciidoctor.registerLogHandler(logHandler);

    File inputFile = classpath.getResource("documentwithnotexistingfile.adoc");
    String renderContent = asciidoctor.convertFile(inputFile,
            options()
                    .inPlace(true)
                    .safe(SafeMode.SERVER)
                    .attributes(
                            AttributesBuilder.attributes().allowUriRead(true))
                    .asMap());

    File expectedFile = new File(inputFile.getParent(), "documentwithnotexistingfile.html");
    expectedFile.delete();

    assertEquals(4, logRecords.size());
    logRecords.clear();

    asciidoctor.unregisterLogHandler(logHandler);

    asciidoctor.convertFile(inputFile,
            options()
                    .inPlace(true)
                    .safe(SafeMode.SERVER)
                    .attributes(
                            AttributesBuilder.attributes().allowUriRead(true))
                    .asMap());

    File expectedFile2 = new File(inputFile.getParent(), "documentwithnotexistingfile.html");
    expectedFile2.delete();
    assertEquals(0, logRecords.size());

}
 
Example #26
Source File: JavaLogger.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
private LogRecord createLogRecord(final ThreadContext threadContext,
                                  final Severity severity,
                                  final Cursor cursor,
                                  final String message) {
  final Optional<BacktraceElement> elem = threadContext.getBacktrace(0)
          .skip(1)
          .findFirst();

  final String sourceFileName = elem.map(BacktraceElement::getFilename).orElse(null);
  final String sourceMethodName = elem.map(BacktraceElement::getMethod).orElse(null);
  final LogRecord record = new LogRecord(severity, cursor, message, sourceFileName, sourceMethodName);
  return record;
}
 
Example #27
Source File: JavaLogger.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
private IRubyObject log(ThreadContext threadContext, IRubyObject[] args, Block block, Severity severity) {
  final IRubyObject rubyMessage;
  if (block.isGiven()) {
    rubyMessage = block.yield(threadContext, getRuntime().getNil());
  } else {
    rubyMessage = args[0];
  }
  final Cursor cursor = getSourceLocation(rubyMessage);
  final String message = formatMessage(rubyMessage);

  final LogRecord record = createLogRecord(threadContext, severity, cursor, message);

  rootLogHandler.log(record);
  return getRuntime().getNil();
}
 
Example #28
Source File: JULLogHandler.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@Override
public void log(LogRecord logRecord) {
    final java.util.logging.LogRecord julLogRecord =
        new java.util.logging.LogRecord(
            mapSeverity(logRecord.getSeverity()),
            logRecord.getCursor() != null ? logRecord.getCursor().toString() + ": " + logRecord.getMessage() : logRecord.getMessage());

    julLogRecord.setSourceClassName(logRecord.getSourceFileName());
    julLogRecord.setSourceMethodName(logRecord.getSourceMethodName());
    julLogRecord.setParameters(new Object[] { logRecord.getCursor() });
    julLogRecord.setLoggerName(LOGGER_NAME);
    LOGGER.log(julLogRecord);
}
 
Example #29
Source File: WhenAsciidoctorLogsToConsole.java    From asciidoctorj with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldOnlyNotifyFromRegisteredAsciidoctor() throws Exception {

    final List<LogRecord> logRecords = new ArrayList<>();

    final Asciidoctor secondInstance = Asciidoctor.Factory.create();

    asciidoctor.registerLogHandler(logRecords::add);

    // Now render via second instance and check that there is no notification
    File inputFile = classpath.getResource("documentwithnotexistingfile.adoc");
    String renderContent1 = secondInstance.convertFile(inputFile,
            options()
                    .inPlace(true)
                    .safe(SafeMode.SERVER)
                    .attributes(
                            AttributesBuilder.attributes().allowUriRead(true))
                    .asMap());

    File expectedFile1 = new File(inputFile.getParent(), "documentwithnotexistingfile.html");
    expectedFile1.delete();

    assertEquals(0, logRecords.size());

    // Now render via first instance and check that notifications appeared.
    String renderContent = asciidoctor.convertFile(inputFile,
            options()
                    .inPlace(true)
                    .safe(SafeMode.SERVER)
                    .attributes(
                            AttributesBuilder.attributes().allowUriRead(true))
                    .asMap());

    File expectedFile2 = new File(inputFile.getParent(), "documentwithnotexistingfile.html");
    expectedFile2.delete();

    assertEquals(4, logRecords.size());
    assertThat(logRecords.get(0).getMessage(), containsString("include file not found"));
    final Cursor cursor = (Cursor) logRecords.get(0).getCursor();
    assertThat(cursor.getDir().replace('\\', '/'), is(inputFile.getParent().replace('\\', '/')));
    assertThat(cursor.getFile(), is(inputFile.getName()));
    assertThat(cursor.getLineNumber(), is(3));
}
 
Example #30
Source File: AbstractAsciiDocMojo.java    From helidon-build-tools with Apache License 2.0 4 votes vote down vote up
@Override
public void log(LogRecord logRecord) {
    if (!isPrelim.get()) {
        System.err.println(logRecord.getMessage());
    }
}