@Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { DeploymentUnit depUnit = phaseContext.getDeploymentUnit(); OSGiMetaData metadata = depUnit.getAttachment(OSGiConstants.OSGI_METADATA_KEY); if (metadata == null || metadata.getBundleActivator() == null) return; String componentClass = metadata.getBundleActivator(); String componentName = BundleActivator.class.getSimpleName(); EEModuleDescription moduleDescription = depUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION); if (moduleDescription != null) { ComponentDescription componentDescription = new ComponentDescription(componentName, componentClass, moduleDescription, depUnit.getServiceName()); moduleDescription.addComponent(componentDescription); } }
public void autostartBundle(@Observes AfterDeploy event) throws Exception { if (event.getDeployableContainer() instanceof CommonDeployableContainer) { CommonDeployableContainer<?> container = (CommonDeployableContainer<?>) event.getDeployableContainer(); if (container.isAutostartBundle()) { Manifest manifest = new Manifest(event.getDeployment().getArchive().get("/META-INF/MANIFEST.MF").getAsset().openStream()); OSGiMetaData metadata = OSGiMetaDataBuilder.load(manifest); if (metadata.getFragmentHost() == null) { container.startBundle(metadata.getBundleSymbolicName(), metadata.getBundleVersion().toString()); } else { logger.debug("Fragment bundle cannot be started"); } } } } }
assertResourceCreated(); try { String symbolicName = metadata.getBundleSymbolicName(); Version bundleVersion = metadata.getBundleVersion(); ParameterizedAttribute idparams = metadata.getBundleParameters(); Map<String, Object> idatts = getAttributes(idparams); Map<String, String> iddirs = getDirectives(idparams); ParameterizedAttribute fragmentHost = metadata.getFragmentHost(); if (fragmentHost == null) { addIdentityCapability(symbolicName, bundleVersion, IDENTITY_TYPE_BUNDLE, idatts, iddirs); List<ParameterizedAttribute> requireBundles = metadata.getRequireBundles(); if (requireBundles != null && requireBundles.isEmpty() == false) { for (ParameterizedAttribute attr : requireBundles) { List<PackageAttribute> exports = metadata.getExportPackages(); if (exports != null && exports.isEmpty() == false) { for (PackageAttribute attr : exports) { List<PackageAttribute> imports = metadata.getImportPackages(); if (imports != null && imports.isEmpty() == false) { for (PackageAttribute attr : imports) { List<PackageAttribute> dynamicImports = metadata.getDynamicImports(); if (dynamicImports != null && dynamicImports.isEmpty() == false) { for (PackageAttribute attr : dynamicImports) {
@Override public void undeploy(Archive<?> archive) throws DeploymentException { try { Manifest manifest = new Manifest(archive.get("/META-INF/MANIFEST.MF").getAsset().openStream()); OSGiMetaData metadata = OSGiMetaDataBuilder.load(manifest); undeploy(metadata.getBundleSymbolicName()); } catch (IOException e) { throw new DeploymentException("Cannot undeploy: " + archive.getName(), e); } }
deployment.addAttachment(BundleInfo.class, info); OSGiMetaData metadata = info.getOSGiMetadata(); deployment.setAutoStart(!metadata.isFragment());
@Override public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException { try { Manifest manifest = new Manifest(archive.get("/META-INF/MANIFEST.MF").getAsset().openStream()); OSGiMetaData metadata = OSGiMetaDataBuilder.load(manifest); BundleHandle handle = installBundle(archive); deployedBundles.put(metadata.getBundleSymbolicName(), handle); } catch (RuntimeException rte) { throw rte; } catch (Exception ex) { throw new DeploymentException("Cannot deploy: " + archive.getName(), ex); } MBeanServerConnection mbeanServer = mbeanServerInstance.get(); return new ProtocolMetaData().addContext(new JMXContext(mbeanServer)); }
deployment.putAttachment(BUNDLE_INFO_KEY, info); OSGiMetaData metadata = info.getOSGiMetadata(); deployment.setAutoStart(!metadata.isFragment());
@Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { DeploymentUnit depUnit = phaseContext.getDeploymentUnit(); OSGiMetaData metadata = depUnit.getAttachment(OSGiConstants.OSGI_METADATA_KEY); if (metadata == null || metadata.getBundleActivator() == null) return; String componentClass = metadata.getBundleActivator(); String componentName = BundleActivator.class.getSimpleName(); EEModuleDescription moduleDescription = depUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION); if (moduleDescription != null) { ComponentDescription componentDescription = new ComponentDescription(componentName, componentClass, moduleDescription, depUnit.getServiceName()); moduleDescription.addComponent(componentDescription); } }
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(); }
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(); }