Created
March 6, 2014 12:12
-
-
Save chetanmeh/9388311 to your computer and use it in GitHub Desktop.
Script to determine OSGi SCR related details like component pid , classnames etc
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 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'[email protected]() | |
def configType = xml.'scr:component'.@'configuration-policy'?.text() ?: null | |
def implClass = xml.'scr:component'[email protected]() | |
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