@Override
public void processDeployment(DeploymentUnitContext context) throws DeploymentUnitProcessingException {
// Check if we already have an OSGi deployment
Deployment deployment = DeploymentAttachment.getDeploymentAttachment(context);
// Check for attached BundleInfo
BundleInfo info = BundleInfoAttachment.getBundleInfoAttachment(context);
if (deployment == null && info != null) {
deployment = DeploymentFactory.createDeployment(info);
deployment.addAttachment(BundleInfo.class, info);
DeploymentAttachment.attachDeployment(context, deployment);
}
// Check for attached OSGiMetaData
OSGiMetaData metadata = OSGiMetaDataAttachment.getOSGiMetaDataAttachment(context);
if (deployment == null && metadata != null) {
VirtualFile virtualFile = VirtualFileAttachment.getVirtualFileAttachment(context);
String location = virtualFile.getPathName();
String symbolicName = metadata.getBundleSymbolicName();
Version version = metadata.getBundleVersion();
deployment = DeploymentFactory.createDeployment(AbstractVFS.adapt(virtualFile), location, symbolicName, version);
deployment.addAttachment(OSGiMetaData.class, metadata);
DeploymentAttachment.attachDeployment(context, deployment);
}
// Check for attached XModule
XModule resModule = XModuleAttachment.getXModuleAttachment(context);
if (deployment == null && resModule != null) {
VirtualFile virtualFile = VirtualFileAttachment.getVirtualFileAttachment(context);
String location = virtualFile.getPathName();
String symbolicName = resModule.getName();
Version version = resModule.getVersion();
deployment = DeploymentFactory.createDeployment(AbstractVFS.adapt(virtualFile), location, symbolicName, version);
deployment.addAttachment(XModule.class, resModule);
DeploymentAttachment.attachDeployment(context, deployment);
}
// Create the {@link OSGiDeploymentService}
if (deployment != null) {
// Prevent garbage collection of the MountHandle which will close the file
MountHandle mount = context.getAttachment(MountHandle.ATTACHMENT_KEY);
deployment.addAttachment(MountHandle.class, mount);
OSGiDeploymentService.addService(context);
}
}