public Bundle install(BundleContext ctx) throws IOException, BundleException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); JarOutputStream jos = null; try { jos = new JarOutputStream(baos, makeManifest()); addFileContent(jos); } finally { if (jos != null) jos.close(); baos.close(); } byte[] inMemoryJar = baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(inMemoryJar); return ctx.installBundle(getFragmentSymbolicName(), bais); }
public void addImportsFromExports(Bundle exportBundle) { String exportString = (String) exportBundle.getHeaders().get(Constants.EXPORT_PACKAGE); if (exportString != null) { String exportVersion = exportBundle.getVersion().toString(); String bundleConstraint = Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE + "=\"" + exportBundle.getSymbolicName() + "\""; String bundleVersionConstraint = Constants.BUNDLE_VERSION_ATTRIBUTE + "=\"[" + exportVersion + "," + exportVersion + "]\""; List<String> exports = parseDelimitedString(exportString, ",", true); for (String export : exports) { importPackages.add(convertExportToImport(export, bundleConstraint, bundleVersionConstraint)); } } }
private void addImportsAndExports(Attributes attrs) { if (!!!importPackages.isEmpty()) { attrs.putValue(Constants.IMPORT_PACKAGE, joinStrings(importPackages, ',')); } if (!!!exportPackages.isEmpty()) { attrs.putValue(Constants.EXPORT_PACKAGE, joinStrings(exportPackages, ',')); } }
private Manifest makeManifest() { String commonVersion = hostBundle.getVersion().toString(); String fragmentHost = hostBundle.getSymbolicName() + ";" + Constants.BUNDLE_VERSION_ATTRIBUTE + "=\"" + commonVersion + "\""; Manifest m = new Manifest(); Attributes manifestAttributes = m.getMainAttributes(); manifestAttributes.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0"); manifestAttributes.putValue(Constants.BUNDLE_MANIFESTVERSION, "2"); manifestAttributes.putValue(Constants.BUNDLE_SYMBOLICNAME, getFragmentSymbolicName()); String bundleName = getFragmentBundleName(); if (bundleName != null) { manifestAttributes.putValue(Constants.BUNDLE_NAME, bundleName); } manifestAttributes.putValue(Constants.BUNDLE_VERSION, commonVersion); manifestAttributes.putValue(Constants.BUNDLE_VENDOR, "Apache"); manifestAttributes.putValue(Constants.FRAGMENT_HOST, fragmentHost); addImportsAndExports(manifestAttributes); return m; }
LOG.debug("Generating JPA fragment for persistence bundle {}", persistenceBundle.getSymbolicName()); FragmentBuilder builder = new FragmentBuilder(persistenceBundle, ".jpa.fragment", "JPA Fragment"); for (ExportPackage exportPackage : providerDescription.getExportPackage()) { builder.addImports(exportPackage.getName() + providerConstraint); fragment = builder.install(containerContext); } catch (IOException e) { throw new RuntimeException("Error installing JPA fragment bundle", e);