You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by GitBox <gi...@apache.org> on 2021/10/17 11:08:48 UTC

[GitHub] [felix-dev] amitjoy commented on a change in pull request #104: FELIX-6319 add configuration printer for framework properties

amitjoy commented on a change in pull request #104:
URL: https://github.com/apache/felix-dev/pull/104#discussion_r730396805



##########
File path: webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/FrameworkPropertiesPrinter.java
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.internal.misc;
+
+
+import java.io.PrintWriter;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.apache.felix.webconsole.internal.AbstractConfigurationPrinter;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.framework.namespace.NativeNamespace;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleWiring;
+
+
+public class FrameworkPropertiesPrinter extends AbstractConfigurationPrinter
+{
+
+    private static final String TITLE = "Framework Properties";
+
+    public String getTitle()
+    {
+        return TITLE;
+    }
+
+    public void printConfiguration( PrintWriter printWriter )
+    {
+        getFrameworkProperties().entrySet().stream().forEach( e -> ConfigurationRender.infoLine( printWriter, null, e.getKey(), e.getValue() ));
+    }
+
+    private Map<String,String> getFrameworkProperties() 
+    {
+        Bundle systemBundle = getBundleContext().getBundle( Constants.SYSTEM_BUNDLE_LOCATION );
+        BundleWiring bundleWiring = systemBundle.adapt(BundleWiring.class);
+        // https://docs.osgi.org/specification/osgi.core/7.0.0/framework.namespaces.html#framework.namespaces.osgi.native
+        Map<String, String> frameworkProperties = new TreeMap<>();
+        for ( BundleCapability capability : bundleWiring.getCapabilities( NativeNamespace.NATIVE_NAMESPACE ) ) 

Review comment:
       You can adapt the system bundle to `FrameworkDTO` and then retrieve the configured framework properties. That would be much easier this way.

##########
File path: webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/FrameworkPropertiesPrinter.java
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.internal.misc;
+
+
+import java.io.PrintWriter;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.apache.felix.webconsole.internal.AbstractConfigurationPrinter;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.framework.namespace.NativeNamespace;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleWiring;
+
+
+public class FrameworkPropertiesPrinter extends AbstractConfigurationPrinter
+{
+
+    private static final String TITLE = "Framework Properties";
+
+    public String getTitle()
+    {
+        return TITLE;
+    }
+
+    public void printConfiguration( PrintWriter printWriter )
+    {
+        getFrameworkProperties().entrySet().stream().forEach( e -> ConfigurationRender.infoLine( printWriter, null, e.getKey(), e.getValue() ));
+    }
+
+    private Map<String,String> getFrameworkProperties() 
+    {
+        Bundle systemBundle = getBundleContext().getBundle( Constants.SYSTEM_BUNDLE_LOCATION );

Review comment:
       You can also use `getBundle(Constants.SYSTEM_BUNDLE_ID)`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@felix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org