Skip to content

Instantly share code, notes, and snippets.

@pedrotoliveira
Last active November 18, 2015 19:17
Show Gist options
  • Save pedrotoliveira/26ffecbdc9c1a4133923 to your computer and use it in GitHub Desktop.
Save pedrotoliveira/26ffecbdc9c1a4133923 to your computer and use it in GitHub Desktop.
Add Serializable for all classes in project
#!/bin/bash
function findClassesToImplementSerializable() {
for filename in $(find . -name "*.java");
do
echo $filename | /bin/grep -v "test";
if [ "${?}" -eq 0 ]
then
echo "$filename";
changeline;
fi
done
}
function changeline() {
local elines=$(/bin/grep -E "import java.io.Serializable;|interface|public enum|serialVersionUID" $filename | wc -l);
if [ "${elines}" -eq 0 ]
then
local line=$(cat $filename | /bin/grep "class" | /bin/grep -v "Serializable" | grep -v "@Remote(" | grep -v "@Local(" | head -1);
#echo "antes: $line";
echo $line | /bin/grep "implements";
if [ "${?}" -eq 0 ]
then
local newline=$(echo $line | tr -d "{")", Serializable {";
else
local newline=$(echo $line | tr -d "{")" implements Serializable {";
fi
#echo "depois: $newline";
sed -i "s/${line}/${newline}/" $filename;
#cat $filename;
addImportSerializable;
echo "========== OK ============";
else
echo "========== NOK ===========";
fi
#addSerialVersionUID;
}
function addImportSerializable() {
#local filename=AssinaturaEletronicaBW.java;
local packageline=$(cat $filename | /bin/grep "package");
#echo $packageline;
local newpackageline=$(echo -e ${packageline}" import java.io.Serializable;");
#echo $newpackageline;
sed -i "s/${packageline}/${newpackageline}/" $filename;
}
##main
findClassesToImplementSerializable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment