This is an automated email from the ASF dual-hosted git repository. amichair pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/aries-rsa.git
commit 4918b527f736f02b677778878ed96568b7fa4b33 Author: Amichai Rothman <[email protected]> AuthorDate: Sun Mar 29 15:09:30 2026 +0300 Remove unnecessary EndpointHelper utility class --- .../rsa/provider/tcp/TcpProviderIntentTest.java | 18 ++++++---- .../rsa/provider/tcp/TcpProviderPrimitiveTest.java | 4 +-- .../aries/rsa/provider/tcp/TcpProviderTLSTest.java | 4 +-- .../aries/rsa/provider/tcp/TcpProviderTest.java | 4 +-- .../aries/rsa/core/RemoteServiceAdminCore.java | 17 ++++----- .../aries/rsa/core/RemoteServiceAdminCoreTest.java | 6 ++-- .../org/apache/aries/rsa/util/EndpointHelper.java | 41 ---------------------- .../org/apache/aries/rsa/util/package-info.java | 2 +- .../exporter/TopologyManagerExport.java | 3 +- 9 files changed, 32 insertions(+), 67 deletions(-) diff --git a/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpProviderIntentTest.java b/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpProviderIntentTest.java index 6e7e3825..d2b019bc 100644 --- a/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpProviderIntentTest.java +++ b/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpProviderIntentTest.java @@ -29,11 +29,11 @@ import java.util.Map; import org.apache.aries.rsa.provider.tcp.myservice.MyService; import org.apache.aries.rsa.provider.tcp.myservice.MyServiceImpl; import org.apache.aries.rsa.spi.Endpoint; -import org.apache.aries.rsa.util.EndpointHelper; import org.easymock.EasyMock; import org.junit.Before; import org.junit.Test; import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; import org.osgi.service.remoteserviceadmin.RemoteConstants; public class TcpProviderIntentTest { @@ -51,10 +51,16 @@ public class TcpProviderIntentTest { myService = new MyServiceImpl(null); } + private Map<String, Object> createProps() { + Map<String, Object> props = new HashMap<>(); + String[] names = Arrays.stream(exportedInterfaces).map(Class::getName).toArray(String[]::new); + props.put(Constants.OBJECTCLASS, names); + return props; + } + @Test public void basicAndAsyncIntents() { - Map<String, Object> props = new HashMap<>(); - EndpointHelper.addObjectClass(props, exportedInterfaces); + Map<String, Object> props = createProps(); String[] standardIntents = {"osgi.basic", "osgi.async"}; props.put(RemoteConstants.SERVICE_EXPORTED_INTENTS, standardIntents); Endpoint ep = provider.exportService(myService, bc, props, exportedInterfaces); @@ -63,8 +69,7 @@ public class TcpProviderIntentTest { @Test public void unknownIntent() { - Map<String, Object> props = new HashMap<>(); - EndpointHelper.addObjectClass(props, exportedInterfaces); + Map<String, Object> props = createProps(); props.put(RemoteConstants.SERVICE_EXPORTED_INTENTS, "unknown"); Endpoint ep = provider.exportService(myService, bc, props, exportedInterfaces); assertThat("Service should not be exported as intent is not supported", ep, nullValue()); @@ -72,8 +77,7 @@ public class TcpProviderIntentTest { @Test public void unknownIntentExtra() { - Map<String, Object> props = new HashMap<>(); - EndpointHelper.addObjectClass(props, exportedInterfaces); + Map<String, Object> props = createProps(); props.put(RemoteConstants.SERVICE_EXPORTED_INTENTS_EXTRA, "unknown"); Endpoint ep = provider.exportService(myService, bc, props, exportedInterfaces); assertThat("Service should not be exported as intent is not supported", ep, nullValue()); diff --git a/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpProviderPrimitiveTest.java b/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpProviderPrimitiveTest.java index 354be26f..abf56382 100644 --- a/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpProviderPrimitiveTest.java +++ b/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpProviderPrimitiveTest.java @@ -40,7 +40,6 @@ import org.apache.aries.rsa.provider.tcp.myservice.PrimitiveService; import org.apache.aries.rsa.provider.tcp.myservice.PrimitiveServiceImpl; import org.apache.aries.rsa.spi.Endpoint; import org.apache.aries.rsa.spi.ImportedService; -import org.apache.aries.rsa.util.EndpointHelper; import org.easymock.EasyMock; import org.junit.AfterClass; import org.junit.Assert; @@ -48,6 +47,7 @@ import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; import org.osgi.framework.Version; public class TcpProviderPrimitiveTest { @@ -62,7 +62,7 @@ public class TcpProviderPrimitiveTest { TcpProvider provider = new TcpProvider(); provider.activate(new HashMap<>()); Map<String, Object> props = new HashMap<>(); - EndpointHelper.addObjectClass(props, exportedInterfaces); + props.put(Constants.OBJECTCLASS, new String[] {PrimitiveService.class.getName()}); props.put(PREFIX + "hostname", "localhost"); props.put(PREFIX + "numThreads", "10"); PrimitiveServiceImpl myService = new PrimitiveServiceImpl(); diff --git a/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpProviderTLSTest.java b/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpProviderTLSTest.java index 17736dff..7c6f8029 100644 --- a/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpProviderTLSTest.java +++ b/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpProviderTLSTest.java @@ -4,11 +4,11 @@ import org.apache.aries.rsa.provider.tcp.myservice.MyService; import org.apache.aries.rsa.provider.tcp.myservice.MyServiceImpl; import org.apache.aries.rsa.spi.Endpoint; import org.apache.aries.rsa.spi.ImportedService; -import org.apache.aries.rsa.util.EndpointHelper; import org.easymock.EasyMock; import org.junit.After; import org.junit.Test; import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; import org.osgi.framework.ServiceException; import java.io.IOException; @@ -56,7 +56,7 @@ public class TcpProviderTLSTest { TcpProvider provider = new TcpProvider(); provider.activate(providerProps); Map<String, Object> props = new HashMap<>(); - EndpointHelper.addObjectClass(props, exportedInterfaces); + props.put(Constants.OBJECTCLASS, new String[] {MyService.class.getName()}); int port = getFreePort(); props.put(Config.HOSTNAME, "localhost"); props.put(Config.PORT, port); diff --git a/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpProviderTest.java b/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpProviderTest.java index ad43dcdb..2ceb8955 100644 --- a/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpProviderTest.java +++ b/provider/tcp/src/test/java/org/apache/aries/rsa/provider/tcp/TcpProviderTest.java @@ -50,13 +50,13 @@ import org.apache.aries.rsa.provider.tcp.myservice.MyService; import org.apache.aries.rsa.provider.tcp.myservice.MyServiceImpl; import org.apache.aries.rsa.spi.Endpoint; import org.apache.aries.rsa.spi.ImportedService; -import org.apache.aries.rsa.util.EndpointHelper; import org.easymock.EasyMock; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; import org.osgi.framework.ServiceException; import org.osgi.util.function.Predicate; import org.osgi.util.promise.Promise; @@ -89,7 +89,7 @@ public class TcpProviderTest { TcpProvider provider = new TcpProvider(); provider.activate(new HashMap<>()); Map<String, Object> props = new HashMap<>(); - EndpointHelper.addObjectClass(props, exportedInterfaces); + props.put(Constants.OBJECTCLASS, new String[] {MyService.class.getName()}); int port = getFreePort(); props.put(PREFIX + "hostname", "localhost"); props.put(PREFIX + "port", port); diff --git a/rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java b/rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java index de033321..ad61786a 100644 --- a/rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java +++ b/rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java @@ -37,10 +37,10 @@ import java.util.Set; import org.apache.aries.rsa.core.event.EventProducer; import org.apache.aries.rsa.spi.DistributionProvider; import org.apache.aries.rsa.spi.Endpoint; -import org.apache.aries.rsa.util.EndpointHelper; import org.apache.aries.rsa.util.StringPlus; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceRegistration; import org.osgi.service.remoteserviceadmin.EndpointDescription; @@ -275,7 +275,7 @@ public class RemoteServiceAdminCore implements RemoteServiceAdmin { * @see RemoteConstants#SERVICE_EXPORTED_INTERFACES */ private List<String> getInterfaceNames(Map<String, Object> serviceProperties) { - List<String> providedInterfaces = StringPlus.normalize(serviceProperties.get(org.osgi.framework.Constants.OBJECTCLASS)); + List<String> providedInterfaces = StringPlus.normalize(serviceProperties.get(Constants.OBJECTCLASS)); if (providedInterfaces == null || providedInterfaces.isEmpty()) { throw new IllegalArgumentException("service is missing the objectClass property"); } @@ -523,8 +523,8 @@ public class RemoteServiceAdminCore implements RemoteServiceAdmin { for (Map.Entry<String, Object> e : additionalProperties.entrySet()) { String key = e.getKey(); String lowerKey = key.toLowerCase(); - if (org.osgi.framework.Constants.SERVICE_ID.toLowerCase().equals(lowerKey) - || org.osgi.framework.Constants.OBJECTCLASS.toLowerCase().equals(lowerKey)) { + if (Constants.SERVICE_ID.toLowerCase().equals(lowerKey) + || Constants.OBJECTCLASS.toLowerCase().equals(lowerKey)) { // objectClass and service.id must not be overwritten LOG.info("exportService called with additional properties map that contained illegal key: {}," + " the key is ignored", key); @@ -561,11 +561,12 @@ public class RemoteServiceAdminCore implements RemoteServiceAdmin { List<String> configTypes, Class<?>[] ifaces) { Map<String, Object> props = new HashMap<>(); copyEndpointProperties(effectiveProps, props); - props.remove(org.osgi.framework.Constants.SERVICE_ID); + props.remove(Constants.SERVICE_ID); props.put(RemoteConstants.SERVICE_EXPORTED_CONFIGS, configTypes); - EndpointHelper.addObjectClass(props, ifaces); - props.put(RemoteConstants.ENDPOINT_SERVICE_ID, effectiveProps.get(org.osgi.framework.Constants.SERVICE_ID)); - String frameworkUUID = bctx.getProperty(org.osgi.framework.Constants.FRAMEWORK_UUID); + String[] inames = Arrays.stream(ifaces).map(Class::getName).toArray(String[]::new); + props.put(Constants.OBJECTCLASS, inames); + props.put(RemoteConstants.ENDPOINT_SERVICE_ID, effectiveProps.get(Constants.SERVICE_ID)); + String frameworkUUID = bctx.getProperty(Constants.FRAMEWORK_UUID); props.put(RemoteConstants.ENDPOINT_FRAMEWORK_UUID, frameworkUUID); for (Class<?> iface : ifaces) { String pkg = iface.getPackage().getName(); diff --git a/rsa/src/test/java/org/apache/aries/rsa/core/RemoteServiceAdminCoreTest.java b/rsa/src/test/java/org/apache/aries/rsa/core/RemoteServiceAdminCoreTest.java index 4b97c3f9..3e89de51 100644 --- a/rsa/src/test/java/org/apache/aries/rsa/core/RemoteServiceAdminCoreTest.java +++ b/rsa/src/test/java/org/apache/aries/rsa/core/RemoteServiceAdminCoreTest.java @@ -328,15 +328,15 @@ public class RemoteServiceAdminCoreTest { public void testCreateEndpointProps() { c.replay(); Map<String, Object> sd = new HashMap<>(); - sd.put(org.osgi.framework.Constants.SERVICE_ID, 42); + sd.put(Constants.SERVICE_ID, 42); Map<String, Object> props = rsaCore.createEndpointProps( sd, Arrays.asList("myconfig"), new Class[]{String.class}); - Assert.assertFalse(props.containsKey(org.osgi.framework.Constants.SERVICE_ID)); + Assert.assertFalse(props.containsKey(Constants.SERVICE_ID)); assertEquals(42, props.get(RemoteConstants.ENDPOINT_SERVICE_ID)); assertEquals("some_uuid1", props.get(RemoteConstants.ENDPOINT_FRAMEWORK_UUID)); assertEquals(Arrays.asList("java.lang.String"), - Arrays.asList((Object[]) props.get(org.osgi.framework.Constants.OBJECTCLASS))); + Arrays.asList((Object[]) props.get(Constants.OBJECTCLASS))); assertEquals(Arrays.asList("myconfig"), props.get(RemoteConstants.SERVICE_EXPORTED_CONFIGS)); assertEquals("1.2.3", props.get("endpoint.package.version.java.lang")); c.verify(); diff --git a/spi/src/main/java/org/apache/aries/rsa/util/EndpointHelper.java b/spi/src/main/java/org/apache/aries/rsa/util/EndpointHelper.java deleted file mode 100644 index ff47bf87..00000000 --- a/spi/src/main/java/org/apache/aries/rsa/util/EndpointHelper.java +++ /dev/null @@ -1,41 +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. - */ -package org.apache.aries.rsa.util; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public final class EndpointHelper { - - private EndpointHelper() { - } - - public static void addObjectClass(Map<String, Object> props, Class<?>[] interfaces) { - props.put(org.osgi.framework.Constants.OBJECTCLASS, getClassNames(interfaces)); - } - - public static String[] getClassNames(Class<?>[] ifaces) { - List<String> ifaceNames = new ArrayList<>(); - for (Class<?> iface : ifaces) { - ifaceNames.add(iface.getName()); - } - return ifaceNames.toArray(new String[]{}); - } -} diff --git a/spi/src/main/java/org/apache/aries/rsa/util/package-info.java b/spi/src/main/java/org/apache/aries/rsa/util/package-info.java index 4c21efbe..10f4c84f 100644 --- a/spi/src/main/java/org/apache/aries/rsa/util/package-info.java +++ b/spi/src/main/java/org/apache/aries/rsa/util/package-info.java @@ -18,5 +18,5 @@ */ @org.osgi.annotation.bundle.Export [email protected]("1.9.0") [email protected]("2.0.0") package org.apache.aries.rsa.util; \ No newline at end of file diff --git a/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/exporter/TopologyManagerExport.java b/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/exporter/TopologyManagerExport.java index 4e3b16e5..7db6647a 100644 --- a/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/exporter/TopologyManagerExport.java +++ b/topology-manager/src/main/java/org/apache/aries/rsa/topologymanager/exporter/TopologyManagerExport.java @@ -30,6 +30,7 @@ import java.util.concurrent.Executor; import org.apache.aries.rsa.spi.ExportPolicy; import org.apache.aries.rsa.util.StringPlus; import org.osgi.framework.Bundle; +import org.osgi.framework.Constants; import org.osgi.framework.Filter; import org.osgi.framework.ServiceEvent; import org.osgi.framework.ServiceListener; @@ -138,7 +139,7 @@ public class TopologyManagerExport implements ServiceListener { Bundle bundle = sref.getBundle(); String bundleName = bundle == null ? null : bundle.getSymbolicName(); LOG.warn("Unable to export service from bundle {}, interfaces {}, as no RemoteServiceAdmin is available. Marked for later export.", - bundleName, sref.getProperty(org.osgi.framework.Constants.OBJECTCLASS)); + bundleName, sref.getProperty(Constants.OBJECTCLASS)); return; } endpointRepo.forEach((rsa, repo) -> repo.addService(sref, exportService(rsa, sref)));
