if ( input fileS is in the format of wrong1.txt ) {
Print the fileS name.
}
wrong1.txt
DataBaseConnection dbconn = new DataBaseConnection(connectionString);
try{
something...
somefuntion(dbconn,...)
dbconn..
..
..
}catch{
print excecption;
}finally{
dbconn.destroy();
}
---->> here connection with DB is outside of Try block -->> is wrong.
NB:
The line --> DataBaseConnection dbconn = new DataBaseConnection(connectionString);
may change (i mean it will not be exactly as it is in all the input files)
is working. But listing in correct1.txt file format. (as in my first post)
i changed the code as
find yourPath -name "*.java" |xargs awk '/try{/{t=1} /}catch/{t=0} (t && $0~/new DataBaseConnection\(/){print FILENAME}'
--> with only t NOT !t
Then i am getting in wrong1.txt file format (as in my first post)
But here the problem is :
the java files Does not containing any database connection is also listing...
i know i did wrong as i deleted the ! charector from t.
but..
could you please change the code to get all the *.java files in Wrong1.txt format Alone.
here i made some dummy java file, and my initial command (with "!t") gives the right result, the java files, which have creating connection statement outside the try/catch block.
basically, the command is NOT gonna print any file, that doesn't containing "
new DataBaseConnection" string. Can that be that the string in your java file as comment? so you think it should be the "correct" case, but listed out by my command?
or you could try grep first, then pass to my awk. (although I thought the printed out file by my awk must contain "new Databaseconnection..." in java codes or java comments). e.g.
grep -il "new databaseconnection(" | xargs awk ....