Skip to content

Instantly share code, notes, and snippets.

@jiafangtao
Created November 17, 2021 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jiafangtao/635dda693e09c3d68d408508910ee22e to your computer and use it in GitHub Desktop.
Save jiafangtao/635dda693e09c3d68d408508910ee22e to your computer and use it in GitHub Desktop.
Check if files are started with comments
#! /usr/bin/groovy
/*******************************************************************
*
* My first groovy script which is used to determine if a file is
* started with JAVA comments, i.e. // or /*.
*
*******************************************************************/
// The file list is piped to the script (i.e. stdin)
// Sample usage: find . | grep java | groovy checkcomments.groovy -
def flist = new ArrayList()
def reader = System.in.newReader()
def result = new ArrayList()
while(true) {
def s = reader.readLine()
if (s == null)
{
break
}
flist.add(s)
}
for (f in flist) {
//println "Checking " + f
def scanner = new Scanner(new File(f))
if (scanner.hasNextLine()) {
line = scanner.nextLine()
if (!line.startsWith("//") && !line.startsWith("/*")) {
println f
result.add(f)
}
}
}
print "Total files count: " + flist.size() + "\n"
print "Matched: " + result.size() + "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment