1 package org
.argeo
.slc
.osgi
;
3 import org
.argeo
.slc
.DefaultNameVersion
;
4 import org
.argeo
.slc
.NameVersion
;
5 import org
.argeo
.slc
.build
.Distribution
;
6 import org
.argeo
.slc
.core
.build
.ResourceDistribution
;
7 import org
.argeo
.slc
.deploy
.DeploymentData
;
8 import org
.argeo
.slc
.deploy
.Module
;
9 import org
.argeo
.slc
.deploy
.ModuleDescriptor
;
10 import org
.argeo
.slc
.deploy
.TargetData
;
11 import org
.argeo
.slc
.execution
.RealizedFlow
;
12 import org
.osgi
.framework
.Bundle
;
13 import org
.osgi
.framework
.Constants
;
14 import org
.springframework
.core
.io
.Resource
;
16 /** A deployed OSGi bundle. */
17 public class OsgiBundle
extends DefaultNameVersion
implements Module
{
18 private ResourceDistribution distribution
;
20 private Long internalBundleId
;
23 private String description
;
29 public OsgiBundle(String name
, String version
) {
33 public OsgiBundle(NameVersion nameVersion
) {
37 public OsgiBundle(Bundle bundle
) {
38 super(bundle
.getSymbolicName(), getVersionSafe(bundle
));
39 internalBundleId
= bundle
.getBundleId();
43 * Initialize from a {@link RealizedFlow}.
45 * @deprecated introduce an unnecessary dependency. TODO: create a separate
48 public OsgiBundle(RealizedFlow realizedFlow
) {
49 super(realizedFlow
.getModuleName(), realizedFlow
.getModuleVersion());
52 /** Utility to avoid NPE. */
53 private static String
getVersionSafe(Bundle bundle
) {
54 Object versionObj
= bundle
.getHeaders().get(Constants
.BUNDLE_VERSION
);
55 if (versionObj
!= null)
56 return versionObj
.toString();
61 /** Unique deployed system id. TODO: use internal bundle id when available? */
62 public String
getDeployedSystemId() {
63 return getName() + ":" + getVersion();
67 * OSGi bundle are self-contained and do not require additional deployment
72 public DeploymentData
getDeploymentData() {
76 /** The related distribution. */
77 public Distribution
getDistribution() {
82 * The related distribution, a jar file with OSGi metadata referenced by a
85 public ResourceDistribution
getResourceDistribution() {
89 /** TODO: reference the {@link OsgiRuntime} as target data? */
90 public TargetData
getTargetData() {
91 throw new UnsupportedOperationException();
94 public void setResourceDistribution(ResourceDistribution distribution
) {
95 this.distribution
= distribution
;
99 * Bundle ID used by the OSGi runtime. To be used for optimization when
100 * looking in the bundle context. Can therefore be null.
102 public Long
getInternalBundleId() {
103 return internalBundleId
;
106 /** Only package access for the time being. e.g. from {@link BundlesManager} */
107 void setInternalBundleId(Long internalBundleId
) {
108 this.internalBundleId
= internalBundleId
;
111 /** Value of the <code>Bundle-Name</code> directive. */
112 public String
getTitle() {
116 public void setTitle(String label
) {
120 /** Value of the <code>Bundle-Description</code> directive. */
121 public String
getDescription() {
125 public void setDescription(String description
) {
126 this.description
= description
;
129 public ModuleDescriptor
getModuleDescriptor() {
130 ModuleDescriptor moduleDescriptor
= new ModuleDescriptor();
131 moduleDescriptor
.setName(getName());
132 moduleDescriptor
.setVersion(getVersion());
133 moduleDescriptor
.setDescription(description
);
134 moduleDescriptor
.setTitle(title
);
135 return moduleDescriptor
;