声纳Qube "Track lack of copyright and license headers"参数



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

请求的参数为:

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

headerFormat    
    Expected copyright and license header

如果" 2008-2013"是一年,我将如何提供允许2015年和2016年的格式?

我们的styleguide要求Java来源的特定标头:

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

[]括号意味着它是可选的,&lt;>表示必须存在,F.E。:

有效

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

该规则必须用您的REGEXP配置为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..+

最新更新