Last active
August 29, 2015 14:20
-
-
Save bdkosher/25c31bffd3cd52cf823c to your computer and use it in GitHub Desktop.
Sonar library scraper
This file contains hidden or 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
| @Grab(group='org.ccil.cowan.tagsoup', module='tagsoup', version='1.2') | |
| def url = 'https://example.com/sonar/dependencies?resource=commons-io%3Acommons-io&search=commons-io%3Acommons-io&version=1.1' | |
| def parser = new XmlSlurper(new org.ccil.cowan.tagsoup.Parser()) | |
| new URL(url).withReader { page -> | |
| def html = parser.parse(page) | |
| html.'**'.find { it.@id == 'results_col' }.'**'.findAll { it.name() == 'td' }.each { td -> | |
| println td.span.text() | |
| } | |
| } |
This file contains hidden or 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
| import groovy.json.* | |
| import groovy.transform.* | |
| def url = new URL('https://example.com/sonar/api/projects/index?libs=true&format=json&desc=false&subprojects=true&versions=true') | |
| @ToString | |
| class Lib { | |
| String id | |
| String name | |
| List<String> versions = [] | |
| } | |
| def libs = new JsonSlurper().parse(url).findAll { it.qu == 'LIB' && !it.nm.startsWith('com.example') } .collect { prj -> | |
| def v = prj.v ? ((prj.v as Map).keySet() as List) : ['unknown'] | |
| new Lib(id: prj.k, name: prj.nm, versions: v) | |
| } | |
| def csv = new File(/C:\Users\jwolf2\Desktop\libs2.csv/) | |
| csv << 'Name,Group ID,Artifact ID,Version\n' | |
| libs.each { lib -> | |
| lib?.versions.each { version -> | |
| def (groupId, artifactId) = lib.id.split(':') | |
| csv << "$lib.name,$groupId,$artifactId,$version\n" | |
| } | |
| } | |
| println "${libs.size()} libraries in total." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment