You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ch...@apache.org on 2017/11/24 05:53:31 UTC

[sling-org-apache-sling-jcr-registration] branch master updated: SLING-7264 - Switch to OSGi annotation

This is an automated email from the ASF dual-hosted git repository.

chetanm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-registration.git


The following commit(s) were added to refs/heads/master by this push:
     new d39cc33  SLING-7264 - Switch to OSGi annotation
d39cc33 is described below

commit d39cc33a8788c2c6b71dd798cfc0a514cf37bd85
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Fri Nov 24 11:23:19 2017 +0530

    SLING-7264 - Switch to OSGi annotation
---
 pom.xml                                            | 25 ++-----
 .../registration/impl/JndiRegistrationSupport.java | 86 ++++++++++++----------
 .../registration/impl/RmiRegistrationSupport.java  | 76 ++++++++++++-------
 .../sling/jcr/registration/package-info.java       |  6 +-
 .../OSGI-INF/metatype/metatype.properties          | 54 --------------
 5 files changed, 105 insertions(+), 142 deletions(-)

diff --git a/pom.xml b/pom.xml
index 34febd7..e876e7f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,8 +22,7 @@
     <parent>
         <groupId>org.apache.sling</groupId>
         <artifactId>sling</artifactId>
-        <version>26</version>
-        <relativePath/>
+        <version>32</version>
     </parent>
 
     <artifactId>org.apache.sling.jcr.registration</artifactId>
@@ -43,11 +42,6 @@
 
     <build>
         <plugins>
-            <!-- generate the SCR descriptors -->
-            <plugin>
-                <groupId>org.apache.felix</groupId>
-                <artifactId>maven-scr-plugin</artifactId>
-            </plugin>
             <plugin>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
@@ -80,25 +74,18 @@
             <version>2.0</version>
         </dependency>
         <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.scr.annotations</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>biz.aQute</groupId>
-            <artifactId>bndlib</artifactId>
-            <scope>provided</scope>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.annotation</artifactId>
         </dependency>
-        
-        <!-- OSGi Libraries -->
         <dependency>
             <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.core</artifactId>
+            <artifactId>osgi.cmpn</artifactId>
         </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.compendium</artifactId>
+            <artifactId>osgi.core</artifactId>
         </dependency>
-        
+
         <!-- Dummy JNDI Initial Context -->
         <dependency>
             <groupId>org.apache.jackrabbit</groupId>
diff --git a/src/main/java/org/apache/sling/jcr/registration/impl/JndiRegistrationSupport.java b/src/main/java/org/apache/sling/jcr/registration/impl/JndiRegistrationSupport.java
index 9b21241..b8a1e97 100644
--- a/src/main/java/org/apache/sling/jcr/registration/impl/JndiRegistrationSupport.java
+++ b/src/main/java/org/apache/sling/jcr/registration/impl/JndiRegistrationSupport.java
@@ -28,15 +28,16 @@ import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.ConfigurationPolicy;
-import org.apache.felix.scr.annotations.Property;
-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.sling.jcr.registration.AbstractRegistrationSupport;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.ConfigurationPolicy;
+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.log.LogService;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
 
 
 /**
@@ -50,41 +51,42 @@ import org.osgi.service.log.LogService;
  * properties.
  */
 @Component(
-        immediate = true,
-        metatype = true,
-        label = "%jndi.name",
-        description = "%jndi.description",
+        configurationPolicy = ConfigurationPolicy.REQUIRE,
         name = "org.apache.sling.jcr.jackrabbit.server.JndiRegistrationSupport",
-        policy = ConfigurationPolicy.REQUIRE
-        )
-@org.apache.felix.scr.annotations.Properties({
-    @Property(
-            name = "java.naming.factory.initial",
-            value = "org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory",
-            label = "%jndi.factory.name",
-            description = "%jndi.factory.description"),
-    @Property(
-            name = "java.naming.provider.url",
-            value = "http://sling.apache.org",
-            label = "%jndi.providerurl.name",
-            description = "%jndi.providerurl.description"),
-    @Property(name = "service.vendor", value = "The Apache Software Foundation", propertyPrivate = true),
-    @Property(name = "service.description", value = "JNDI Repository Registration", propertyPrivate = true)
-})
-@References({
-    @Reference(
-            name = "Repository",
-            policy = ReferencePolicy.DYNAMIC,
-            cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE,
-            referenceInterface = Repository.class),
-    @Reference(referenceInterface=LogService.class,
-            bind="bindLog", unbind="unbindLog",
-            cardinality = ReferenceCardinality.OPTIONAL_UNARY, policy = ReferencePolicy.DYNAMIC)
-})
+        reference = {
+                @Reference(name = "Repository", policy = ReferencePolicy.DYNAMIC,
+                        bind = "bindRepository", unbind = "unbindRepository",
+                        cardinality = ReferenceCardinality.MULTIPLE, service = Repository.class),
+                @Reference(name = "Log", policy = ReferencePolicy.DYNAMIC,
+                        bind = "bindLog", unbind = "unbindLog",
+                        cardinality = ReferenceCardinality.OPTIONAL, service = LogService.class),
+        }
+)
+@Designate(ocd = JndiRegistrationSupport.Configuration.class)
 public class JndiRegistrationSupport extends AbstractRegistrationSupport {
 
     private Context jndiContext;
 
+    // ---------- Configuration ---------------------------------------------
+
+    @ObjectClassDefinition(name = "Apache Sling JCR Repository JNDI Registrar",
+            description = "The JNDI Registrar listens for embedded repositories " +
+                    "to be registered as services and registers them in the JNDI context under the " +
+                    "name specified in the \"name\" service property.")
+    public @interface Configuration {
+
+        @AttributeDefinition(
+                name = "Initial Context Factory",
+                description = "The fully qualified class name of the factory class that will create an initial context.")
+        String java_naming_factory_initial() default "org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory";
+
+        @AttributeDefinition(
+                name = "Provider URL",
+                description = "An URL string for the service provider (e.g. ldap://somehost:389)")
+        String java_naming_provider_url() default "http://sling.apache.org";
+
+    }
+
     // ---------- SCR intergration ---------------------------------------------
 
     @Override
@@ -183,4 +185,14 @@ public class JndiRegistrationSupport extends AbstractRegistrationSupport {
             }
         }
     }
+
+    @Override
+    protected void bindLog(LogService log) {
+        super.bindLog(log);
+    }
+
+    @Override
+    protected void unbindLog(LogService log) {
+        super.unbindLog(log);
+    }
 }
diff --git a/src/main/java/org/apache/sling/jcr/registration/impl/RmiRegistrationSupport.java b/src/main/java/org/apache/sling/jcr/registration/impl/RmiRegistrationSupport.java
index 0894e60..a1d2c89 100644
--- a/src/main/java/org/apache/sling/jcr/registration/impl/RmiRegistrationSupport.java
+++ b/src/main/java/org/apache/sling/jcr/registration/impl/RmiRegistrationSupport.java
@@ -27,17 +27,18 @@ import java.rmi.server.UnicastRemoteObject;
 
 import javax.jcr.Repository;
 
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.ConfigurationPolicy;
-import org.apache.felix.scr.annotations.Property;
-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.jackrabbit.rmi.server.RemoteAdapterFactory;
 import org.apache.jackrabbit.rmi.server.ServerAdapterFactory;
 import org.apache.sling.jcr.registration.AbstractRegistrationSupport;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.ConfigurationPolicy;
+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.log.LogService;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
 
 /**
  * The <code>RmiRegistrationSupport</code> extends the
@@ -47,30 +48,20 @@ import org.osgi.service.log.LogService;
  * Note: Currently only registries in this Java VM are supported. In the future
  * support for external registries may be added.
  */
+
 @Component(
-        immediate = true,
-        metatype = true,
-        label = "%rmi.name",
-        description = "%rmi.description",
+        configurationPolicy = ConfigurationPolicy.REQUIRE,
         name = "org.apache.sling.jcr.jackrabbit.server.RmiRegistrationSupport",
-        policy = ConfigurationPolicy.REQUIRE)
-@org.apache.felix.scr.annotations.Properties({
-    @Property(name = "service.vendor", value = "The Apache Software Foundation", propertyPrivate = true),
-    @Property(name = "service.description", value = "RMI based Repository Registration", propertyPrivate = true)
-})
-@References({
-    @Reference(
-            name = "Repository",
-            policy = ReferencePolicy.DYNAMIC,
-            cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE,
-            referenceInterface = Repository.class),
-    @Reference(referenceInterface=LogService.class,
-            bind="bindLog", unbind="unbindLog",
-            cardinality = ReferenceCardinality.OPTIONAL_UNARY, policy = ReferencePolicy.DYNAMIC)
-})
+        reference = {
+                @Reference(name = "Repository", policy = ReferencePolicy.DYNAMIC,
+                        cardinality = ReferenceCardinality.MULTIPLE, service = Repository.class),
+                @Reference(name = "Log", policy = ReferencePolicy.DYNAMIC,
+                        bind = "bindLog", unbind = "unbindLog",
+                        cardinality = ReferenceCardinality.OPTIONAL, service = LogService.class),
+        }
+)
+@Designate(ocd = RmiRegistrationSupport.Configuration.class)
 public class RmiRegistrationSupport extends AbstractRegistrationSupport {
-
-    @Property(intValue = 1099, label = "%rmi.port.name", description = "%rmi.port.description")
     public static final String PROP_REGISTRY_PORT = "port";
 
     private int registryPort;
@@ -80,6 +71,25 @@ public class RmiRegistrationSupport extends AbstractRegistrationSupport {
 
     private boolean registryIsPrivate;
 
+    // ---------- Configuration ---------------------------------------------
+
+    @ObjectClassDefinition(name = "Apache Sling JCR Repository RMI Registrar",
+            description = "The RMI Registrar listens for embedded repositories " +
+                    " to be registered as services and registers them in an RMI registry under the " +
+                    " name specified in the \"name\" service property.")
+    public @interface Configuration {
+
+        @AttributeDefinition(
+                name = "Port Number",
+                description = "Port number of the RMI registry to use. The RMI Registrar first tries to " +
+                        "create a private RMI registry at this port. If this fails, an existing registry " +
+                        "is tried to connect at this port on local host. If this number is negative, " +
+                        "the RMI egistrar is disabled. If this number is higher than 65535, an error " +
+                        "message is logged and the RMI Registrar is also  disabled. If this number is " +
+                        "zero, the system default RMI Registry port 1099 is used.")
+        int port() default 1099;
+    }
+
     // ---------- SCR intergration ---------------------------------------------
 
     /**
@@ -311,4 +321,14 @@ public class RmiRegistrationSupport extends AbstractRegistrationSupport {
             }
         }
     }
+
+    @Override
+    protected void bindLog(LogService log) {
+        super.bindLog(log);
+    }
+
+    @Override
+    protected void unbindLog(LogService log) {
+        super.unbindLog(log);
+    }
 }
diff --git a/src/main/java/org/apache/sling/jcr/registration/package-info.java b/src/main/java/org/apache/sling/jcr/registration/package-info.java
index 86981fd..91dade1 100644
--- a/src/main/java/org/apache/sling/jcr/registration/package-info.java
+++ b/src/main/java/org/apache/sling/jcr/registration/package-info.java
@@ -23,10 +23,8 @@
  * class which may be extended by service exposing JCR Repository services
  * in any one non-OSGi registry such as RMI or JNDI.
  */
-@Version("1.1")
-@Export(optional = "provide:=true")
+@Version("1.1.1")
 package org.apache.sling.jcr.registration;
 
-import aQute.bnd.annotation.Export;
-import aQute.bnd.annotation.Version;
 
+import org.osgi.annotation.versioning.Version;
\ No newline at end of file
diff --git a/src/main/resources/OSGI-INF/metatype/metatype.properties b/src/main/resources/OSGI-INF/metatype/metatype.properties
deleted file mode 100644
index cf44eab..0000000
--- a/src/main/resources/OSGI-INF/metatype/metatype.properties
+++ /dev/null
@@ -1,54 +0,0 @@
-#
-#  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.
-#
-
-#
-# This file contains localization strings for configuration labels and
-# descriptions as used in the metatype.xml descriptor generated by the
-# the Sling SCR plugin
-
-#
-# JNDI Registration Support
-jndi.name = Apache Sling JCR Repository JNDI Registrar
-jndi.description = The JNDI Registrar listens for embedded repositories \
- to be registered as services and registers them in the JNDI context under the \
- name specified in the "name" service property.
-
-jndi.factory.name = Initial Context Factory
-jndi.factory.description = The fully qualified class name of the factory class \
- that will create an initial context.
-     
-jndi.providerurl.name = Provider URL
-jndi.providerurl.description =  An URL string for the service provider (e.g. \
- "ldap://somehost:389").
-     
-#
-# RMI Registration Support
-rmi.name = Apache Sling JCR Repository RMI Registrar
-rmi.description = The RMI Registrar listens for embedded repositories \
- to be registered as services and registers them in an RMI registry under the \
- name specified in the "name" service property.
-
-rmi.port.name = Port Number
-rmi.port.description = Port number of the RMI registry to use. The RMI Registrar \
- first tries to create a private RMI registry at this port. If this fails, an \
- existing registry is tried to connect at this port on local host. If this \
- number is negative, the RMI Registrar is disabled. If this number is higher \
- than 65535, an error message is logged and the RMI Registrar is also \
- disabled. If this number is zero, the system default RMI Registry port 1099 \
- is used.

-- 
To stop receiving notification emails like this one, please contact
['"commits@sling.apache.org" <co...@sling.apache.org>'].