@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
DeploymentUnit depUnit = phaseContext.getDeploymentUnit();
XBundle bundle = depUnit.getAttachment(OSGiConstants.BUNDLE_KEY);
if (bundle == null || bundle.isFragment())
return;
// Add a dependency on the Bundle RESOLVED service
BundleManager bundleManager = depUnit.getAttachment(OSGiConstants.BUNDLE_MANAGER_KEY);
ServiceName bundleResolve = bundleManager.getServiceName(bundle, Bundle.RESOLVED);
phaseContext.addDeploymentDependency(bundleResolve, AttachmentKey.create(Object.class));
// Add a dependency on the Module service
XBundleRevision brev = bundle.getBundleRevision();
ServiceName moduleService = ServiceModuleLoader.moduleServiceName(brev.getModuleIdentifier());
phaseContext.addDeploymentDependency(moduleService, Attachments.MODULE);
// Defer the module phase if the bundle is not resolved
if (bundle.isResolved() == false) {
depUnit.putAttachment(Attachments.DEFERRED_ACTIVATION_COUNT, new AtomicInteger());
DeploymentUtils.addDeferredModule(depUnit);
}
}