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

时间:2016-12-21 14:47:03

标签: sonarqube

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

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

for item in inventory_url:
    if all(kw in item for kw in keywords):
        print(item) 

要求的参数是:

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

isRegularExpression 
    Whether the headerFormat is a regular expression (Default Value: false)

如果“2008-2013”​​改为一年,我将如何提供允许2015年和2016年的格式?

1 个答案:

答案 0 :(得分:1)

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

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

[]括号表示它是可选的,&lt;&gt;意味着这必须存在,例如:

有效

/*
 *  03.05.2016
 *  Copyright (c) 2016 FOO-COMPANY. All Rights Reserved.  
 */

也有效

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

正则表达式确保日期有效,并且还可以有多个日期,例如: :

/*
 *  23.09.2016
 *  Copyright (c) 2013-2016 FOO-COMPANY. All Rights Reserved.  
 */

/*
 *  23.09.2016
 *  Copyright (c) 2013,2014,2016 FOO-COMPANY. All Rights Reserved.  
 */

规则必须使用正则表达式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\..+