static ServiceController<XBundle> addService(ServiceTarget serviceTarget, DeploymentUnit depUnit, XBundle bundle) { ServiceName serviceName = depUnit.getServiceName().append("Activate"); BundleActivateService service = new BundleActivateService(depUnit, bundle); ServiceBuilder<XBundle> builder = serviceTarget.addService(serviceName, service); // Add a dependency on the BundleActivator component OSGiMetaData metadata = depUnit.getAttachment(OSGiConstants.OSGI_METADATA_KEY); if (metadata != null && metadata.getBundleActivator() != null) { String activatorClass = metadata.getBundleActivator(); EEModuleDescription moduleDescription = depUnit.getAttachment(EE_MODULE_DESCRIPTION); if (moduleDescription != null) { for (ComponentDescription componentDescription : moduleDescription.getComponentDescriptions()) { if (activatorClass.equals(componentDescription.getComponentClassName())) { ServiceName startServiceName = componentDescription.getStartServiceName(); builder.addDependency(startServiceName, Component.class, service.injectedComponent); } } } } // Add other named dependencies builder.addDependencies(depUnit.getAttachmentList(Attachments.BUNDLE_ACTIVE_DEPENDENCIES)); return builder.install(); }
static ServiceController<XBundle> addService(ServiceTarget serviceTarget, DeploymentUnit depUnit, XBundle bundle) { BundleManager bundleManager = depUnit.getAttachment(OSGiConstants.BUNDLE_MANAGER_KEY); ServiceName resolvedBundle = bundleManager.getServiceName(bundle, Bundle.RESOLVED); ServiceName serviceName = depUnit.getServiceName().append("Activate"); BundleActivateService service = new BundleActivateService(depUnit); ServiceBuilder<XBundle> builder = serviceTarget.addService(serviceName, service); builder.addDependency(resolvedBundle, XBundle.class, service.injectedBundle); // Add a dependency on the BundleActivator component OSGiMetaData metadata = depUnit.getAttachment(OSGiConstants.OSGI_METADATA_KEY); if (metadata != null && metadata.getBundleActivator() != null) { String activatorClass = metadata.getBundleActivator(); EEModuleDescription moduleDescription = depUnit.getAttachment(EE_MODULE_DESCRIPTION); for (ComponentDescription componentDescription : moduleDescription.getComponentDescriptions()) { if (activatorClass.equals(componentDescription.getComponentClassName())) { ServiceName startServiceName = componentDescription.getStartServiceName(); builder.addDependency(startServiceName, Component.class, service.injectedComponent); } } } return builder.install(); }
@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; ServiceController<XBundle> controller = BundleActivateService.addService(phaseContext.getServiceTarget(), depUnit, bundle); phaseContext.addDependency(controller.getName(), AttachmentKey.create(XBundle.class)); }
@Override public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { DeploymentUnit depUnit = phaseContext.getDeploymentUnit(); XBundleRevision brev = depUnit.getAttachment(OSGiConstants.BUNDLE_REVISION_KEY); if (brev == null || brev.isFragment()) return; ServiceController<XBundle> controller = BundleActivateService.addService(phaseContext.getServiceTarget(), depUnit, brev.getBundle()); phaseContext.addDependency(controller.getName(), AttachmentKey.create(XBundle.class)); }