Skip to content

Instantly share code, notes, and snippets.

Searching Online JDK 7 Javadoc API Documentation for string '1.7'
#!/usr/bin/env groovy
// searchJdk7ApiDocsForSince17.groovy
def anchorString = '<a href="'
def anchorStringUpper = anchorString.toUpperCase()
def urls = new ArrayList<String>()
"http://download.oracle.com/javase/7/docs/api/allclasses-frame.html".toURL().eachLine
{
def startIndex = -1
if (it.contains(anchorString))
{
startIndex = it.indexOf(anchorString) + anchorString.size()
}
else if (it.contains(anchorStringUpper))
{
startIndex = it.indexOf(anchorStringUpper) + anchorStringUpper.size()
}
if (startIndex > -1)
{
def endIndex = it.indexOf('"', startIndex)
if (endIndex > startIndex)
{
def url = it.substring(startIndex, endIndex)
urls.add(url)
}
}
}
def numUrlsProcessed = 0
def numUrlsMatching = 0
println "${urls.size()} total URLs to search for 1.7 text."
def withJava7 = new ArrayList<String>()
urls.each
{
def match = false
numUrlsProcessed++
def eachUrl = "http://download.oracle.com/javase/7/docs/api/${it}"
try
{
if (eachUrl.toURL().text.contains("1.7"))
{
numUrlsMatching++
match = true
withJava7.add(it)
}
}
catch (Exception ex) // catch HTTP problems like 404 or 504.
{
println "ERROR trying to acces ${eachUrl}: ${ex.toString()}"
}
println "${numUrlsMatching} of ${numUrlsProcessed} match 1.7 (${match ? eachUrl : '-'})!"
}
println "Javadoc files with 1.7: "
withJava7.each
{
println "\t${it}"
}
@dustinmarx
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment