X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.ui.workbench%2Fsrc%2Forg%2Fargeo%2Fcms%2Fspring%2Fosgi%2FOsgiModuleLabel.java;fp=org.argeo.cms.ui.workbench%2Fsrc%2Forg%2Fargeo%2Fcms%2Fspring%2Fosgi%2FOsgiModuleLabel.java;h=f085d6a23feacf0dba5bffa9e6b1629ef41af58a;hb=810aecacb19916bade7e4bcfcbbb54c301f672df;hp=0000000000000000000000000000000000000000;hpb=ca59ec5bdf16364159d8d826306c90762192e12c;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms.ui.workbench/src/org/argeo/cms/spring/osgi/OsgiModuleLabel.java b/org.argeo.cms.ui.workbench/src/org/argeo/cms/spring/osgi/OsgiModuleLabel.java new file mode 100644 index 000000000..f085d6a23 --- /dev/null +++ b/org.argeo.cms.ui.workbench/src/org/argeo/cms/spring/osgi/OsgiModuleLabel.java @@ -0,0 +1,41 @@ +package org.argeo.cms.spring.osgi; + +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 + ")"; + } +}