You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2021/12/02 09:56:25 UTC
[sling-org-apache-sling-models-jacksonexporter] branch master updated: SLING-10959 Sling Models Exporter: Migrate from Felix SCR annotations to OSGi R7 annotations, Update to Parent 46 (#4)
This is an automated email from the ASF dual-hosted git repository.
sseifert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-models-jacksonexporter.git
The following commit(s) were added to refs/heads/master by this push:
new c7db896 SLING-10959 Sling Models Exporter: Migrate from Felix SCR annotations to OSGi R7 annotations, Update to Parent 46 (#4)
c7db896 is described below
commit c7db896c2d4871f88869fc54bedffb1cdb5760ad
Author: Stefan Seifert <st...@users.noreply.github.com>
AuthorDate: Thu Dec 2 10:56:05 2021 +0100
SLING-10959 Sling Models Exporter: Migrate from Felix SCR annotations to OSGi R7 annotations, Update to Parent 46 (#4)
---
pom.xml | 94 +++++++++++-----------
.../models/jacksonexporter/ModuleProvider.java | 5 +-
.../jacksonexporter/impl/JacksonExporter.java | 19 +++--
.../impl/RequestModuleProvider.java | 10 +--
.../impl/ResourceModuleProvider.java | 36 ++++-----
.../sling/models/jacksonexporter/package-info.java | 4 +-
6 files changed, 82 insertions(+), 86 deletions(-)
diff --git a/pom.xml b/pom.xml
index f35563a..7975d44 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,26 +1,33 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
-<!-- 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. -->
+<!--
+ 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.
+-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.sling</groupId>
- <artifactId>sling</artifactId>
- <version>25</version>
+ <artifactId>sling-bundle-parent</artifactId>
+ <version>46</version>
<relativePath />
</parent>
<artifactId>org.apache.sling.models.jacksonexporter</artifactId>
<version>1.0.9-SNAPSHOT</version>
- <packaging>bundle</packaging>
<name>Apache Sling Models Jackson Exporter</name>
<description>Apache Sling Models Client Model Exporter - Jackson</description>
@@ -29,50 +36,45 @@
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-models-jacksonexporter.git</developerConnection>
<url>https://gitbox.apache.org/repos/asf?p=sling-org-apache-sling-models-jacksonexporter.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>
- <Embed-Dependency>*;scope=compile</Embed-Dependency>
- <Conditional-Package>org.apache.sling.commons.osgi</Conditional-Package>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
+
+ <properties>
+ <sling.java.version>8</sling.java.version>
+ <project.build.outputTimestamp>2021-12-01T00:00:00Z</project.build.outputTimestamp>
+ </properties>
+
<dependencies>
<dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.models.api</artifactId>
- <version>1.3.0</version>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.component</artifactId>
<scope>provided</scope>
</dependency>
+
+ <!-- OSGi annotations -->
<dependency>
<groupId>org.osgi</groupId>
- <artifactId>org.osgi.compendium</artifactId>
+ <artifactId>org.osgi.annotation.versioning</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
+ <artifactId>org.osgi.service.component.annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.metatype.annotations</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.models.api</artifactId>
+ <version>1.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.scr.annotations</artifactId>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
@@ -94,7 +96,6 @@
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
- <version>16.0.2</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -111,7 +112,7 @@
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
+ <artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
@@ -120,9 +121,8 @@
<version>4.1</version>
<scope>provided</scope>
</dependency>
- <!-- *************************************************************** -->
- <!-- JACKSON -->
- <!-- *************************************************************** -->
+
+ <!-- Jackson -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
@@ -141,5 +141,7 @@
<version>2.3.2</version>
<scope>provided</scope>
</dependency>
+
</dependencies>
+
</project>
diff --git a/src/main/java/org/apache/sling/models/jacksonexporter/ModuleProvider.java b/src/main/java/org/apache/sling/models/jacksonexporter/ModuleProvider.java
index 29dd8a8..a1e62e2 100644
--- a/src/main/java/org/apache/sling/models/jacksonexporter/ModuleProvider.java
+++ b/src/main/java/org/apache/sling/models/jacksonexporter/ModuleProvider.java
@@ -16,9 +16,9 @@
*/
package org.apache.sling.models.jacksonexporter;
-import com.fasterxml.jackson.databind.Module;
+import org.osgi.annotation.versioning.ConsumerType;
-import aQute.bnd.annotation.ConsumerType;
+import com.fasterxml.jackson.databind.Module;
/**
* Extension interface which allows for plugging in Jackson Modules
@@ -28,4 +28,5 @@ import aQute.bnd.annotation.ConsumerType;
public interface ModuleProvider {
Module getModule();
+
}
diff --git a/src/main/java/org/apache/sling/models/jacksonexporter/impl/JacksonExporter.java b/src/main/java/org/apache/sling/models/jacksonexporter/impl/JacksonExporter.java
index 9bac480..03887e3 100644
--- a/src/main/java/org/apache/sling/models/jacksonexporter/impl/JacksonExporter.java
+++ b/src/main/java/org/apache/sling/models/jacksonexporter/impl/JacksonExporter.java
@@ -22,17 +22,16 @@ import java.io.IOException;
import java.io.StringWriter;
import java.util.Map;
-import org.apache.felix.scr.annotations.Component;
-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.Service;
import org.apache.sling.commons.osgi.Order;
import org.apache.sling.commons.osgi.RankedServices;
import org.apache.sling.models.export.spi.ModelExporter;
import org.apache.sling.models.factory.ExportException;
import org.apache.sling.models.jacksonexporter.ModuleProvider;
import org.jetbrains.annotations.NotNull;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
+import org.osgi.service.component.annotations.ReferencePolicy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -44,8 +43,7 @@ import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
-@Component
-@Service
+@Component(service = ModelExporter.class)
public class JacksonExporter implements ModelExporter {
private static final Logger log = LoggerFactory.getLogger(JacksonExporter.class);
@@ -58,9 +56,7 @@ public class JacksonExporter implements ModelExporter {
private static final int MAPPER_FEATURE_PREFIX_LENGTH = MAPPER_FEATURE_PREFIX.length();
- @Reference(name = "moduleProvider", referenceInterface = ModuleProvider.class,
- cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC)
- private final RankedServices<ModuleProvider> moduleProviders = new RankedServices<ModuleProvider>(Order.ASCENDING);
+ private final RankedServices<ModuleProvider> moduleProviders = new RankedServices<>(Order.ASCENDING);
@Override
public boolean isSupported(@NotNull Class<?> clazz) {
@@ -124,6 +120,9 @@ public class JacksonExporter implements ModelExporter {
}
}
+ @Reference(name = "moduleProvider", service = ModuleProvider.class,
+ cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC,
+ bind = "bindModuleProvider", unbind = "unbindModuleProvider")
protected void bindModuleProvider(final ModuleProvider moduleProvider, final Map<String, Object> props) {
moduleProviders.bind(moduleProvider, props);
}
diff --git a/src/main/java/org/apache/sling/models/jacksonexporter/impl/RequestModuleProvider.java b/src/main/java/org/apache/sling/models/jacksonexporter/impl/RequestModuleProvider.java
index 3312058..30c0856 100644
--- a/src/main/java/org/apache/sling/models/jacksonexporter/impl/RequestModuleProvider.java
+++ b/src/main/java/org/apache/sling/models/jacksonexporter/impl/RequestModuleProvider.java
@@ -21,19 +21,14 @@ import java.util.Enumeration;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.models.jacksonexporter.ModuleProvider;
-import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Component;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.module.SimpleModule;
-@Component
-@Service
-@Property(name = Constants.SERVICE_RANKING, intValue = 0)
+@Component(service = ModuleProvider.class)
public class RequestModuleProvider implements ModuleProvider {
private final SimpleModule moduleInstance;
@@ -50,4 +45,5 @@ public class RequestModuleProvider implements ModuleProvider {
public Module getModule() {
return moduleInstance;
}
+
}
diff --git a/src/main/java/org/apache/sling/models/jacksonexporter/impl/ResourceModuleProvider.java b/src/main/java/org/apache/sling/models/jacksonexporter/impl/ResourceModuleProvider.java
index 1027a93..7418c2a 100644
--- a/src/main/java/org/apache/sling/models/jacksonexporter/impl/ResourceModuleProvider.java
+++ b/src/main/java/org/apache/sling/models/jacksonexporter/impl/ResourceModuleProvider.java
@@ -16,38 +16,38 @@
*/
package org.apache.sling.models.jacksonexporter.impl;
-import java.util.Map;
-
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-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.commons.osgi.PropertiesUtil;
import org.apache.sling.models.jacksonexporter.ModuleProvider;
-import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.module.SimpleModule;
-@Component(metatype = true, label = "Apache Sling Models Jackson Exporter - Resource object support",
- description = "Provider of a Jackson Module which enables support for proper serialization of Resource objects")
-@Service
-@Property(name = Constants.SERVICE_RANKING, intValue = 0, propertyPrivate = true)
+@Component(service = ModuleProvider.class)
+@Designate(ocd = ResourceModuleProvider.Config.class)
public class ResourceModuleProvider implements ModuleProvider {
private static final int DEFAULT_MAX_RECURSION_LEVELS = -1;
- @Property(label = "Maximum Recursion Levels",
- description = "Maximum number of levels of child resources which will be exported for each resource. Specify -1 for infinite.",
- intValue = DEFAULT_MAX_RECURSION_LEVELS)
- private static final String PROP_MAX_RECURSION_LEVELS = "max.recursion.levels";
+ @ObjectClassDefinition(name = "Apache Sling Models Jackson Exporter - Resource object support",
+ description = "Provider of a Jackson Module which enables support for proper serialization of Resource objects")
+ static @interface Config {
+
+ @AttributeDefinition(name ="Maximum Recursion Levels",
+ description = "Maximum number of levels of child resources which will be exported for each resource. Specify -1 for infinite.")
+ int max_recursion_levels() default DEFAULT_MAX_RECURSION_LEVELS;
+
+ }
private SimpleModule moduleInstance;
@Activate
- private void activate(Map<String, Object> props) {
- final int maxRecursionLevels = PropertiesUtil.toInteger(props.get(PROP_MAX_RECURSION_LEVELS), DEFAULT_MAX_RECURSION_LEVELS);
+ private void activate(Config config) {
+ final int maxRecursionLevels = config.max_recursion_levels();
this.moduleInstance = new SimpleModule();
ModelSkippingSerializers serializers = new ModelSkippingSerializers();
serializers.addSerializer(Resource.class, new ResourceSerializer(maxRecursionLevels));
diff --git a/src/main/java/org/apache/sling/models/jacksonexporter/package-info.java b/src/main/java/org/apache/sling/models/jacksonexporter/package-info.java
index 58da044..d7cbbc1 100644
--- a/src/main/java/org/apache/sling/models/jacksonexporter/package-info.java
+++ b/src/main/java/org/apache/sling/models/jacksonexporter/package-info.java
@@ -15,7 +15,5 @@
* limitations under the License.
*/
-@Version("1.0.0")
+@org.osgi.annotation.versioning.Version("1.0.1")
package org.apache.sling.models.jacksonexporter;
-
-import aQute.bnd.annotation.Version;
\ No newline at end of file