SLING-6621 Use official OSGi annotations

git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1785978 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index 6b8ae9a..69cf804 100644
--- a/pom.xml
+++ b/pom.xml
@@ -46,10 +46,6 @@
         <plugins>
             <plugin>
                 <groupId>org.apache.felix</groupId>
-                <artifactId>maven-scr-plugin</artifactId>
-            </plugin>
-            <plugin>
-                <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
                 <extensions>true</extensions>
                 <configuration>
diff --git a/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzScheduler.java b/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzScheduler.java
index 2447b34..7f3be9b 100644
--- a/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzScheduler.java
+++ b/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzScheduler.java
@@ -26,19 +26,17 @@
 import java.util.Set;
 import java.util.UUID;
 
-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.Service;
 import org.apache.sling.commons.scheduler.Job;
 import org.apache.sling.commons.scheduler.ScheduleOptions;
 import org.apache.sling.commons.threads.ThreadPoolManager;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleEvent;
 import org.osgi.framework.BundleListener;
+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.metatype.annotations.Designate;
 import org.quartz.CronExpression;
 import org.quartz.CronScheduleBuilder;
 import org.quartz.JobBuilder;
@@ -58,11 +56,13 @@
  * The quartz based implementation of the scheduler.
  *
  */
-@Component(immediate=true,
-           metatype=true, label="Apache Sling Scheduler",
-           description="The scheduler is able to run services and jobs at specific " +
-                       "times or periodically based on cron expressions.")
-@Service(value=QuartzScheduler.class)
+@Component(
+    service = QuartzScheduler.class,
+    immediate = true
+)
+@Designate(
+    ocd = QuartzSchedulerConfiguration.class
+)
 public class QuartzScheduler implements BundleListener {
 
     /** Map key for the job object */
@@ -86,17 +86,6 @@
     /** Map key for the bundle information (Long). */
     static final String DATA_MAP_SERVICE_ID = "QuartzJobScheduler.serviceId";
 
-    @Property(label="Thread Pool Name",
-            description="The name of a configured thread pool - if no name is configured " +
-                        "the default pool is used.")
-    private static final String PROPERTY_POOL_NAME = "poolName";
-
-    @Property(label="Allowed Thread Pools",
-             description="The names of thread pools that are allowed to be used by jobs. " +
-                        "If a job is using a pool not in this list, the default pool is used.",
-             unbounded=PropertyUnbounded.ARRAY)
-    private static final String PROPERTY_ALLOWED_POOLS = "allowedPoolNames";
-
     /** Default logger. */
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
@@ -118,32 +107,14 @@
      * @throws Exception
      */
     @Activate
-    protected void activate(final BundleContext ctx, final Map<String, Object> props) {
+    protected void activate(final BundleContext ctx, final QuartzSchedulerConfiguration configuration) {
         // SLING-2261 Prevent Quartz from checking for updates
         System.setProperty("org.terracotta.quartz.skipUpdateCheck", Boolean.TRUE.toString());
 
-        final Object poolNameObj = props.get(PROPERTY_POOL_NAME);
-        if ( poolNameObj != null && poolNameObj.toString().trim().length() > 0 ) {
-            this.defaultPoolName = poolNameObj.toString().trim();
-        } else {
-            this.defaultPoolName = ThreadPoolManager.DEFAULT_THREADPOOL_NAME;
-        }
-        final Object value = props.get(PROPERTY_ALLOWED_POOLS);
-        if ( value instanceof String[] ) {
-            this.allowedPoolNames = (String[])value;
-        } else if ( value != null ) {
-            this.allowedPoolNames = new String[] {value.toString()};
-        }
-        if ( this.allowedPoolNames == null ) {
-            this.allowedPoolNames = new String[0];
-        } else {
-            for(int i=0;i<this.allowedPoolNames.length;i++) {
-                if ( this.allowedPoolNames[i] == null ) {
-                    this.allowedPoolNames[i] = "";
-                } else {
-                    this.allowedPoolNames[i] = this.allowedPoolNames[i].trim();
-                }
-            }
+        defaultPoolName = configuration.poolName();
+        allowedPoolNames = configuration.allowedPoolNames();
+        if (allowedPoolNames == null) {
+            allowedPoolNames = new String[0];
         }
         ctx.addBundleListener(this);
 
diff --git a/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzSchedulerConfiguration.java b/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzSchedulerConfiguration.java
new file mode 100644
index 0000000..6183e6d
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/scheduler/impl/QuartzSchedulerConfiguration.java
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+package org.apache.sling.commons.scheduler.impl;
+
+import org.apache.sling.commons.threads.ThreadPoolManager;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
+
+@ObjectClassDefinition(
+    name = "Apache Sling Scheduler",
+    description = "The scheduler is able to run services and jobs at specific times or periodically based on cron expressions."
+)
+@interface QuartzSchedulerConfiguration {
+
+    @AttributeDefinition(
+        name = "Thread Pool Name",
+        description = "The name of a configured thread pool - if no name is configured the default pool is used."
+    )
+    String poolName() default ThreadPoolManager.DEFAULT_THREADPOOL_NAME;
+
+    @AttributeDefinition(
+        name = "Allowed Thread Pools",
+        description="The names of thread pools that are allowed to be used by jobs. If a job is using a pool not in this list, the default pool is used."
+    )
+    String[] allowedPoolNames();
+
+}
diff --git a/src/main/java/org/apache/sling/commons/scheduler/impl/SchedulerServiceFactory.java b/src/main/java/org/apache/sling/commons/scheduler/impl/SchedulerServiceFactory.java
index e11de04..c27bcfa 100644
--- a/src/main/java/org/apache/sling/commons/scheduler/impl/SchedulerServiceFactory.java
+++ b/src/main/java/org/apache/sling/commons/scheduler/impl/SchedulerServiceFactory.java
@@ -21,13 +21,12 @@
 import java.util.Map;
 import java.util.NoSuchElementException;
 
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.commons.scheduler.ScheduleOptions;
 import org.apache.sling.commons.scheduler.Scheduler;
 import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
 
 /**
  * This is a proxy implementation of the scheduler service.
@@ -35,8 +34,10 @@
  * scheduler implementation, the QuartzScheduler has the same
  * API however in addition each method gets the using bundleId.
  */
-@Component
-@Service(value=Scheduler.class, serviceFactory=true)
+@Component(
+    service = Scheduler.class,
+    servicefactory = true
+)
 public class SchedulerServiceFactory implements Scheduler {
 
     private long bundleId;
diff --git a/src/main/java/org/apache/sling/commons/scheduler/impl/TopologyHandler.java b/src/main/java/org/apache/sling/commons/scheduler/impl/TopologyHandler.java
index 69881fe..3821572 100644
--- a/src/main/java/org/apache/sling/commons/scheduler/impl/TopologyHandler.java
+++ b/src/main/java/org/apache/sling/commons/scheduler/impl/TopologyHandler.java
@@ -16,20 +16,20 @@
  */
 package org.apache.sling.commons.scheduler.impl;
 
-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.Service;
 import org.apache.sling.discovery.TopologyEvent;
 import org.apache.sling.discovery.TopologyEvent.Type;
 import org.apache.sling.discovery.TopologyEventListener;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
 
 /**
  * Optional service - if the Sling discovery service is running, additional features
  *                    are available
  */
-@Component
-@Service(value=TopologyEventListener.class)
+@Component(
+    service = TopologyEventListener.class
+)
 public class TopologyHandler implements TopologyEventListener {
 
     @Activate
diff --git a/src/main/java/org/apache/sling/commons/scheduler/impl/WhiteboardHandler.java b/src/main/java/org/apache/sling/commons/scheduler/impl/WhiteboardHandler.java
index 715d4ee..cfd92d7 100644
--- a/src/main/java/org/apache/sling/commons/scheduler/impl/WhiteboardHandler.java
+++ b/src/main/java/org/apache/sling/commons/scheduler/impl/WhiteboardHandler.java
@@ -20,10 +20,6 @@
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
-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.Reference;
 import org.apache.sling.commons.scheduler.Job;
 import org.apache.sling.commons.scheduler.ScheduleOptions;
 import org.apache.sling.commons.scheduler.Scheduler;
@@ -31,6 +27,10 @@
 import org.osgi.framework.Constants;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
+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.util.tracker.ServiceTracker;
 import org.osgi.util.tracker.ServiceTrackerCustomizer;
 import org.slf4j.Logger;
@@ -40,7 +40,9 @@
  * The quartz based implementation of the scheduler.
  *
  */
-@Component(immediate=true)
+@Component(
+    immediate = true
+)
 public class WhiteboardHandler {
 
     private static final String SCHEDULED_JOB_FILTER =
diff --git a/src/test/java/org/apache/sling/commons/scheduler/impl/ActivatedQuartzSchedulerFactory.java b/src/test/java/org/apache/sling/commons/scheduler/impl/ActivatedQuartzSchedulerFactory.java
index f0aa0cd..5c06a81 100644
--- a/src/test/java/org/apache/sling/commons/scheduler/impl/ActivatedQuartzSchedulerFactory.java
+++ b/src/test/java/org/apache/sling/commons/scheduler/impl/ActivatedQuartzSchedulerFactory.java
@@ -18,14 +18,15 @@
 
 import java.lang.reflect.Field;
 import java.util.Dictionary;
-import java.util.HashMap;
 import java.util.Hashtable;
-import java.util.Map;
 
 import org.apache.sling.commons.threads.impl.DefaultThreadPoolManager;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
 /**
  * This is just a class with helper static method,
  * since we need an activated QuartzScheduler in many tests.
@@ -44,13 +45,16 @@
             f.setAccessible(true);
             f.set(quartzScheduler, new DefaultThreadPoolManager(context, props));
 
-            Map<String, Object> scheduleActivationProps = new HashMap<String, Object>();
-            scheduleActivationProps.put("poolName", poolName == null ? "testName" : poolName);
-            if ( poolName != null ) {
-                scheduleActivationProps.put("allowedPoolNames", new String[] {"testName", "allowed"});
+            final QuartzSchedulerConfiguration configuration = mock(QuartzSchedulerConfiguration.class);
+            if (poolName == null) {
+                when(configuration.poolName()).thenReturn("testName");
+            } else {
+                final String[] allowedPoolNames = new String[] {"testName", "allowed"};
+                when(configuration.poolName()).thenReturn(poolName);
+                when(configuration.allowedPoolNames()).thenReturn(allowedPoolNames);
             }
 
-            quartzScheduler.activate(context, scheduleActivationProps);
+            quartzScheduler.activate(context, configuration);
             context.registerService("scheduler", quartzScheduler, props);
         }
         return quartzScheduler;