Finished the migration to Sling 41 / Java 11
and made sure the bundle installed and enables fine.
diff --git a/bnd.bnd b/bnd.bnd
deleted file mode 100644
index a326674..0000000
--- a/bnd.bnd
+++ /dev/null
@@ -1 +0,0 @@
-Sling-Nodetypes: SLING-INF/nodetypes/superimposing.cnd
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index f29fc21..394259e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -45,8 +45,44 @@
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>run-bnd</id>
+ <goals>
+ <goal>bnd-process</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <bnd><![CDATA[
+Sling-Nodetypes: SLING-INF/nodetypes/superimposing.cnd
+Sling-Initial-Content: SLING-INF/apps/superimposing;path:=/apps/superimposing;overwrite:=true;overwriteProperties:=true
+ ]]></bnd>
+ </configuration>
</plugin>
-
+ <plugin>
+ <groupId>biz.aQute.bnd</groupId>
+ <artifactId>bnd-baseline-maven-plugin</artifactId>
+ <configuration>
+ <failOnMissing>false</failOnMissing>
+ </configuration>
+ </plugin>
+<!-- <plugin>-->
+<!-- <groupId>org.apache.felix</groupId>-->
+<!-- <artifactId>maven-bundle-plugin</artifactId>-->
+<!-- <extensions>true</extensions>-->
+<!-- <configuration>-->
+<!-- <instructions>-->
+<!-- <Export-Package>org.apache.sling.superimposing</Export-Package>-->
+<!-- <Private-Package>org.apache.sling.superimposing.impl</Private-Package>-->
+<!-- <DynamicImport-Package>org.apache.felix.webconsole</DynamicImport-Package>-->
+<!-- <Sling-Nodetypes>SLING-INF/nodetypes/superimposing.cnd</Sling-Nodetypes>-->
+<!-- <Sling-Initial-Content>-->
+<!-- SLING-CONTENT/apps/superimposing;path:=/apps/superimposing;overwrite:=true;overwriteProperties:=true-->
+<!-- </Sling-Initial-Content>-->
+<!-- </instructions>-->
+<!-- </configuration>-->
+<!-- </plugin>-->
</plugins>
</build>
@@ -71,9 +107,9 @@
</dependency>
<dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>2.4</version>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.9</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -135,10 +171,14 @@
<dependency>
<groupId>org.slf4j</groupId>
- <artifactId>slf4j-nop</artifactId>
- <version>1.5.2</version>
- <scope>test</scope>
+ <artifactId>slf4j-simple</artifactId>
</dependency>
+<!-- <dependency>-->
+<!-- <groupId>org.slf4j</groupId>-->
+<!-- <artifactId>slf4j-nop</artifactId>-->
+<!-- <version>1.5.2</version>-->
+<!-- <scope>test</scope>-->
+<!-- </dependency>-->
</dependencies>
diff --git a/src/main/java/org/apache/sling/superimposing/impl/SuperimposingManagerImpl.java b/src/main/java/org/apache/sling/superimposing/impl/SuperimposingManagerImpl.java
index bdd4d2d..8c61138 100644
--- a/src/main/java/org/apache/sling/superimposing/impl/SuperimposingManagerImpl.java
+++ b/src/main/java/org/apache/sling/superimposing/impl/SuperimposingManagerImpl.java
@@ -22,7 +22,6 @@
import static org.apache.sling.superimposing.SuperimposingResourceProvider.PROP_SUPERIMPOSE_SOURCE_PATH;
import java.util.ArrayList;
-import java.util.Dictionary;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -39,13 +38,12 @@
import javax.jcr.observation.EventListener;
import org.apache.commons.collections.IteratorUtils;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.resource.ResourceUtil;
-import org.apache.sling.commons.osgi.PropertiesUtil;
import org.apache.sling.superimposing.SuperimposingManager;
import org.apache.sling.superimposing.SuperimposingResourceProvider;
import org.osgi.framework.BundleContext;
@@ -69,6 +67,9 @@
@Designate(ocd = SuperimposingManagerImpl.SuperimposingManagerConfig.class)
public class SuperimposingManagerImpl implements SuperimposingManager, EventListener {
+ static final String FIND_ALL_QUERIES_DEFAULT = "JCR-SQL2|SELECT * FROM [" + MIXIN_SUPERIMPOSE + "] WHERE ISDESCENDANTNODE('/content')";
+ static final String OBSERVATION_PATHS_DEFAULT = "/content";
+
@ObjectClassDefinition(name = "Apache Sling Superimposing Resource Manager", description = "Manages the resource registrations for the Superimposing Resource Provider")
public @interface SuperimposingManagerConfig {
@@ -77,11 +78,10 @@
@AttributeDefinition(name = "Find all Queries", description = "List of query expressions to find all existing superimposing registrations on service startup. "
+ "Query syntax is depending on underlying resource provdider implementation. Prepend the query with query syntax name separated by \"|\".")
- String[] findAllQueries() default {
- "JCR-SQL2|SELECT * FROM [" + MIXIN_SUPERIMPOSE + "] WHERE ISDESCENDANTNODE('/content')" };
+ String[] findAllQueries() default { FIND_ALL_QUERIES_DEFAULT };
@AttributeDefinition(name = "Obervation paths", description = "List of paths that should be monitored for resource events to detect superimposing content nodes")
- String[] observationPaths() default { "/content" };
+ String[] observationPaths() default { OBSERVATION_PATHS_DEFAULT };
}
private boolean enabled;
@@ -120,10 +120,9 @@
private static final Logger log = LoggerFactory.getLogger(SuperimposingManagerImpl.class);
- public SuperimposingManagerImpl(@Reference
- private ResourceResolverFactory resolverFactory){
-
- }
+// public SuperimposingManagerImpl(ResourceResolverFactory resolverFactory){
+//
+// }
/**
@@ -279,25 +278,23 @@
// ---------- SCR Integration
@Activate
- protected synchronized void activate(final ComponentContext ctx) throws LoginException, RepositoryException {
-
+ protected synchronized void activate(BundleContext bundleContext, SuperimposingManagerConfig configuration)
+ throws LoginException, RepositoryException
+ {
+ this.bundleContext = bundleContext;
// check enabled state
- @SuppressWarnings("unchecked")
- final Dictionary<String, Object> props = ctx.getProperties();
- this.enabled = PropertiesUtil.toBoolean(props.get(ENABLED_PROPERTY), ENABLED_DEFAULT);
+ this.enabled = configuration.enabled();
log.debug("Config: " + "Enabled={} ", enabled);
if (!isEnabled()) {
return;
}
// get "find all" queries
- this.findAllQueries = PropertiesUtil.toStringArray(props.get(FINDALLQUERIES_PROPERTY),
- new String[] { FINDALLQUERIES_DEFAULT });
- this.obervationPaths = PropertiesUtil.toStringArray(props.get(OBSERVATION_PATHS_PROPERTY),
- new String[] { OBSERVATION_PATHS_DEFAULT });
+ this.findAllQueries = configuration.findAllQueries();
+ this.obervationPaths = configuration.observationPaths();
if (null == resolver) {
- bundleContext = ctx.getBundleContext();
+ //TODO: Migrate this to a Service Resource Resolver
resolver = resolverFactory.getAdministrativeResourceResolver(null);
// Watch for events on the root to register/deregister superimposings at runtime
diff --git a/src/main/java/org/apache/sling/superimposing/impl/SuperimposingResourceProviderImpl.java b/src/main/java/org/apache/sling/superimposing/impl/SuperimposingResourceProviderImpl.java
index aaede8c..a929b08 100644
--- a/src/main/java/org/apache/sling/superimposing/impl/SuperimposingResourceProviderImpl.java
+++ b/src/main/java/org/apache/sling/superimposing/impl/SuperimposingResourceProviderImpl.java
@@ -24,7 +24,7 @@
import javax.jcr.Session;
import javax.servlet.http.HttpServletRequest;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceWrapper;
diff --git a/src/main/resources/SLING-INF/apps/superimposing/config/org.apache.sling.jcr.base.internal.LoginAdminWhitelist.fragment-sir.config b/src/main/resources/SLING-INF/apps/superimposing/config/org.apache.sling.jcr.base.internal.LoginAdminWhitelist.fragment-sir.config
new file mode 100644
index 0000000..5b46f66
--- /dev/null
+++ b/src/main/resources/SLING-INF/apps/superimposing/config/org.apache.sling.jcr.base.internal.LoginAdminWhitelist.fragment-sir.config
@@ -0,0 +1,22 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+whitelist.bundles=[ \
+ "org.apache.sling.superimposing", \
+ "org.apache.sling.superimposing.impl", \
+ ]
+whitelist.name="sir"
diff --git a/src/test/java/org/apache/sling/superimposing/impl/SuperimposingManagerImplTest.java b/src/test/java/org/apache/sling/superimposing/impl/SuperimposingManagerImplTest.java
index 2ed1365..7fe0c53 100644
--- a/src/test/java/org/apache/sling/superimposing/impl/SuperimposingManagerImplTest.java
+++ b/src/test/java/org/apache/sling/superimposing/impl/SuperimposingManagerImplTest.java
@@ -21,11 +21,13 @@
import static org.apache.sling.superimposing.SuperimposingResourceProvider.PROP_SUPERIMPOSE_OVERLAYABLE;
import static org.apache.sling.superimposing.SuperimposingResourceProvider.PROP_SUPERIMPOSE_REGISTER_PARENT;
import static org.apache.sling.superimposing.SuperimposingResourceProvider.PROP_SUPERIMPOSE_SOURCE_PATH;
+import static org.apache.sling.superimposing.impl.SuperimposingManagerImpl.FIND_ALL_QUERIES_DEFAULT;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Iterator;
@@ -49,6 +51,7 @@
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.wrappers.ValueMapDecorator;
import org.apache.sling.superimposing.SuperimposingResourceProvider;
+import org.apache.sling.superimposing.impl.SuperimposingManagerImpl.SuperimposingManagerConfig;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -77,6 +80,9 @@
private ResourceResolver resourceResolver;
@Mock(answer=Answers.RETURNS_DEEP_STUBS)
private Session session;
+ @Mock
+ private SuperimposingManagerConfig configuration;
+
private List<ServiceRegistration> serviceRegistrations = new ArrayList<ServiceRegistration>();
private SuperimposingManagerImpl underTest;
@@ -88,9 +94,9 @@
@SuppressWarnings("unchecked")
@Before
public void setUp() throws LoginException {
- when(componentContext.getBundleContext()).thenReturn(bundleContext);
- when(componentContext.getProperties()).thenReturn(componentContextProperties);
- when(componentContextProperties.get(SuperimposingManagerImpl.OBSERVATION_PATHS_PROPERTY)).thenReturn(new String[] { OBSERVATION_PATH });
+ when(configuration.enabled()).thenReturn(true);
+ when(configuration.findAllQueries()).thenReturn(new String[] {FIND_ALL_QUERIES_DEFAULT});
+ when(configuration.observationPaths()).thenReturn(new String[] {OBSERVATION_PATH});
when(resourceResolverFactory.getAdministrativeResourceResolver(any(Map.class))).thenReturn(resourceResolver);
when(resourceResolver.adaptTo(Session.class)).thenReturn(session);
@@ -159,10 +165,17 @@
}
private void initialize(boolean enabled) throws InterruptedException, LoginException, RepositoryException {
- when(componentContextProperties.get(SuperimposingManagerImpl.ENABLED_PROPERTY)).thenReturn(enabled);
+ this.initialize(enabled, true);
+ }
+
+ private void initialize(boolean enabled, boolean createDefaultFind) throws InterruptedException, LoginException, RepositoryException {
+ when(configuration.enabled()).thenReturn(enabled);
+ if(createDefaultFind) {
+ when(resourceResolver.findResources(anyString(), anyString())).thenReturn(Collections.emptyIterator());
+ }
underTest = new SuperimposingManagerImpl().withResourceResolverFactory(resourceResolverFactory);
- underTest.activate(componentContext);
+ underTest.activate(bundleContext, configuration);
if (underTest.isEnabled()) {
// verify observation registration
@@ -222,7 +235,7 @@
@Test
public void testFindAllSuperimposings() throws InterruptedException, LoginException, RepositoryException {
// prepare a query that returns one existing superimposed resource
- when(componentContextProperties.get(SuperimposingManagerImpl.FINDALLQUERIES_PROPERTY)).thenReturn("syntax|query");
+ when(configuration.findAllQueries()).thenReturn(new String[] {"syntax|query"});
when(resourceResolver.findResources("query", "syntax")).then(new Answer<Iterator<Resource>>() {
public Iterator<Resource> answer(InvocationOnMock invocation) {
return Arrays.asList(new Resource[] {
@@ -230,7 +243,7 @@
}).iterator();
}
});
- initialize(true);
+ initialize(true, false);
// ensure the superimposed resource is detected and registered
List<SuperimposingResourceProvider> providers = IteratorUtils.toList(underTest.getRegisteredProviders());
@@ -344,7 +357,7 @@
@SuppressWarnings("unchecked")
@Test
public void testSuperimposedResourceCreateMove() throws InterruptedException, LoginException, RepositoryException {
- when(componentContextProperties.get(SuperimposingManagerImpl.FINDALLQUERIES_PROPERTY)).thenReturn("syntax|query");
+ when(configuration.findAllQueries()).thenReturn(new String[] {"syntax|query"});
initialize(true);
// simulate node create event