public static OSGiMetaData load(InputStream input) throws IOException { if (input == null) throw new IllegalArgumentException("Null input"); return load(new InputStreamReader(input)); }
public static OSGiMetaData load(Reader reader) throws IOException { if (reader == null) throw new IllegalArgumentException("Null reader"); Properties props = new Properties(); props.load(reader); return load(props); }
public static OSGiMetaData load(Properties props) { if (props == null) throw new IllegalArgumentException("Null props"); Manifest manifest = new Manifest(); Attributes mainAttributes = manifest.getMainAttributes(); for (Object key : props.keySet()) { Attributes.Name name = new Attributes.Name((String) key); mainAttributes.put(name, props.get(key)); } return load(manifest); }
protected OSGiMetaData getOSGiMetaDataFromManifest(XResource resource) throws IOException { OSGiMetaData result = null; Manifest manifest = getResourceManifest(resource); if (OSGiManifestBuilder.isValidBundleManifest(manifest)) { result = OSGiMetaDataBuilder.load(manifest); } return result; }
try { Manifest manifest = new JarInputStream(content).getManifest(); OSGiMetaData metaData = OSGiMetaDataBuilder.load(manifest); builder.load(metaData); } catch (Exception ex) {
@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); } }
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"); } } } } }
@Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { // Check if we already have an OSGi deployment DeploymentUnit depUnit = phaseContext.getDeploymentUnit(); if (depUnit.hasAttachment(OSGiConstants.OSGI_METADATA_KEY)) return; // Get the OSGi XService properties VirtualFile virtualFile = depUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot(); VirtualFile xserviceFile = virtualFile.getChild(XSERVICE_PROPERTIES_NAME); if (xserviceFile.exists() == false) return; try { Properties props = new Properties(); props.load(xserviceFile.openStream()); OSGiMetaData metadata = OSGiMetaDataBuilder.load(props); depUnit.putAttachment(OSGiConstants.OSGI_METADATA_KEY, metadata); } catch (IOException ex) { throw MESSAGES.cannotParseOSGiMetadata(ex, xserviceFile); } }
@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)); }
@Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { // Check if we already have {@link OSGiMetaData} attached // or if we already have a bundle {@link Deployment} DeploymentUnit depUnit = phaseContext.getDeploymentUnit(); OSGiMetaData metadata = depUnit.getAttachment(OSGiConstants.OSGI_METADATA_KEY); Deployment dep = BundleLifecycleIntegration.getDeployment(depUnit.getName()); if (metadata != null || dep != null) return; // Get the OSGi XService properties VirtualFile virtualFile = depUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot(); VirtualFile xserviceFile = virtualFile.getChild(XSERVICE_PROPERTIES_NAME); if (xserviceFile.exists() == false) return; try { Properties props = new Properties(); props.load(xserviceFile.openStream()); metadata = OSGiMetaDataBuilder.load(props); } catch (IOException ex) { throw MESSAGES.cannotParseOSGiMetadata(ex, xserviceFile); } depUnit.putAttachment(OSGiConstants.OSGI_METADATA_KEY, metadata); depUnit.putAttachment(OSGiConstants.DEPLOYMENT_TYPE_KEY, DeploymentType.Module); }
@Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit depUnit = phaseContext.getDeploymentUnit(); if (depUnit.hasAttachment(Attachments.OSGI_MANIFEST) || depUnit.hasAttachment(OSGiConstants.OSGI_METADATA_KEY)) return; final ResourceRoot deploymentRoot = depUnit.getAttachment(Attachments.DEPLOYMENT_ROOT); if (deploymentRoot == null) return; // Check whether this is an OSGi manifest Manifest manifest = deploymentRoot.getAttachment(Attachments.MANIFEST); if (OSGiManifestBuilder.isValidBundleManifest(manifest)) { depUnit.putAttachment(Attachments.OSGI_MANIFEST, manifest); OSGiMetaData metadata = OSGiMetaDataBuilder.load(manifest); depUnit.putAttachment(OSGiConstants.OSGI_METADATA_KEY, metadata); } }
@Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { DeploymentUnit depUnit = phaseContext.getDeploymentUnit(); OSGiMetaData metadata = depUnit.getAttachment(OSGiConstants.OSGI_METADATA_KEY); // Check if we already have a bundle {@link Deployment} Deployment dep = BundleLifecycleIntegration.getDeployment(depUnit.getName()); if (metadata == null && dep != null) { metadata = dep.getAttachment(IntegrationConstants.OSGI_METADATA_KEY); } Manifest manifest = depUnit.getAttachment(Attachments.OSGI_MANIFEST); if (metadata == null && manifest != null) { metadata = OSGiMetaDataBuilder.load(manifest); } // Add a dependency on the {@link FrameworkBootstrapService} // for any deployment that has valid {@link OSGiMetaData} if (metadata != null) { depUnit.putAttachment(OSGiConstants.OSGI_METADATA_KEY, metadata); phaseContext.addDependency(FrameworkBootstrapService.SERVICE_NAME, AttachmentKey.create(Void.class)); } }