felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1809313 - in /felix/trunk/webconsole-plugins/ds: ./ src/main/java/org/apache/felix/webconsole/plugins/ds/internal/
Date Fri, 22 Sep 2017 13:15:14 GMT
Author: cziegeler
Date: Fri Sep 22 13:15:14 2017
New Revision: 1809313

URL: http://svn.apache.org/viewvc?rev=1809313&view=rev
Log:
FELIX-5697 : DS WebConsole Plugin should neither require Configuration Admin nor Metatype

Added:
    felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/ConfigurationAdminSupport.java
  (with props)
    felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/ConfigurationSupport.java
  (with props)
    felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/MetatypeSupport.java
  (with props)
Modified:
    felix/trunk/webconsole-plugins/ds/changelog.txt
    felix/trunk/webconsole-plugins/ds/pom.xml
    felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/WebConsolePlugin.java

Modified: felix/trunk/webconsole-plugins/ds/changelog.txt
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/ds/changelog.txt?rev=1809313&r1=1809312&r2=1809313&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/ds/changelog.txt (original)
+++ felix/trunk/webconsole-plugins/ds/changelog.txt Fri Sep 22 13:15:14 2017
@@ -1,3 +1,10 @@
+Changes from 2.0.6 to 2.0.8
+---------------------------
+** Improvement
+    * [FELIX-5697] : DS WebConsole Plugin should neither require Configuration Admin nor
Metatype
+    * [FELIX-5538] : Replace own JSONWriter with version from utils
+
+
 Changes from 2.0.4 to 2.0.6
 ---------------------------
 ** Improvement

Modified: felix/trunk/webconsole-plugins/ds/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/ds/pom.xml?rev=1809313&r1=1809312&r2=1809313&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/ds/pom.xml (original)
+++ felix/trunk/webconsole-plugins/ds/pom.xml Fri Sep 22 13:15:14 2017
@@ -73,10 +73,14 @@
                             {maven-resources},OSGI-INF=target/classes/OSGI-INF
                         </Include-Resource>
                         <Import-Package>
-                             org.osgi.service.cm;version="[1.2,2)",
-                             org.osgi.service.metatype;version="[1.1,2)",
-                             *
+                            org.osgi.service.cm;version="[1.2,2)";resolution:=optional,
+                            org.osgi.service.metatype;version="[1.2,2)";resolution:=optional,
+                            *
                         </Import-Package>
+                        <DynamicImport-Package>
+                            org.osgi.service.cm;version="[1.2,2)",
+                            org.osgi.service.metatype;version="[1.2,2)"
+                        </DynamicImport-Package>
                         <Embed-Dependency>
                              org.apache.felix.utils;inline=org/apache/felix/utils/json/JSONWriter**
                         </Embed-Dependency>

Added: felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/ConfigurationAdminSupport.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/ConfigurationAdminSupport.java?rev=1809313&view=auto
==============================================================================
--- felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/ConfigurationAdminSupport.java
(added)
+++ felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/ConfigurationAdminSupport.java
Fri Sep 22 13:15:14 2017
@@ -0,0 +1,56 @@
+/*
+ * 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.felix.webconsole.plugins.ds.internal;
+
+import java.io.IOException;
+
+import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+public class ConfigurationAdminSupport
+{
+
+    public boolean check(final Object obj, final String pid)
+    {
+        final ConfigurationAdmin ca = (ConfigurationAdmin)obj;
+        try
+        {
+            // we use listConfigurations to not create configuration
+            // objects persistently without the user providing actual
+            // configuration
+            String filter = '(' + Constants.SERVICE_PID + '=' + pid + ')';
+            Configuration[] configs = ca.listConfigurations(filter);
+            if (configs != null && configs.length > 0)
+            {
+                return true;
+            }
+        }
+        catch (InvalidSyntaxException ise)
+        {
+            // should print message
+        }
+        catch (IOException ioe)
+        {
+            // should print message
+        }
+        return false;
+    }
+}

Propchange: felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/ConfigurationAdminSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/ConfigurationAdminSupport.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Added: felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/ConfigurationSupport.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/ConfigurationSupport.java?rev=1809313&view=auto
==============================================================================
--- felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/ConfigurationSupport.java
(added)
+++ felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/ConfigurationSupport.java
Fri Sep 22 13:15:14 2017
@@ -0,0 +1,76 @@
+/*
+ * 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.felix.webconsole.plugins.ds.internal;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class ConfigurationSupport {
+
+    private final ServiceTracker<Object, Object> configAdminTracker;
+
+    private final ServiceTracker<Object, Object> metatypeTracker;
+
+    public ConfigurationSupport(final BundleContext bundleContext)
+    {
+        this.configAdminTracker = new ServiceTracker<Object, Object>(bundleContext,
"org.osgi.service.cm.ConfigurationAdmin", null);
+        this.metatypeTracker = new ServiceTracker<Object, Object>(bundleContext, "org.osgi.service.metatype.MetaTypeService",
null);
+
+        configAdminTracker.open();
+        this.metatypeTracker.open();
+    }
+
+    public void close()
+    {
+        this.configAdminTracker.close();
+        this.metatypeTracker.close();
+    }
+
+    /**
+     * Check if the component with the specified pid is
+     * configurable
+     * @param providingBundle The Bundle providing the component. This may be
+     *      theoretically be <code>null</code>.
+     * @param pid A non null pid
+     * @return <code>true</code> if the component is configurable.
+     */
+    public boolean isConfigurable(final Bundle providingBundle, final String pid)
+    {
+        // we first check if the config admin has something for this pid
+        final Object ca = this.configAdminTracker.getService();
+        if (ca != null)
+        {
+            if ( new ConfigurationAdminSupport().check(ca, pid) )
+            {
+                return true;
+            }
+        }
+        // second check is using the meta type service
+        if (providingBundle != null)
+        {
+            final Object mts = this.metatypeTracker.getService();
+            if (mts != null)
+            {
+                return new MetatypeSupport().check(mts, providingBundle, pid);
+            }
+        }
+        return false;
+    }
+}
\ No newline at end of file

Propchange: felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/ConfigurationSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/ConfigurationSupport.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Added: felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/MetatypeSupport.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/MetatypeSupport.java?rev=1809313&view=auto
==============================================================================
--- felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/MetatypeSupport.java
(added)
+++ felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/MetatypeSupport.java
Fri Sep 22 13:15:14 2017
@@ -0,0 +1,42 @@
+/*
+ * 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.felix.webconsole.plugins.ds.internal;
+
+import org.osgi.framework.Bundle;
+import org.osgi.service.metatype.MetaTypeInformation;
+import org.osgi.service.metatype.MetaTypeService;
+
+public class MetatypeSupport
+{
+
+    public boolean check(final Object obj, final Bundle providingBundle, final String pid)
+    {
+        final MetaTypeService mts = (MetaTypeService)obj;
+        final MetaTypeInformation mti = mts.getMetaTypeInformation(providingBundle);
+        if (mti != null)
+        {
+            try {
+                return mti.getObjectClassDefinition(pid, null) != null;
+            } catch (final IllegalArgumentException e) {
+                return false;
+            }
+        }
+        return false;
+    }
+}
\ No newline at end of file

Propchange: felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/MetatypeSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/MetatypeSupport.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Modified: felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/WebConsolePlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/WebConsolePlugin.java?rev=1809313&r1=1809312&r2=1809313&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/WebConsolePlugin.java
(original)
+++ felix/trunk/webconsole-plugins/ds/src/main/java/org/apache/felix/webconsole/plugins/ds/internal/WebConsolePlugin.java
Fri Sep 22 13:15:14 2017
@@ -37,18 +37,14 @@ import org.apache.felix.webconsole.Defau
 import org.apache.felix.webconsole.SimpleWebConsolePlugin;
 import org.apache.felix.webconsole.WebConsoleUtil;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
 import org.osgi.service.component.ComponentConstants;
 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;
-import org.osgi.service.metatype.MetaTypeInformation;
-import org.osgi.service.metatype.MetaTypeService;
 import org.osgi.util.promise.Promise;
 
 /**
@@ -73,12 +69,12 @@ class WebConsolePlugin extends SimpleWeb
 
     // needed services
     static final String SCR_SERVICE = ServiceComponentRuntime.class.getName(); //$NON-NLS-1$
-    private static final String META_TYPE_NAME = "org.osgi.service.metatype.MetaTypeService";
//$NON-NLS-1$
-    private static final String CONFIGURATION_ADMIN_NAME = "org.osgi.service.cm.ConfigurationAdmin";
//$NON-NLS-1$
 
     // templates
     private final String TEMPLATE;
 
+    private volatile ConfigurationSupport optionalSupport;
+
     /** Default constructor */
     WebConsolePlugin()
     {
@@ -88,6 +84,26 @@ class WebConsolePlugin extends SimpleWeb
         TEMPLATE = readTemplateFile("/res/plugin.html"); //$NON-NLS-1$
     }
 
+
+    @Override
+    public void deactivate() {
+        if ( this.optionalSupport != null )
+        {
+            this.optionalSupport.close();
+            this.optionalSupport = null;
+        }
+        super.deactivate();
+    }
+
+
+    @Override
+    public void activate(final BundleContext bundleContext)
+    {
+        super.activate(bundleContext);
+        this.optionalSupport = new ConfigurationSupport(bundleContext);
+    }
+
+
     @Override
     public String getCategory()
     {
@@ -187,6 +203,7 @@ class WebConsolePlugin extends SimpleWeb
     /**
      * @see org.apache.felix.webconsole.AbstractWebConsolePlugin#renderContent(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
      */
+    @SuppressWarnings("unchecked")
     @Override
     protected void renderContent(HttpServletRequest request, HttpServletResponse response)
             throws IOException
@@ -266,7 +283,7 @@ class WebConsolePlugin extends SimpleWeb
         }
         jw.key("pid"); //$NON-NLS-1$
         jw.value(pid);
-        if (isConfigurable(
+        if (this.optionalSupport.isConfigurable(
                 this.getBundleContext().getBundle(0).getBundleContext().getBundle(desc.bundle.id),
                 configurationPid))
         {
@@ -499,76 +516,13 @@ class WebConsolePlugin extends SimpleWeb
         }
     }
 
-    /**
-     * Check if the component with the specified pid is
-     * configurable
-     * @param providingBundle The Bundle providing the component. This may be
-     *      theoretically be <code>null</code>.
-     * @param pid A non null pid
-     * @return <code>true</code> if the component is configurable.
-     */
-    private boolean isConfigurable(final Bundle providingBundle, final String pid)
-    {
-        // we first check if the config admin has something for this pid
-        final ConfigurationAdmin ca = this.getConfigurationAdmin();
-        if (ca != null)
-        {
-            try
-            {
-                // we use listConfigurations to not create configuration
-                // objects persistently without the user providing actual
-                // configuration
-                String filter = '(' + Constants.SERVICE_PID + '=' + pid + ')';
-                Configuration[] configs = ca.listConfigurations(filter);
-                if (configs != null && configs.length > 0)
-                {
-                    return true;
-                }
-            }
-            catch (InvalidSyntaxException ise)
-            {
-                // should print message
-            }
-            catch (IOException ioe)
-            {
-                // should print message
-            }
-        }
-        // second check is using the meta type service
-        if (providingBundle != null)
-        {
-            final MetaTypeService mts = this.getMetaTypeService();
-            if (mts != null)
-            {
-                final MetaTypeInformation mti = mts.getMetaTypeInformation(providingBundle);
-                if (mti != null)
-                {
-                    try {
-                        return mti.getObjectClassDefinition(pid, null) != null;
-                    } catch (IllegalArgumentException e) {
-                        return false;
-                    }
-                }
-            }
-        }
-        return false;
-    }
 
-    private final ConfigurationAdmin getConfigurationAdmin()
-    {
-        return (ConfigurationAdmin) getService(CONFIGURATION_ADMIN_NAME);
-    }
 
     final ServiceComponentRuntime getScrService()
     {
         return (ServiceComponentRuntime) getService(SCR_SERVICE);
     }
 
-    private final MetaTypeService getMetaTypeService()
-    {
-        return (MetaTypeService) getService(META_TYPE_NAME);
-    }
-
     private final class RequestInfo
     {
         public final String extension;



Mime
View raw message