Kotlinc: Exclude module-info.class from resulting jar when "-include-runtime" is specified
This commit is contained in:
committed by
Alexander Udalov
parent
742fef9042
commit
4374438ff1
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.cli.jvm.compiler;
|
|||||||
import com.intellij.openapi.util.io.FileUtil;
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
import com.intellij.openapi.util.io.FileUtilRt;
|
import com.intellij.openapi.util.io.FileUtilRt;
|
||||||
import kotlin.io.FilesKt;
|
import kotlin.io.FilesKt;
|
||||||
|
import kotlin.text.StringsKt;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.backend.common.output.OutputFile;
|
import org.jetbrains.kotlin.backend.common.output.OutputFile;
|
||||||
@@ -131,6 +132,9 @@ public class CompileEnvironmentUtil {
|
|||||||
if (e == null) {
|
if (e == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (StringsKt.substringAfterLast(e.getName(), "/", e.getName()).equals("module-info.class")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (resetJarTimestamps) {
|
if (resetJarTimestamps) {
|
||||||
e.setTime(DOS_EPOCH);
|
e.setTime(DOS_EPOCH);
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-12
@@ -17,16 +17,14 @@
|
|||||||
package org.jetbrains.kotlin.cli
|
package org.jetbrains.kotlin.cli
|
||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileInputStream
|
|
||||||
import java.util.jar.JarInputStream
|
|
||||||
import java.util.zip.ZipEntry
|
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertNotEquals
|
import kotlin.test.assertNotEquals
|
||||||
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
|
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.CompileEnvironmentUtil.DOS_EPOCH
|
import org.jetbrains.kotlin.cli.jvm.compiler.CompileEnvironmentUtil.DOS_EPOCH
|
||||||
import org.jetbrains.kotlin.test.TestCaseWithTmpdir
|
import org.jetbrains.kotlin.test.TestCaseWithTmpdir
|
||||||
|
import java.util.jar.JarFile
|
||||||
|
|
||||||
class DeterministicOutputTest : TestCaseWithTmpdir() {
|
class JarOutputTest : TestCaseWithTmpdir() {
|
||||||
|
|
||||||
fun testDeterministicOutput() {
|
fun testDeterministicOutput() {
|
||||||
val fooKt = tmpdir.resolve("foo.kt").also {
|
val fooKt = tmpdir.resolve("foo.kt").also {
|
||||||
@@ -63,21 +61,40 @@ class DeterministicOutputTest : TestCaseWithTmpdir() {
|
|||||||
assertNoTimestampsAreReset(jar)
|
assertNoTimestampsAreReset(jar)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* KT-44078
|
||||||
|
*/
|
||||||
|
fun testNoModuleInfoClass() {
|
||||||
|
val fooKt = tmpdir.resolve("foo.kt").also {
|
||||||
|
it.writeText("class Foo")
|
||||||
|
}
|
||||||
|
val jar = tmpdir.resolve("jarWithoutModuleInfoClass.jar")
|
||||||
|
AbstractCliTest.executeCompilerGrabOutput(
|
||||||
|
K2JVMCompiler(),
|
||||||
|
listOf(fooKt.path, "-d", jar.path, "-include-runtime")
|
||||||
|
)
|
||||||
|
|
||||||
|
assertNoModuleInfoClass(jar)
|
||||||
|
}
|
||||||
|
|
||||||
private fun assertAllTimestampsAreReset(jar: File) {
|
private fun assertAllTimestampsAreReset(jar: File) {
|
||||||
val zis = JarInputStream(FileInputStream(jar))
|
for (entry in JarFile(jar).entries()) {
|
||||||
var entry: ZipEntry? = zis.nextEntry
|
|
||||||
while (entry != null) {
|
|
||||||
assertEquals(entry.time, DOS_EPOCH, "$entry timestamp should be reset")
|
assertEquals(entry.time, DOS_EPOCH, "$entry timestamp should be reset")
|
||||||
entry = zis.nextEntry
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun assertNoTimestampsAreReset(jar: File) {
|
private fun assertNoTimestampsAreReset(jar: File) {
|
||||||
val zis = JarInputStream(FileInputStream(jar))
|
for (entry in JarFile(jar).entries()) {
|
||||||
var entry: ZipEntry? = zis.nextEntry
|
|
||||||
while (entry != null) {
|
|
||||||
assertNotEquals(entry.time, DOS_EPOCH, "$entry timestamp should not be reset")
|
assertNotEquals(entry.time, DOS_EPOCH, "$entry timestamp should not be reset")
|
||||||
entry = zis.nextEntry
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertNoModuleInfoClass(jar: File) {
|
||||||
|
for (entry in JarFile(jar).entries()) {
|
||||||
|
assertNotEquals(
|
||||||
|
"module-info.class", entry.name.substringAfterLast("/"),
|
||||||
|
"$entry is expected to be excluded from the resulting jar"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user