SLING-6125 - Switch HTL to OSGi R6 annotations

* removed maven-scr-plugin and configured maven-bundle-plugin to generate SCR metadata
* replaced Felix SCR annotations with OSGi Component + Metatype annotations
* removed unused dependencies

git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1764122 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index d980884..a4c61fa 100644
--- a/pom.xml
+++ b/pom.xml
@@ -55,13 +55,18 @@
         <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>
+                <executions>
+                    <execution>
+                        <id>scr-metadata</id>
+                        <goals>
+                            <goal>manifest</goal>
+                        </goals>
+                    </execution>
+                </executions>
                 <configuration>
+                    <exportScr>true</exportScr>
                     <instructions>
                         <Sling-Bundle-Resources>/libs/sling/sightly/js;path:=/SLING-INF/libs/sling/sightly/js</Sling-Bundle-Resources>
                         <Require-Capability>io.sightly; filter:="(&amp;(version&gt;=1.0)(!(version&gt;=2.0)))"</Require-Capability>
@@ -116,30 +121,18 @@
             <version>2.0.32</version>
             <scope>provided</scope>
         </dependency>
-        <dependency>
-            <groupId>org.apache.sling</groupId>
-            <artifactId>org.apache.sling.commons.osgi</artifactId>
-            <version>2.2.0</version>
-            <scope>provided</scope>
-        </dependency>
 
         <!-- HTL -->
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.scripting.sightly</artifactId>
-            <version>1.0.21-SNAPSHOT</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.sling</groupId>
-            <artifactId>org.apache.sling.scripting.sightly.compiler</artifactId>
-            <version>1.0.1-SNAPSHOT</version>
+            <version>1.0.20</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.scripting.sightly.compiler.java</artifactId>
-            <version>1.0.1-SNAPSHOT</version>
+            <version>1.0.0</version>
             <scope>provided</scope>
         </dependency>
 
@@ -165,8 +158,7 @@
         </dependency>
         <dependency>
             <groupId>javax.servlet</groupId>
-            <artifactId>servlet-api</artifactId>
-            <version>2.5</version>
+            <artifactId>javax.servlet-api</artifactId>
             <scope>provided</scope>
         </dependency>
 
diff --git a/src/main/java/org/apache/sling/scripting/sightly/js/impl/JsUseProvider.java b/src/main/java/org/apache/sling/scripting/sightly/js/impl/JsUseProvider.java
index 887ae2d..0e17a7b 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/js/impl/JsUseProvider.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/js/impl/JsUseProvider.java
@@ -22,13 +22,7 @@
 import javax.script.ScriptEngine;
 import javax.script.ScriptEngineManager;
 
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Properties;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.scripting.SlingScriptHelper;
 import org.apache.sling.scripting.sightly.SightlyException;
 import org.apache.sling.scripting.sightly.js.impl.async.AsyncContainer;
@@ -39,28 +33,42 @@
 import org.apache.sling.scripting.sightly.use.ProviderOutcome;
 import org.apache.sling.scripting.sightly.use.UseProvider;
 import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
 
 /**
  * Use provider for JavaScript Use-API objects.
  */
 @Component(
-    metatype = true,
-    label = "Apache Sling Scripting HTL JavaScript Use Provider",
-    description = "The JavaScript Use Provider is responsible for instantiating JavaScript Use-API objects."
+        service = UseProvider.class,
+        configurationPid = "org.apache.sling.scripting.sightly.js.impl.JsUseProvider",
+        property = {
+                Constants.SERVICE_RANKING + ":Integer=80"
+        }
 )
-@Service(UseProvider.class)
-@Properties({
-                @Property(
-                    name = Constants.SERVICE_RANKING,
-                    label = "Service Ranking",
-                    description = "The Service Ranking value acts as the priority with which this Use Provider is queried to return an " +
-                        "Use-object. A higher value represents a higher priority.",
-                    intValue = 80,
-                    propertyPrivate = false
-                )
-            })
+@Designate(
+        ocd = JsUseProvider.Configuration.class
+)
 public class JsUseProvider implements UseProvider {
 
+    @ObjectClassDefinition(
+            name = "Apache Sling Scripting HTL JavaScript Use Provider Configuration",
+            description = "HTL JavaScript Use Provider configuration options"
+    )
+    @interface Configuration {
+
+        @AttributeDefinition(
+                name = "Service Ranking",
+                description = "The Service Ranking value acts as the priority with which this Use Provider is queried to return an " +
+                        "Use-object. A higher value represents a higher priority."
+        )
+        int service_ranking() default 80;
+
+    }
+
     private static final String JS_ENGINE_NAME = "javascript";
     private static final JsValueAdapter jsValueAdapter = new JsValueAdapter(new AsyncExtractor());
 
diff --git a/src/main/java/org/apache/sling/scripting/sightly/js/impl/jsapi/ProxyAsyncScriptableFactory.java b/src/main/java/org/apache/sling/scripting/sightly/js/impl/jsapi/ProxyAsyncScriptableFactory.java
index 3a38cac..75217b8 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/js/impl/jsapi/ProxyAsyncScriptableFactory.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/js/impl/jsapi/ProxyAsyncScriptableFactory.java
@@ -23,18 +23,18 @@
 import javax.script.SimpleBindings;
 
 import org.apache.commons.lang.StringUtils;
-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.scripting.sightly.js.impl.rhino.HybridObject;
 import org.mozilla.javascript.Scriptable;
 import org.mozilla.javascript.ScriptableObject;
 import org.mozilla.javascript.Undefined;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-@Component
-@Service(ProxyAsyncScriptableFactory.class)
+@Component(
+        service = ProxyAsyncScriptableFactory.class
+)
 public class ProxyAsyncScriptableFactory {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(ProxyAsyncScriptableFactory.class);
@@ -56,7 +56,7 @@
 
         private String clazz;
         private Bindings bindings;
-        private Set<String> scriptNSUse = new HashSet<String>();
+        private Set<String> scriptNSUse = new HashSet<>();
 
         public ShadowScriptableObject(String clazz, Bindings bindings) {
             this.clazz = clazz;
diff --git a/src/main/java/org/apache/sling/scripting/sightly/js/impl/jsapi/SlyBindingsValuesProvider.java b/src/main/java/org/apache/sling/scripting/sightly/js/impl/jsapi/SlyBindingsValuesProvider.java
index 9ecb4e2..65e9c48 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/js/impl/jsapi/SlyBindingsValuesProvider.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/js/impl/jsapi/SlyBindingsValuesProvider.java
@@ -22,7 +22,6 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.util.Collections;
-import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.Map;
 import javax.script.Bindings;
@@ -32,14 +31,6 @@
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.commons.io.IOUtils;
-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.Properties;
-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.api.resource.LoginException;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
@@ -62,31 +53,45 @@
 import org.mozilla.javascript.Scriptable;
 import org.mozilla.javascript.ScriptableObject;
 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.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+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;
 
 /**
  * Provides the {@code sightly} namespace for usage in HTL &amp; JS scripts called from Sightly
  */
-@Component(metatype = true, label = "Apache Sling Scripting HTL JavaScript Bindings Provider",
-        description = "The Apache Sling Scripting HTL JavaScript Bindings Provider loads the JS Use-API and makes it available in the" +
-                " bindings map.")
-@Service(SlyBindingsValuesProvider.class)
-@Properties({
-        @Property(
-                name = SlyBindingsValuesProvider.SCR_PROP_JS_BINDING_IMPLEMENTATIONS,
-                value = {
-                    "sightly:" + SlyBindingsValuesProvider.SLING_NS_PATH
-                },
-                unbounded = PropertyUnbounded.ARRAY,
-                label = "Script Factories",
-                description = "Script factories to load in the bindings map. The entries should be in the form " +
-                        "'namespace:/path/from/repository'."
-        )
-})
+@Component(
+        service = SlyBindingsValuesProvider.class,
+        configurationPid = "org.apache.sling.scripting.sightly.js.impl.jsapi.SlyBindingsValuesProvider"
+)
+@Designate(
+        ocd = SlyBindingsValuesProvider.Configuration.class
+)
 @SuppressWarnings("unused")
 public class SlyBindingsValuesProvider {
 
+    @ObjectClassDefinition(
+            name = "Apache Sling Scripting HTL JavaScript Use-API Factories Configuration",
+            description = "HTL JavaScript Use-API Factories configuration options"
+    )
+    @interface Configuration {
+
+        @AttributeDefinition(
+                name = "Script Factories",
+                description = "Script factories to load in the bindings map. The entries should be in the form " +
+                        "'namespace:/path/from/repository'."
+
+        )
+        String[] org_apache_sling_scripting_sightly_js_bindings() default "sightly:" + SlyBindingsValuesProvider.SLING_NS_PATH;
+
+    }
+
     public static final String SCR_PROP_JS_BINDING_IMPLEMENTATIONS = "org.apache.sling.scripting.sightly.js.bindings";
 
     public static final String SLING_NS_PATH = "/libs/sling/sightly/js/internal/sly.js";
@@ -144,9 +149,11 @@
     }
 
     @Activate
-    protected void activate(ComponentContext componentContext) {
-        Dictionary properties = componentContext.getProperties();
-        String[] factories = PropertiesUtil.toStringArray(properties.get(SCR_PROP_JS_BINDING_IMPLEMENTATIONS), new String[]{SLING_NS_PATH});
+    protected void activate(Configuration configuration) {
+        String[] factories = PropertiesUtil.toStringArray(
+                configuration.org_apache_sling_scripting_sightly_js_bindings(),
+                new String[]{SLING_NS_PATH}
+        );
         scriptPaths = new HashMap<>(factories.length);
         for (String f : factories) {
             String[] parts = f.split(":");