SonarQube“跟踪缺少版权和许可证标题”参数

zod*_*dac 5 sonarqube

SonarQube 有一个规则,允许您验证每个文件是否有版权和/或许可证。但是,我不确定如何使用可变年份指定版权。

例如,这是他们的合规解决方案:

/*
 * SonarQube, open source software quality management tool.
 * Copyright (C) 2008-2013 SonarSource
 * mailto:contact AT sonarsource DOT com
 *
 * SonarQube is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * SonarQube is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
Run Code Online (Sandbox Code Playgroud)

请求的参数是:

isRegularExpression 
    Whether the headerFormat is a regular expression (Default Value: false)
Run Code Online (Sandbox Code Playgroud)

.

headerFormat    
    Expected copyright and license header
Run Code Online (Sandbox Code Playgroud)

例如,如果“2008-2013”​​是一年,我将如何提供既允许 2015 年又允许 2016 年的格式?

Reb*_*bse 2

我们的样式指南需要 Java 源代码的特定标头:

/*
 * [optional text] <CreationDate> [optional text]
 * <Copyright (c) yyyy FOO-COMPANY. All Rights Reserved.>
 */
Run Code Online (Sandbox Code Playgroud)

[] 括号表示它是可选的,<> 表示它必须存在, fe :

有效的

/*
 *  03.05.2016
 *  Copyright (c) 2016 FOO-COMPANY. All Rights Reserved.  
 */
Run Code Online (Sandbox Code Playgroud)

也有效

/*
 *  just some text 03.05.2016 Fred Fart
 *  Copyright (c) 2016 FOO-COMPANY. All Rights Reserved.  
 */
Run Code Online (Sandbox Code Playgroud)

正则表达式确保日期有效,并且也可以有多个日期, fe :

/*
 *  23.09.2016
 *  Copyright (c) 2013-2016 FOO-COMPANY. All Rights Reserved.  
 */
Run Code Online (Sandbox Code Playgroud)

或者

/*
 *  23.09.2016
 *  Copyright (c) 2013,2014,2016 FOO-COMPANY. All Rights Reserved.  
 */
Run Code Online (Sandbox Code Playgroud)

该规则必须使用您的正则表达式进行配置headerFormatisRegularExpression=true
我们的正则表达式配置如下:

^.+(?:0[1-9]|[12][0-9]|3[01])\.(0[1-9]|1[012])\.(19[7-9]\d|20[0-2]\d).+?Copyright \(c\) ((\b19[7-9]\d|20[0-2]\d)([,|-])?\b)* FOO-COMPANY\. All Rights Reserved\..+
Run Code Online (Sandbox Code Playgroud)