From bac1cc4a4e2ff40b7d29c6687fc5420dc1a2717d Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 1 Sep 2016 09:34:40 +0300 Subject: [PATCH] build scripts: add kotlin compiler jars to classpath inside the script to allow developers run gant build scripts directly from IDEA --- .../intellij/build/impl/BuildTasksImpl.groovy | 20 +++++++++++++++ .../intellij/build/impl/BuildUtils.groovy | 25 ++++++++++++++++--- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/build/groovy/org/jetbrains/intellij/build/impl/BuildTasksImpl.groovy b/build/groovy/org/jetbrains/intellij/build/impl/BuildTasksImpl.groovy index 6d03a54eca40..0f9d54819ded 100644 --- a/build/groovy/org/jetbrains/intellij/build/impl/BuildTasksImpl.groovy +++ b/build/groovy/org/jetbrains/intellij/build/impl/BuildTasksImpl.groovy @@ -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 tasks) { if (!buildContext.options.runBuildStepsInParallel) { tasks.each { diff --git a/build/groovy/org/jetbrains/intellij/build/impl/BuildUtils.groovy b/build/groovy/org/jetbrains/intellij/build/impl/BuildUtils.groovy index 7d2737ab416b..197a3abe9eba 100644 --- a/build/groovy/org/jetbrains/intellij/build/impl/BuildUtils.groovy +++ b/build/groovy/org/jetbrains/intellij/build/impl/BuildUtils.groovy @@ -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") } }