• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 package kotlinx.coroutines.validator
6 
7 import org.junit.Test
8 import java.util.jar.*
9 import kotlin.test.*
10 
11 class MavenPublicationVersionValidator {
12 
13     @Test
testMppJarnull14     fun testMppJar() {
15         val clazz = Class.forName("kotlinx.coroutines.Job")
16         JarFile(clazz.protectionDomain.codeSource.location.file).checkForVersion("kotlinx_coroutines_core.version")
17     }
18 
19     @Test
testAndroidJarnull20     fun testAndroidJar() {
21         val clazz = Class.forName("kotlinx.coroutines.android.HandlerDispatcher")
22         JarFile(clazz.protectionDomain.codeSource.location.file).checkForVersion("kotlinx_coroutines_android.version")
23     }
24 
checkForVersionnull25     private fun JarFile.checkForVersion(file: String) {
26         val actualFile = "META-INF/$file"
27         val version = System.getenv("version")
28         use {
29             for (e in entries()) {
30                 if (e.name == actualFile) {
31                     val string = getInputStream(e).readAllBytes().decodeToString()
32                     assertEquals(version, string)
33                     return
34                 }
35             }
36             error("File $file not found")
37         }
38     }
39 }
40