This is an automated email from the ASF dual-hosted git repository. cziegeler pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git
The following commit(s) were added to refs/heads/master by this push: new 74ec227 SLING-12060 : Remove dependency to Sling osgi.commons 74ec227 is described below commit 74ec2277c70ea07fe14d154b6ab212613dc73e95 Author: Carsten Ziegeler <cziege...@apache.org> AuthorDate: Sun Oct 1 11:40:03 2023 +0200 SLING-12060 : Remove dependency to Sling osgi.commons --- pom.xml | 12 ++--- .../impl/ResourceResolverFactoryActivator.java | 9 ++-- .../impl/helper/ResourceDecoratorTracker.java | 21 +++------ .../legacy/LegacyResourceProviderWhiteboard.java | 17 ++++--- .../observation/ResourceChangeListenerInfo.java | 53 ++++++++++------------ .../impl/providers/ResourceProviderInfo.java | 22 +++++---- 6 files changed, 60 insertions(+), 74 deletions(-) diff --git a/pom.xml b/pom.xml index 8be245b..f6da4c1 100644 --- a/pom.xml +++ b/pom.xml @@ -144,9 +144,9 @@ <scope>provided</scope> </dependency> <dependency> - <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.commons.osgi</artifactId> - <version>2.4.2</version> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.util.converter</artifactId> + <version>1.0.9</version> <scope>provided</scope> </dependency> <dependency> @@ -240,12 +240,6 @@ <version>3.3.8</version> <scope>test</scope> </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.util.converter</artifactId> - <version>1.0.0</version> - <scope>test</scope> - </dependency> <dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.util.function</artifactId> diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java b/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java index 0a3cd2f..4b249d3 100644 --- a/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java +++ b/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java @@ -46,6 +46,7 @@ import org.apache.sling.resourceresolver.impl.providers.ResourceProviderTracker. import org.apache.sling.resourceresolver.impl.providers.RuntimeServiceImpl; import org.apache.sling.serviceusermapping.ServiceUserMapper; import org.osgi.framework.BundleContext; +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; @@ -390,15 +391,15 @@ public class ResourceResolverFactoryActivator { * Bind a resource decorator. */ @Reference(service = ResourceDecorator.class, cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) - protected void bindResourceDecorator(final ResourceDecorator decorator, final Map<String, Object> props) { - this.resourceDecoratorTracker.bindResourceDecorator(decorator, props); + protected void bindResourceDecorator(final ResourceDecorator decorator, final ServiceReference<ResourceDecorator> ref) { + this.resourceDecoratorTracker.bindResourceDecorator(decorator, ref); } /** * Unbind a resource decorator. */ - protected void unbindResourceDecorator(final ResourceDecorator decorator, final Map<String, Object> props) { - this.resourceDecoratorTracker.unbindResourceDecorator(decorator, props); + protected void unbindResourceDecorator(final ResourceDecorator decorator) { + this.resourceDecoratorTracker.unbindResourceDecorator(decorator); } /** diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceDecoratorTracker.java b/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceDecoratorTracker.java index 727a3bd..6616bd5 100644 --- a/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceDecoratorTracker.java +++ b/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceDecoratorTracker.java @@ -22,12 +22,10 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; -import java.util.Map; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceDecorator; -import org.apache.sling.commons.osgi.Order; -import org.apache.sling.commons.osgi.ServiceUtil; +import org.osgi.framework.ServiceReference; /** * Helper class to track the resource decorators and keep them sorted by their @@ -79,13 +77,12 @@ public class ResourceDecoratorTracker { /** * Bind a resource decorator. * @param decorator The decorator - * @param props The service properties + * @param ref The service reference */ public void bindResourceDecorator(final ResourceDecorator decorator, - final Map<String, Object> props) { + final ServiceReference<ResourceDecorator> ref) { synchronized (this.resourceDecorators) { - this.resourceDecorators.add(new ResourceDecoratorEntry(decorator, - ServiceUtil.getComparableForServiceRanking(props, Order.ASCENDING))); + this.resourceDecorators.add(new ResourceDecoratorEntry(decorator, ref)); Collections.sort(this.resourceDecorators); updateResourceDecoratorsArray(); } @@ -94,13 +91,10 @@ public class ResourceDecoratorTracker { /** * Unbind a resouce decorator. * @param decorator The decorator - * @param props The service properties */ - public void unbindResourceDecorator(final ResourceDecorator decorator, - final Map<String, Object> props) { + public void unbindResourceDecorator(final ResourceDecorator decorator) { synchronized (this.resourceDecorators) { - final Iterator<ResourceDecoratorEntry> i = this.resourceDecorators - .iterator(); + final Iterator<ResourceDecoratorEntry> i = this.resourceDecorators.iterator(); while (i.hasNext()) { final ResourceDecoratorEntry current = i.next(); if (current.decorator == decorator) { @@ -143,8 +137,7 @@ public class ResourceDecoratorTracker { final ResourceDecorator decorator; - public ResourceDecoratorEntry(final ResourceDecorator d, - final Comparable<Object> comparable) { + public ResourceDecoratorEntry(final ResourceDecorator d, final Comparable<Object> comparable) { this.comparable = comparable; this.decorator = d; } diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/legacy/LegacyResourceProviderWhiteboard.java b/src/main/java/org/apache/sling/resourceresolver/impl/legacy/LegacyResourceProviderWhiteboard.java index d069ad0..9529bd1 100644 --- a/src/main/java/org/apache/sling/resourceresolver/impl/legacy/LegacyResourceProviderWhiteboard.java +++ b/src/main/java/org/apache/sling/resourceresolver/impl/legacy/LegacyResourceProviderWhiteboard.java @@ -23,7 +23,6 @@ import static org.apache.sling.api.resource.ResourceProvider.OWNS_ROOTS; import static org.apache.sling.api.resource.ResourceProvider.ROOTS; import static org.apache.sling.api.resource.ResourceProvider.USE_RESOURCE_ACCESS_SECURITY; import static org.apache.sling.api.resource.ResourceProviderFactory.PROPERTY_REQUIRED; -import static org.apache.sling.commons.osgi.PropertiesUtil.toBoolean; import static org.apache.sling.spi.resource.provider.ResourceProvider.PROPERTY_ADAPTABLE; import static org.apache.sling.spi.resource.provider.ResourceProvider.PROPERTY_ATTRIBUTABLE; import static org.apache.sling.spi.resource.provider.ResourceProvider.PROPERTY_AUTHENTICATE; @@ -51,7 +50,6 @@ import org.apache.sling.api.resource.RefreshableResourceProvider; import org.apache.sling.api.resource.ResourceProvider; import org.apache.sling.api.resource.ResourceProviderFactory; import org.apache.sling.api.resource.runtime.dto.AuthType; -import org.apache.sling.commons.osgi.PropertiesUtil; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceRegistration; @@ -59,6 +57,7 @@ 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.osgi.util.converter.Converters; @SuppressWarnings("deprecation") @Component @@ -74,10 +73,10 @@ public class LegacyResourceProviderWhiteboard { final ResourceProvider provider = bundleContext.getService(ref); if ( provider != null ) { final String[] propertyNames = ref.getPropertyKeys(); - final boolean ownsRoot = toBoolean(ref.getProperty(OWNS_ROOTS), false); + final boolean ownsRoot = Converters.standardConverter().convert(ref.getProperty(OWNS_ROOTS)).to(boolean.class); final List<ServiceRegistration> newServices = new ArrayList<>(); - for (final String path : PropertiesUtil.toStringArray(ref.getProperty(ROOTS), new String[0])) { + for (final String path : Converters.standardConverter().convert(ref.getProperty(ROOTS)).to(String[].class)) { if ( path != null && !path.isEmpty() ) { final Dictionary<String, Object> newProps = new Hashtable<>(); newProps.put(PROPERTY_AUTHENTICATE, AuthType.no.toString()); @@ -97,7 +96,7 @@ public class LegacyResourceProviderWhiteboard { newProps.put(SERVICE_RANKING, ref.getProperty(SERVICE_RANKING)); } - String[] languages = PropertiesUtil.toStringArray(ref.getProperty(LANGUAGES), new String[0]); + String[] languages = Converters.standardConverter().convert(ref.getProperty(LANGUAGES)).to(String[].class); ServiceRegistration reg = bundleContext.registerService( org.apache.sling.spi.resource.provider.ResourceProvider.class.getName(), new LegacyResourceProviderAdapter(provider, languages, ownsRoot), newProps); @@ -120,13 +119,13 @@ public class LegacyResourceProviderWhiteboard { final ResourceProviderFactory factory = bundleContext.getService(ref); if ( factory != null ) { final String[] propertyNames = ref.getPropertyKeys(); - final boolean ownsRoot = toBoolean(ref.getProperty(OWNS_ROOTS), false); + final boolean ownsRoot = Converters.standardConverter().convert(ref.getProperty(OWNS_ROOTS)).to(boolean.class); final List<ServiceRegistration> newServices = new ArrayList<>(); - for (final String path : PropertiesUtil.toStringArray(ref.getProperty(ROOTS), new String[0])) { + for (final String path : Converters.standardConverter().convert(ref.getProperty(ROOTS)).to(String[].class)) { if ( path != null && !path.isEmpty() ) { final Dictionary<String, Object> newProps = new Hashtable<>(); - if (PropertiesUtil.toBoolean(ref.getProperty(PROPERTY_REQUIRED), false)) { + if (Converters.standardConverter().convert(ref.getProperty(PROPERTY_REQUIRED)).to(boolean.class)) { newProps.put(PROPERTY_AUTHENTICATE, AuthType.required.toString()); } else { newProps.put(PROPERTY_AUTHENTICATE, AuthType.lazy.toString()); @@ -146,7 +145,7 @@ public class LegacyResourceProviderWhiteboard { if (ArrayUtils.contains(propertyNames, SERVICE_RANKING)) { newProps.put(SERVICE_RANKING, ref.getProperty(SERVICE_RANKING)); } - String[] languages = PropertiesUtil.toStringArray(ref.getProperty(LANGUAGES), new String[0]); + String[] languages = Converters.standardConverter().convert(ref.getProperty(LANGUAGES)).to(String[].class); ServiceRegistration reg = bundleContext.registerService( org.apache.sling.spi.resource.provider.ResourceProvider.class.getName(), new LegacyResourceProviderFactoryAdapter(factory, languages, ownsRoot), newProps); diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/observation/ResourceChangeListenerInfo.java b/src/main/java/org/apache/sling/resourceresolver/impl/observation/ResourceChangeListenerInfo.java index 70c7238..a1c4b68 100644 --- a/src/main/java/org/apache/sling/resourceresolver/impl/observation/ResourceChangeListenerInfo.java +++ b/src/main/java/org/apache/sling/resourceresolver/impl/observation/ResourceChangeListenerInfo.java @@ -20,7 +20,6 @@ package org.apache.sling.resourceresolver.impl.observation; import static org.apache.sling.api.resource.observation.ResourceChangeListener.CHANGES; import static org.apache.sling.api.resource.observation.ResourceChangeListener.PATHS; -import static org.apache.sling.commons.osgi.PropertiesUtil.toStringArray; import java.util.Collections; import java.util.EnumSet; @@ -36,8 +35,8 @@ import org.apache.sling.api.resource.observation.ResourceChange.ChangeType; import org.apache.sling.api.resource.observation.ResourceChangeListener; import org.apache.sling.api.resource.path.Path; import org.apache.sling.api.resource.path.PathSet; -import org.apache.sling.commons.osgi.PropertiesUtil; import org.osgi.framework.ServiceReference; +import org.osgi.util.converter.Converters; /** * Information about a resource change listener. @@ -65,31 +64,29 @@ public class ResourceChangeListenerInfo implements Comparable<ResourceChangeList public ResourceChangeListenerInfo(final ServiceReference<ResourceChangeListener> ref, final List<String> searchPaths) { boolean configValid = true; final Set<String> pathsSet = new HashSet<>(); - final String paths[] = toStringArray(ref.getProperty(PATHS), null); - if ( paths != null ) { - for(final String p : paths) { - boolean isGlobPattern = false; - String normalisedPath = ResourceUtil.normalize(p); - if (p.startsWith(Path.GLOB_PREFIX)) { - isGlobPattern = true; - normalisedPath = ResourceUtil.normalize(p.substring(Path.GLOB_PREFIX.length())); - } - if (!".".equals(p) && normalisedPath.isEmpty()) { - configValid = false; - } else if ( normalisedPath.startsWith("/") && !isGlobPattern ) { - pathsSet.add(normalisedPath); - } else if (normalisedPath.startsWith("/") && isGlobPattern) { - pathsSet.add(Path.GLOB_PREFIX + normalisedPath); - } else { - for(final String sp : searchPaths) { - if ( p.equals(".") ) { - pathsSet.add(sp); + final String paths[] = Converters.standardConverter().convert(ref.getProperty(PATHS)).to(String[].class); + for(final String p : paths) { + boolean isGlobPattern = false; + String normalisedPath = ResourceUtil.normalize(p); + if (p.startsWith(Path.GLOB_PREFIX)) { + isGlobPattern = true; + normalisedPath = ResourceUtil.normalize(p.substring(Path.GLOB_PREFIX.length())); + } + if (!".".equals(p) && normalisedPath.isEmpty()) { + configValid = false; + } else if ( normalisedPath.startsWith("/") && !isGlobPattern ) { + pathsSet.add(normalisedPath); + } else if (normalisedPath.startsWith("/") && isGlobPattern) { + pathsSet.add(Path.GLOB_PREFIX + normalisedPath); + } else { + for(final String sp : searchPaths) { + if ( p.equals(".") ) { + pathsSet.add(sp); + } else { + if (isGlobPattern) { + pathsSet.add(Path.GLOB_PREFIX + ResourceUtil.normalize(sp + normalisedPath)); } else { - if (isGlobPattern) { - pathsSet.add(Path.GLOB_PREFIX + ResourceUtil.normalize(sp + normalisedPath)); - } else { - pathsSet.add(ResourceUtil.normalize(sp + normalisedPath)); - } + pathsSet.add(ResourceUtil.normalize(sp + normalisedPath)); } } } @@ -119,7 +116,7 @@ public class ResourceChangeListenerInfo implements Comparable<ResourceChangeList final Set<ChangeType> rts = new HashSet<>(); final Set<ChangeType> pts = new HashSet<>(); try { - for (final String changeName : toStringArray(ref.getProperty(CHANGES))) { + for (final String changeName : Converters.standardConverter().convert(ref.getProperty(CHANGES)).to(String[].class)) { final ChangeType ct = ChangeType.valueOf(changeName); if (ct.ordinal() < ChangeType.PROVIDER_ADDED.ordinal()) { rts.add(ct); @@ -153,7 +150,7 @@ public class ResourceChangeListenerInfo implements Comparable<ResourceChangeList if ( ref.getProperty(ResourceChangeListener.PROPERTY_NAMES_HINT) != null ) { this.propertyNamesHint = new HashSet<>(); - for(final String val : PropertiesUtil.toStringArray(ref.getProperty(ResourceChangeListener.PROPERTY_NAMES_HINT)) ) { + for(final String val : Converters.standardConverter().convert(ref.getProperty(ResourceChangeListener.PROPERTY_NAMES_HINT)).to(String[].class) ) { this.propertyNamesHint.add(val); } } else { diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/providers/ResourceProviderInfo.java b/src/main/java/org/apache/sling/resourceresolver/impl/providers/ResourceProviderInfo.java index e5653a9..62b1707 100644 --- a/src/main/java/org/apache/sling/resourceresolver/impl/providers/ResourceProviderInfo.java +++ b/src/main/java/org/apache/sling/resourceresolver/impl/providers/ResourceProviderInfo.java @@ -19,9 +19,10 @@ package org.apache.sling.resourceresolver.impl.providers; import org.apache.sling.api.resource.runtime.dto.AuthType; -import org.apache.sling.commons.osgi.PropertiesUtil; import org.apache.sling.spi.resource.provider.ResourceProvider; import org.osgi.framework.ServiceReference; +import org.osgi.util.converter.Converter; +import org.osgi.util.converter.Converters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -60,11 +61,12 @@ public class ResourceProviderInfo implements Comparable<ResourceProviderInfo> { @SuppressWarnings("rawtypes") public ResourceProviderInfo(final ServiceReference<ResourceProvider> ref) { + final Converter c = Converters.standardConverter(); this.ref = ref; - this.path = PropertiesUtil.toString(ref.getProperty(ResourceProvider.PROPERTY_ROOT), ""); - this.name = PropertiesUtil.toString(ref.getProperty(ResourceProvider.PROPERTY_NAME), null); - this.useResourceAccessSecurity = PropertiesUtil.toBoolean(ref.getProperty(ResourceProvider.PROPERTY_USE_RESOURCE_ACCESS_SECURITY), false); - final String authType = PropertiesUtil.toString(ref.getProperty(ResourceProvider.PROPERTY_AUTHENTICATE), AuthType.no.name()); + this.path = c.convert(ref.getProperty(ResourceProvider.PROPERTY_ROOT)).defaultValue("").to(String.class); + this.name = c.convert(ref.getProperty(ResourceProvider.PROPERTY_NAME)).to(String.class); + this.useResourceAccessSecurity = c.convert(ref.getProperty(ResourceProvider.PROPERTY_USE_RESOURCE_ACCESS_SECURITY)).to(boolean.class); + final String authType = c.convert(ref.getProperty(ResourceProvider.PROPERTY_AUTHENTICATE)).defaultValue(AuthType.no.name()).to(String.class); AuthType aType = null; try { aType = AuthType.valueOf(authType); @@ -72,11 +74,11 @@ public class ResourceProviderInfo implements Comparable<ResourceProviderInfo> { logger.error("Illegal auth type {} for resource provider {}", authType, name); } this.authType = aType; - this.modifiable = PropertiesUtil.toBoolean(ref.getProperty(ResourceProvider.PROPERTY_MODIFIABLE), false); - this.adaptable = PropertiesUtil.toBoolean(ref.getProperty(ResourceProvider.PROPERTY_ADAPTABLE), false); - this.refreshable = PropertiesUtil.toBoolean(ref.getProperty(ResourceProvider.PROPERTY_REFRESHABLE), false); - this.attributable = PropertiesUtil.toBoolean(ref.getProperty(ResourceProvider.PROPERTY_ATTRIBUTABLE), false); - final String modeValue = PropertiesUtil.toString(ref.getProperty(ResourceProvider.PROPERTY_MODE), ResourceProvider.MODE_OVERLAY).toUpperCase(); + this.modifiable = c.convert(ref.getProperty(ResourceProvider.PROPERTY_MODIFIABLE)).to(boolean.class); + this.adaptable = c.convert(ref.getProperty(ResourceProvider.PROPERTY_ADAPTABLE)).to(boolean.class); + this.refreshable = c.convert(ref.getProperty(ResourceProvider.PROPERTY_REFRESHABLE)).to(boolean.class); + this.attributable = c.convert(ref.getProperty(ResourceProvider.PROPERTY_ATTRIBUTABLE)).to(boolean.class); + final String modeValue = c.convert(ref.getProperty(ResourceProvider.PROPERTY_MODE)).defaultValue(ResourceProvider.MODE_OVERLAY.toUpperCase()).to(String.class); Mode mode = null; try { mode = Mode.valueOf(modeValue);