Ant task: use preloader instead of AntClassLoader
Speeds up AntTaskJvmTest by 50%
This commit is contained in:
@@ -9,5 +9,6 @@
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="ant-1.7" level="project" />
|
||||
<orderEntry type="library" name="kotlin-runtime" level="project" />
|
||||
<orderEntry type="module" module-name="preloader" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -25,13 +25,13 @@ import org.apache.tools.ant.types.Commandline
|
||||
import java.io.PrintStream
|
||||
import org.apache.tools.ant.AntClassLoader
|
||||
import java.lang.ref.SoftReference
|
||||
import org.apache.tools.ant.Project
|
||||
import org.jetbrains.jet.preloading.ClassPreloadingUtils
|
||||
import java.net.JarURLConnection
|
||||
|
||||
object CompilerClassLoaderHolder {
|
||||
private var classLoaderRef = SoftReference<ClassLoader?>(null)
|
||||
|
||||
synchronized fun getOrCreateClassLoader(project: Project?): ClassLoader {
|
||||
synchronized fun getOrCreateClassLoader(): ClassLoader {
|
||||
val cached = classLoaderRef.get()
|
||||
if (cached != null) return cached
|
||||
|
||||
@@ -49,7 +49,7 @@ object CompilerClassLoaderHolder {
|
||||
throw IllegalStateException("kotlin-compiler.jar is not found in the directory of Kotlin Ant task")
|
||||
}
|
||||
|
||||
val classLoader = AntClassLoader(myLoader, project, Path(project, compilerJarPath.path), /* parentFirst = */ false)
|
||||
val classLoader = ClassPreloadingUtils.preloadClasses(listOf(compilerJarPath), 4096, myLoader, null)
|
||||
classLoaderRef = SoftReference(classLoader)
|
||||
|
||||
return classLoader
|
||||
@@ -112,7 +112,7 @@ public abstract class KotlinCompilerBaseTask : Task() {
|
||||
final override fun execute() {
|
||||
fillArguments()
|
||||
|
||||
val compilerClass = CompilerClassLoaderHolder.getOrCreateClassLoader(project).loadClass(compilerFqName)
|
||||
val compilerClass = CompilerClassLoaderHolder.getOrCreateClassLoader().loadClass(compilerFqName)
|
||||
val compiler = compilerClass.newInstance()
|
||||
val exec = compilerClass.getMethod("execFullPathsInMessages", javaClass<PrintStream>(), javaClass<Array<String>>())
|
||||
|
||||
|
||||
@@ -641,7 +641,8 @@
|
||||
<compilerarg value="-Xlint:all"/>
|
||||
<classpath>
|
||||
<file file="${kotlin-home}/lib/${compiler.manifest.class.path}"/>
|
||||
<fileset dir="${dependencies.dir}/ant-1.7/lib" includes="ant.jar"/>
|
||||
<pathelement location="${dependencies.dir}/ant-1.7/lib/ant.jar"/>
|
||||
<pathelement location="${kotlin-home}/lib/kotlin-preloader.jar"/>
|
||||
</classpath>
|
||||
</javac2>
|
||||
|
||||
@@ -657,7 +658,7 @@
|
||||
<attribute name="Implementation-Title" value="${manifest.impl.title.kotlin.compiler.ant.task}"/>
|
||||
<attribute name="Implementation-Version" value="${build.number}"/>
|
||||
|
||||
<attribute name="Class-Path" value="${compiler.manifest.class.path}"/>
|
||||
<attribute name="Class-Path" value="${compiler.manifest.class.path} kotlin-preloader.jar"/>
|
||||
</manifest>
|
||||
</jar>
|
||||
</target>
|
||||
|
||||
Reference in New Issue
Block a user