如何在Eclipse插件项目的源文件中管理许可证横幅 [英] How to manage license banners in source files of Eclipse plug-in projects

查看:144
本文介绍了如何在Eclipse插件项目的源文件中管理许可证横幅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要发布一组Eclipse插件作为开源,并注意到,根据LGPL / EPL发布的大多数源代码在每个文件中包含引用许可证或包含许可证本身的标题横幅。



由于手动将这些横幅添加到每个文件中似乎是一个令人生畏和容易出错的任务。如何自动插入这些横幅?

解决方案

关于最佳做法,我相信您应该将许可证文本一个单独的文件,并有一个构建工具(即ant)将其添加到所有其他文件的开头。因为你在谈论一个开源项目,所以你需要一个构建过程,就像生成javadocs,发布版本等一样。



BTW,ant任务是简单的Java类所以如果你没有找到一个蚂蚁插件,那么你应该很容易写一个。



根据我的知识,它不能做某事喜欢这个。我可以想到的最快的方式是使用bash(如果你正在使用Linux)。假设文件msg包含要在每个文件开头添加的文本。


  1. 创建一个新目录来存储文件:



    mkdir〜/ outdir


  2. 在每个文件的开始添加msg并放在 ls* .java中的我的outdir



    的结果;做猫msg $ i>〜/ outdir / $ i;完成


同样,您可以编写一个递归执行相同命令的命令,另外还需要创建一个目录strucutre:

  mkdir〜/ outdir 
for i in`find-type d | sed的/ \ grep -v^ $`;做mkdir〜/ outdir $ i;完成
为我在`find -name'* .java`;做猫msg $ i> 〜/ outdir / $ i;完成


I'm about to release a set of Eclipse plug-ins as Open Source and noticed that most source code released under the 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 to be a daunting and error-prone task. How can I go about automating the insertion of these banners?

解决方案

Concerning best practises, I believe you should have your license text in a separate file and have a build tool (ie ant) to add it at the beginning of all other files. Since you are talking about an open source project you would need a build process anyway for thinks like generating the javadocs, publishing releases etc.

BTW,ant tasks are simple Java classes so it should be easy to write one yourself if you don't find an ant plugin that does exactly that.

Coming to eclipse, to my knowledge, it cannot do something like this. The quickest way I can think of to do it is with bash (if you are using Linux). Assume the file msg contains the text you want to add at the beginning of every file.

  1. Create a new directory to store the files:

    mkdir ~/outdir

  2. Add the msg at the beginning of every file and put the result at the outdir

    for i 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 directory strucutre:

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

这篇关于如何在Eclipse插件项目的源文件中管理许可证横幅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆