Scripts to be used through Felix Script Console http://felix.apache.org/documentation/subprojects/apache-felix-script-console-plugin.html
Last active
October 10, 2015 20:48
-
-
Save chetanmeh/3748614 to your computer and use it in GitHub Desktop.
Scripts to be used through Felix Script Console http://felix.apache.org/documentation/subprojects/apache-felix-script-console-plugin.html
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
//Provide details around the bootdelgation state | |
println "Bootdelgation property value :- "+bundleContext.getProperty("org.osgi.framework.bootdelegation") | |
println "Felix bootdelgation entries" | |
bundleContext.bundle.framework.bootPackages.each { | |
println it | |
} |
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
//This script finds out which bundle embeds the given class | |
import org.osgi.framework.Bundle | |
import org.osgi.framework.BundleContext | |
//Name of the class | |
def className = "org.apache.sling.engine.impl.SlingMainServlet" | |
def resPath = className.replaceAll('.','/')+".class" | |
def bundles = bundleContext.getBundles().findAll{Bundle b -> | |
b.getEntry(resPath) != null | |
} | |
println "Following bundles have the class" | |
bundles.each{ | |
println it | |
} |
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 | |
import groovy.text.SimpleTemplateEngine | |
def pkgName = 'org.slf4j' | |
def data = [] | |
bundleContext.getBundles().findAll{b -> | |
def impPkg = b.headers.get('Import-Package') | |
if(impPkg){ | |
def header = ManifestHeader.parse(impPkg) | |
header.entries.each { e -> | |
if(e.value.startsWith(pkgName)){ | |
def version = e.attributes.find {it.name == 'version'} | |
data << [bundleName:b.symbolicName, pkgName:e.value, version:version?.value] | |
//println "${b.symbolicName} -> ${e.value} (${version?.value})" | |
} | |
} | |
} | |
} | |
def ttf = new TemplateFactory() | |
ttf.columns = [ | |
[name:'bundleName', displayName:'Bundle Name', size:40], | |
[name:'pkgName', displayName:'Package Name', size:20], | |
[name:'version', displayName:'Version', size:10], | |
] | |
println new SimpleTemplateEngine().createTemplate(ttf.template).make([rows:data]).toString() | |
class ConfluenceTemplateFactory { | |
def columns = [] | |
def getTemplate() { """ | |
||${columns.collect{ " <%print \"$it.displayName\"%> " }.join("||")}|| | |
<% rows.each {%>${"|"+columns.collect{ " \${it.${it.name}.toString()} " }.join("|")+"|"} | |
<% } %>""" | |
} | |
} | |
class TemplateFactory { | |
def columns = [] | |
def getTemplate() { """ | |
${columns.collect{ " <%print \"$it.displayName\".center($it.size)%> " }.join()} | |
${columns.collect{ " <%print \"_\"*$it.size %> " }.join()} | |
<% rows.each {%>${columns.collect{ " \${it.${it.name}.toString().padRight($it.size).substring(0,$it.size)} " }.join()} | |
<% } %>""" | |
} | |
} |
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
//Logs in using SlingRepository service and opens a session | |
import org.apache.sling.jcr.api.SlingRepository | |
import javax.jcr.Session | |
import javax.jcr.Node | |
import javax.jcr.Property | |
SlingRepository repo = osgi.getService(SlingRepository.class) | |
Session s = null | |
InputStream is = null | |
try { | |
s = repo.loginAdministrative(null) | |
Node n = s.getNode('/etc/designs/crx/welcome/crx') | |
Node n2 = n.addNode("p4.png","nt:file") | |
Node contentNode = n2.addNode("jcr:content","nt:resource") | |
is = new FileInputStream(new File('/foo.png')) | |
contentNode.setProperty("jcr:data",s.valueFactory.createBinary(is)) | |
n2.setProperty("foo","bar") | |
s.save() | |
} finally { | |
is?.close() | |
s?.logout() | |
} |
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.jcr.api.SlingRepository | |
import javax.jcr.Session | |
import javax.jcr.Node | |
import javax.jcr.Property | |
import org.apache.jackrabbit.api.JackrabbitSession | |
SlingRepository repo = osgi.getService(SlingRepository.class) | |
Session s = null | |
try { | |
s = repo.loginAdministrative(null) | |
JackrabbitSession js = s | |
js.userManager.createUser("admin","admin") | |
} finally { | |
s?.logout() | |
} |
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.jcr.api.SlingRepository | |
import javax.jcr.Session | |
import javax.jcr.Node | |
import javax.jcr.Property | |
import javax.jcr.SimpleCredentials | |
import javax.security.auth.Subject | |
SlingRepository repo = osgi.getService(SlingRepository.class) | |
Session s = null | |
try { | |
SimpleCredentials sc = new SimpleCredentials("administrator","password".getChars()) | |
s = repo.login(sc) | |
def o1 = java.lang.reflect.Proxy.getInvocationHandler(s) | |
Subject subject = o1.delegatee.subject | |
subject.principals.each {p -> | |
println p | |
} | |
} finally { | |
s?.logout() | |
} |
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
//Symbolic name of bundle for which the source code location is to be find out | |
def name = 'com.adobe.cq.social.cq-social-commons-oauth' | |
def bundle = bundleContext.getBundles().find{b -> | |
b.symbolicName == name | |
} | |
def pomEnumeration = bundle.findEntries('META-INF/maven','pom.xml',true) | |
if(!pomEnumeration){ | |
println "No pom found" | |
return | |
} | |
def pom = pomEnumeration.toList().first().getText() | |
def xml = new XmlSlurper().parseText(pom) | |
println xml.scm?.developerConnection |
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 javax.management.remote.JMXConnectorFactory as JmxFactory | |
import javax.management.remote.JMXServiceURL as JmxUrl | |
def serverUrl = 'service:jmx:rmi:///jndi/rmi://localhost:40322/jmxrmi' | |
def server = JmxFactory.connect(new JmxUrl(serverUrl)).MBeanServerConnection | |
def fwkBean = new GroovyMBean(server, 'osgi.core:type=framework,version=1.5') | |
def bundleState = new GroovyMBean(server, 'osgi.core:type=bundleState,version=1.5') | |
def secProvider = bundleState.listBundles().findResult {id, e -> | |
if(e.get('SymbolicName') == 'org.apache.sling.extensions.webconsolesecurityprovider'){ | |
return e | |
} | |
} | |
assert secProvider | |
def id = secProvider.get('Identifier') | |
fwkBean.uninstallBundle(id) | |
println "Uninstalled bundle ${secProvider.get('SymbolicName')}" |
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.osgi.framework.Bundle | |
import org.osgi.framework.BundleContext | |
//Script to load a class which is not exported and then invoke some static method on that class | |
//Name of the class | |
def className = "org.apache.sling.engine.impl.SlingMainServlet" | |
def resPath = className.replaceAll('.','/')+".class" | |
def bundles = bundleContext.getBundles().findAll{Bundle b -> | |
b.getEntry(resPath) != null | |
} | |
if(!bundles){ | |
println "No bundle found for class $className" | |
return | |
} | |
def b = bundles.asList().first() | |
def clazz = b.loadClass(className) | |
//Invoke some static method | |
def result = clazz.metaClass.invokeStaticMethod(clazz, 'foo', arg1) | |
println result |
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
//Digs out the servlets which are programatically registered with HTTP Service | |
import org.osgi.service.http.HttpService | |
import org.osgi.framework.FrameworkUtil | |
import org.osgi.framework.Bundle | |
def httpService = osgi.getService(HttpService.class) | |
httpService.handlerRegistry.aliasMap.each{alias,servlet -> | |
Bundle bnd = FrameworkUtil.getBundle(servlet.class) | |
println "$alias : ${servlet.class.name} ($bnd.symbolicName)" | |
} |
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.api.resource.ResourceResolverFactory | |
import org.apache.sling.api.resource.ResourceResolver | |
import org.apache.sling.api.resource.Resource | |
ResourceResolverFactory rrf = osgi.getService(ResourceResolverFactory.class) | |
ResourceResolver resolver = rrf.getAdministrativeResourceResolver(null) | |
try{ | |
final String queryString = "SELECT sling:vanityPath, sling:redirect, sling:redirectStatus FROM sling:VanityPath WHERE sling:vanityPath IS NOT NULL ORDER BY sling:vanityOrder DESC"; | |
final Iterator<Resource> i = resolver.findResources(queryString, "sql"); | |
i.each{ | |
println it | |
} | |
}finally{ | |
resolver?.close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice scripts! I had to double escape the dot in the regex though for it to work: className.replaceAll('\.','/')+".class"