X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=runtime%2Forg.argeo.slc.support.osgi%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fosgi%2FOsgiBundle.java;h=420c7ad3d83cd071cc740c9e09cbd0be008498b9;hb=74904a755b5b344238eafa798419b80c5e74f7ed;hp=45cee40e2e98eab4f996c6c6a0dda1638e930ae2;hpb=ee6c3543a0ff9403420ce6a9c647723269f14331;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiBundle.java b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiBundle.java index 45cee40e2..420c7ad3d 100644 --- a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiBundle.java +++ b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiBundle.java @@ -1,75 +1,120 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed 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.argeo.slc.osgi; +import org.argeo.slc.BasicNameVersion; +import org.argeo.slc.NameVersion; import org.argeo.slc.build.Distribution; -import org.argeo.slc.core.deploy.ResourceDistribution; +import org.argeo.slc.core.build.ResourceDistribution; import org.argeo.slc.deploy.DeploymentData; import org.argeo.slc.deploy.Module; +import org.argeo.slc.deploy.ModuleDescriptor; import org.argeo.slc.deploy.TargetData; import org.argeo.slc.process.RealizedFlow; import org.osgi.framework.Bundle; import org.osgi.framework.Constants; +import org.springframework.core.io.Resource; -public class OsgiBundle implements Module { - private String name; - private String version; - private Distribution distribution; +/** A deployed OSGi bundle. */ +public class OsgiBundle extends BasicNameVersion implements Module { + private static final long serialVersionUID = 35073826504550477L; + + private ResourceDistribution distribution; private Long internalBundleId; + private String title; + private String description; + public OsgiBundle() { } + public OsgiBundle(String name, String version) { + super(name, version); + } + + public OsgiBundle(NameVersion nameVersion) { + super(nameVersion); + } + public OsgiBundle(Bundle bundle) { - name = bundle.getSymbolicName(); - version = bundle.getHeaders().get(Constants.BUNDLE_VERSION).toString(); + super(bundle.getSymbolicName(), getVersionSafe(bundle)); internalBundleId = bundle.getBundleId(); } + /** + * Initialize from a {@link RealizedFlow}. + * + * @deprecated introduce an unnecessary dependency. TODO: create a separate + * helper. + */ public OsgiBundle(RealizedFlow realizedFlow) { - name = realizedFlow.getModuleName(); - version = realizedFlow.getModuleVersion(); + super(realizedFlow.getModuleName(), realizedFlow.getModuleVersion()); + } + + /** Utility to avoid NPE. */ + private static String getVersionSafe(Bundle bundle) { + Object versionObj = bundle.getHeaders().get(Constants.BUNDLE_VERSION); + if (versionObj != null) + return versionObj.toString(); + else + return null; } + /** Unique deployed system id. TODO: use internal bundle id when available? */ public String getDeployedSystemId() { - return name + ":" + version; + return getName() + ":" + getVersion(); } + /** + * OSGi bundle are self-contained and do not require additional deployment + * data. + * + * @return always null + */ public DeploymentData getDeploymentData() { - throw new UnsupportedOperationException(); + return null; } + /** The related distribution. */ public Distribution getDistribution() { return distribution; } - public TargetData getTargetData() { - throw new UnsupportedOperationException(); - } - - public String getName() { - return name; - } - - public String getVersion() { - return version; - } - - public void setName(String name) { - this.name = name; + /** + * The related distribution, a jar file with OSGi metadata referenced by a + * {@link Resource}. + */ + public ResourceDistribution getResourceDistribution() { + return distribution; } - public void setVersion(String version) { - this.version = version; + /** TODO: reference the {@link OsgiRuntime} as target data? */ + public TargetData getTargetData() { + throw new UnsupportedOperationException(); } - public void setDistribution(Distribution distribution) { + public void setResourceDistribution(ResourceDistribution distribution) { this.distribution = distribution; } /** - * To be used for optimization when looking in the bundle context. Can - * therefore be null. + * Bundle ID used by the OSGi runtime. To be used for optimization when + * looking in the bundle context. Can therefore be null. */ public Long getInternalBundleId() { return internalBundleId; @@ -80,4 +125,30 @@ public class OsgiBundle implements Module { this.internalBundleId = internalBundleId; } + /** Value of the Bundle-Name directive. */ + public String getTitle() { + return title; + } + + public void setTitle(String label) { + this.title = label; + } + + /** Value of the Bundle-Description directive. */ + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public ModuleDescriptor getModuleDescriptor() { + ModuleDescriptor moduleDescriptor = new ModuleDescriptor(); + moduleDescriptor.setName(getName()); + moduleDescriptor.setVersion(getVersion()); + moduleDescriptor.setDescription(description); + moduleDescriptor.setTitle(title); + return moduleDescriptor; + } }