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年的格式? 最佳答案 我们的样式指南要求Java源有特定的 header :/* * [optional text] <CreationDate> [optional text] * <Copyright (c) yyyy FOO-COMPANY. All Rights Reserved.> */[]中的括号表示它是可选的,表示必须存在,例如:有效的/* * 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. */必须使用您的正则表达式将规则配置为headerFormat和isRegularExpression=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\..+
10-08 19:06