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

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

问题描述

我将以开放源代码的形式发布一组Eclipse插件,并注意到在LGPL/EPL下发布的大多数源代码在每个引用许可证或包含许可证本身的文件中都包含一个标题横幅. /p>

由于将这些标语手动添加到每个文件似乎是一项艰巨且容易出错的任务.我该如何自动插入这些横幅?

我最终找到了版权生成器是Eclipse插件, ins,还可以更新现有的许可证标语.

解决方案

关于最佳实践,我认为您应该将许可证文本保存在单独的文件中,并使用构建工具(例如ant)将其添加到所有文件的开头其它文件.由于您正在谈论的是开源项目,因此无论如何都需要一个构建过程来进行思考,例如生成javadocs,发布发行版等.

BTW,ant任务是简单的Java类,因此,如果您没有找到能完全做到这一点的ant插件,应该很容易自己编写一个.

据我所知,日食无法做到这一点.我能想到的最快方法是使用bash(如果您使用的是Linux).假设文件msg包含要在每个文件开头添加的文本.

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

    mkdir〜/outdir

  2. 在每个文件的开头添加味精,并将结果放在outdir

    对于ls "*.java"中的i;做猫味精$ i>〜/outdir/$ i;完成

类似地,您可以编写一个递归执行此命令的命令,并额外执行一个步骤来创建目录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

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?

Edit: I've eventually found Copyright Wizard and Copyright Generator which are Eclipse plug-ins which also allow for updating existing license 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天全站免登陆