Skip to content

Instantly share code, notes, and snippets.

@yesil
Forked from stillalex/install-clean.groovy
Created March 31, 2016 12:45
Show Gist options
  • Save yesil/191b04f968c728962aefa00b927bec5f to your computer and use it in GitHub Desktop.
Save yesil/191b04f968c728962aefa00b927bec5f to your computer and use it in GitHub Desktop.
import org.apache.jackrabbit.oak.spi.commit.CommitInfo
import org.apache.jackrabbit.oak.spi.commit.EmptyHook
import org.apache.jackrabbit.oak.spi.state.NodeState
import org.apache.jackrabbit.oak.spi.state.NodeBuilder
class LibsCleaner {
def session
def scanBundles(remove = false) {
def root = session.store.root
def builder = root.builder()
scanBundlesInt(session, remove, root.getChildNode("libs"), builder.getChildNode("libs"), "/libs")
if(remove) {
session.store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY)
}
println "finished"
}
def scanBundlesInt(def session, Boolean remove, NodeState nodeState, NodeBuilder nodeBuilder, String path) {
for(entry in nodeState.getChildNodeEntries()) {
def ns = entry.nodeState
def name = entry.name
def builder = nodeBuilder.getChildNode(name)
def current = path + "/" + name
if(name == "install") {
for(cnes in ns.getChildNodeNames()) {
if(cnes.endsWith(".jar")) {
if(remove) {
println "Removing ${current}/${cnes}"
builder.getChildNode(cnes).remove()
} else {
println "Found ${current}/${cnes}"
}
}
}
} else if(ns.getName("jcr:primaryType") == "nt:folder") {
scanBundlesInt(session, remove, ns, builder, current)
}
}
}
}
libsCleaner = new LibsCleaner(session: session)
@gogohoho
Copy link

How to hack.fb with your code thanks
screenshot_2016-08-29-18-48-50 h

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