@Override public boolean contains(ArchivePath path) throws IllegalArgumentException { return delegate.contains(path); }
@Override public boolean contains(String path) throws IllegalArgumentException { return delegate.contains(path); }
private static void enrichWithGlues(final Class<?> javaClass, final LibraryContainer<?> libraryContainer, final String ln) { final Collection<Class<?>> glues = Glues.findGlues(javaClass); final StringBuilder gluesStr = new StringBuilder(); if (!glues.isEmpty()) { final JavaArchive gluesJar = create(JavaArchive.class, "cukespace-glues.jar"); { // glues txt file for (final Class<?> g : glues) { gluesStr.append(g.getName()).append(ln); } gluesJar.add(new StringAsset(gluesStr.toString()), ClientServerFiles.GLUES_LIST); } { // classes gluesJar.addClasses(glues.toArray(new Class<?>[glues.size()])); for (final Class<?> clazz : glues) { Class<?> current = clazz.getSuperclass(); while (!Object.class.equals(current)) { if (!gluesJar.contains(AssetUtil.getFullPathForClassResource(current))) { gluesJar.addClass(current); } current = current.getSuperclass(); } } } libraryContainer.addAsLibrary(gluesJar); } }
private void assertClassesWereAdded(JavaArchive archive) { Assert.assertTrue("Class in default package was not added to archive", archive.contains(classInDefaultPackagePath)); Assert.assertTrue("Inner class in default package was not added to archive", archive.contains(innerClassInDefaultPackagePath)); }
/** * Import from file and make sure the file is closed. * * @param log the logger * @param set the dependency set * @param jar the archive * @param file the file, must not be {@code null} */ private void embedDependency(Log log, DependencySet set, JavaArchive jar, File file) { try (FileInputStream fis = new FileInputStream(file)) { jar.as(ZipImporter.class).importFrom(fis, path -> { if (jar.contains(path)) { log.debug(path.get() + " already embedded in the jar"); return false; } if (!toExclude(set, path)) { return true; } else { log.debug("Excluding " + path.get() + " from " + file.getName()); return false; } }); } catch (Exception e) { throw new RuntimeException("Unable to read the file " + file.getAbsolutePath(), e); } }
/** * Tests that a default MANIFEST.MF is generated through the addManifest method call. SHRINKWRAP-191 * * @throws Exception */ @Test public void testAddManifest() throws Exception { String expectedManifestPath = "META-INF/MANIFEST.MF"; JavaArchive archive = ShrinkWrap.create(JavaArchive.class); Assert.assertFalse("Archive should not contain manifest file", archive.contains(expectedManifestPath)); archive.addManifest(); Assert.assertTrue("Archive should contain manifest file: " + expectedManifestPath, archive.contains(expectedManifestPath)); }
/** * Reproduces the bug in SHRINKWRAP-300 */ @Test public void testAddFileWithWhitespaceInFilename() { String manifest = "Whitespace manifest.MF"; JavaArchive archive = ShrinkWrap.create(JavaArchive.class); org.junit.Assert.assertFalse("Archive should not contain file", archive.contains(manifest)); archive.addAsResource(manifest); Assert.assertTrue("Archive should contain file: " + manifest, archive.contains(manifest)); }
public static JavaArchive generateUberJar(Archive<?> archive) { // start from war JavaArchive javaArchive = generateWar(archive, Collections.singletonList("com.kumuluz.ee:kumuluzee-loader:")); // explode application archive and kumuluzee-loader lib into root explodeAppArchiveToRoot(javaArchive); explodeLoaderArchiveToRoot(javaArchive); // apply necessary transformations from web archive to java archive moveDir(javaArchive, "/WEB-INF/classes", ""); // CDI enricher adds beans.xml to the WEB-INF directory, if supplied archive is WebArchive. // If that is the case, we need to move it to the META-INF directory. if (javaArchive.contains("/WEB-INF/beans.xml") && !javaArchive.contains("/META-INF/beans.xml")) { javaArchive.move("/WEB-INF/beans.xml", "/META-INF/beans.xml"); } // add required root classes to classes dir for (Class<?> klass : rootClasses) { javaArchive.addClass(klass); // will get added to root, which is correct } javaArchive.addAsManifestResource("KumuluzEEManifest.MF", "MANIFEST.MF"); javaArchive.addAsManifestResource( new StringAsset("main-class=" + MainWrapper.class.getName()), "kumuluzee/boot-loader.properties"); return javaArchive; }
/** * SHRINKWRAP-474 */ @Test public void canRoundTrip() { // Define a path/name for the archive and the file it contains final String embeddedArchiveName = "lib.jar"; final String emptyFileName = "empty.file"; // Create an archive which contains another archive in the lib dir final JavaArchive embeddedArchive = ShrinkWrap.create(JavaArchive.class, embeddedArchiveName) .add(EmptyAsset.INSTANCE, emptyFileName); final WebArchive outerArchive = ShrinkWrap.create(WebArchive.class).addAsLibraries(embeddedArchive); // Now pull the embedded archive back out final JavaArchive roundtrip = outerArchive.getAsType(JavaArchive.class, ArchivePaths.create("WEB-INF/lib", embeddedArchiveName), this.getArchiveFormat()); Assert.assertTrue("roundtrip could not be obtained", roundtrip != null); Assert.assertTrue( "contents of embedded archive are not intact after roundtrip", roundtrip.contains(emptyFileName)); } }