Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SonarQube "Track lack of copyright and license headers" parameters

Tags:

sonarqube

SonarQube has a rule that allows you to verify each file is headed by a copyright and/or license. However, I'm not certain how to specify a copyright with a variable year.

For example, here is their compliant solution:

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

The params requested are:

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

.

headerFormat    
    Expected copyright and license header

If the "2008-2013" was instead a single year, how would I provide a format that would allow both 2015 and 2016, for example?

like image 268
zodac Avatar asked Dec 21 '16 14:12

zodac


1 Answers

Our styleguide demands a specific header for Java sources :

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

[] brackets means it's optional, <> means this must be present, f.e. :

valid

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

also valid

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

The regex ensures that dates are valid, and also multiple dates are possible, f.e. :

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

or

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

The rule has to be configured with your regexp as headerFormat and isRegularExpression=true
Our regex is configured like that:

^.+(?: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\..+
like image 189
Rebse Avatar answered Nov 17 '22 00:11

Rebse