Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically managing license/author/version header in source files

It is generally considered good practice to add some lines with author, version and license information to the top of source files. For instance, Gnu GPL v3 suggests to add

<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year>  <name of author>

This program is free software: you can redistribute it and/or modify
it under the terms [SNIP]

I find it tedious to add it manually to each file, and to have to update them all every now and then when some of this information changes (new authors, copyright years, version bumps).

Is there a way to manage this automatically, so that I only have to edit this stuff in one place and it gets automagically copied around?

If needed, you may assume that I am using any modern revision control system.

like image 240
Federico Poloni Avatar asked Apr 03 '12 08:04

Federico Poloni


People also ask

What is a license Header?

License headers allow someone examining the file to know the terms governing use of the work, even when it is distributed without the rest of the distribution. Without a licensing notice, it must be assumed that the author has reserved all rights, including the right to copy, modify, and redistribute.

Does MIT license need to be in every file?

No, you don't have to put the license in each source code file.

Is a Header a source file?

So what's the difference between Header files and Source files? Basically, header files are #included and not compiled, whereas source files are compiled and not #included. You can try to side-step these conventions and make a file with a source extension behave like a header or vice-versa, but you shouldn't.

How do you add copyright to a file in Java?

Solution 1.Go to preferences -> Java -> Code Style -> Code Templates, expands Code and select “New Java Files”, edit the template to add whatever copyright messages you want. Now, that copyright message will be injected on every newly created Java class.


1 Answers

It is generally considered good practice to add some lines with author, version and license information to the top of source files.

That depends. First of all there are two (and more) ways to do this:

  • manage licensing information per file
  • manage licensing information in a central location

If you start a project from scratch, the per-file method is often easy to do while keeping things clear. As you write, over time it becomes more difficult to keep track of things. So more and more projects switch to the central location variant.

The file-by-file method has the benefit that the scope of a work is clear. Often you write the name of the application in the file-comment. If a single file is taken out for some reason, the information is still in there and the documentation chain is not broken.

With the central location method, the benefit is that this is normally supported by your version control software, for example GIT. Commits can be signed by the committing person, and author can be given. It's documented who has written which code automatically and that information is stored in a central location: the VCS.

Keep a COPYING file with your package where you provide the main information centrally. You can easily generate the list of authors via the VCS. And per each file you can create one header that just specifies which software and where to look into, just a bare outline:

/**
 * Flux Deluxe v3.2.0 - Vector Drawing Redefined
 *
 * Copyright 2010, 2012 by its authors. 
 * Some rights reserved. See COPYING, AUTHORS.
 */

If you release a new version in a new year it's a no-brainer to update all files.

like image 106
hakre Avatar answered Oct 01 '22 02:10

hakre