Groovy scripts are tremendously helpful to run ad-hoc scripts for extracting report data, performing bulk updates on the fly or debugging issues.
To execute a Groovy script, create a file with the .groovy extension and then execute the script in the Composum editor. One important thing to note is that you want to make sure your return is not session-bound, because it closes the resource resolver before printing the result.
The Composum Groovy script executor binds the following variables for your use:
Since Groovy is executing in the context of an OSGi container, you may want to retrieve an OSGi service, unfortunately, it’s not quite as easy as the AEM Groovy Console, but it can be done:
import org.osgi.framework.*;
import org.apache.sling.api.resource.*;
BundleContext bundleContext = FrameworkUtil.getBundle(ResourceResolverFactory.class).getBundleContext();
def serviceReference = bundleContext.getServiceReference(ResourceResolverFactory.class);
def service = bundleContext.getService(serviceReference);
println service;
bundleContext.ungetService(serviceReference);
Naturally, to use the Groovy script execution feature in Composum Browser, you need Groovy installed. At the time this post was written, Groovy is not installed in the Apache Sling Starter 11 or Sling CMS 0.16.2. The easiest way to install Groovy is to install Groovy All 2.4.19. In future versions of Sling CMS and Sling Starter the expectation is Groovy 3 will be pre-installed.
In more recent versions of Composum (at least 1.12+) you can see the system nodes in the JCR, including:
To see the system properties change the Filter for tree option to unfiltered and then expand /jcr:system.
Composum supports executing queries in the search bar. In addition, you can download the results of the query by selecting the Export Query Result dropdown on the right-hand side of the search bar. The export option supports JSON (full tree), CSV (summary), and TSV (summary).
Composum Node Browser is a powerful tool for managing Apache Sling based repositories. Check it out via the Apache Sling Starter or Sling CMS or download Composum directly from GitHub.