Skip to content

Commit

Permalink
Get rid of 'previous-compilation-data.bin' in META-INF (#3675)
Browse files Browse the repository at this point in the history
* Include only module-info.class from the corresponding JavaCompile task

Fixes #3668
  • Loading branch information
qwwdfsad authored Mar 13, 2023
1 parent dd52d18 commit 9f9cb87
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/Java9Modularity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ object Java9Modularity {
attributes("Multi-Release" to true)
}
from(compileJavaModuleInfo) {
// Include **only** file we are interested in as JavaCompile output also contains some tmp files
include("module-info.class")
into("META-INF/versions/9/")
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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 org.objectweb.asm.*
import org.objectweb.asm.ClassReader.*
import org.objectweb.asm.ClassWriter.*
import org.objectweb.asm.Opcodes.*
import java.util.jar.*
import kotlin.test.*

class MavenPublicationMetaInfValidator {

@Test
fun testMetaInfCoreStructure() {
val clazz = Class.forName("kotlinx.coroutines.Job")
JarFile(clazz.protectionDomain.codeSource.location.file).checkMetaInfStructure(
setOf(
"MANIFEST.MF",
"kotlinx-coroutines-core.kotlin_module",
"com.android.tools/proguard/coroutines.pro",
"com.android.tools/r8/coroutines.pro",
"proguard/coroutines.pro",
"versions/9/module-info.class",
"kotlinx_coroutines_core.version"
)
)
}

@Test
fun testMetaInfAndroidStructure() {
val clazz = Class.forName("kotlinx.coroutines.android.HandlerDispatcher")
JarFile(clazz.protectionDomain.codeSource.location.file).checkMetaInfStructure(
setOf(
"MANIFEST.MF",
"kotlinx-coroutines-android.kotlin_module",
"services/kotlinx.coroutines.CoroutineExceptionHandler",
"services/kotlinx.coroutines.internal.MainDispatcherFactory",
"com.android.tools/r8-from-1.6.0/coroutines.pro",
"com.android.tools/r8-upto-3.0.0/coroutines.pro",
"com.android.tools/proguard/coroutines.pro",
"proguard/coroutines.pro",
"versions/9/module-info.class",
"kotlinx_coroutines_android.version"
)
)
}

private fun JarFile.checkMetaInfStructure(expected: Set<String>) {
val actual = HashSet<String>()
for (e in entries()) {
if (e.isDirectory() || !e.realName.contains("META-INF")) {
continue
}
val partialName = e.realName.substringAfter("META-INF/")
actual.add(partialName)
}

if (actual != expected) {
val intersection = actual.intersect(expected)
val mismatch = actual.subtract(intersection) + expected.subtract(intersection)
fail("Mismatched files: " + mismatch)
}

close()
}
}

0 comments on commit 9f9cb87

Please sign in to comment.