Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tool for adding license headers to source files? [closed]

I'm looking for a tool that will, in bulk, add a license header to some source files, some of which already have the header. Is there a tool out there that will insert a header, if it is not already present?

Edit: I am intentionally not marking an answer to this question, since answers are basically all environment-specific and subjective

like image 841
Alex Lyman Avatar asked Sep 30 '08 03:09

Alex Lyman


People also ask

What are license headers?

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.

How do I add a comment to a header in eclipse?

You need to specify a licence in project|general > Preferences > java > JAutodoc > FileHeader and later in the project use: project > JAutodoc > Add Header , make sure the option Replace Existing Header is on. The template is writing using Velocity, so you can add all the information you need as variables.


2 Answers

#!/bin/bash  for i in *.cc # or whatever other pattern... do   if ! grep -q Copyright $i   then     cat copyright.txt $i >$i.new && mv $i.new $i   fi done 
like image 88
Tim Avatar answered Oct 05 '22 09:10

Tim


Here's a Bash script that'll do the trick, assuming you have the license header in the file license.txt:

File addlicense.sh:

#!/bin/bash   for x in $*; do   head -$LICENSELEN $x | diff license.txt - || ( ( cat license.txt; echo; cat $x) > /tmp/file;   mv /tmp/file $x )   done   

Now run this in your source directory:

export LICENSELEN=`wc -l license.txt | cut -f1 -d ' '`   find . -type f \(-name \*.cpp -o -name \*.h \) -print0 | xargs -0 ./addlicense.sh   
like image 23
Adam Rosenfield Avatar answered Oct 05 '22 10:10

Adam Rosenfield