deployment.addAttachment(OSGiMetaData.class, metadata);
OSGiDeploymentAttachment.attachDeployment(deploymentUnit, deployment);
}
// Check for attached XModule
XModule resModule = XModuleAttachment.getXModuleAttachment(deploymentUnit);
if (deployment == null && resModule != null) {
String symbolicName = resModule.getName();
Version version = resModule.getVersion();
VirtualFile virtualFile = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
deployment = DeploymentFactory.createDeployment(AbstractVFS.adapt(virtualFile), contextName, symbolicName, version);
deployment.setAutoStart(true);
deployment.addAttachment(XModule.class, resModule);
OSGiDeploymentAttachment.attachDeployment(deploymentUnit, deployment);