Support default module name for withKotlin ant task
This commit is contained in:
@@ -70,12 +70,9 @@ public class Kotlin2JvmTask : KotlinCompilerBaseTask() {
|
||||
args.add(it.list().join(pathSeparator))
|
||||
}
|
||||
|
||||
|
||||
if (moduleName == null) {
|
||||
if (owningTarget != null) {
|
||||
moduleName = owningTarget.name
|
||||
} else if (getProject() != null) {
|
||||
moduleName = getProject().name
|
||||
}
|
||||
moduleName = defaultModuleName
|
||||
}
|
||||
|
||||
moduleName?.let {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.ant
|
||||
|
||||
import org.apache.tools.ant.AntClassLoader
|
||||
import org.apache.tools.ant.Task
|
||||
import org.jetbrains.kotlin.preloading.ClassPreloadingUtils
|
||||
import org.jetbrains.kotlin.preloading.Preloader
|
||||
import java.io.File
|
||||
@@ -63,4 +64,8 @@ object KotlinAntTaskUtil {
|
||||
|
||||
return classLoader
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public val Task.defaultModuleName: String?
|
||||
get() = owningTarget?.name ?: project?.name
|
||||
@@ -92,6 +92,9 @@ public class KotlinCompilerAdapter extends Javac13 {
|
||||
|
||||
kotlinc.setExternalAnnotations(externalAnnotations);
|
||||
|
||||
if (moduleName == null) {
|
||||
moduleName = AntPackage.getDefaultModuleName(javac);
|
||||
}
|
||||
kotlinc.setModuleName(moduleName);
|
||||
|
||||
kotlinc.getAdditionalArguments().addAll(additionalArguments);
|
||||
|
||||
@@ -563,7 +563,7 @@
|
||||
<target name="kotlinr">
|
||||
<cleandir dir="${output}/classes/kotlinr"/>
|
||||
|
||||
<kotlinc output="${output}/classes/kotlinr">
|
||||
<kotlinc output="${output}/classes/kotlinr" modulename="kotlin-rmi">
|
||||
<src>
|
||||
<pathelement path="compiler/rmi/kotlinr/src"/>
|
||||
</src>
|
||||
@@ -583,7 +583,7 @@
|
||||
<target name="android-compiler-plugin">
|
||||
<cleandir dir="${output}/classes/android-compiler-plugin"/>
|
||||
|
||||
<kotlinc output="${output}/classes/android-compiler-plugin">
|
||||
<kotlinc output="${output}/classes/android-compiler-plugin" modulename="kotlin-android-compiler-plugin">
|
||||
<src>
|
||||
<pathelement path="plugins/android-compiler-plugin/src"/>
|
||||
</src>
|
||||
@@ -606,7 +606,7 @@
|
||||
<cleandir dir="${output}/classes/ant"/>
|
||||
<javac2 destdir="${output}/classes/ant" debug="true" debuglevel="lines,vars,source" includeAntRuntime="false"
|
||||
source="${java.target}" target="${java.target}">
|
||||
<withKotlin externalannotations="${external.annotations.path}"/>
|
||||
<withKotlin externalannotations="${external.annotations.path}" modulename="kotlin-ant-tools"/>
|
||||
<skip pattern="kotlin/jvm/internal/.*"/>
|
||||
<src>
|
||||
<dirset dir="${basedir}/ant">
|
||||
@@ -911,7 +911,7 @@
|
||||
|
||||
<javac2 destdir="${output}/classes/idea-analysis" debug="true" debuglevel="lines,vars,source" includeAntRuntime="false"
|
||||
source="${java.target}" target="${java.target}">
|
||||
<withKotlin externalannotations="${external.annotations.path}"/>
|
||||
<withKotlin externalannotations="${external.annotations.path}" modulename="kotlin-for-upsource"/>
|
||||
<skip pattern="kotlin/jvm/internal/.*"/>
|
||||
<src>
|
||||
<dirset dir="${basedir}/idea/ide-common" includes="src"/>
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
OUT:
|
||||
Buildfile: [TestData]/build.xml
|
||||
|
||||
build:
|
||||
[mkdir] Created dir: [Temp]/classes
|
||||
[javac] Compiling 1 source file to [Temp]/classes
|
||||
[javac] Compiling [[TestData]] => [[Temp]/classes]
|
||||
[javac] Running javac...
|
||||
[jar] Building jar: [Temp]/hello.jar
|
||||
[java] Module info 'META-INF/build.kotlin_module' exists
|
||||
|
||||
BUILD SUCCESSFUL
|
||||
Total time: [time]
|
||||
|
||||
Return code: 0
|
||||
@@ -0,0 +1,20 @@
|
||||
<project name="Ant Task Test" default="build">
|
||||
<taskdef resource="org/jetbrains/kotlin/ant/antlib.xml" classpath="${kotlin.lib}/kotlin-ant.jar"/>
|
||||
|
||||
<target name="build">
|
||||
<mkdir dir="${temp}/classes"/>
|
||||
<javac srcdir="${test.data}" destdir="${temp}/classes" includeantruntime="false">
|
||||
<withKotlin/>
|
||||
</javac>
|
||||
<jar destfile="${temp}/hello.jar">
|
||||
<fileset dir="${temp}/classes"/>
|
||||
</jar>
|
||||
|
||||
<java classname="hello.HelloPackage" fork="true">
|
||||
<classpath>
|
||||
<pathelement location="${temp}/hello.jar"/>
|
||||
<pathelement location="${kotlin.runtime.jar}"/>
|
||||
</classpath>
|
||||
</java>
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,11 @@
|
||||
package hello
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val systemClassLoader = ClassLoader.getSystemClassLoader()
|
||||
val moduleFile = "META-INF/build.kotlin_module"
|
||||
val resourceAsStream = systemClassLoader.getResourceAsStream(moduleFile)
|
||||
|
||||
if (resourceAsStream != null) {
|
||||
println("Module info '$moduleFile' exists")
|
||||
}
|
||||
}
|
||||
@@ -77,6 +77,12 @@ public class AntTaskTestGenerated extends AbstractAntTaskTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("moduleNameWithKotlin")
|
||||
public void testModuleNameWithKotlin() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/moduleNameWithKotlin/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("noStdlibForJavac")
|
||||
public void testNoStdlibForJavac() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/noStdlibForJavac/");
|
||||
|
||||
Reference in New Issue
Block a user