SonarQube Rules squid:S1451 Copyright and license headers should be defined

六月ゝ 毕业季﹏ 提交于 2019-12-23 12:14:09

问题


All of my SonarQube code analysis Java projects are failing on this rule.

Each source file should start with a header stating file ownership and the license which must be used to distribute the application. This rule must be fed with the header text that is expected at the beginning of every file.

There is one parameter:

headerFormat Expected copyright and license header (plain text)

But there are no examples of how this should be configured. By default headerFormat is empty and I cannot find documentation on configuring this rule.

I'm guessing there should be some kind of regular expression or template language that can be used?


回答1:


squid:S1451 "Copyright and license headers should be defined" has two parameters:

  1. headerFormat
  2. isRegularExpression

In headerFormat you define expected text. If you set isRegularExpression to true, then the text will be treated as regular expression.

If you use normal text, then you need to put full license, e.g.:

/*
 * 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
 */

If you use regular expression, then you can omit some parts, e.g.:

^\/\*.+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:.+$



回答2:


only change the default text for "headerFormat" on SonarQube server:



来源:https://stackoverflow.com/questions/31462870/sonarqube-rules-squids1451-copyright-and-license-headers-should-be-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!