@Override
public void processDeployment(DeploymentUnitContext context) throws DeploymentUnitProcessingException {
// Check if we already have an OSGi deployment
Deployment deployment = DeploymentAttachment.getDeploymentAttachment(context);
if (deployment != null)
return;
// Get the OSGi XService properties
String resName = "META-INF/jbosgi-xservice.properties";
VirtualFile virtualFile = VirtualFileAttachment.getVirtualFileAttachment(context);
VirtualFile xserviceFile = virtualFile.getChild(resName);
if (xserviceFile.exists()) {
try {
OSGiMetaData metadata = OSGiMetaDataBuilder.load(xserviceFile.openStream());
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);
OSGiMetaDataAttachment.attachOSGiMetaData(context, metadata);
DeploymentAttachment.attachDeployment(context, deployment);
} catch (IOException ex) {
throw new DeploymentUnitProcessingException("Cannot parse: " + xserviceFile);
}