final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final String contextName = deploymentUnit.getName();
// Check if we already have an OSGi deployment
Deployment deployment = OSGiDeploymentAttachment.getDeployment(deploymentUnit);
// Check if {@link InstallHandlerIntegration} provided the {@link Deployment}
if (deployment == null) {
ServiceRegistry serviceRegistry = phaseContext.getServiceRegistry();
ServiceController<Deployment> controller = DeploymentHolderService.getDeployment(serviceRegistry, contextName);
if (controller != null) {
deployment = controller.getValue();
controller.setMode(Mode.REMOVE);
}
}
// Check for attached BundleInfo
BundleInfo info = BundleInfoAttachment.getBundleInfo(deploymentUnit);
if (deployment == null && info != null) {
deployment = DeploymentFactory.createDeployment(info);
deployment.addAttachment(BundleInfo.class, info);
deployment.setAutoStart(true);
OSGiDeploymentAttachment.attachDeployment(deploymentUnit, deployment);
}
// Check for attached OSGiMetaData
OSGiMetaData metadata = OSGiMetaDataAttachment.getOSGiMetaData(deploymentUnit);
if (deployment == null && metadata != null) {
String symbolicName = metadata.getBundleSymbolicName();
Version version = metadata.getBundleVersion();
VirtualFile virtualFile = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
deployment = DeploymentFactory.createDeployment(AbstractVFS.adapt(virtualFile), contextName, symbolicName, version);
deployment.setAutoStart(true);
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);
}
// Create the {@link BundleInstallService}
if (deployment != null) {