1 /*
2  * Copyright 2016-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 import java.util.jar.JarFile
6 import kotlin.test.Test
7 import kotlin.test.fail
8 
9 class MavenPublicationMetaInfValidator {
10     @Test
testMetaInfContentsnull11     fun testMetaInfContents() {
12         val clazz = Class.forName("kotlinx.atomicfu.AtomicFU")
13         JarFile(clazz.protectionDomain.codeSource.location.file).compareMetaInfContents(
14             setOf(
15                 "MANIFEST.MF",
16                 "atomicfu.kotlin_module",
17                 "versions/9/module-info.class"
18             )
19         )
20     }
21 
compareMetaInfContentsnull22     private fun JarFile.compareMetaInfContents(expected: Set<String>) {
23         val actual = entries().toList()
24                 .filter { !it.isDirectory && it.realName.contains("META-INF")}
25                 .map { it.realName.substringAfter("META-INF/") }
26                 .toSet()
27         if (actual != expected) {
28             val intersection = actual.intersect(expected)
29             fail("Mismatched files: " + (actual.subtract(intersection) + expected.subtract(intersection)))
30         }
31         close()
32     }
33 }