Skip to content

Instantly share code, notes, and snippets.

@chetanmeh
Created March 6, 2014 12:12
Show Gist options
  • Save chetanmeh/9388311 to your computer and use it in GitHub Desktop.
Save chetanmeh/9388311 to your computer and use it in GitHub Desktop.
Script to determine OSGi SCR related details like component pid , classnames etc
import org.apache.sling.commons.osgi.ManifestHeader
def oakBundles = bundleContext.getBundles().findAll {b ->
def name = b.symbolicName
return name.startsWith('org.apache.jackrabbit.oak')
}
oakBundles.each{b ->
def scs = b.headers.get('Service-Component')
if(!scs) return
def scHeader = ManifestHeader.parse(scs)
scHeader.entries.each { e ->
def xmlPath = e.value
//println(xmlPath)
def url = b.getEntry(xmlPath)
def text = url.text
def ns = getNS(text)
def xml = new XmlSlurper().parseText(text).declareNamespace([scr:ns])
def name = xml.'scr:component'.@name.text()
def configType = xml.'scr:component'.@'configuration-policy'?.text() ?: null
def implClass = xml.'scr:component'.implementation.@class.text()
println ("$implClass")
println (" PID -$name")
if(configType) println (" Config Type -$configType")
//println (" Path -$xmlPath")
}
}
def getNS(text){
def prefix = "http://www.osgi.org/xmlns/scr/v"
def posVersion = ["1.0.0","1.1.0", "1.2.0"]
def ns = posVersion.find{text.contains("$prefix$it")}
assert ns, "No namespace in $text"
return "$prefix$ns".trim()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment