How to manage licensed banners in Eclipse plug-in source files

I am going to release a set of Eclipse plug-ins as Open Source and noticed that most of the source code released under LGPL / EPL contains a header banner in each file that refers to the license or contains the license itself.

Since adding these banners to each file manually seems like a daunting and error-prone task. How can I automate the insertion of these banners?

+17
eclipse plugins banner
Oct. 15 '08 at 13:22
source share
2 answers

As for best practices, I believe that you should have your license text in a separate file and have a build tool (i.e. ant) ​​to add it at the beginning of all other files. Since you're talking about an open source project, you still need a build process to think about how to generate javadocs, publish releases, etc.

BTW, ant tasks are simple Java classes, so it's easy to write them yourself if you don't find the ant plugin that does just that.

Having come to an eclipse, as far as I know, he cannot do something like that. The fastest way I can do is bash (if you are using Linux). Suppose the msg file contains the text you want to add at the beginning of each file.

  • Create a new directory for storing files:

    mkdir ~ / outdir

  • Add msg at the beginning of each file and put the result in outdir

    for I'm in ls "*.java" ; do cat msg $ i> ~ / outdir / $ i; done

Similarly, you can write a command that does the same recursively, with an extra step to create the strucutre directory:

 mkdir ~/outdir for i in `find -type d | sed 's/\.//' | grep -v "^$"`; do mkdir ~/outdir$i; done for i in `find -name "*.java"`; do cat msg $i > ~/outdir/$i ; done 
+6
Oct. 15 '08 at 14:28
source share

A more Eclipse-like approach than adding to a manual approach is this: it is done through a graphical interface in Eclipse. Please note that this is a Linux / Windows menu; Mac is a little different.

  • Open Windows->Preferences
  • Go to Java->Code Style->Code Templates
  • Edit the comment template Comments->Files to include your template.
    There are variables for the current year, file name, etc.

Please note that this solution is only for new files; it will not help you with old files; for this i would use something like idrosid solution for your existing code

+2
Oct. 15 '08 at 21:37
source share



All Articles