-
-
Save helms-charity/cfa7af9c11add70b35cc0996c11168da to your computer and use it in GitHub Desktop.
This file contains 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.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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
:load https://gist.github.com/stillalex/02c4dca098b409fafbb2/raw/75d931c39710bf9994ef1858951cff8baa330934/install-clean.groovy
// to just output 'libs' candidates
libsCleaner.scanBundles()
// to remove all .jar files under 'libs/*/install'
libsCleaner.scanBundles(true)