SLING-11380: Upgrade to sling 48 (#1)

* SLING-11380: fix PR comments

* SLING-11380: update to sling 48
diff --git a/pom.xml b/pom.xml
index d56e883..118d50d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,15 +22,14 @@
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <groupId>org.apache.sling</groupId>
-        <artifactId>sling</artifactId>
-        <version>26</version>
+        <artifactId>sling-bundle-parent</artifactId>
+        <version>48</version>
         <relativePath/>
     </parent>
 
     <groupId>org.apache.sling</groupId>
     <artifactId>org.apache.sling.jmx.provider</artifactId>
     <version>1.0.3-SNAPSHOT</version>
-    <packaging>bundle</packaging>
 
     <name>Apache Sling JMX Resource Provider</name>
 
@@ -40,26 +39,10 @@
         <url>https://gitbox.apache.org/repos/asf?p=sling-org-apache-sling-jmx-provider.git</url>
     </scm>
 
-    <build>
-        <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>
-                    <instructions>
-                        <Private-Package>
-                            org.apache.sling.jmx.provider.impl
-                        </Private-Package>
-                    </instructions>
-                </configuration>
-            </plugin>
-        </plugins>
-    </build>
+    <properties>
+        <sling.java.version>8</sling.java.version>
+        <project.build.outputTimestamp>1</project.build.outputTimestamp>
+    </properties>
     
     <dependencies>
         <dependency>
@@ -69,18 +52,14 @@
     	    <scope>provided</scope>
         </dependency>
         <dependency>
-            <groupId>org.apache.sling</groupId>
-            <artifactId>org.apache.sling.commons.osgi</artifactId>
-            <version>2.1.0</version>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.metatype.annotations</artifactId>
             <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.compendium</artifactId>
-        </dependency>
-        <dependency>
-        	<groupId>org.apache.felix</groupId>
-        	<artifactId>org.apache.felix.scr.annotations</artifactId>
+            <artifactId>org.osgi.service.component.annotations</artifactId>
+            <scope>provided</scope>
         </dependency>
         <dependency>
         	<groupId>org.slf4j</groupId>
@@ -88,7 +67,20 @@
         </dependency>
         <dependency>
         	<groupId>javax.servlet</groupId>
-        	<artifactId>servlet-api</artifactId>
+        	<artifactId>javax.servlet-api</artifactId>
+        </dependency>
+
+        <!-- Test Dependencies -->
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.testing.osgi-mock.junit4</artifactId>
+            <version>3.2.2</version>
+            <scope>test</scope>
         </dependency>
     </dependencies>
 </project>
diff --git a/src/main/java/org/apache/sling/jmx/provider/impl/JMXResourceProvider.java b/src/main/java/org/apache/sling/jmx/provider/impl/JMXResourceProvider.java
index 63e9c08..a123dce 100644
--- a/src/main/java/org/apache/sling/jmx/provider/impl/JMXResourceProvider.java
+++ b/src/main/java/org/apache/sling/jmx/provider/impl/JMXResourceProvider.java
@@ -45,29 +45,17 @@
 import javax.management.ReflectionException;
 import javax.servlet.http.HttpServletRequest;
 
-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.Service;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceProvider;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ResourceUtil;
-import org.apache.sling.commons.osgi.PropertiesUtil;
+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.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
 
-@Component(metatype=true,
-    label="Apache Sling JMX Resource Provider",
-    description="This provider mounts JMX mbeans into the resource tree.")
-@Service(value = ResourceProvider.class)
-@Properties({
-    @Property(name = ResourceProvider.ROOTS, value="/system/sling/monitoring/mbeans",
-            label="Root",
-            description="The mount point of the JMX beans"),
-    @Property(name = ResourceProvider.USE_RESOURCE_ACCESS_SECURITY, boolValue=true, propertyPrivate=true),
-    @Property(name = ResourceProvider.OWNS_ROOTS, boolValue=true, propertyPrivate=true)
-})
 /**
  * Brief summary of a "good" object name:
  *
@@ -85,6 +73,8 @@
  * {name property} : is the value of the name property or "{noname}" if no name property is set
  * {all other props} : name/value pairs containing all additional props
  */
+@Component(service = {ResourceProvider.class})
+@Designate(ocd = JMXResourceProvider.Config.class)
 public class JMXResourceProvider implements ResourceProvider {
 
     /** Configured root paths, ending with a slash */
@@ -96,11 +86,26 @@
     /** The mbean server. */
     private MBeanServer mbeanServer;
 
+    @SuppressWarnings("java:S100")
+    @ObjectClassDefinition(name = "Apache Sling JMX Resource Provider",
+            description = "This provider mounts JMX mbeans into the resource tree.")
+    public @interface Config {
+
+        @AttributeDefinition(name = "Root", description = "The mount point of the JMX beans")
+        String[] provider_roots() default {"/system/sling/monitoring/mbeans"};
+
+        @AttributeDefinition
+        boolean provider_useResourceAccessSecurity() default true;
+
+        @AttributeDefinition
+        boolean provider_ownsRoots() default true;
+    }
+
     @Activate
-    protected void activate(final Map<String, Object> props) {
-        final String paths[] = PropertiesUtil.toStringArray(props.get(ResourceProvider.ROOTS));
-        final List<String> rootsList = new ArrayList<String>();
-        final List<String> rootsWithSlashList = new ArrayList<String>();
+    protected void activate(final Config config) {
+        final String[] paths = config.provider_roots();
+        final List<String> rootsList = new ArrayList<>();
+        final List<String> rootsWithSlashList = new ArrayList<>();
         if ( paths != null ) {
             for(final String p : paths) {
                 if ( p.length() > 0 ) {
@@ -215,7 +220,7 @@
         Set<ObjectName> names = allNames;
         if ( prefix != null ) {
             final String pathPrefix = prefix + '/';
-            names = new HashSet<ObjectName>();
+            names = new HashSet<>();
             for(final ObjectName name : allNames) {
                 final String path = this.convertObjectNameToResourcePath(name);
                 if ( path.startsWith(pathPrefix) ) {
@@ -234,7 +239,7 @@
             if ( info.isRoot || info.mbeanInfo == null ) {
                 // list all MBeans
                 final Set<ObjectName> names = this.queryObjectNames(info.isRoot ? null : info.pathInfo);
-                final Set<String> filteredNames = new HashSet<String>();
+                final Set<String> filteredNames = new HashSet<>();
                 final String prefix = (info.isRoot ? null : info.pathInfo + "/");
                 for(final ObjectName name : names) {
                     final String path = this.convertObjectNameToResourcePath(name);
@@ -309,7 +314,7 @@
                     } else {
                         parentResource = (MBeanResource)this.getResource(parent.getResourceResolver(), parent.getPath());
                     }
-                    final List<Resource> list = new ArrayList<Resource>();
+                    final List<Resource> list = new ArrayList<>();
                     list.add(new AttributesResource(parent.getResourceResolver(), parent.getPath() + "/mbean:attributes", parentResource));
                     return list.iterator();
                 } else if ( info.pathInfo.equals("mbean:attributes") ) {
@@ -323,7 +328,7 @@
                     final AttributeList result = parentMBeanResource.getAttributes();
 
                     final MBeanAttributeInfo[] infos = info.mbeanInfo.getAttributes();
-                    final Map<String, MBeanAttributeInfo> infoMap = new HashMap<String, MBeanAttributeInfo>();
+                    final Map<String, MBeanAttributeInfo> infoMap = new HashMap<>();
                     for(final MBeanAttributeInfo i : infos) {
                         infoMap.put(i.getName(), i);
                     }
diff --git a/src/test/java/org/apache/sling/jmx/provider/impl/JMXResourceProviderTest.java b/src/test/java/org/apache/sling/jmx/provider/impl/JMXResourceProviderTest.java
new file mode 100644
index 0000000..6c40122
--- /dev/null
+++ b/src/test/java/org/apache/sling/jmx/provider/impl/JMXResourceProviderTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.jmx.provider.impl;
+
+import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import static org.junit.Assert.assertNotNull;
+
+public class JMXResourceProviderTest {
+
+    @Rule
+    public final OsgiContext context = new OsgiContext();
+    private JMXResourceProvider jmxResourceProvider;
+
+    @Before
+    public void setUp() throws Exception {
+        Dictionary<String, Object> properties = new Hashtable<>();
+        jmxResourceProvider = context.registerInjectActivateService(JMXResourceProvider.class, new JMXResourceProvider(), properties);
+    }
+
+    @Test
+    public void testIfServiceActive() {
+        assertNotNull(jmxResourceProvider);
+    }
+}
\ No newline at end of file