From 1a15a7bccf0da871e78d1bf9d9f5648b9e3a2a75 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Fri, 22 Mar 2013 14:08:02 +0000 Subject: [PATCH] Introduce OsgiModuleLabel https://www.argeo.org/bugzilla/show_bug.cgi?id=153 git-svn-id: https://svn.argeo.org/commons/trunk@6196 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../argeo/security/core/OsgiModuleLabel.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/core/OsgiModuleLabel.java diff --git a/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/core/OsgiModuleLabel.java b/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/core/OsgiModuleLabel.java new file mode 100644 index 000000000..45c9e16b0 --- /dev/null +++ b/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/core/OsgiModuleLabel.java @@ -0,0 +1,41 @@ +package org.argeo.security.core; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; + +/** + * Logs the name and version of an OSGi bundle based on its + * {@link BundleContext}. + */ +public class OsgiModuleLabel { + private final static Log log = LogFactory.getLog(OsgiModuleLabel.class); + + private Bundle bundle; + + public OsgiModuleLabel() { + } + + /** Sets without logging. */ + public OsgiModuleLabel(Bundle bundle) { + this.bundle = bundle; + } + + /** + * Retrieved bundle from a bundle context and logs it. Typically to be set + * as a Spring bean. + */ + public void setBundleContext(BundleContext bundleContext) { + this.bundle = bundleContext.getBundle(); + log.info(msg()); + } + + public String msg() { + String name = bundle.getHeaders().get(Constants.BUNDLE_NAME).toString(); + String symbolicName = bundle.getSymbolicName(); + String version = bundle.getVersion().toString(); + return name + " v" + version + " (" + symbolicName + ")"; + } +} -- 2.30.2