/** create a copy of the given ZIP as a JAR with the given entries removed, returning the new temp file */ public File copyRemoving(File f, final Set<String> itemsToRemove) { return copyRemoving(f, new Predicate<String>(){ @Override public boolean apply(String input) { return !itemsToRemove.contains(input); } }); }
@Test public void testCopyRemovingItems() throws Exception { tempJar = bundleMaker.copyAdding(emptyJar, ImmutableMap.of( new ZipEntry("myfile.txt"), new ByteArrayInputStream("mytext".getBytes()), new ZipEntry("myfile2.txt"), new ByteArrayInputStream("mytext2".getBytes()))); generatedJar = bundleMaker.copyRemoving(tempJar, ImmutableSet.of("myfile.txt")); assertJarContents(generatedJar, ImmutableMap.of("myfile2.txt", "mytext2"), false); }
@Test public void testCopyRemovingItemsUnmatched() throws Exception { tempJar = bundleMaker.copyAdding(emptyJar, ImmutableMap.of(new ZipEntry("myfile.txt"), new ByteArrayInputStream("mytext".getBytes()))); generatedJar = bundleMaker.copyRemoving(tempJar, ImmutableSet.of("wrong.txt")); assertJarContents(generatedJar, ImmutableMap.of("myfile.txt", "mytext"), false); }
@Test public void testCopyRemovingPredicate() throws Exception { tempJar = bundleMaker.copyAdding(emptyJar, ImmutableMap.of( new ZipEntry("myfile.txt"), new ByteArrayInputStream("mytext".getBytes()), new ZipEntry("myfile2.txt"), new ByteArrayInputStream("mytext2".getBytes()))); generatedJar = bundleMaker.copyRemoving(tempJar, Predicates.equalTo("myfile.txt")); assertJarContents(generatedJar, ImmutableMap.of("myfile.txt", "mytext"), false); }
@Test(enabled=false) public void testCopyRemovingItemDir() throws Exception { tempJar = bundleMaker.copyAdding(emptyJar, ImmutableMap.of( new ZipEntry("mydir/myfile.txt"), new ByteArrayInputStream("mytext".getBytes()), new ZipEntry("mydir2/myfile2.txt"), new ByteArrayInputStream("mytext2".getBytes()))); generatedJar = bundleMaker.copyRemoving(tempJar, ImmutableSet.of("mydir")); assertJarContents(generatedJar, ImmutableMap.of("mydir2/myfile2.txt", "mytext2"), false); }
static void installJavaScanningMoreEntitiesV2(ManagementContext mgmt, Object context) throws FileNotFoundException { // scanning bundle functionality added in 0.12.0, relatively new compared to non-osgi scanning TestResourceUnavailableException.throwIfResourceUnavailable(context.getClass(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_PATH); TestResourceUnavailableException.throwIfResourceUnavailable(context.getClass(), OsgiTestResources.BROOKLYN_TEST_MORE_ENTITIES_V2_PATH); CampYamlLiteTest.installWithoutCatalogBom(mgmt, OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_PATH); BundleMaker bm = new BundleMaker(mgmt); File f = Os.newTempFile(context.getClass(), "jar"); Streams.copy(ResourceUtils.create(context).getResourceFromUrl(OsgiTestResources.BROOKLYN_TEST_MORE_ENTITIES_V2_PATH), new FileOutputStream(f)); f = bm.copyRemoving(f, MutableSet.of("catalog.bom")); f = bm.copyAdding(f, MutableMap.of(new ZipEntry("catalog.bom"), new ByteArrayInputStream( Strings.lines( "brooklyn.catalog:", " scanJavaAnnotations: true").getBytes() ) )); ((ManagementContextInternal)mgmt).getOsgiManager().get().install(new FileInputStream(f)).checkNoError(); }
@Test public void testCatalogBomFromBundleWithManualManifest() throws Exception { bm.setDefaultClassForLoading(getClass()); File jf = bm.createJarFromClasspathDir("osgi/catalog-bundle-1"); jf = bm.copyRemoving(jf, MutableSet.of(JarFile.MANIFEST_NAME)); String customName = "catalog-bundle-1-manual-"+Identifiers.makeRandomId(4); jf = bm.copyAddingManifest(jf, MutableMap.of( "Manifest-Version", "2.0", "Bundle-SymbolicName", customName, "Bundle-Version", "0.0.0.SNAPSHOT")); Assert.assertTrue(bm.hasOsgiManifest(jf)); installBundle(jf); assertHasBasic1(); Entity basic1 = assertBasic1DeploysAndHasSensor(); RegisteredType item = mgmt().getTypeRegistry().get( basic1.getCatalogItemId() ); Collection<OsgiBundleWithUrl> libs = item.getLibraries(); Asserts.assertSize(libs, 1); Assert.assertEquals(Iterables.getOnlyElement(libs).getSymbolicName(), customName); }