Apache Sling Resource Presence

Clone this repo:
  1. a41d713 Adding sonarqube badges as per SLING-9682 by Dan Klco · 8 months ago master
  2. aa318a2 Updating badges for org-apache-sling-resource-presence by Radu Cotescu · 8 months ago
  3. e1e56fe pull build section up by Oliver Lietz · 1 year, 1 month ago
  4. 2353587 SLING-9282 Update Pax Exam to 4.13.3 by Oliver Lietz · 1 year, 1 month ago
  5. 986a4f5 SLING-9281 Update to Sling Bundle Parent 38 by Oliver Lietz · 1 year, 1 month ago

Apache Sling

Build Status Test Status Coverage Sonarcloud Status JavaDoc Maven Central License

Apache Sling Resource Presence

This module is part of the Apache Sling project.

This module creates proxy OSGi services that are registered only if specific resources are present.

Like for example:

private ResourcePresence barIsPresent;

The barIsPresent service is registered only if the /content/foo/bar resource is present, allowing OSGi components to be dependent on the presence of specific Resources.

This is mostly meant for testing, to wait for test content before running specific tests.

Getting Started

  1. Configure a service user mapping for org.apache.sling.resource.presence to allow reading resources, using e.g. service user sling-readall.

  2. Configure a presenter to observe a resource by path, e.g. path=/apps

    Whenever resource /apps is available the presenter will register an OSGi service for it and unregister it whenever /apps gets removed.

  3. You can depend on that service now, e.g. using a @Reference annotation with a target on your component:

            target = "(path=/apps)"
        private ResourcePresence apps;

Using Resource Presence with Pax Exam

When running tests with resources involved, you can use a resource presence to delay test execution until required resources are available.

@Filter(value = "(path=/apps)")
private ResourcePresence apps;

public Option[] configuration() {
    return new Option[]{
            .put("path", "/apps")

public void testApps() {
    assertThat(apps.getPath(), is("/apps"));