- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
本文整理了Java中com.puppycrawl.tools.checkstyle.XMLLogger
类的一些代码示例,展示了XMLLogger
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XMLLogger
类的具体详情如下:
包路径:com.puppycrawl.tools.checkstyle.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;"},
{"abc;", "abc;"},
{"�", "&#0;"},
{"�", "&#0"},
{"�", "&#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());
}
}
发现一个类似的问题,关于 QAPlug-FindBugs 和 FindBugs-IDEA 之间的区别,但不是关于 CheckStyle... 我认为(根据以前的经验)这些插件的一个区别是 QAPlug
试图弄清楚我是否做错了什么,或者这是否是 maven checkstyle 插件中的错误。如果我执行 mvn checkstyle:check 我会得到这个: jonathanfisher@odin
我想确保我的代码不超过 5 级缩进,如下所示: class Foo { // 0 void bar() { // 1 if () { // 2 if (
FileTabCharacter检查似乎对我不起作用。下面是我的配置: .. .. .. .. .. .. 我有 XML 文件 - pom.xml和 checksty
有没有办法设置 checkstyle 来防止方法体中的前导、多个或尾随空行: 例如 private void a() { - int a = 1; doStuff(a); - - doMoreStuf
有没有办法设置 checkstyle 来防止方法体中的前导、多个或尾随空行: 例如 private void a() { - int a = 1; doStuff(a); - - doMoreStuf
我是 CheckStyle 等 Java 静态代码分析工具的新手。我下载了 Checkstyle 包并看到了 2 组检查: checkstyle_checks.xml sun_checks.xml。
我想使用//@checkstyle:off 和//@checkstyle:on 来免除代码的某些部分被 checkstyle 检查,但它仍然在提示。 public void invoke() {
我正在尝试将 import-control 添加到我们的 checkstyle 中,使 import-control 文件存在于制作 checstyle.xml 文件的项目中,而不是我们稍后构建的项目
我跑了mvn checkstyle:checkstyle ,但它没有使用我的自定义 checkstyle XML 文件。 请告诉我如何使用我自己的 checkstyle 文件而不是默认/现在配置的文件
执行命令mvn checkstyle:checkstyle时出现以下错误: An error has occurred in Checkstyle report generation. ... Cau
在我正在处理的一个项目中,我们有很多自定义 Checkstyle 检查。例如,我们使用 RegexpSingleline 模块排除所有类型的东西。我们的检查样式规则如下所示:
我正在使用 checkstyle获取有关我的源代码的报告。这个问题是关于MagicNumberCheck . 我正在使用 Date/(org.joda.)DateTime在我的源代码中是这样的: Da
我通过命令行上的 mvn 构建我的项目。 每当发生 checkStyle 错误时,我都会看到这种类型的输出: [ERROR] Failed to execute goal org.apache.mav
我有一个使用 Tycho 构建的 Eclipse 插件代码库。它使用在依赖 Artifact 中定义的父 POM,该 Artifact 指定 Checkstyle 配置的名称。 我还使用 checks
我是使用 Jenkins 的新手,我最近用它构建了一个项目并安装了“Checkstyle”插件并收到了一份报告。 我想知道如何配置“Checkstyle”以忽略空格或其他可能出现的标准? 谢谢! 最佳
我过去使用过检查样式,记得使用快捷键来应用检查样式修复(节省大量点击)。我不记得我是否为它设置了快捷方式,或者它是否已经附带了一个。 我的问题分为两部分:1)有没有一种简单的方法来检查是否有“Appl
我正在使用一个基本的 maven 项目,其中在 pom.xml 中只定义了以下内容: 依赖 javaee-api 依赖 junit 插件 maven-compile-plugin 插件 maven-w
我试图让 maven-checkstyle-plugin 对我们所有的项目使用相同的配置文件。 我尝试了几种方法,但没有一种是有效的。 唯一似乎有效的是当我将配置文件放在我的 maven 项目的根目录
我在 maven 构建中添加了 checkstyle 但由于某种原因它只检查 src/main 文件夹并忽略 src/test 文件夹,这是我的项目结构: Proj - Module A -
我是一名优秀的程序员,十分优秀!