final DeploymentUnit depUnit = phaseContext.getDeploymentUnit();
final Deployment deployment = depUnit.getAttachment(OSGiConstants.DEPLOYMENT_KEY);
if (deployment != null) {
ServiceName serviceName;
try {
final BundleManager bundleManager = depUnit.getAttachment(OSGiConstants.BUNDLE_MANAGER_KEY);
if (!deploymentTracker.isClosed() && deploymentTracker.hasDeploymentName(depUnit.getName())) {
restoreStorageState(phaseContext, deployment);
serviceName = bundleManager.installBundle(deployment, deploymentTracker.getBundleInstallListener());
deploymentTracker.registerBundleInstallService(serviceName);
} else {
serviceName = bundleManager.installBundle(deployment, null);
}
} catch (BundleException ex) {
throw new DeploymentUnitProcessingException(ex);
}
phaseContext.addDeploymentDependency(serviceName, OSGiConstants.INSTALLED_BUNDLE_KEY);