From 25cd9de71a629c9f26ef4ccce674eacf9f2ddc40 Mon Sep 17 00:00:00 2001 From: Michael Bogdanov Date: Tue, 8 Sep 2015 11:04:17 +0300 Subject: [PATCH] Support default module name in ant task --- ant/src/org/jetbrains/kotlin/ant/Kotlin2JvmTask.kt | 8 ++++++++ .../ant/jvm/moduleName/build.log.expected | 11 +++++++++++ .../integration/ant/jvm/moduleName/build.xml | 14 ++++++++++++++ .../integration/ant/jvm/moduleName/hello.kt | 11 +++++++++++ .../ant/jvm/moduleNameDefault/build.log.expected | 11 +++++++++++ .../ant/jvm/moduleNameDefault/build.xml | 14 ++++++++++++++ .../integration/ant/jvm/moduleNameDefault/hello.kt | 11 +++++++++++ .../kotlin/integration/AntTaskTestGenerated.java | 12 ++++++++++++ 8 files changed, 92 insertions(+) create mode 100644 compiler/testData/integration/ant/jvm/moduleName/build.log.expected create mode 100644 compiler/testData/integration/ant/jvm/moduleName/build.xml create mode 100644 compiler/testData/integration/ant/jvm/moduleName/hello.kt create mode 100644 compiler/testData/integration/ant/jvm/moduleNameDefault/build.log.expected create mode 100644 compiler/testData/integration/ant/jvm/moduleNameDefault/build.xml create mode 100644 compiler/testData/integration/ant/jvm/moduleNameDefault/hello.kt diff --git a/ant/src/org/jetbrains/kotlin/ant/Kotlin2JvmTask.kt b/ant/src/org/jetbrains/kotlin/ant/Kotlin2JvmTask.kt index 5bd28044cda..b0fa7bf1b8b 100644 --- a/ant/src/org/jetbrains/kotlin/ant/Kotlin2JvmTask.kt +++ b/ant/src/org/jetbrains/kotlin/ant/Kotlin2JvmTask.kt @@ -70,6 +70,14 @@ public class Kotlin2JvmTask : KotlinCompilerBaseTask() { args.add(it.list().join(pathSeparator)) } + if (moduleName == null) { + if (owningTarget != null) { + moduleName = owningTarget.name + } else { + moduleName = getProject().name + } + } + moduleName?.let { args.add("-module-name") args.add(moduleName!!) diff --git a/compiler/testData/integration/ant/jvm/moduleName/build.log.expected b/compiler/testData/integration/ant/jvm/moduleName/build.log.expected new file mode 100644 index 00000000000..f3ebd0b0a4f --- /dev/null +++ b/compiler/testData/integration/ant/jvm/moduleName/build.log.expected @@ -0,0 +1,11 @@ +OUT: +Buildfile: [TestData]/build.xml + +build: + [kotlinc] Compiling [[TestData]/hello.kt] => [[Temp]/hello.jar] + [java] Module info 'META-INF/test.kotlin_module' exists + +BUILD SUCCESSFUL +Total time: [time] + +Return code: 0 diff --git a/compiler/testData/integration/ant/jvm/moduleName/build.xml b/compiler/testData/integration/ant/jvm/moduleName/build.xml new file mode 100644 index 00000000000..4f4738428d1 --- /dev/null +++ b/compiler/testData/integration/ant/jvm/moduleName/build.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/compiler/testData/integration/ant/jvm/moduleName/hello.kt b/compiler/testData/integration/ant/jvm/moduleName/hello.kt new file mode 100644 index 00000000000..dfc8315b01c --- /dev/null +++ b/compiler/testData/integration/ant/jvm/moduleName/hello.kt @@ -0,0 +1,11 @@ +package hello + +fun main(args : Array) { + val systemClassLoader = ClassLoader.getSystemClassLoader() + val moduleName = "META-INF/test.kotlin_module" + val resourceAsStream = systemClassLoader.getResourceAsStream(moduleName) + + if (resourceAsStream != null) { + println("Module info '$moduleName' exists") + } +} diff --git a/compiler/testData/integration/ant/jvm/moduleNameDefault/build.log.expected b/compiler/testData/integration/ant/jvm/moduleNameDefault/build.log.expected new file mode 100644 index 00000000000..ead2cbe8b0d --- /dev/null +++ b/compiler/testData/integration/ant/jvm/moduleNameDefault/build.log.expected @@ -0,0 +1,11 @@ +OUT: +Buildfile: [TestData]/build.xml + +build: + [kotlinc] Compiling [[TestData]/hello.kt] => [[Temp]/hello.jar] + [java] Module info 'META-INF/build.kotlin_module' exists + +BUILD SUCCESSFUL +Total time: [time] + +Return code: 0 diff --git a/compiler/testData/integration/ant/jvm/moduleNameDefault/build.xml b/compiler/testData/integration/ant/jvm/moduleNameDefault/build.xml new file mode 100644 index 00000000000..23fc47d8f15 --- /dev/null +++ b/compiler/testData/integration/ant/jvm/moduleNameDefault/build.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/compiler/testData/integration/ant/jvm/moduleNameDefault/hello.kt b/compiler/testData/integration/ant/jvm/moduleNameDefault/hello.kt new file mode 100644 index 00000000000..a161a0b029c --- /dev/null +++ b/compiler/testData/integration/ant/jvm/moduleNameDefault/hello.kt @@ -0,0 +1,11 @@ +package hello + +fun main(args : Array) { + val systemClassLoader = ClassLoader.getSystemClassLoader() + val moduleName = "META-INF/build.kotlin_module" + val resourceAsStream = systemClassLoader.getResourceAsStream(moduleName) + + if (resourceAsStream != null) { + println("Module info '$moduleName' exists") + } +} diff --git a/compiler/tests/org/jetbrains/kotlin/integration/AntTaskTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/integration/AntTaskTestGenerated.java index 767b993702c..1db5817d4f2 100644 --- a/compiler/tests/org/jetbrains/kotlin/integration/AntTaskTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/integration/AntTaskTestGenerated.java @@ -65,6 +65,18 @@ public class AntTaskTestGenerated extends AbstractAntTaskTest { doTest(fileName); } + @TestMetadata("moduleName") + public void testModuleName() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/moduleName/"); + doTest(fileName); + } + + @TestMetadata("moduleNameDefault") + public void testModuleNameDefault() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/moduleNameDefault/"); + doTest(fileName); + } + @TestMetadata("noStdlibForJavac") public void testNoStdlibForJavac() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/noStdlibForJavac/");