lluissm / license-header-checker

Command line utility to check whether the license headers are included in the source code files of a project. It can also insert/replace.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to properly set the license template file for some variable?

tonyho opened this issue · comments

In the license template, some string may vary in every file, take a license template(C/C++ language) as example:

/********************************************************************************************************
 * @file     [File name]
 *
 * @brief    [XXXX]
 *
 * @author       [Owner]
 * @date         [yyyy]
 *
 * @par      Copyright (c) [yyyy], ZZZ Co., Ltd.
 *           All rights reserved.
 *
 *           The information contained herein is confidential property of ZZZZ
 *           Co., Ltd. and is available under the terms
 *           of Commercial License Agreement between ZZZ
 *           Co., Ltd. and the licensee or the terms described here-in. This heading
 *           MUST NOT be removed from this file.
 *
 *           Licensees are granted free, non-transferable use of the information in this
 *           file under Mutual Non-Disclosure Agreement. NO WARRENTY of ANY KIND is provided.
 *
 *******************************************************************************************************/

The File name , XXX , Owner , yyy and some other info may vary in every file, how to set these variables in template correctly ?

Hi @tonyho,

If I understood well your question, what you are requesting is not currently supported by the tool. It has been designed taking into account that the target license header will be the same for all files (which is quite common nowadays).

Something like:

/* MIT License
* Copyright (c) [yyyy] [Company Name]
* Permission is hereby granted, free of charge, to any person obtaining a copy
* ...
*/

What the tool currently does is:

Check if the target license header exists in the file (looking for the whole header). If that's the case, the file is considered to be OK.

In case the target license header is not present, it checks whether there is a license in the file by looking for a /*comment block*/ at the beginning of the file that contains the words "copyright" or "license".

If a license header is found, it will be replaced by the target one. In case no license was found, the target one will be inserted.

Thus, in your case all headers would be replaced by the target one, loosing the information about author name, etc.

I use this tool with my ARM firmware projects in C++ (with visual studio code) without major issues as nowadays information like author name and date of change can be obtained via git and displayed directly in the IDE (not only on a file basis but you can also see for every line who changed it and when).

Thanks. Understood. Will this feature be added in future or any other tool recommanded?

Hi @tonyho, I don't think this feature will be added in the future as it goes a little bit against the goals of this tool (to have a simple, fast and 100% reliable tool to be integrated in CI systems) and I do not know of any tool that does support it.

I would probably recommend to get rid of the author and date fields and move the comment out of the header. But if that is not an option, have you considered a simple search and replace of the license portion that starts with @par?

Thanks for your advise, I want to use this tool in CI too, I will take you advise to use the grep/pregrep + sed to achive the purpose.

@lluissm
Thanks for this little tool.
After reading your first comment above: Please adapt your DISCLAIMER in the README.md with that check-mechanism, that not only a comment /* .. */ at the beginning is checked but it also needs to contain the word(s) license and/or copyright as well (licensed would work as well, so sub-string seems to be ok).
It would have saved me a couple of hours figuring out why replacing works the first time but after that a change to the license text provided me with a skipped_add hint for all files after a new check.
While doing this, please also inform the user about issue #31 that the build tags on top of the file will be recognized/kept.
Thank you.
Best regards, Dany

Hi @Daniel-BB

Thank you for taking the time to comment, I really appreciate it.

I have updated the README.md as suggested and I hope the tool will be useful to you.

Best regards,
Lluis

Hi @lluissm ,
thank you, looks good to me.
Sorry for commenting here again, but I'd like to add, that your install script (and thus the command you're showing) is also running on Windows (not only on Linux and MacOS), provided that one has Git for Windows installed which contains Git Bash (MINGW64). Windows is also already detected as target OS inside your script.
Please keep up your great work.
Best regards, Dany

Hi @Daniel-BB,

Thanks again, I will update the README.md with this information too.

Have a nice weekend,
Lluis