BundleMaker { public File copyAddingManifest(File f, Map<String,String> attrs) { return copyAddingManifest(f, manifestOf(attrs)); } BundleMaker(@Nonnull ResourceUtils resources);  BundleMaker(@Nonnull Framework f, @Nonnull ResourceUtils resources);  BundleMaker(@Nonnull ManagementContext mgmt); void setDefaultClassForLoading(Class<?> optionalDefaultClassForLoading); File createJarFromClasspathDir(String path); boolean hasOsgiManifest(File f); Manifest getManifest(File f); File copyAddingManifest(File f, Map<String,String> attrs); File copyAddingManifest(File f, Manifest mf); File copyAdding(File f, Map<ZipEntry, ? extends InputStream> entries); File copyAddingAtEnd(File f, Map<ZipEntry, ? extends InputStream> entries); File copyRemoving(File f, final Set<String> itemsToRemove); File copyRemoving(File f, Predicate<? super String> filter); @Deprecated Bundle installBundle(File f, boolean start); File createTempBundle(String nameHint, Manifest mf, Map<ZipEntry, InputStream> files); File createTempBundle(String nameHint, Map<String, String> mf, Map<ZipEntry, InputStream> files); File createTempZip(String nameHint, Map<ZipEntry, InputStream> files);  }
@Test public void testCopyAddingManifest() throws Exception { Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.2.3"); manifest.getMainAttributes().putValue("mykey", "myval"); generatedJar = bundleMaker.copyAddingManifest(emptyJar, manifest); String expectedManifest = "Manifest-Version: 1.2.3\r\n" + "mykey: myval\r\n" + "\r\n"; assertJarContents(generatedJar, ImmutableMap.of(JarFile.MANIFEST_NAME, expectedManifest), false); }
@Test public void testCopyAddingManifestByMap() throws Exception { Map<String, String> manifest = ImmutableMap.of(Attributes.Name.MANIFEST_VERSION.toString(), "1.2.3", "mykey", "myval"); generatedJar = bundleMaker.copyAddingManifest(emptyJar, manifest); String expectedManifest = "Manifest-Version: 1.2.3\r\n" + "mykey: myval\r\n" + "\r\n"; assertJarContents(generatedJar, ImmutableMap.of(JarFile.MANIFEST_NAME, expectedManifest), false); }
@Test public void testCopyAddingManifestOverwritesExisting() throws Exception { Map<String, String> origManifest = ImmutableMap.of(Attributes.Name.MANIFEST_VERSION.toString(), "4.5.6", "preExistingKey", "preExistingVal"); tempJar = bundleMaker.copyAddingManifest(emptyJar, origManifest); Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.2.3"); manifest.getMainAttributes().putValue("mykey", "myval"); generatedJar = bundleMaker.copyAddingManifest(tempJar, manifest); String expectedManifest = "Manifest-Version: 1.2.3\r\n" + "mykey: myval\r\n" + "\r\n"; assertJarContents(generatedJar, ImmutableMap.of(JarFile.MANIFEST_NAME, expectedManifest), false); }