Merge branch '4.0.x' into 4.1.x

Closes gh-51651
This commit is contained in:
Andy Wilkinson
2026-09-09 15:31:57 +01:00
6 changed files with 100 additions and 5 deletions
@@ -55,6 +55,7 @@ import org.springframework.util.StringUtils;
* @author Stephane Nicoll
* @author Madhura Bhave
* @author Scott Frederick
* @author Cobi Eun
* @since 2.3.0
*/
public abstract class Packager {
@@ -422,7 +423,8 @@ public abstract class Packager {
}
private boolean isCycloneDxBom(JarEntry entry) {
if (!entry.getName().startsWith("META-INF/sbom/")) {
if (!entry.getName().startsWith("META-INF/sbom/")
&& !entry.getName().startsWith(getLayout().getClassesLocation() + "META-INF/sbom/")) {
return false;
}
return entry.getName().endsWith(".cdx.json") || entry.getName().endsWith("/bom.json");
@@ -687,16 +687,26 @@ abstract class AbstractPackagerTests<P extends Packager> {
}
@Test
void sbomManifestEntriesAreWritten() throws IOException {
this.testJarFile.addClass("com/example/Application.class", ClassWithMainMethod.class);
this.testJarFile.addFile("META-INF/sbom/application.cdx.json", new ByteArrayInputStream(new byte[0]));
void sbomManifestEntriesAreWrittenForJar() throws IOException {
sbomManifestEntriesAreWritten(new Layouts.Jar(), "");
}
@Test
void sbomManifestEntriesAreWrittenForWar() throws IOException {
sbomManifestEntriesAreWritten(new Layouts.War(), "WEB-INF/classes/");
}
private void sbomManifestEntriesAreWritten(Layout layout, String prefix) throws IOException {
this.testJarFile.addClass(prefix + "com/example/Application.class", ClassWithMainMethod.class);
this.testJarFile.addFile(prefix + "META-INF/sbom/application.cdx.json", new ByteArrayInputStream(new byte[0]));
P packager = createPackager(this.testJarFile.getFile());
packager.setLayout(layout);
execute(packager, NO_LIBRARIES);
Manifest manifest = getPackagedManifest();
assertThat(manifest).isNotNull();
assertThat(manifest.getMainAttributes().getValue("Sbom-Format")).isEqualTo("CycloneDX");
assertThat(manifest.getMainAttributes().getValue("Sbom-Location"))
.isEqualTo("META-INF/sbom/application.cdx.json");
.isEqualTo(prefix + "META-INF/sbom/application.cdx.json");
}
private File createLibraryJar() throws IOException {