Reputation: 1831
I hava a Java project with a lot of files. In some of this I inserted a JavaDoc @author tag just before class/interface declaration, but not in all. I would like a script (bash, perl, whatever) able to add @author tag in the right position (just before class declaration) for all files that doesn't have one. Ho to find the right line where to add this javadoc?:
/*
* @author alepac
*/
Upvotes: 1
Views: 2244
Reputation: 3651
Not a script but if your Java project happens to be built with Maven then you could use the javadoc:fix goal of Javadoc plugin which you can configure so that it inserts the @author
tag wherever it's missing including the cases where there is no javadoc at all:
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>2.10.3</version>
<configuration>
<fixTags>author</fixTags>
<force>true</force>
<fixFieldComment>false</fixFieldComment>
<fixMethodComment>false</fixMethodComment>
</configuration>
</plugin>
Upvotes: 1
Reputation: 995
You can try with the following script,
#!/bin/bash
function proccess_all_files {
FILES="./*"
cd "$1"
for i in $FILES
do
if [[ -d "$i" ]]; then
echo "Directory $i found...no action taken"
else
echo "Processing $i file..."
sed '/*
* @author alepac
*/' $i > $i.bak
mv "$i.bak" "$i"
fi
done
for j in * .[!.]* ..?*; do
cd "$1"
test -d "$1/$j" && proccess_all_files "$1/$j"
done
}
proccess_all_files "`DIRECTORY NAME`"
Let me know whether it helped you or not, or whether this is exactly what you are looking for or not.
Hope it helps.
Upvotes: 0