From 76e900dcb605493888d9a3a788d93e03f4fe15c8 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Sun, 2 Nov 2025 17:25:48 +0100 Subject: [PATCH] Replace internal REFERENCE_NAME_SATISFYING_CONDITION with OSGi spec constant (#8) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com> --- .../apache/felix/scr/impl/manager/DependencyManager.java | 2 +- .../apache/felix/scr/impl/metadata/ReferenceMetadata.java | 8 +------- .../java/org/apache/felix/scr/impl/xml/XmlHandler.java | 7 ++++--- .../components/SatisfyingConditionComponentClass.java | 4 ++-- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java index 031b2c1c01..6736acf29b 100644 --- a/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java +++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/DependencyManager.java @@ -2516,7 +2516,7 @@ private ServiceReference getTrueConditionRef() { return null; } - if (ReferenceMetadata.REFERENCE_NAME_SATISFYING_CONDITION.equals( + if (ComponentConstants.REFERENCE_NAME_SATISFYING_CONDITION.equals( m_dependencyMetadata.getName()) == false) { return null; diff --git a/scr/src/main/java/org/apache/felix/scr/impl/metadata/ReferenceMetadata.java b/scr/src/main/java/org/apache/felix/scr/impl/metadata/ReferenceMetadata.java index 985c8ec3d0..2ed6e38114 100644 --- a/scr/src/main/java/org/apache/felix/scr/impl/metadata/ReferenceMetadata.java +++ b/scr/src/main/java/org/apache/felix/scr/impl/metadata/ReferenceMetadata.java @@ -28,6 +28,7 @@ import org.apache.felix.scr.impl.metadata.MetadataStoreHelper.MetaDataReader; import org.apache.felix.scr.impl.metadata.MetadataStoreHelper.MetaDataWriter; +import org.osgi.service.component.ComponentConstants; /** * Information associated to a dependency @@ -101,13 +102,6 @@ public enum ReferenceScope {bundle, prototype, prototype_required} public static final String CONDITION_TRUE_FILTER = "(osgi.condition.id=true)"; - /** - * The reference name for the implicit satisfying condition as defined in the - * OSGi R8 Declarative Services specification (see https://github.com/osgi/osgi/pull/875). - * This reference is automatically added to components when a true condition service is available. - */ - public static final String REFERENCE_NAME_SATISFYING_CONDITION = "osgi.ds.satisfying.condition"; - // Name for the reference (required) private String m_name; diff --git a/scr/src/main/java/org/apache/felix/scr/impl/xml/XmlHandler.java b/scr/src/main/java/org/apache/felix/scr/impl/xml/XmlHandler.java index a7588f6d68..e2cd476b89 100644 --- a/scr/src/main/java/org/apache/felix/scr/impl/xml/XmlHandler.java +++ b/scr/src/main/java/org/apache/felix/scr/impl/xml/XmlHandler.java @@ -35,6 +35,7 @@ import org.apache.felix.scr.impl.metadata.ServiceMetadata; import org.osgi.framework.Bundle; import org.osgi.framework.ServiceReference; +import org.osgi.service.component.ComponentConstants; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; @@ -493,7 +494,7 @@ else if ( localName.equals( XmlConstants.EL_FACTORY_PROPERTY ) && m_pendingFacto boolean missingSatisfyingConditionRef = true; for (ReferenceMetadata ref : m_currentComponent.getDependencies()) { - if (ReferenceMetadata.REFERENCE_NAME_SATISFYING_CONDITION.equals( + if (ComponentConstants.REFERENCE_NAME_SATISFYING_CONDITION.equals( ref.getName())) { missingSatisfyingConditionRef = false; @@ -504,7 +505,7 @@ else if ( localName.equals( XmlConstants.EL_FACTORY_PROPERTY ) && m_pendingFacto { ReferenceMetadata trueReference = new ReferenceMetadata(); trueReference.setName( - ReferenceMetadata.REFERENCE_NAME_SATISFYING_CONDITION); + ComponentConstants.REFERENCE_NAME_SATISFYING_CONDITION); trueReference.setTarget(ReferenceMetadata.CONDITION_TRUE_FILTER); trueReference.setInterface(ReferenceMetadata.CONDITION_SERVICE_CLASS); trueReference.setPolicy(ReferenceMetadata.POLICY_DYNAMIC); @@ -515,7 +516,7 @@ else if ( localName.equals( XmlConstants.EL_FACTORY_PROPERTY ) && m_pendingFacto // condition targets via the osgi.ds.satisfying.condition.target property. PropertyMetadata prop = new PropertyMetadata(true); prop.setName( - ReferenceMetadata.REFERENCE_NAME_SATISFYING_CONDITION + ".target"); + ComponentConstants.REFERENCE_NAME_SATISFYING_CONDITION + ".target"); prop.setValue(ReferenceMetadata.CONDITION_TRUE_FILTER); m_currentComponent.addProperty(prop); } diff --git a/scr/src/test/java/org/apache/felix/scr/integration/components/SatisfyingConditionComponentClass.java b/scr/src/test/java/org/apache/felix/scr/integration/components/SatisfyingConditionComponentClass.java index e68eb293be..1cf2a14d72 100644 --- a/scr/src/test/java/org/apache/felix/scr/integration/components/SatisfyingConditionComponentClass.java +++ b/scr/src/test/java/org/apache/felix/scr/integration/components/SatisfyingConditionComponentClass.java @@ -18,7 +18,7 @@ */ package org.apache.felix.scr.integration.components; -import org.apache.felix.scr.impl.metadata.ReferenceMetadata; +import org.osgi.service.component.ComponentConstants; import org.osgi.service.component.ComponentContext; public class SatisfyingConditionComponentClass @@ -27,7 +27,7 @@ public class SatisfyingConditionComponentClass void activate(ComponentContext cc) { Object trueCondition = cc.locateService( - ReferenceMetadata.REFERENCE_NAME_SATISFYING_CONDITION); + ComponentConstants.REFERENCE_NAME_SATISFYING_CONDITION); System.out.println("Found condition: " + trueCondition); }