Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public void copyTo(Path directory) throws IOException
if (isIncluded("META-INF") && !isExcluded("META-INF"))
{
Path metaInf = directory.resolve("META-INF");
Files.createDirectory(metaInf);
Files.createDirectories(metaInf);
Path f = metaInf.resolve("MANIFEST.MF");
try (OutputStream fout = Files.newOutputStream(f))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@

package org.eclipse.jetty.ee10.maven.plugin;

import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;

import org.eclipse.jetty.maven.SelectiveJarResource;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
Expand All @@ -27,6 +33,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -111,4 +118,36 @@ public void testIncludesExcludes(WorkDir workDir) throws Exception
assertFalse(Files.exists(unpackDir.resolve("cc/c2.html")));
}
}

@Test
public void testCopyToWithManifestAndMavenDescriptor(WorkDir workDir) throws Exception
{
Path base = workDir.getPath();
Path jar = base.resolve("overlay.jar");
Manifest manifest = new Manifest();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
String pomEntry = "META-INF/maven/com.example/demo/pom.xml";
try (OutputStream output = Files.newOutputStream(jar);
JarOutputStream jarOutput = new JarOutputStream(output, manifest))
{
jarOutput.putNextEntry(new JarEntry(pomEntry));
jarOutput.write("<project/>".getBytes(StandardCharsets.UTF_8));
jarOutput.closeEntry();
}

Path unpackDir = base.resolve("unpacked");
Files.createDirectories(unpackDir);
try (ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable())
{
Resource resource = resourceFactory.newJarFileResource(jar.toUri());
SelectiveJarResource selectiveJarResource = new SelectiveJarResource(resource);
selectiveJarResource.copyTo(unpackDir);
}

Path manifestFile = unpackDir.resolve("META-INF/MANIFEST.MF");
Path pomFile = unpackDir.resolve(pomEntry);
assertTrue(Files.isRegularFile(manifestFile));
assertTrue(Files.readString(manifestFile).contains("Manifest-Version"));
assertEquals("<project/>", Files.readString(pomFile));
}
}
Loading