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

stbischof pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git


The following commit(s) were added to refs/heads/master by this push:
     new efa5526f0f Enable conditional command registration.
efa5526f0f is described below

commit efa5526f0fd356a3e978cb865d2aa2d068fba042
Author: Stefan Bischof <[email protected]>
AuthorDate: Fri Aug 15 16:37:52 2025 +0200

    Enable conditional command registration.
    
    - Add `ds.commands.enabled` property to control command registration.
    - Update `Activator` to conditionally register component commands.
    - Extend `ScrConfigurationImpl` to handle `ds.commands.enabled`.
    - Add MetaType Attreibute definition.
    
    Signed-off-by: Stefan Bischof <[email protected]>
---
 .../main/java/org/apache/felix/scr/impl/Activator.java |  5 ++++-
 .../felix/scr/impl/config/ScrConfigurationImpl.java    | 18 +++++++++++++++++-
 .../felix/scr/impl/config/ScrMetaTypeProvider.java     |  6 ++++++
 .../felix/scr/impl/manager/ScrConfiguration.java       |  5 ++++-
 4 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/scr/src/main/java/org/apache/felix/scr/impl/Activator.java 
b/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
index 6cc2e4c397..b1b41cce0a 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/Activator.java
@@ -226,7 +226,10 @@ public class Activator extends AbstractExtender
         super.doStart();
 
         m_componentCommands = new ComponentCommands(m_context, 
m_globalContext, runtime, m_configuration);
-        m_componentCommands.register();
+        if(m_configuration.isCommandsEnabled()) {
+            m_componentCommands.register();
+        }
+
         
m_componentCommands.updateProvideScrInfoService(m_configuration.infoAsService());
         m_configuration.setScrCommand(m_componentCommands);
     }
diff --git 
a/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfigurationImpl.java 
b/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfigurationImpl.java
index 2e7aadf377..e5ca01c0a1 100644
--- 
a/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfigurationImpl.java
+++ 
b/scr/src/main/java/org/apache/felix/scr/impl/config/ScrConfigurationImpl.java
@@ -86,6 +86,8 @@ public class ScrConfigurationImpl implements ScrConfiguration
     private boolean isLogEnabled;
 
     private boolean isLogExtensionEnabled;
+    
+    private boolean commandsEnabled;
 
     private long lockTimeout = DEFAULT_LOCK_TIMEOUT_MILLISECONDS;
 
@@ -184,6 +186,7 @@ public class ScrConfigurationImpl implements 
ScrConfiguration
                         cacheMetadata = false;
                         isLogEnabled = true;
                         isLogExtensionEnabled = false;
+                        commandsEnabled = true;
                     }
                     else
                     {
@@ -198,6 +201,7 @@ public class ScrConfigurationImpl implements 
ScrConfiguration
                         cacheMetadata = getDefaultCacheMetadata();
                         isLogEnabled = getDefaultLogEnabled();
                         isLogExtensionEnabled = getDefaultLogExtension();
+                        commandsEnabled = getDefaultCommandsEnabled();
                     }
                 }
                 else
@@ -220,6 +224,8 @@ public class ScrConfigurationImpl implements 
ScrConfiguration
                     String.valueOf(config.get(PROP_CACHE_METADATA)));
                 isLogEnabled = checkIfLogEnabled(config);
                 isLogExtensionEnabled = 
VALUE_TRUE.equalsIgnoreCase(String.valueOf(config.get(PROP_LOG_EXTENSION)));
+                Object cmdEnabled =  config.get( PROP_COMMANDS_ENABLED );
+                commandsEnabled=cmdEnabled == null ? true : 
VALUE_TRUE.equalsIgnoreCase(cmdEnabled.toString());
             }
             if ( scrCommand != null )
             {
@@ -446,6 +452,16 @@ public class ScrConfigurationImpl implements 
ScrConfiguration
         }
         return isLogEnabled == null ? true : 
Boolean.parseBoolean(isLogEnabled.toString());
     }
-    
 
+    private boolean getDefaultCommandsEnabled()
+    {
+       String commandsEnabled = 
bundleContext.getProperty(PROP_COMMANDS_ENABLED);
+        return commandsEnabled == null ? true : 
VALUE_TRUE.equalsIgnoreCase(commandsEnabled);
+    }
+    
+    @Override
+    public boolean isCommandsEnabled() 
+       {
+               return commandsEnabled;
+       }
 }
diff --git 
a/scr/src/main/java/org/apache/felix/scr/impl/config/ScrMetaTypeProvider.java 
b/scr/src/main/java/org/apache/felix/scr/impl/config/ScrMetaTypeProvider.java
index deb212fa3e..9a7a7d5c36 100644
--- 
a/scr/src/main/java/org/apache/felix/scr/impl/config/ScrMetaTypeProvider.java
+++ 
b/scr/src/main/java/org/apache/felix/scr/impl/config/ScrMetaTypeProvider.java
@@ -123,6 +123,12 @@ class ScrMetaTypeProvider implements MetaTypeProvider
                 "Whether to extend all bundles whether or not visible to this 
bundle.",
                 false ) );
 
+        adList.add( new AttributeDefinitionImpl(
+                ScrConfiguration.PROP_COMMANDS_ENABLED,
+                "Commands Enabled",
+                "Whether to enable the Felix SCR commands. If set to false, 
the commands will not be registered and thus not available.",
+                true ) );
+
         return new ObjectClassDefinition()
         {
 
diff --git 
a/scr/src/main/java/org/apache/felix/scr/impl/manager/ScrConfiguration.java 
b/scr/src/main/java/org/apache/felix/scr/impl/manager/ScrConfiguration.java
index f4b89f96bb..01eeb69cad 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/ScrConfiguration.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/ScrConfiguration.java
@@ -68,8 +68,9 @@ public interface ScrConfiguration extends LogConfiguration
     String PROP_SERVICE_CHANGECOUNT_TIMEOUT = "ds.service.changecount.timeout";
 
     String PROP_CACHE_METADATA = "ds.cache.metadata";
-    
 
+    String PROP_COMMANDS_ENABLED = "ds.commands.enabled";
+    
     boolean isFactoryEnabled();
 
 
@@ -94,4 +95,6 @@ public interface ScrConfiguration extends LogConfiguration
 
     boolean cacheMetadata();
 
+       boolean isCommandsEnabled();
+
 }

Reply via email to