This is a simple collection of tools for inserting, removing and replacing a copyright notice to any kinds of source code files.
The only requirement is to have JDK installed( >1.7).
To build copyright-tools project you may run terminal/console and navigate to the progect's root folder. Now you can execute:
./gradlew build(Linux/macOS)gradlew build(Windows)
The commands require root, notice and extensions arguments.
-
insert - inserts a notice before/after the file content. Requires all mandatory arguments. Example usage:
insert --root "<pathToInputFolder>" --notice "<pathToTheNotice>" --extensions <ListOfExtensions> -
remove - removes the first occurrence of the notice. Requires all mandatory arguments. This is an example usage with short options:
remove -r "<pathToInputFolder>" -n "<pathToTheNotice>" -e <ListOfExtensions> -
replace - replaces an old notice with a new one. Requires the mandatory argument and a
new-noticeargument. Example:
replace -r "<pathToInputFolder>" -n "<pathToTheNotice>" --new-notice "<pathToTheNewNotice>" -e <ListOfExtensions>. The command may be used to replace all occurrences of a specified string with another one. Just add a-s(--string) option somewhere.
-hor--help- prints help, no mandatory option with no arguments.-ror--root- option for a path to the root directory. Requires a path to the source folder as argument. If the path contains\character you must to replace with\\. This is a mandatory option.-nor--notice- the option requires a path to the notice as argument. If the path contains\character you must to replace with\\. Mandatory option.-eor--extensions- list of the file extensions on which you want to execute the command. Example:.java .gradle.-blor--blank- with this option a blank line will be inserted after the notice. If you use with a--bootomoption a blank line will be inserted before the notice.-ior--info- enable log info. Log file will be created in the root directory.-nnor--new-notice- if you want to replace an old notice with a new notice this will be the path to the new notice.-bor--bottom- use this option if you want to insert notice after the source. This is an optional argument.-oor--output- with this option you can specify an output directory. The result will be stored in the output folder and root's folder will stay unchanged. Requires a path to an output folder as argument. It's a no mandatory option.
This is a standard argument's body:
-r "<pathToInputFolder>" -n "<pathToNoticeTextFile>" -e <extensionsList>--root "<pathToInputFolder>" --notice "<pathToNoticeTextFile>" --extensions <extensionsList>
There are two ways:
- From
build/libfolder runjava -jar copyright-inserter-<version>.jar <arguments>(Linux/macOS/Windows) - From
build/scriptsrun:./copyright-tools <arguments>(Linux/macOS)copyright-tools.bat <arguments>(Windows)
-
Suppose you want to insert a notice with a blank line (after the notice) before all
javaandgradlefiles from the project, you can run this command:
insert -r "C:\\targetDir" -n "C:\\Notice.txt" -e .java .gradle -bl. -
If you want to insert the notice at the bottom of the code: just add
--bottomto the above command (or-boption). In this case the blank line will be inserted before the notice. -
Suppose you want to remove a notice from existing code, you may run:
remove --root "C:/targetDir" --notice "C:/NoticeToRemove.txt" -e .java. -
To replace an old copyright notice with a new one:
repalce -r "C:/targetDir" -n "C:/old-notice.txt" -nn "C:/new-notice.txt" -e .java
To replace a string with a new one:
replace -r "D:/MyProject" -n "old_string" -nn "new_string" -e .gradle -s. -
If you want to keep your original files untouched - simply run the above commands with
--output(or-o) option and a path to desired output destination as an argument:
insert -r "C:\\targetDir" -n "C:\\Notice.txt" -e .java .gradle -bl -o "C:\\output" -e .java.