Merge remote-tracking branch 'origin/master' into org.apache.sling.tenant-1.1.3
diff --git a/pom.xml b/pom.xml
index 026acaa..e853f45 100644
--- a/pom.xml
+++ b/pom.xml
@@ -67,11 +67,6 @@
     
     <dependencies>
         <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.scr.annotations</artifactId>
-            <version>1.11.0</version>
-        </dependency>
-        <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.api</artifactId>
             <version>2.5.0</version>
@@ -84,6 +79,16 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.component.annotations</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.metatype.annotations</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>javax.jcr</groupId>
             <artifactId>jcr</artifactId>
         </dependency>
diff --git a/src/main/java/org/apache/sling/tenant/internal/TenantProviderImpl.java b/src/main/java/org/apache/sling/tenant/internal/TenantProviderImpl.java
index cff472e..8371471 100644
--- a/src/main/java/org/apache/sling/tenant/internal/TenantProviderImpl.java
+++ b/src/main/java/org/apache/sling/tenant/internal/TenantProviderImpl.java
@@ -29,16 +29,6 @@
 import java.util.SortedMap;

 import java.util.TreeMap;

 

-import org.apache.felix.scr.annotations.Activate;

-import org.apache.felix.scr.annotations.Component;

-import org.apache.felix.scr.annotations.Deactivate;

-import org.apache.felix.scr.annotations.Property;

-import org.apache.felix.scr.annotations.PropertyUnbounded;

-import org.apache.felix.scr.annotations.Reference;

-import org.apache.felix.scr.annotations.ReferenceCardinality;

-import org.apache.felix.scr.annotations.ReferencePolicy;

-import org.apache.felix.scr.annotations.References;

-import org.apache.felix.scr.annotations.Service;

 import org.apache.sling.api.resource.LoginException;

 import org.apache.sling.api.resource.ModifiableValueMap;

 import org.apache.sling.api.resource.PersistenceException;

@@ -59,6 +49,15 @@
 import org.osgi.framework.Filter;

 import org.osgi.framework.FrameworkUtil;

 import org.osgi.framework.InvalidSyntaxException;

+import org.osgi.service.component.annotations.Activate;

+import org.osgi.service.component.annotations.Component;

+import org.osgi.service.component.annotations.Deactivate;

+import org.osgi.service.component.annotations.Reference;

+import org.osgi.service.component.annotations.ReferenceCardinality;

+import org.osgi.service.component.annotations.ReferencePolicy;

+import org.osgi.service.metatype.annotations.AttributeDefinition;

+import org.osgi.service.metatype.annotations.Designate;

+import org.osgi.service.metatype.annotations.ObjectClassDefinition;

 import org.slf4j.Logger;

 import org.slf4j.LoggerFactory;

 

@@ -66,24 +65,26 @@
  * Resource based Tenant Provider implementation.

  */

 @Component(

-        metatype = true,

-        label = "Apache Sling Tenant Provider",

-        description = "Service responsible for providing Tenants",

-        immediate = true)

-@Service(value = {TenantProvider.class, TenantManager.class})

-@Property(name = Constants.SERVICE_DESCRIPTION, value = "Apache Sling Tenant Provider")

-@References({

-    @Reference(

-        name = "tenantSetup",

-        referenceInterface = TenantCustomizer.class,

-        cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE,

-        policy = ReferencePolicy.DYNAMIC),

-    @Reference(

-            name = "hook",

-            referenceInterface = TenantManagerHook.class,

-            cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE,

-            policy = ReferencePolicy.DYNAMIC)

-})

+    service = {TenantProvider.class, TenantManager.class},

+    property = {

+            Constants.SERVICE_VENDOR + "=The Apache Software Foundation",

+            Constants.SERVICE_DESCRIPTION + "=Apache Sling Tenant Provider"

+    },

+    immediate = true,

+    reference = {

+        @Reference(

+            name = "tenantSetup",

+            service = TenantCustomizer.class,

+            cardinality = ReferenceCardinality.MULTIPLE,

+            policy = ReferencePolicy.DYNAMIC),

+        @Reference(

+                name = "hook",

+                service = TenantManagerHook.class,

+                cardinality = ReferenceCardinality.MULTIPLE,

+                policy = ReferencePolicy.DYNAMIC)

+    }

+)

+@Designate(ocd = TenantProviderImpl.Configuration.class)

 public class TenantProviderImpl implements TenantProvider, TenantManager {

 

     /** default log */

@@ -94,8 +95,22 @@
      */

     private static final String RESOURCE_TENANT_ROOT = "/etc/tenants";

 

-    @Property(value = RESOURCE_TENANT_ROOT, label = "Tenants Root Path", description = "Defines tenants root path")

-    private static final String TENANT_ROOT = "tenant.root";

+    @ObjectClassDefinition(name = "Apache Sling Tenant Provider",

+            description = "Service responsible for providing Tenants.")

+    public @interface Configuration {

+

+        @AttributeDefinition(

+            name = "Tenants Root Path",

+            description = "Defines tenants root path",

+            defaultValue = RESOURCE_TENANT_ROOT

+        )

+        String tenant_root();

+        @AttributeDefinition(

+            name = "Tenants Path Matcher",

+            description = "Defines tenants path matcher i.e. /content/sample/([^/]+)/*, used while resolving path to tenant"

+        )

+        String[] tenant_path_matcher();

+    }

 

     private static final String[] DEFAULT_PATH_MATCHER = {};

 

@@ -105,13 +120,6 @@
     private SortedMap<Comparable<Object>, TenantManagerHook> registeredHooks = new TreeMap<Comparable<Object>, TenantManagerHook>(

             Collections.reverseOrder());

 

-    @Property(

-            value = {},

-            unbounded = PropertyUnbounded.ARRAY,

-            label = "Tenants Path Matcher",

-            description = "Defines tenants path matcher i.e. /content/sample/([^/]+)/*, used while resolving path to tenant")

-    private static final String TENANT_PATH_MATCHER = "tenant.path.matcher";

-

     private String tenantRootPath = RESOURCE_TENANT_ROOT;

 

     @Reference

@@ -122,9 +130,9 @@
     private WebConsolePlugin plugin;

 

     @Activate

-    protected void activate(final BundleContext bundleContext, final Map<String, Object> properties) {

-        this.tenantRootPath = PropertiesUtil.toString(properties.get(TENANT_ROOT), RESOURCE_TENANT_ROOT);

-        this.adapterFactory = new TenantAdapterFactory(bundleContext, this, PropertiesUtil.toStringArray(properties.get(TENANT_PATH_MATCHER), DEFAULT_PATH_MATCHER));

+    protected void activate(final BundleContext bundleContext, final Configuration configuration) {

+        this.tenantRootPath = PropertiesUtil.toString(configuration.tenant_root(), RESOURCE_TENANT_ROOT);

+        this.adapterFactory = new TenantAdapterFactory(bundleContext, this, PropertiesUtil.toStringArray(configuration.tenant_path_matcher(), DEFAULT_PATH_MATCHER));

         this.plugin = new WebConsolePlugin(bundleContext, this);

     }

 

diff --git a/src/test/java/org/apache/sling/tenant/internal/TenantProviderImplTest.java b/src/test/java/org/apache/sling/tenant/internal/TenantProviderImplTest.java
index c3ff612..1628fe5 100644
--- a/src/test/java/org/apache/sling/tenant/internal/TenantProviderImplTest.java
+++ b/src/test/java/org/apache/sling/tenant/internal/TenantProviderImplTest.java
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.tenant.internal;
 
+import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -41,7 +42,21 @@
         Mockito.when(rrf.getServiceResourceResolver(
                 Mockito.anyMapOf(String.class, Object.class))).thenReturn(rr);
         set(provider, "factory", rrf);
-        provider.activate(context, new HashMap<String, Object>());
+        TenantProviderImpl.Configuration configuration = new TenantProviderImpl.Configuration() {
+            @Override
+            public Class<? extends Annotation> annotationType() {
+                return null;
+            }
+            @Override
+            public String tenant_root() {
+                return "/etc/tenants";
+            }
+            @Override
+            public String[] tenant_path_matcher() {
+                return new String[] {};
+            }
+        };
+        provider.activate(context, configuration);
         Iterator<Tenant> tenants = provider.getTenants();
         TestCase.assertNotNull(tenants);
         TestCase.assertFalse(tenants.hasNext());