gpt4 book ai didi

com.puppycrawl.tools.checkstyle.XMLLogger类的使用及代码示例

转载 作者:知者 更新时间:2024-03-20 21:51:40 28 4
gpt4 key购买 nike

本文整理了Java中com.puppycrawl.tools.checkstyle.XMLLogger类的一些代码示例,展示了XMLLogger类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XMLLogger类的具体详情如下:
包路径:com.puppycrawl.tools.checkstyle.XMLLogger
类名称:XMLLogger

XMLLogger介绍

[英]Simple XML logger. It outputs everything in UTF-8 (default XML encoding is UTF-8) in case we want to localize error messages or simply that file names are localized and takes care about escaping as well.
[中]简单的XML记录器。它以UTF-8(默认XML编码为UTF-8)输出所有内容,以防我们想要本地化错误消息,或者仅仅是本地化文件名,并考虑转义。

代码示例

代码示例来源:origin: checkstyle/checkstyle

@Test
public void testFileStarted()
    throws Exception {
  final XMLLogger logger = new XMLLogger(outStream, true);
  logger.auditStarted(null);
  final AuditEvent ev = new AuditEvent(this, "Test.java");
  logger.fileStarted(ev);
  logger.fileFinished(ev);
  logger.auditFinished(null);
  verifyXml(getPath("ExpectedXMLLogger.xml"), outStream);
}

代码示例来源:origin: checkstyle/checkstyle

/**
 * Prints the "file" opening tag with the given filename.
 * @param fileName The filename to output.
 */
private void writeFileOpeningTag(String fileName) {
  writer.println("<file name=\"" + encode(fileName) + "\">");
}

代码示例来源:origin: checkstyle/checkstyle

@Test
public void testAddIgnored() throws Exception {
  final XMLLogger logger = new XMLLogger(outStream, true);
  logger.auditStarted(null);
  final LocalizedMessage message =
      new LocalizedMessage(1, 1,
          "messages.properties", "key", null, SeverityLevel.IGNORE, null,
          getClass(), null);
  final AuditEvent ev = new AuditEvent(this, "Test.java", message);
  logger.addError(ev);
  logger.auditFinished(null);
  verifyXml(getPath("ExpectedXMLLoggerEmpty.xml"), outStream);
}

代码示例来源:origin: checkstyle/checkstyle

@Test
public void testFinishLocalSetup() {
  final XMLLogger logger = new XMLLogger(outStream, true);
  logger.finishLocalSetup();
  logger.auditStarted(null);
  logger.auditFinished(null);
  assertNotNull("instance should not be null", logger);
}

代码示例来源:origin: checkstyle/checkstyle

/**
 * Returns a new AuditListener for this OutputFormat.
 * @param out the output stream
 * @param options the output stream options
 * @return a new AuditListener for this OutputFormat
 */
public AuditListener createListener(OutputStream out,
                  AutomaticBean.OutputStreamOptions options) {
  final AuditListener result;
  if (this == XML) {
    result = new XMLLogger(out, options);
  }
  else {
    result = new DefaultLogger(out, options);
  }
  return result;
}

代码示例来源:origin: checkstyle/checkstyle

@Test
public void testCloseStream()
    throws Exception {
  final XMLLogger logger = new XMLLogger(outStream,
      AutomaticBean.OutputStreamOptions.CLOSE);
  logger.auditStarted(null);
  logger.auditFinished(null);
  assertEquals("Invalid close count", 1, outStream.getCloseCount());
  verifyXml(getPath("ExpectedXMLLoggerEmpty.xml"), outStream);
}

代码示例来源:origin: checkstyle/checkstyle

@Test
public void testEncode()
    throws IOException {
  final XMLLogger test = new XMLLogger(outStream, false);
  assertNotNull("should be able to create XMLLogger without issue", test);
  final String[][] encodings = {
    {"<", "&lt;"},
    {">", "&gt;"},
    {"'", "&apos;"},
    {"\"", "&quot;"},
    {"&", "&amp;"},
    {"&lt;", "&amp;lt;"},
    {"abc;", "abc;"},
    {"&#0;", "&amp;#0;"},
    {"&#0", "&amp;#0"},
    {"&#X0;", "&amp;#X0;"},
    {"\u0001", "#x1;"},
    {"\u0080", "#x80;"},
  };
  for (String[] encoding : encodings) {
    final String encoded = XMLLogger.encode(encoding[0]);
    assertEquals("\"" + encoding[0] + "\"", encoding[1], encoded);
  }
  outStream.close();
}

代码示例来源:origin: checkstyle/checkstyle

@Test
public void testIsReference()
    throws IOException {
  final XMLLogger test = new XMLLogger(outStream, false);
  assertNotNull("should be able to create XMLLogger without issue", test);
  final String[] references = {
  for (String reference : references) {
    assertTrue("reference: " + reference,
        XMLLogger.isReference(reference));
  for (String noReference : noReferences) {
    assertFalse("no reference: " + noReference,
        XMLLogger.isReference(noReference));

代码示例来源:origin: checkstyle/checkstyle

/**
 * Creates XML logger.
 * @param task the task to possibly log to
 * @return an XMLLogger instance
 * @throws IOException if an error occurs
 */
private AuditListener createXmlLogger(Task task) throws IOException {
  final AuditListener xmlLogger;
  if (toFile == null || !useFile) {
    xmlLogger = new XMLLogger(new LogOutputStream(task, Project.MSG_INFO),
        AutomaticBean.OutputStreamOptions.CLOSE);
  }
  else {
    xmlLogger = new XMLLogger(Files.newOutputStream(toFile.toPath()),
        AutomaticBean.OutputStreamOptions.CLOSE);
  }
  return xmlLogger;
}

代码示例来源:origin: checkstyle/checkstyle

@Test
public void testNoCloseStream()
    throws Exception {
  final XMLLogger logger = new XMLLogger(outStream,
      AutomaticBean.OutputStreamOptions.NONE);
  logger.auditStarted(null);
  logger.auditFinished(null);
  assertEquals("Invalid close count", 0, outStream.getCloseCount());
  outStream.close();
  verifyXml(getPath("ExpectedXMLLoggerEmpty.xml"), outStream);
}

代码示例来源:origin: checkstyle/checkstyle

@Test
public void testFileFinished()
    throws Exception {
  final XMLLogger logger = new XMLLogger(outStream, true);
  logger.auditStarted(null);
  final AuditEvent ev = new AuditEvent(this, "Test.java");
  logger.fileFinished(ev);
  logger.auditFinished(null);
  verifyXml(getPath("ExpectedXMLLogger.xml"), outStream);
}

代码示例来源:origin: checkstyle/checkstyle

@Test
public void testNullOutputStreamOptions() {
  try {
    final XMLLogger logger = new XMLLogger(outStream, null);
    // assert required to calm down eclipse's 'The allocated object is never used' violation
    assertNotNull("Null instance", logger);
    fail("Exception was expected");
  }
  catch (IllegalArgumentException exception) {
    assertEquals("Invalid error message", "Parameter outputStreamOptions can not be null",
        exception.getMessage());
  }
}

代码示例来源:origin: checkstyle/checkstyle

@Test
public void testAddErrorModuleId() throws Exception {
  final XMLLogger logger = new XMLLogger(outStream, true);
  logger.auditStarted(null);
  final LocalizedMessage message =
    new LocalizedMessage(1, 1,
      "messages.properties", "key", null, SeverityLevel.ERROR, "module",
        getClass(), null);
  final AuditEvent ev = new AuditEvent(this, "Test.java", message);
  logger.addError(ev);
  logger.auditFinished(null);
  verifyXml(getPath("ExpectedXMLLoggerErrorModuleId.xml"), outStream, message.getMessage());
}

代码示例来源:origin: checkstyle/checkstyle

/**
 * Writes the exception event to the print writer.
 * @param throwable The
 */
private void writeException(Throwable throwable) {
  writer.println("<exception>");
  writer.println("<![CDATA[");
  final StringWriter stringWriter = new StringWriter();
  final PrintWriter printer = new PrintWriter(stringWriter);
  throwable.printStackTrace(printer);
  writer.println(encode(stringWriter.toString()));
  writer.println("]]>");
  writer.println("</exception>");
}

代码示例来源:origin: checkstyle/checkstyle

@Test
public void testAddError() throws Exception {
  final XMLLogger logger = new XMLLogger(outStream, true);
  logger.auditStarted(null);
  final LocalizedMessage message =
    new LocalizedMessage(1, 1,
      "messages.properties", "key", null, SeverityLevel.ERROR, null,
        getClass(), null);
  final AuditEvent ev = new AuditEvent(this, "Test.java", message);
  logger.fileStarted(ev);
  logger.addError(ev);
  logger.fileFinished(ev);
  logger.auditFinished(null);
  verifyXml(getPath("ExpectedXMLLoggerError.xml"), outStream, message.getMessage());
}

代码示例来源:origin: checkstyle/checkstyle

checker.setBasedir(getPath(""));
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final XMLLogger logger = new XMLLogger(out, AutomaticBean.OutputStreamOptions.NONE);
checker.addListener(logger);

代码示例来源:origin: checkstyle/checkstyle

@Test
public void testAddErrorWithNullFileName() throws Exception {
  final XMLLogger logger = new XMLLogger(outStream, true);
  logger.auditStarted(null);
  final LocalizedMessage message =
      new LocalizedMessage(1, 1,
          "messages.properties", "key", null, SeverityLevel.ERROR, null,
          getClass(), null);
  final AuditEvent ev = new AuditEvent(this, null, message);
  logger.addError(ev);
  logger.auditFinished(null);
  verifyXml(getPath("ExpectedXMLLoggerErrorNullFileName.xml"), outStream,
      message.getMessage());
}

代码示例来源:origin: checkstyle/checkstyle

/**
 * Outputs the given event to the writer.
 * @param event An event to print.
 */
private void writeFileError(AuditEvent event) {
  writer.print("<error" + " line=\"" + event.getLine() + "\"");
  if (event.getColumn() > 0) {
    writer.print(" column=\"" + event.getColumn() + "\"");
  }
  writer.print(" severity=\""
      + event.getSeverityLevel().getName()
      + "\"");
  writer.print(" message=\""
      + encode(event.getMessage())
      + "\"");
  writer.print(" source=\"");
  if (event.getModuleId() == null) {
    writer.print(encode(event.getSourceName()));
  }
  else {
    writer.print(encode(event.getModuleId()));
  }
  writer.println("\"/>");
}

代码示例来源:origin: checkstyle/checkstyle

@Test
public void testAddErrorOnZeroColumns() throws Exception {
  final XMLLogger logger = new XMLLogger(outStream, true);
  logger.auditStarted(null);
  final LocalizedMessage message =
      new LocalizedMessage(1, 0,
          "messages.properties", "key", null, SeverityLevel.ERROR, null,
          getClass(), null);
  final AuditEvent ev = new AuditEvent(this, "Test.java", message);
  logger.fileStarted(ev);
  logger.addError(ev);
  logger.fileFinished(ev);
  logger.auditFinished(null);
  verifyXml(getPath("ExpectedXMLLoggerErrorZeroColumn.xml"), outStream,
      message.getMessage());
}

代码示例来源:origin: checkstyle/checkstyle

@Test
public void testXmlLoggerClosesItStreams() throws Exception {
  final Checker checker = new Checker();
  try (CloseAndFlushTestByteArrayOutputStream testInfoOutputStream =
      new CloseAndFlushTestByteArrayOutputStream()) {
    checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
    checker.addListener(new XMLLogger(testInfoOutputStream, true));
    final File tmpFile = temporaryFolder.newFile("file.java");
    final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
    verify(checker, tmpFile.getPath(), tmpFile.getPath(), expected);
    assertEquals("Close count was not expected",
        1, testInfoOutputStream.getCloseCount());
    assertEquals("Flush count was not expected",
        0, testInfoOutputStream.getFlushCount());
  }
}

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com