Skip to content

Instantly share code, notes, and snippets.

@pmanvi
Created January 17, 2013 10:53
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 pmanvi/bedd1fdc88879b4c7794 to your computer and use it in GitHub Desktop.
Save pmanvi/bedd1fdc88879b4c7794 to your computer and use it in GitHub Desktop.
AndroidCompliantReport.groovy
def androidpakcageaNames = [
"java.applet",
"java.awt",
"java.beans",
"java.lang.management",
"java.rmi",
"javax.accessibility",
"javax.accessibility",
"javax.activity",
"javax.imageio",
"javax.management",
"javax.naming",
"javax.print",
"javax.rmi",
"javax.security",
"javax.swing",
"javax.transaction",
"javax.xml",
"org.ietf",
"org.omg",
"org.w3c",
]
def allImports = new TreeMap()
//external dependencies:
//junit, junitx,apache commons,w3c,icu
def javasrcDir = "<your src directory here>"
def packageList =new File(javasrcDir).list()
def androidWarnings = []
packageList.each() { pakcageaName ->
androidWarnings.add("\n\n========================================\n")
androidWarnings.add(" "+pakcageaName.toUpperCase()+"\n")
androidWarnings.add("========================================\n")
def p = ~/.*\.java/
new File(javasrcDir+pakcageaName).eachDirRecurse() { file ->
file.eachFileMatch(p) {
f ->
def imports = []
f.eachLine {
// condition to detect an import instruction
ln -> if ( ln =~ '^import .*' ) {
imports << "${ln - 'import '}"
}
}
if ( ! imports.empty ) {
//println f
imports.each() { i ->
if(!(//i.startsWith("com.westgroup.novus.cache") ||
i.startsWith("static") ||
i.startsWith("com.westgroup.novus.search"))) {
def obj = allImports.put(i,f.getName())
if(obj!=null){
// something already exists, let's append the same
allImports.put(i,f.getName()+"-"+obj)
}
}
androidpakcageaNames.each() { androidpakcageaName ->
if(i.startsWith(androidpakcageaName)) {
androidWarnings.add("\n"+f.getName()+" : "+i+" : "+androidpakcageaName)
//println f.getName()+" : "+i+" : "+androidpakcageaName
}
}
}
}
}
}
def file = new File('d:/'+pakcageaName+'.csv')
def count =1
file.withWriter() { out ->
out.append 'Number,pakcageaName, List of Java classes'
out.append '\n'
allImports.each() { key, value ->
def row = [count++, key, value]
out.append row.join(',')
out.append '\n'
}
}
def androidWarningsFile = new File("d:/androidWarnings12.txt")
androidWarningsFile.withWriter() { out ->
androidWarnings.each() {
out.append it
}
}
}
println 'done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment