File tree 4 files changed +76
-1
lines changed
4 files changed +76
-1
lines changed Original file line number Diff line number Diff line change @@ -233,6 +233,40 @@ configure(subprojects.findAll { !unpublished.contains(it.name) }) {
233
233
}
234
234
}
235
235
}
236
+
237
+ def thisProject = it
238
+ if (thisProject. name in sourceless) {
239
+ return
240
+ }
241
+
242
+ def versionFileTask = thisProject. tasks. register(" versionFileTask" ) {
243
+ def name = thisProject. name. replace(" -" , " _" )
244
+ def versionFile = thisProject. layout. buildDirectory. file(" ${ name} .version" )
245
+ it. outputs. file(versionFile)
246
+
247
+ it. doLast {
248
+ versionFile. get(). asFile. text = version. toString()
249
+ }
250
+ }
251
+
252
+ List<String > jarTasks
253
+ if (it. name == " kotlinx-coroutines-core" ) {
254
+ jarTasks = [" jvmJar" , " metadataJar" ]
255
+ } else if (it. name == " kotlinx-coroutines-debug" ) {
256
+ // We shadow debug module instead of just packaging it
257
+ jarTasks = [" shadowJar" ]
258
+ } else {
259
+ jarTasks = [" jar" ]
260
+ }
261
+
262
+ for (name in jarTasks) {
263
+ thisProject. tasks. named(name, Jar ) {
264
+ it. dependsOn versionFileTask
265
+ it. from(versionFileTask) {
266
+ into(" META-INF" )
267
+ }
268
+ }
269
+ }
236
270
}
237
271
238
272
// Report Kotlin compiler version when building project
Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ task npmTest(type: Test) {
58
58
}
59
59
60
60
task mavenTest (type : Test ) {
61
+ environment " version" , version
61
62
def sourceSet = sourceSets. mavenTest
62
63
dependsOn(project(' :' ). getTasksByName(" publishToMavenLocal" , true ))
63
64
testClassesDirs = sourceSet. output. classesDirs
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import org.junit.*
8
8
import org.junit.Assert.assertTrue
9
9
import java.util.jar.*
10
10
11
- class MavenPublicationValidator {
11
+ class MavenPublicationAtomicfuValidator {
12
12
private val ATOMIC_FU_REF = " Lkotlinx/atomicfu/" .toByteArray()
13
13
14
14
@Test
Original file line number Diff line number Diff line change
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.*
8
+ import org.junit.Test
9
+ import java.util.jar.*
10
+ import kotlin.test.*
11
+
12
+ class MavenPublicationVersionValidator {
13
+
14
+ @Test
15
+ fun testMppJar () {
16
+ val clazz = Class .forName(" kotlinx.coroutines.Job" )
17
+ JarFile (clazz.protectionDomain.codeSource.location.file).checkForVersion(" kotlinx_coroutines_core.version" )
18
+ }
19
+
20
+ @Test
21
+ fun testAndroidJar () {
22
+ val clazz = Class .forName(" kotlinx.coroutines.android.HandlerDispatcher" )
23
+ JarFile (clazz.protectionDomain.codeSource.location.file).checkForVersion(" kotlinx_coroutines_android.version" )
24
+ }
25
+
26
+ private fun JarFile.checkForVersion (file : String ) {
27
+ val actualFile = " META-INF/$file "
28
+ val version = System .getenv(" version" )
29
+ use {
30
+ for (e in entries()) {
31
+ if (e.name == actualFile) {
32
+ val string = getInputStream(e).readAllBytes().decodeToString()
33
+ assertEquals(version, string)
34
+ return
35
+ }
36
+ }
37
+ error(" File $file not found" )
38
+ }
39
+ }
40
+ }
You can’t perform that action at this time.
0 commit comments