将标头(版权)信息添加到现有源文件

发布于 2024-10-07 04:33:54 字数 123 浏览 0 评论 0原文

我想将我们公司的版权信息添加到我们所有现有的源代码文件中。

该项目是在 Eclipse 中开发的。因此,对于新文件,我可以按照建议修改设置

任何基于 Windows 的文本操作脚本语言也会有所帮助。

I want to add our company's copyright information to all of our EXISTING source code files.

The project is developed in Eclipse. so, for new files I can modify the settings as suggested here. But for existing files, how am I supposed to do this. How can I modify hundreds of java files to add the copyright information. (And I'm unable to open the releng plugin mentioned in the above link.

Any windows based text maniputaion scripting language will also help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

〗斷ホ乔殘χμё〖 2024-10-14 04:33:54

纠正康斯坦丁的解决方案:

find . -name \*.java -exec sh -c "mv '{}' tmp && cp copyright '{}' && cat tmp >> '{}' && rm tmp" \;

问题是&&由 shell 直接解释,而不是传递给 find。转义它们也不是解决方案,因为 find exec 不理解它们。所以只需将整个命令交给某个 shell 即可。

Correcting Konstantin's solution:

find . -name \*.java -exec sh -c "mv '{}' tmp && cp copyright '{}' && cat tmp >> '{}' && rm tmp" \;

Problem was that && is being interpreted by the shell directly instead of being passed to find. Escaping them is no solution either, as the find exec does not understand them. So just give the whole command to some shell.

山人契 2024-10-14 04:33:54

请尝试 eclipse Releng 插件。
这将有助于在所有 .java 文件和 .properties 中修复/添加版权声明。
只需右键单击项目并选择“修复版权”。
链接

Please try eclipse Releng plugin.
This would help to fix/add copyright statement in all .java files and .properties.
Simply right click on the project and select "Fix copyright".
Link.

眼睛会笑 2024-10-14 04:33:54

我会安装 CygWin (core + find) 并做一些类似

find 的事情。 -name *.java -exec mv '{}' tmp && cp 版权 '{}' &&猫tmp>> '{}' && rm tmp \;

I would install CygWin (core + find) and do something of a kind

find . -name *.java -exec mv '{}' tmp && cp copyright '{}' && cat tmp >> '{}' && rm tmp \;

若水微香 2024-10-14 04:33:54

您可以使用 Maven 许可证插件来执行此操作。

检查这个。该插件支持许可证头的模板,删除许可证并检查所有文件中的许可证。

You can use maven license plugin to do this.

Check this and this. The plugin support templates for your license header, remove the license and check for the license in all your files.

好久不见√ 2024-10-14 04:33:54

我认为您可以使用正则表达式使用 Eclipse 替换命令。

想象一下你的版权是这样的:

/* jQuery UI CSS Framework
*  Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
*  Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses.
*/

那么

1. Go to menu: Search -> File

2. in the Search dialog 
2.1. check the "Regular Expression"
2.2. in the Containing text:
    \A[^(\Q/*\E\s+jQuery.*)]
2.3 click the Replace
    past your copyright

正则表达式的解释:

\A - 文件开头

\Q...\E - 这是正则表达式关键字(因为 / 和 * 是正则表达式中的键)

\s+ - 空格

[^( ..)] - 表示除了

I think you can use Eclipse replace command using Regular Expression.

Imagine that your copyright is something like:

/* jQuery UI CSS Framework
*  Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
*  Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses.
*/

then

1. Go to menu: Search -> File

2. in the Search dialog 
2.1. check the "Regular Expression"
2.2. in the Containing text:
    \A[^(\Q/*\E\s+jQuery.*)]
2.3 click the Replace
    past your copyright

Explanation of regex:

\A - Start of the file

\Q...\E - Here goes the regex keywords ( because / and * are keys in regex )

\s+ - whitespaces

[^(..)] - means except

生死何惧 2024-10-14 04:33:54

您可以使用记事本++。它可以使用“扩展模式”上的“在文件中查找”功能搜索和替换所有文件中的文本。使用 \r\n (或文件的换行符序列)作为搜索输入。

You can use Notepad++. It can search and replace text in all files with "Find in Files" feature on "Extended Mode". Use \r\n (or your file's newline sequence) as the search input.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文