Created
November 17, 2021 06:37
-
-
Save jiafangtao/635dda693e09c3d68d408508910ee22e to your computer and use it in GitHub Desktop.
Check if files are started with comments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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