-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathMavenPublicationVersionValidator.kt
39 lines (33 loc) · 1.18 KB
/
MavenPublicationVersionValidator.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package kotlinx.coroutines.validator
import org.junit.Test
import java.util.jar.*
import kotlin.test.*
class MavenPublicationVersionValidator {
@Test
fun testMppJar() {
val clazz = Class.forName("kotlinx.coroutines.Job")
JarFile(clazz.protectionDomain.codeSource.location.file).checkForVersion("kotlinx_coroutines_core.version")
}
@Test
fun testAndroidJar() {
val clazz = Class.forName("kotlinx.coroutines.android.HandlerDispatcher")
JarFile(clazz.protectionDomain.codeSource.location.file).checkForVersion("kotlinx_coroutines_android.version")
}
private fun JarFile.checkForVersion(file: String) {
val actualFile = "META-INF/$file"
val version = System.getenv("version")
use {
for (e in entries()) {
if (e.name == actualFile) {
val string = getInputStream(e).readAllBytes().decodeToString()
assertEquals(version, string)
return
}
}
error("File $file not found")
}
}
}