5

我所有的 SonarQube 代码分析 Java 项目都未能遵守此规则。

每个源文件都应以标头开头,说明文件所有权和分发应用程序必须使用的许可证。此规则必须与每个文件开头预期的标题文本一起提供。

有一个参数:

headerFormat 预期的版权和许可标题(纯文本)

但是没有关于如何配置的示例。默认情况下 headerFormat 为空,我找不到有关配置此规则的文档。

我猜应该有某种可以使用的正则表达式或模板语言?

4

2 回答 2

4

squid:S1451 "Copyright and license headers should be defined"有两个参数:

  1. 标头格式
  2. 是正则表达式

headerFormat中,您定义预期的文本。如果将isRegularExpression设置为 true,则文本将被视为正则表达式。

如果你使用普通文本,那么你需要把完整的许可证,例如:

/*
 * Maven Plugin Utils
 * http://www.gabrys.biz/projects/maven-plugin-utils/
 *
 * Copyright (c) 2015 Adam Gabryś
 *
 * This file is licensed under the BSD 3-Clause (the "License").
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *      https://raw.githubusercontent.com/gabrysbiz/maven-plugin-utils/master/src/main/resources/license.txt
 */

如果你使用正则表达式,那么你可以省略一些部分,例如:

^\/\*.+www\.gabrys\.biz\/projects\/.+Copyright \(c\) [0-9]{4}.+This file is licensed under the.+\(the "License"\)\..+You may not use this file except in compliance with the License\..+You may obtain a copy of the License at:.+$
于 2015-07-16T19:35:51.473 回答
1

仅更改 SonarQube 服务器上“headerFormat”的默认文本:

质量概况示例

于 2019-01-07T16:42:06.957 回答