@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
DeploymentUnit depUnit = phaseContext.getDeploymentUnit();
ContextActivator activator = depUnit.getAttachment(ContextActivator.ATTACHMENT_KEY);
XBundle bundle = depUnit.getAttachment(OSGiConstants.BUNDLE_KEY);
if (activator != null && bundle != null) {
// Add the {@link ContextActivator} to the {@link XBundleRevision}
XBundleRevision brev = bundle.getBundleRevision();
brev.addAttachment(ContextActivator.class, activator);
// Start the context when the bundle will get started automatically
Deployment deployment = bundle.adapt(Deployment.class);
if (deployment.isAutoStart()) {
activator.startAsync();
}
}
}