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
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.
No, you don't have to put the license in each source code file.
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.
#!/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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With