build scripts: add kotlin compiler jars to classpath inside the script to allow developers run gant build scripts directly from IDEA

This commit is contained in:
nik
2016-09-01 09:39:24 +03:00
parent b771c46894
commit bac1cc4a4e
2 changed files with 41 additions and 4 deletions
@@ -388,6 +388,8 @@ idea.fatal.error.notification=disabled
return
}
ensureKotlinCompilerAddedToClassPath()
buildContext.projectBuilder.cleanOutput()
if (moduleNames == null) {
buildContext.projectBuilder.buildProduction()
@@ -406,6 +408,24 @@ idea.fatal.error.notification=disabled
}
}
private void ensureKotlinCompilerAddedToClassPath() {
try {
Class.forName("org.jetbrains.kotlin.jps.build.KotlinBuilder")
return
}
catch (ClassNotFoundException ignored) {}
def kotlinPluginLibPath = "$buildContext.paths.communityHome/build/kotlinc/plugin/Kotlin/lib"
if (new File(kotlinPluginLibPath).exists()) {
["jps/kotlin-jps-plugin.jar", "kotlin-plugin.jar", "kotlin-runtime.jar"].each {
BuildUtils.addToJpsClassPath("$kotlinPluginLibPath/$it", buildContext.ant)
}
}
else {
buildContext.messages.error("Could not find Kotlin JARs at $kotlinPluginLibPath: run download_kotlin.gant script to download them")
}
}
private void runInParallel(List<BuildTaskRunnable> tasks) {
if (!buildContext.options.runBuildStepsInParallel) {
tasks.each {
@@ -18,9 +18,10 @@ package org.jetbrains.intellij.build.impl
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.text.StringUtil
import groovy.transform.CompileStatic
import org.apache.tools.ant.BuildException
import org.apache.tools.ant.Main
import org.apache.tools.ant.Project
import org.codehaus.gant.GantBinding
import org.codehaus.groovy.tools.RootLoader
/**
* @author nik
@@ -28,13 +29,29 @@ import org.codehaus.gant.GantBinding
@CompileStatic
class BuildUtils {
static void addToClassPath(String path, AntBuilder ant) {
def classLoader = (GroovyClassLoader)BuildUtils.class.classLoader
addToClassLoaderClassPath(path, ant, BuildUtils.class.classLoader)
}
static void addToJpsClassPath(String path, AntBuilder ant) {
//we need to add path to classloader of BuilderService to ensure that classes from that path will be returned by JpsServiceManager.getExtensions
addToClassLoaderClassPath(path, ant, Class.forName("org.jetbrains.jps.incremental.BuilderService").classLoader)
}
private static void addToClassLoaderClassPath(String path, AntBuilder ant, ClassLoader classLoader) {
if (new File(path).exists()) {
if (classLoader instanceof GroovyClassLoader) {
classLoader.addClasspath(path)
}
else if (classLoader instanceof RootLoader) {
classLoader.addURL(new File(path).toURI().toURL())
}
else {
throw new BuildException("Cannot add to classpath: non-groovy classloader $classLoader")
}
ant.project.log("'$path' added to classpath", Project.MSG_INFO)
classLoader.addClasspath(path)
}
else {
ant.project.log("Cannot add to classpath: $path doesn't exist", Project.MSG_WARN)
throw new BuildException("Cannot add to classpath: $path doesn't exist")
}
}