Add header(copyright) information to existing source files
Asked Answered
B

6

8

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.

Backhand answered 14/12, 2010 at 7:21 Comment(2)
Do any of the existing files have either the new file header already OR do any of them have an old one that needs to be replaced?Kwabena
@Craig: the existing files does not have any header. We need to add fresh.Backhand
H
8

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.

Headmost answered 10/1, 2011 at 20:29 Comment(0)
B
5

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.

Blithering answered 8/10, 2012 at 18:50 Comment(0)
D
2

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

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

Dorotea answered 14/12, 2010 at 7:42 Comment(1)
hi I tried this - as it is. but am getting error "find: missing argument to -exec"Backhand
T
2

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

Toastmaster answered 14/12, 2010 at 7:59 Comment(0)
F
2

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.

Fearfully answered 13/1, 2011 at 8:53 Comment(0)
D
-2

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.

Delftware answered 11/11, 2021 at 19:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.