How to satisfy the rule: "Track lack of copyright and license headers" in Sonarqube

HI All,

One of our user is asking how to satisfy the rule “Track lack of copyright and license headers” in SonarQube and getting blocker because of this.

Can someone help us on this.

Thanks
Thulasiraman

Hi,

i guess you’re talking about the java:S1451 rule.
see the rule description

Each source file should start with a header stating file ownership and the license which must be used to distribute the application.

This rule must be fed with the header text that is expected at the beginning of every file

So it depends on how your rule is configured.
i.e. at our side it is configured as regular expression

^.+(?: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-BAR\. All Rights Reserved\..+

You should propose valid headers in rule description via the ‘Extend Description’ feature, i.e.
our extended description

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

/*
 *  03.05.2016 someuserid  
 *  Copyright (c) 2015,2016 FOO-BAR. All Rights Reserved.  
 */

/*
 *  03.05.2016 Fred Fart
 *  Copyright (c) 2016 FOO-BAR. All Rights Reserved.  
 */

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

For backward compatibility the old format is valid too :
/*
 * @(#) <Classname> <CreationDate> [ forename surname | UserID ]
 * Copyright (c) yyyy FOO-BAR. All Rights Reserved.
 */

To get blocker issues this rule has to be part of / activated for the used quality profile.

Gilbert

1 Like