@Test public void manifestWithManifestSections() { // When final Archive<?> archive = ShrinkWrap.create(MavenImporter.class) .loadPomFromFile("src/it/jar-with-mf-sample/pom-e.xml") .importBuildOutput() .as(JavaArchive.class); // Then assertThat(archive.getContent(), contains("META-INF/MANIFEST.MF")); assertThat( archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Created-By", "ShrinkWrap Maven Resolver")); assertThat( archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Specification-Title")); assertThat( archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Specification-Vendor", "Arquillian")); assertThat( archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("MyFirstSection", "Foo", "bar")); assertThat( archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("MySecondSection", "Foo2", "bar2")); }
private static String readFileFromArchive(Archive archive, String path) throws IOException { try (InputStream manifest = archive.get(path).getAsset().openStream()) { BufferedReader reader = new BufferedReader(new InputStreamReader(manifest, StandardCharsets.UTF_8)); return reader.lines().collect(Collectors.joining()); } }
@Test public void manifestWithCustomManifestEntries() { // When final Archive<?> archive = ShrinkWrap.create(MavenImporter.class) .loadPomFromFile("src/it/war-sample/pom.xml") .importBuildOutput() .as(JavaArchive.class); // Then assertThat(archive.getContent(), contains("META-INF/MANIFEST.MF")); assertThat( archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Created-By", "ShrinkWrap Maven Resolver")); assertThat(archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Dependencies")); }
@Test public void suppliedManifestHasPrecedence() { // When final Archive<?> archive = ShrinkWrap.create(MavenImporter.class) .loadPomFromFile("src/it/jar-with-mf-sample/pom.xml") .importBuildOutput() .as(JavaArchive.class); // Then assertThat(archive.getContent(), contains("META-INF/MANIFEST.MF")); assertThat( archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Created-By", "User")); assertThat( archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry(Attributes.Name.MANIFEST_VERSION.toString(), "1.0")); }
@Test public void manifestWithDefaultImplementationEntries() { // When final Archive<?> archive = ShrinkWrap.create(MavenImporter.class) .loadPomFromFile("src/it/jar-with-mf-sample/pom-b.xml") .importBuildOutput() .as(JavaArchive.class); // Then assertThat(archive.getContent(), contains("META-INF/MANIFEST.MF")); assertThat( archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Created-By", "ShrinkWrap Maven Resolver")); assertThat( archive.get("META-INF/MANIFEST.MF").getAsset(), hasManifestEntry("Implementation-Title")); assertThat( archive.get("META-INF/MANIFEST.MF").getAsset(), not(hasManifestEntry("Implementation-Vendor"))); }
/** * Attempt to get the asset from a nested archive. * * @param path * @return */ private Node getNestedNode(ArchivePath path) { // Iterate through nested archives for (Entry<ArchivePath, ArchiveAsset> nestedArchiveEntry : nestedArchives.entrySet()) { ArchivePath archivePath = nestedArchiveEntry.getKey(); ArchiveAsset archiveAsset = nestedArchiveEntry.getValue(); // Check to see if the requested path starts with the nested archive path if (startsWith(path, archivePath)) { Archive<?> nestedArchive = archiveAsset.getArchive(); // Get the asset path from within the nested archive ArchivePath nestedAssetPath = getNestedPath(path, archivePath); // Recurse the call to the nested archive return nestedArchive.get(nestedAssetPath); } } return null; }
protected File export(Archive<?> archive) throws Exception { if (archive instanceof WebArchive == false) { throw new IllegalArgumentException("Can only handle .war deployments: " + archive); } Node dockerFile = archive.get("Dockerfile"); if (dockerFile == null) { if (configuration.getFrom() == null) { throw new IllegalArgumentException("Missing Docker's FROM value!"); } log.info("Using Docker FROM: " + configuration.getFrom()); String content = "FROM " + configuration.getFrom() + "\n" + "ADD . /app" + "\n"; archive.add(new StringAsset(content), "Dockerfile"); } return super.export(archive); }