You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2017/10/03 09:37:03 UTC

[1/3] karaf git commit: [KARAF-5400] Remove usage of felix scr compatibility bundle

Repository: karaf
Updated Branches:
  refs/heads/master 1a834e745 -> 9248128b4


[KARAF-5400] Remove usage of felix scr compatibility bundle


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/66a75fcd
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/66a75fcd
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/66a75fcd

Branch: refs/heads/master
Commit: 66a75fcd89f9692411394c07360e344fff3fd80a
Parents: 1a834e7
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Tue Oct 3 10:42:54 2017 +0200
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Tue Oct 3 10:43:10 2017 +0200

----------------------------------------------------------------------
 assemblies/features/standard/pom.xml            |   5 -
 .../standard/src/main/feature/feature.xml       |   1 -
 .../src/test/filtered-resources/etc/feature.xml |   1 -
 pom.xml                                         |   6 -
 .../karaf/scr/command/action/ListAction.java    |   3 +-
 scr/management/pom.xml                          |   5 -
 .../scr/management/codec/JmxComponent.java      |  45 +-
 .../scr/management/codec/JmxReference.java      |  30 +-
 .../scr/management/internal/ScrService.java     | 507 +++++++++++++++++++
 .../internal/ScrServiceMBeanImpl.java           |  66 ++-
 .../internal/ScrServiceMBeanImpl.properties     |   1 +
 11 files changed, 581 insertions(+), 89 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/66a75fcd/assemblies/features/standard/pom.xml
----------------------------------------------------------------------
diff --git a/assemblies/features/standard/pom.xml b/assemblies/features/standard/pom.xml
index 3ed2a6a..e5a6f13 100644
--- a/assemblies/features/standard/pom.xml
+++ b/assemblies/features/standard/pom.xml
@@ -384,11 +384,6 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.scr.compat</artifactId>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
             <groupId>org.apache.karaf.scr</groupId>
             <artifactId>org.apache.karaf.scr.command</artifactId>
             <scope>provided</scope>

http://git-wip-us.apache.org/repos/asf/karaf/blob/66a75fcd/assemblies/features/standard/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/assemblies/features/standard/src/main/feature/feature.xml b/assemblies/features/standard/src/main/feature/feature.xml
index c2d7b9c..a731f51 100644
--- a/assemblies/features/standard/src/main/feature/feature.xml
+++ b/assemblies/features/standard/src/main/feature/feature.xml
@@ -946,7 +946,6 @@
     <feature name="scr" description="Declarative Service support" version="${project.version}">
         <bundle dependency="true" start-level="30">mvn:org.apache.felix/org.apache.felix.metatype/${felix.metatype.version}</bundle>
         <bundle start-level="30">mvn:org.apache.felix/org.apache.felix.scr/${felix.scr.version}</bundle>
-        <bundle start-level="30">mvn:org.apache.felix/org.apache.felix.scr.compat/${felix.scr.compat.version}</bundle>
         <conditional>
             <condition>management</condition>
             <bundle start-level="30">mvn:org.apache.karaf.scr/org.apache.karaf.scr.management/${project.version}</bundle>

http://git-wip-us.apache.org/repos/asf/karaf/blob/66a75fcd/itests/src/test/filtered-resources/etc/feature.xml
----------------------------------------------------------------------
diff --git a/itests/src/test/filtered-resources/etc/feature.xml b/itests/src/test/filtered-resources/etc/feature.xml
index c2d7b9c..a731f51 100644
--- a/itests/src/test/filtered-resources/etc/feature.xml
+++ b/itests/src/test/filtered-resources/etc/feature.xml
@@ -946,7 +946,6 @@
     <feature name="scr" description="Declarative Service support" version="${project.version}">
         <bundle dependency="true" start-level="30">mvn:org.apache.felix/org.apache.felix.metatype/${felix.metatype.version}</bundle>
         <bundle start-level="30">mvn:org.apache.felix/org.apache.felix.scr/${felix.scr.version}</bundle>
-        <bundle start-level="30">mvn:org.apache.felix/org.apache.felix.scr.compat/${felix.scr.compat.version}</bundle>
         <conditional>
             <condition>management</condition>
             <bundle start-level="30">mvn:org.apache.karaf.scr/org.apache.karaf.scr.management/${project.version}</bundle>

http://git-wip-us.apache.org/repos/asf/karaf/blob/66a75fcd/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 469bf04..47a4fc6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -206,7 +206,6 @@
         <felix.eventadmin.webconsole.plugin.version>1.1.6</felix.eventadmin.webconsole.plugin.version>
         <felix.obr.version>1.0.2</felix.obr.version>
         <felix.scr.version>2.0.12</felix.scr.version>
-        <felix.scr.compat.version>1.0.4</felix.scr.compat.version>
         <felix.scr.webconsole.plugin.version>2.0.6</felix.scr.webconsole.plugin.version>
         <felix.scr.annotation.version>1.12.0</felix.scr.annotation.version>
         <felix.resolver.version>1.14.0</felix.resolver.version>
@@ -967,11 +966,6 @@
             </dependency>
             <dependency>
                 <groupId>org.apache.felix</groupId>
-                <artifactId>org.apache.felix.scr.compat</artifactId>
-                <version>${felix.scr.compat.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.apache.felix</groupId>
                 <artifactId>org.apache.felix.resolver</artifactId>
                 <version>${felix.resolver.version}</version>
             </dependency>

http://git-wip-us.apache.org/repos/asf/karaf/blob/66a75fcd/scr/command/src/main/java/org/apache/karaf/scr/command/action/ListAction.java
----------------------------------------------------------------------
diff --git a/scr/command/src/main/java/org/apache/karaf/scr/command/action/ListAction.java b/scr/command/src/main/java/org/apache/karaf/scr/command/action/ListAction.java
index be90d11..2403248 100755
--- a/scr/command/src/main/java/org/apache/karaf/scr/command/action/ListAction.java
+++ b/scr/command/src/main/java/org/apache/karaf/scr/command/action/ListAction.java
@@ -17,7 +17,6 @@
 package org.apache.karaf.scr.command.action;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 
 import org.apache.karaf.scr.command.ScrCommandConstants;
@@ -50,7 +49,7 @@ public class ListAction extends ScrActionSupport {
         for (ComponentDescriptionDTO component : serviceComponentRuntime.getComponentDescriptionDTOs()) {
             configs.addAll(serviceComponentRuntime.getComponentConfigurationDTOs(component));
         }
-        Collections.sort(configs, idComparator);
+        configs.sort(idComparator);
         for (ComponentConfigurationDTO config : configs) {
             // Display only non hidden components, or all if showHidden is true
             if (showHidden || !ScrActionSupport.isHiddenComponent(config)) {

http://git-wip-us.apache.org/repos/asf/karaf/blob/66a75fcd/scr/management/pom.xml
----------------------------------------------------------------------
diff --git a/scr/management/pom.xml b/scr/management/pom.xml
index 6e900d2..159ae1b 100644
--- a/scr/management/pom.xml
+++ b/scr/management/pom.xml
@@ -54,11 +54,6 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.scr.compat</artifactId>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
             <groupId>biz.aQute.bnd</groupId>
             <artifactId>bndlib</artifactId>
             <scope>provided</scope>

http://git-wip-us.apache.org/repos/asf/karaf/blob/66a75fcd/scr/management/src/main/java/org/apache/karaf/scr/management/codec/JmxComponent.java
----------------------------------------------------------------------
diff --git a/scr/management/src/main/java/org/apache/karaf/scr/management/codec/JmxComponent.java b/scr/management/src/main/java/org/apache/karaf/scr/management/codec/JmxComponent.java
index 55a72ae..bec4673 100644
--- a/scr/management/src/main/java/org/apache/karaf/scr/management/codec/JmxComponent.java
+++ b/scr/management/src/main/java/org/apache/karaf/scr/management/codec/JmxComponent.java
@@ -16,8 +16,8 @@
  */
 package org.apache.karaf.scr.management.codec;
 
-import org.apache.felix.scr.Component;
 import org.apache.karaf.scr.management.ScrServiceMBean;
+import org.apache.karaf.scr.management.internal.ScrService;
 
 import javax.management.openmbean.CompositeData;
 import javax.management.openmbean.CompositeDataSupport;
@@ -28,6 +28,7 @@ import javax.management.openmbean.SimpleType;
 import javax.management.openmbean.TabularData;
 import javax.management.openmbean.TabularDataSupport;
 import javax.management.openmbean.TabularType;
+import java.util.Arrays;
 
 public class JmxComponent {
 
@@ -35,7 +36,7 @@ public class JmxComponent {
     /**
      * The CompositeType which represents a single component
      */
-    public final static CompositeType COMPONENT = createComponenetType();
+    public final static CompositeType COMPONENT = createComponentType();
 
     /**
      * The TabularType which represents a list of components
@@ -44,7 +45,7 @@ public class JmxComponent {
 
     private final CompositeData data;
     
-    public JmxComponent(Component component) {
+    public JmxComponent(ScrService.Component component) {
         try {
             String[] itemNames = ScrServiceMBean.COMPONENT;
             Object[] itemValues = new Object[itemNames.length];
@@ -63,15 +64,19 @@ public class JmxComponent {
         return data;
     }
 
-    public static TabularData tableFrom(Component... components) {
+    public static TabularData tableFrom(ScrService.Component... components) {
+        return tableFrom(Arrays.asList(components));
+    }
+
+    public static TabularData tableFrom(Iterable<ScrService.Component> components) {
         TabularDataSupport table = new TabularDataSupport(COMPONENT_TABLE);
-        for (Component component : components) {
+        for (ScrService.Component component : components) {
             table.put(new JmxComponent(component).asCompositeData());
         }
         return table;
     }
 
-    private static CompositeType createComponenetType() {
+    private static CompositeType createComponentType() {
         try {
             String description = "This type encapsulates Scr references";
             String[] itemNames = ScrServiceMBean.COMPONENT;
@@ -107,33 +112,33 @@ public class JmxComponent {
 
 
     /**
-     * Returns a literal for the {@link Component} state.
-     * @param component     The target {@link Component}.
+     * Returns a literal for the {@link ScrService.Component} state.
+     * @param component     The target {@link ScrService.Component}.
      * @return
      */
-    private static String getState(Component component) {
+    private static String getState(ScrService.Component component) {
         switch (component.getState()) {
-            case Component.STATE_ACTIVE:
+            case ScrService.Component.STATE_ACTIVE:
                 return "Active";
-            case Component.STATE_ACTIVATING:
+            case ScrService.Component.STATE_ACTIVATING:
                 return "Activating";
-            case Component.STATE_DEACTIVATING:
+            case ScrService.Component.STATE_DEACTIVATING:
                 return "Deactivating";
-            case Component.STATE_DISABLED:
+            case ScrService.Component.STATE_DISABLED:
                 return "Disabled";
-            case Component.STATE_DISABLING:
+            case ScrService.Component.STATE_DISABLING:
                 return "Disabling";
-            case Component.STATE_DISPOSED:
+            case ScrService.Component.STATE_DISPOSED:
                 return "Disposed";
-            case Component.STATE_DISPOSING:
+            case ScrService.Component.STATE_DISPOSING:
                 return "Disposing";
-            case Component.STATE_ENABLING:
+            case ScrService.Component.STATE_ENABLING:
                 return "Enabling";
-            case Component.STATE_FACTORY:
+            case ScrService.Component.STATE_FACTORY:
                 return "Factory";
-            case Component.STATE_REGISTERED:
+            case ScrService.Component.STATE_REGISTERED:
                 return "Registered";
-            case Component.STATE_UNSATISFIED:
+            case ScrService.Component.STATE_UNSATISFIED:
                 return "Unsatisfied";
         }
         return "Unknown";

http://git-wip-us.apache.org/repos/asf/karaf/blob/66a75fcd/scr/management/src/main/java/org/apache/karaf/scr/management/codec/JmxReference.java
----------------------------------------------------------------------
diff --git a/scr/management/src/main/java/org/apache/karaf/scr/management/codec/JmxReference.java b/scr/management/src/main/java/org/apache/karaf/scr/management/codec/JmxReference.java
index 8436ad9..deb4334 100644
--- a/scr/management/src/main/java/org/apache/karaf/scr/management/codec/JmxReference.java
+++ b/scr/management/src/main/java/org/apache/karaf/scr/management/codec/JmxReference.java
@@ -16,8 +16,8 @@
  */
 package org.apache.karaf.scr.management.codec;
 
-import org.apache.felix.scr.Reference;
 import org.apache.karaf.scr.management.ScrServiceMBean;
+import org.apache.karaf.scr.management.internal.ScrService;
 import org.osgi.framework.Constants;
 
 import javax.management.openmbean.ArrayType;
@@ -46,7 +46,7 @@ public class JmxReference {
     private final CompositeData data;
     //String[] COMPONENT = { REFERENCE_NAME, REFERENCE_STATE, REFERENCE_CARDINALITY, REFERENCE_AVAILABILITY, REFERENCE_POLICY, REFERENCE_BOUND_SERVICES};
 
-    public JmxReference(Reference reference) {
+    public JmxReference(ScrService.Reference reference) {
         try {
             String[] itemNames = ScrServiceMBean.REFERENCE;
             Object[] itemValues = new Object[itemNames.length];
@@ -66,10 +66,10 @@ public class JmxReference {
         return data;
     }
 
-    public static TabularData tableFrom(Reference... references) {
+    public static TabularData tableFrom(ScrService.Reference... references) {
         TabularDataSupport table = new TabularDataSupport(REFERENCE_TABLE);
         if (references != null) {
-            for (Reference reference : references) {
+            for (ScrService.Reference reference : references) {
                 table.put(new JmxReference(reference).asCompositeData());
             }
         }
@@ -114,11 +114,11 @@ public class JmxReference {
 
 
     /**
-     * Returns a literal for the {@link Reference} cardinality.
-     * @param reference     The target {@link Reference}.
+     * Returns a literal for the {@link ScrService.Reference} cardinality.
+     * @param reference     The target {@link ScrService.Reference}.
      * @return              "Multiple" or "Single".
      */
-    private static String getCardinality(Reference reference) {
+    private static String getCardinality(ScrService.Reference reference) {
         if (reference.isMultiple()) {
             return ScrServiceMBean.REFERENCE_CARDINALITY_MULTIPLE;
         } else {
@@ -127,11 +127,11 @@ public class JmxReference {
     }
 
     /**
-     * Returns a literal for the {@link Reference} availability.
-     * @param reference     The target {@link Reference}.
+     * Returns a literal for the {@link ScrService.Reference} availability.
+     * @param reference     The target {@link ScrService.Reference}.
      * @return              "Mandatory" or "Optional".
      */
-    private static String getAvailability(Reference reference) {
+    private static String getAvailability(ScrService.Reference reference) {
         if (reference.isOptional()) {
             return ScrServiceMBean.REFERENCE_AVAILABILITY_OPTIONAL;
         } else {
@@ -140,11 +140,11 @@ public class JmxReference {
     }
 
     /**
-     * Returns a literal for the {@link Reference} policy.
-     * @param reference     The target {@link Reference}.
+     * Returns a literal for the {@link ScrService.Reference} policy.
+     * @param reference     The target {@link ScrService.Reference}.
      * @return              "Static" or "Dynamic".
      */
-    private static String getPolicy(Reference reference) {
+    private static String getPolicy(ScrService.Reference reference) {
         if (reference.isStatic()) {
             return ScrServiceMBean.REFERENCE_POLICY_STATIC;
         } else {
@@ -154,10 +154,10 @@ public class JmxReference {
 
     /**
      * Returns The bound service ids.
-     * @param reference     The target {@link Reference}.
+     * @param reference     The target {@link ScrService.Reference}.
      * @return
      */
-    private static String[] getBoundServices(Reference reference) {
+    private static String[] getBoundServices(ScrService.Reference reference) {
         if (reference.getBoundServiceReferences() == null || reference.getBoundServiceReferences().length == 0) {
             return new String[0];
         } else {

http://git-wip-us.apache.org/repos/asf/karaf/blob/66a75fcd/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrService.java
----------------------------------------------------------------------
diff --git a/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrService.java b/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrService.java
new file mode 100644
index 0000000..0d8d5b5
--- /dev/null
+++ b/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrService.java
@@ -0,0 +1,507 @@
+/*
+ * 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.karaf.scr.management.internal;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.List;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.dto.ServiceReferenceDTO;
+import org.osgi.service.component.ComponentInstance;
+import org.osgi.service.component.runtime.ServiceComponentRuntime;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
+import org.osgi.service.component.runtime.dto.ComponentDescriptionDTO;
+import org.osgi.service.component.runtime.dto.ReferenceDTO;
+import org.osgi.service.component.runtime.dto.SatisfiedReferenceDTO;
+
+public class ScrService
+{
+
+    private final BundleContext context;
+    private final ServiceComponentRuntime runtime;
+
+
+    public ScrService(BundleContext context, final ServiceComponentRuntime runtime)
+    {
+        // we always use the system bundle to avoid problems if subsystems etc.
+        // are used and the SCR implemented extends those "invisible" bundles
+        this.context = context.getBundle(0).getBundleContext();
+        this.runtime = runtime;
+    }
+
+
+    // ScrService
+
+    public Component[] getComponents()
+    {
+        List<Component> result = new ArrayList<>();
+
+        final Collection<ComponentDescriptionDTO> descriptions = this.runtime.getComponentDescriptionDTOs();
+        for(final ComponentDescriptionDTO descDTO : descriptions )
+        {
+            final Collection<ComponentConfigurationDTO> configs = this.runtime.getComponentConfigurationDTOs(descDTO);
+            ComponentConfigurationDTO configDTO = null;
+            if ( !configs.isEmpty() )
+            {
+                configDTO = configs.iterator().next();
+            }
+            result.add(new Component(this.context, this.runtime, descDTO, configDTO));
+        }
+
+        return result.toArray( new Component[result.size()] );
+    }
+
+
+    public Component[] getComponents(final String componentName )
+    {
+        List<Component> result = new ArrayList<Component>();
+
+        final Collection<ComponentDescriptionDTO> descriptions = this.runtime.getComponentDescriptionDTOs();
+        for(final ComponentDescriptionDTO descDTO : descriptions )
+        {
+            if ( descDTO.name.equals(componentName) ) {
+                final Collection<ComponentConfigurationDTO> configs = this.runtime.getComponentConfigurationDTOs(descDTO);
+                ComponentConfigurationDTO configDTO = null;
+                if ( !configs.isEmpty() )
+                {
+                    configDTO = configs.iterator().next();
+                }
+                result.add(new Component(this.context, this.runtime, descDTO, configDTO));
+            }
+        }
+
+        return result.isEmpty() ? null : result.toArray( new Component[result.size()] );
+    }
+
+
+    public static final class Component
+    {
+        /**
+         * The Component has just been created and is still disabled or it has
+         * been disabled by calling the {@link #disable()} method (value is 1).
+         */
+        public static final int STATE_DISABLED = 1;
+
+        /**
+         * The Component is being enabled (value is 512). After the component has
+         * been enabled it enters the {@link #STATE_UNSATISFIED} state.
+         * @since 1.2
+         * @deprecated since 1.8.0
+         */
+        @Deprecated
+        public static final int STATE_ENABLING = 512;
+
+        /**
+         * The Component has been enabled and is now going to be activated (value
+         * is 2).
+         * @deprecated as of version 1.2 the enabled state is collapsed into the
+         *      {@link #STATE_UNSATISFIED} state. This status code is never returned
+         *      from the {@link #getState()} method.
+         */
+        @Deprecated
+        public static final int STATE_ENABLED = 2;
+
+        /**
+         * The Component activation failed because any dependency is not satisfied
+         * (value is 4).
+         */
+        public static final int STATE_UNSATISFIED = 4;
+
+        /**
+         * The Component is currently being activated either because it has been
+         * enabled or because any dependency which was previously unsatisfied has
+         * become satisfied (value is 8).
+         * @deprecated since 1.8.0 transient states are no longer used
+         */
+        @Deprecated
+        public static final int STATE_ACTIVATING = 8;
+
+        /**
+         * The Component has successfully been activated and is fully functional
+         * (value is 16). This is the state of immediate components after
+         * successful activation. Delayed and Service Factory Components enter
+         * this state when the service instance has actually been instantiated because
+         * the service has been acquired.
+         */
+        public static final int STATE_ACTIVE = 16;
+
+        /**
+         * The Component has successfully been activated but is a Delayed or Service
+         * Factory Component pending instantiation on first use (value is 32).
+         */
+        public static final int STATE_REGISTERED = 32;
+
+        /**
+         * The Component is a Component Factory ready to create Component instances
+         * with the <code>ComponentFactory.newInstance(Dictionary)</code> method
+         * or (if enabled with the <code>ds.factory.enabled</code> configuration) to
+         * manage Component instances from configuration data received from the
+         * Configuration Admin Service (value is 64).
+         */
+        public static final int STATE_FACTORY = 64;
+
+        /**
+         * The Component is being deactivated either because it is being disabled
+         * or because a dependency is not satisfied any more (value is 128). After
+         * deactivation the Component enters the {@link #STATE_UNSATISFIED} state.
+         * @deprecated since 1.8.0 transient states are no longer used
+         */
+        @Deprecated
+        public static final int STATE_DEACTIVATING = 128;
+
+        /**
+         * The Component is being disabled (value is 1024). After the component has
+         * been disabled it enters the {@link #STATE_DISABLED} state.
+         * @since 1.2
+         * @deprecated since 1.8.0 transient states are no longer used
+         */
+        @Deprecated
+        public static final int STATE_DISABLING = 1024;
+
+        /**
+         * The Component is being disposed off (value is 2048). After the component
+         * has been disposed off it enters the {@link #STATE_DESTROYED} state.
+         * @since 1.2
+         * @deprecated since 1.8.0 transient states are no longer used
+         */
+        @Deprecated
+        public static final int STATE_DISPOSING = 2048;
+
+        /**
+         * The Component has been destroyed and cannot be used any more (value is
+         * 256). This state is only used when the bundle declaring the component
+         * is being stopped and all components have to be removed.
+         * @deprecated as of version 1.2 this constant has been renamed to
+         *      {@link #STATE_DISPOSED}.
+         */
+        @Deprecated
+        public static final int STATE_DESTROYED = 256;
+
+        /**
+         * The Component has been disposed off and cannot be used any more (value is
+         * 256). This state is used when the bundle declaring the component
+         * is being stopped and all components have to be removed. This status is
+         * also the final status of a component after the
+         * <code>ComponentInstance.dispose()</code> method has been called.
+         * @since 1.2
+         */
+        public static final int STATE_DISPOSED = 256;
+
+        private final ComponentDescriptionDTO description;
+
+        private final ComponentConfigurationDTO configuration;
+
+        private final BundleContext bundleContext;
+
+        private final ServiceComponentRuntime runtime;
+
+        public Component(final BundleContext bundleContext,
+                         final ServiceComponentRuntime runtime,
+                         final ComponentDescriptionDTO description,
+                         final ComponentConfigurationDTO configuration)
+        {
+            this.bundleContext = bundleContext;
+            this.description = description;
+            this.configuration = configuration;
+            this.runtime = runtime;
+        }
+
+        public long getId()
+        {
+            return configuration != null ? configuration.id : -1;
+        }
+
+        public String getName()
+        {
+            return description.name;
+        }
+
+        public int getState()
+        {
+            if ( configuration == null )
+            {
+                return STATE_UNSATISFIED; // TODO Check!
+            }
+            final int s = configuration.state;
+            switch ( s )
+            {
+                case ComponentConfigurationDTO.ACTIVE : return STATE_ACTIVE;
+                case ComponentConfigurationDTO.SATISFIED : return STATE_ENABLED;
+                case ComponentConfigurationDTO.UNSATISFIED_CONFIGURATION : return STATE_UNSATISFIED;
+                case ComponentConfigurationDTO.UNSATISFIED_REFERENCE : return STATE_UNSATISFIED;
+                default: // satisfied
+                    return STATE_ENABLED;
+            }
+        }
+
+        public Bundle getBundle()
+        {
+            return this.bundleContext.getBundle(this.description.bundle.id);
+        }
+
+        public String getFactory()
+        {
+            return this.description.factory;
+        }
+
+        public boolean isServiceFactory()
+        {
+            return !"singleton".equals(this.description.scope);
+        }
+
+        public String getClassName()
+        {
+            return this.description.implementationClass;
+        }
+
+        public boolean isDefaultEnabled()
+        {
+            return this.description.defaultEnabled;
+        }
+
+        public boolean isImmediate()
+        {
+            return this.description.immediate;
+        }
+
+        public String[] getServices()
+        {
+            return this.description.serviceInterfaces.length == 0 ? null : this.description.serviceInterfaces;
+        }
+
+        public Dictionary getProperties()
+        {
+            return new Hashtable<>(this.description.properties);
+        }
+
+        public Reference[] getReferences()
+        {
+            if ( this.configuration == null )
+            {
+                return null;
+            }
+
+            final List<Reference> result = new ArrayList<Reference>();
+            for(final ReferenceDTO dto : this.description.references)
+            {
+                SatisfiedReferenceDTO sRef = null;
+                for(final SatisfiedReferenceDTO r : this.configuration.satisfiedReferences)
+                {
+                    if ( r.name.equals(dto.name) )
+                    {
+                        sRef = r;
+                        break;
+                    }
+                }
+                result.add(new Reference(this.bundleContext, dto, sRef));
+            }
+
+            if ( result.isEmpty() )
+            {
+                return null;
+            }
+
+            return result.toArray(new Reference[result.size()]);
+        }
+
+        public ComponentInstance getComponentInstance()
+        {
+            // returning null as we should have never returned this in the first place
+            return null;
+        }
+
+        public String getActivate()
+        {
+            return this.description.activate;
+        }
+
+        public boolean isActivateDeclared()
+        {
+            return this.description.activate != null;
+        }
+
+        public String getDeactivate()
+        {
+            return this.description.deactivate;
+        }
+
+        public boolean isDeactivateDeclared()
+        {
+            return this.description.deactivate != null;
+        }
+
+        public String getModified()
+        {
+            return this.description.modified;
+        }
+
+        public String getConfigurationPolicy()
+        {
+            return this.description.configurationPolicy;
+        }
+
+        public String getConfigurationPid()
+        {
+            final String[] pids = this.description.configurationPid;
+            return pids[0];
+        }
+
+        public boolean isConfigurationPidDeclared()
+        {
+            return true;
+        }
+
+        public void enable()
+        {
+            // noop as the old model was broken
+        }
+
+        public void disable()
+        {
+            // noop as the old model was broken
+        }
+    }
+
+    public static final class Reference
+    {
+        // constant for option single reference - 0..1
+        private static final String CARDINALITY_0_1 = "0..1";
+
+        // constant for option multiple reference - 0..n
+        private static final String CARDINALITY_0_N = "0..n";
+
+        // constant for required multiple reference - 1..n
+        private static final String CARDINALITY_1_N = "1..n";
+
+        // constant for static policy
+        private static final String POLICY_STATIC = "static";
+
+        // constant for reluctant policy option
+        private static final String POLICY_OPTION_RELUCTANT = "reluctant";
+
+        private final ReferenceDTO dto;
+
+        private final SatisfiedReferenceDTO satisfiedDTO;
+
+        private final BundleContext bundleContext;
+
+        public Reference(
+                final BundleContext bundleContext,
+                final ReferenceDTO dto,
+                final SatisfiedReferenceDTO satisfied)
+        {
+            this.bundleContext = bundleContext;
+            this.dto = dto;
+            this.satisfiedDTO = satisfied;
+        }
+
+        public String getName()
+        {
+            return dto.name;
+        }
+
+        public String getServiceName()
+        {
+            return dto.interfaceName;
+        }
+
+        public ServiceReference[] getServiceReferences()
+        {
+            if ( this.satisfiedDTO == null )
+            {
+                return null;
+            }
+            final List<ServiceReference<?>> refs = new ArrayList<ServiceReference<?>>();
+            for(ServiceReferenceDTO dto : this.satisfiedDTO.boundServices)
+            {
+                try
+                {
+                    final ServiceReference<?>[] serviceRefs = this.bundleContext.getServiceReferences((String)null,
+                            "(" + Constants.SERVICE_ID + "=" + String.valueOf(dto.id) + ")");
+                    if ( serviceRefs != null && serviceRefs.length > 0 )
+                    {
+                        refs.add(serviceRefs[0]);
+                    }
+                }
+                catch ( final InvalidSyntaxException ise)
+                {
+                    // ignore
+                }
+            }
+            return refs.toArray(new ServiceReference<?>[refs.size()]);
+        }
+
+        public ServiceReference<?>[] getBoundServiceReferences()
+        {
+            return this.getServiceReferences();
+        }
+
+        public boolean isSatisfied()
+        {
+            return this.satisfiedDTO != null;
+        }
+
+        public boolean isOptional()
+        {
+            return CARDINALITY_0_1.equals(dto.cardinality) || CARDINALITY_0_N.equals(dto.cardinality);
+        }
+
+        public boolean isMultiple()
+        {
+            return CARDINALITY_1_N.equals(dto.cardinality) || CARDINALITY_0_N.equals(dto.cardinality);
+        }
+
+        public boolean isStatic()
+        {
+            return POLICY_STATIC.equals(dto.policy);
+        }
+
+        public boolean isReluctant()
+        {
+            return POLICY_OPTION_RELUCTANT.equals(dto.policyOption);
+        }
+
+        public String getTarget()
+        {
+            return this.dto.target;
+        }
+
+        public String getBindMethodName()
+        {
+            return this.dto.bind;
+        }
+
+        public String getUnbindMethodName()
+        {
+            return this.dto.unbind;
+        }
+
+        public String getUpdatedMethodName()
+        {
+            return this.dto.unbind;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/karaf/blob/66a75fcd/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.java
----------------------------------------------------------------------
diff --git a/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.java b/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.java
index 480eecf..625e006 100644
--- a/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.java
+++ b/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.java
@@ -16,31 +16,33 @@
  */
 package org.apache.karaf.scr.management.internal;
 
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
-import javax.management.*;
-import javax.management.openmbean.TabularData;
-
-import aQute.bnd.annotation.component.Activate;
-import aQute.bnd.annotation.component.Deactivate;
-import aQute.bnd.annotation.component.Reference;
-
-import org.apache.felix.scr.Component;
-import org.apache.felix.scr.ScrService;
 import org.apache.karaf.scr.management.ScrServiceMBean;
-
 import org.apache.karaf.scr.management.codec.JmxComponent;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.runtime.ServiceComponentRuntime;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-@aQute.bnd.annotation.component.Component(
+import javax.management.MBeanException;
+import javax.management.MBeanServer;
+import javax.management.NotCompliantMBeanException;
+import javax.management.ObjectName;
+import javax.management.StandardMBean;
+import javax.management.openmbean.TabularData;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+@Component(
         name = ScrServiceMBeanImpl.COMPONENT_NAME,
         enabled = true,
         immediate = true,
-        properties = {"hidden.component=true"})
+        properties = {"org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.properties"})
 public class ScrServiceMBeanImpl extends StandardMBean implements ScrServiceMBean {
 
     public static final String OBJECT_NAME = "org.apache.karaf:type=scr,name=" + System.getProperty("karaf.name", "root");
@@ -110,7 +112,7 @@ public class ScrServiceMBeanImpl extends StandardMBean implements ScrServiceMBea
     @Override
     public TabularData getComponents() {
         try {
-            return JmxComponent.tableFrom(safe(scrService.getComponents()));
+            return JmxComponent.tableFrom(scrService.getComponents());
         } catch (Exception e) {
             e.printStackTrace(System.out);
             return null;
@@ -118,7 +120,7 @@ public class ScrServiceMBeanImpl extends StandardMBean implements ScrServiceMBea
     }
 
     public String[] listComponents() {
-        Component[] components = safe(scrService.getComponents());
+        ScrService.Component[] components = scrService.getComponents();
         String[] componentNames = new String[components.length];
         for (int i = 0; i < componentNames.length; i++) {
             componentNames[i] = components[i].getName();
@@ -128,7 +130,7 @@ public class ScrServiceMBeanImpl extends StandardMBean implements ScrServiceMBea
 
     public boolean isComponentActive(String componentName) throws MBeanException {
         try {
-            return componentState(componentName) == Component.STATE_ACTIVE;
+            return componentState(componentName) == ScrService.Component.STATE_ACTIVE;
         } catch (Exception e) {
             throw new MBeanException(null, e.toString());
         }
@@ -136,7 +138,7 @@ public class ScrServiceMBeanImpl extends StandardMBean implements ScrServiceMBea
 
     public int componentState(String componentName) {
         int state = -1;
-        final Component component = findComponent(componentName);
+        final ScrService.Component component = findComponent(componentName);
         if (component != null)
             state = component.getState();
         else
@@ -145,7 +147,7 @@ public class ScrServiceMBeanImpl extends StandardMBean implements ScrServiceMBea
     }
 
     public void activateComponent(String componentName) {
-        final Component component = findComponent(componentName);
+        final ScrService.Component component = findComponent(componentName);
         if (component != null)
             component.enable();
         else
@@ -153,28 +155,24 @@ public class ScrServiceMBeanImpl extends StandardMBean implements ScrServiceMBea
     }
 
     public void deactivateComponent(String componentName) {
-        final Component component = findComponent(componentName);
+        final ScrService.Component component = findComponent(componentName);
         if (component != null)
             component.disable();
         else
             LOGGER.warn("No component found for name: " + componentName);
     }
 
-    private Component findComponent(String componentName) {
-        Component answer = null;
+    private ScrService.Component findComponent(String componentName) {
+        ScrService.Component answer = null;
         if (scrService.getComponents(componentName) != null) {
-            Component[] components = scrService.getComponents(componentName);
-            for (Component component : safe(components)) {
+            ScrService.Component[] components = scrService.getComponents(componentName);
+            for (ScrService.Component component : components) {
                 answer = component;
             }
         }
         return answer;
     }
 
-    private Component[] safe(Component[] components) {
-        return components == null ? new Component[0] : components;
-    }
-
     @Reference
     public void setmBeanServer(MBeanServer mBeanServer) {
         this.mBeanServer = mBeanServer;
@@ -185,11 +183,11 @@ public class ScrServiceMBeanImpl extends StandardMBean implements ScrServiceMBea
     }
 
     @Reference
-    public void setScrService(ScrService scrService) {
-        this.scrService = scrService;
+    public void setScrService(ServiceComponentRuntime scrService) {
+        this.scrService = new ScrService(FrameworkUtil.getBundle(getClass()).getBundleContext(), scrService);
     }
 
-    public void unsetScrService(ScrService scrService) {
+    public void unsetScrService(ServiceComponentRuntime scrService) {
         this.scrService = null;
     }
 

http://git-wip-us.apache.org/repos/asf/karaf/blob/66a75fcd/scr/management/src/main/resources/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.properties
----------------------------------------------------------------------
diff --git a/scr/management/src/main/resources/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.properties b/scr/management/src/main/resources/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.properties
new file mode 100644
index 0000000..850a51d
--- /dev/null
+++ b/scr/management/src/main/resources/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.properties
@@ -0,0 +1 @@
+hidden.component = true
\ No newline at end of file


[3/3] karaf git commit: Provide a SecuredCommand#toString implementation to ease debugging

Posted by gn...@apache.org.
Provide a SecuredCommand#toString implementation to ease debugging


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/9248128b
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/9248128b
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/9248128b

Branch: refs/heads/master
Commit: 9248128b4131e8f352cac46b4acc5d6543379a70
Parents: 9d6e48e
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Tue Oct 3 10:54:18 2017 +0200
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Tue Oct 3 10:54:18 2017 +0200

----------------------------------------------------------------------
 .../karaf/shell/impl/console/osgi/secured/SecuredCommand.java   | 5 +++++
 1 file changed, 5 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/9248128b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/secured/SecuredCommand.java
----------------------------------------------------------------------
diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/secured/SecuredCommand.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/secured/SecuredCommand.java
index 00c1d99..e6e8ef7 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/secured/SecuredCommand.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/osgi/secured/SecuredCommand.java
@@ -106,6 +106,11 @@ public class SecuredCommand implements Command, Function {
             CommandSession commandSession = (CommandSession) session.get(".commandSession");
             return closure.execute(commandSession, arguments);
         }
+
+        @Override
+        public String toString() {
+            return closure.toString();
+        }
     }
 
 }


[2/3] karaf git commit: [KARAF-5401] Upgrade to Aries Blueprint Spring 0.5.0

Posted by gn...@apache.org.
[KARAF-5401] Upgrade to Aries Blueprint Spring 0.5.0


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/9d6e48e5
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/9d6e48e5
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/9d6e48e5

Branch: refs/heads/master
Commit: 9d6e48e5050e124e389e2e3fe0b2db6f5490840f
Parents: 66a75fc
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Tue Oct 3 10:53:52 2017 +0200
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Tue Oct 3 10:53:52 2017 +0200

----------------------------------------------------------------------
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/9d6e48e5/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 47a4fc6..a63877a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -218,7 +218,7 @@
         <aries.blueprint.core.compatibility.version>1.0.0</aries.blueprint.core.compatibility.version>
         <aries.blueprint.cm.version>1.1.0</aries.blueprint.cm.version>
         <aries.blueprint.web.version>1.0.1</aries.blueprint.web.version>
-        <aries.blueprint.spring.version>0.4.0</aries.blueprint.spring.version>
+        <aries.blueprint.spring.version>0.5.0</aries.blueprint.spring.version>
         <aries.blueprint.spring.extender.version>0.3.0</aries.blueprint.spring.extender.version>
         <aries.jmx.api.version>1.1.5</aries.jmx.api.version>
         <aries.jmx.core.version>1.1.7</aries.jmx.core.version>