From 9f786611dcbb0dc6fc55c57b2ced34738cfec98e Mon Sep 17 00:00:00 2001 From: "Dmitriy.Panov" Date: Mon, 15 Jul 2019 16:03:29 +0300 Subject: [PATCH] executing Toolbox Lite-Gen on JBR11 GitOrigin-RevId: 6a1ded65ec65961ddde5e117d9e2fc16cf78fff2 --- .../build/ExternalPluginBundler.groovy | 2 +- .../intellij/build/BuildOptions.groovy | 3 +- .../intellij/build/GradleRunner.groovy | 51 +++++++++++++++---- .../intellij/build/impl/BuildTasksImpl.groovy | 2 +- .../build/impl/CompilationContextImpl.groovy | 2 +- 5 files changed, 47 insertions(+), 13 deletions(-) diff --git a/build/groovy/org/jetbrains/intellij/build/ExternalPluginBundler.groovy b/build/groovy/org/jetbrains/intellij/build/ExternalPluginBundler.groovy index 0715604f57d3..61bd36d9c356 100644 --- a/build/groovy/org/jetbrains/intellij/build/ExternalPluginBundler.groovy +++ b/build/groovy/org/jetbrains/intellij/build/ExternalPluginBundler.groovy @@ -10,7 +10,7 @@ class ExternalPluginBundler { String targetDirectory, String buildTaskName = pluginName) { def dependenciesProjectDir = new File(dependenciesPath) - new GradleRunner(dependenciesProjectDir, buildContext.messages, SystemProperties.getJavaHome()).run( + new GradleRunner(dependenciesProjectDir, buildContext.paths.projectHome, buildContext.messages, SystemProperties.getJavaHome()).run( "Downloading $pluginName plugin...", "setup${buildTaskName}Plugin") Properties properties = new Properties() new File(dependenciesProjectDir, "gradle.properties").withInputStream { diff --git a/platform/build-scripts/groovy/org/jetbrains/intellij/build/BuildOptions.groovy b/platform/build-scripts/groovy/org/jetbrains/intellij/build/BuildOptions.groovy index 5e73462765d7..2d94adca5f48 100644 --- a/platform/build-scripts/groovy/org/jetbrains/intellij/build/BuildOptions.groovy +++ b/platform/build-scripts/groovy/org/jetbrains/intellij/build/BuildOptions.groovy @@ -141,7 +141,8 @@ class BuildOptions { /** * Specifies Jetbrains JDK version to be used by build scripts, 8 by default. */ - int jdkVersion = System.getProperty("intellij.build.jdk.version", "8").toInteger() + static final String JDK_VERSION_OPTION = "intellij.build.jdk.version" + int jdkVersion = System.getProperty(JDK_VERSION_OPTION, "8").toInteger() /** * Specifies an algorithm to build distribution checksums. diff --git a/platform/build-scripts/groovy/org/jetbrains/intellij/build/GradleRunner.groovy b/platform/build-scripts/groovy/org/jetbrains/intellij/build/GradleRunner.groovy index 10d772a2b5cd..90f292811e19 100644 --- a/platform/build-scripts/groovy/org/jetbrains/intellij/build/GradleRunner.groovy +++ b/platform/build-scripts/groovy/org/jetbrains/intellij/build/GradleRunner.groovy @@ -16,30 +16,47 @@ package org.jetbrains.intellij.build import com.intellij.openapi.util.SystemInfo +import com.intellij.openapi.util.io.FileUtil import groovy.transform.CompileStatic +import org.jetbrains.jps.model.java.JdkVersionDetector @CompileStatic class GradleRunner { - private final File projectDir + private final File gradleProjectDir + private final String projectDir private final BuildMessages messages private final String javaHome + @Lazy + private volatile GradleRunner modularGradleRunner = { + createModularRunner() + }() - GradleRunner(File projectDir, BuildMessages messages, String javaHome) { + GradleRunner(File gradleProjectDir, String projectDir, BuildMessages messages, String javaHome) { this.messages = messages this.projectDir = projectDir + this.gradleProjectDir = gradleProjectDir this.javaHome = javaHome } /** - * Invokes Gradle tasks on {@link #projectDir} project. + * Invokes Gradle tasks on {@link #gradleProjectDir} project. * Logs error and stops the build process if Gradle process is failed. */ boolean run(String title, String... tasks) { return runInner(title, false, tasks) } - + /** - * Invokes Gradle tasks on {@link #projectDir} project. + * + * @see GradleRunner#run(java.lang.String, java.lang.String [ ]) + */ + boolean runWithModularRuntime(String title, String... tasks) { + if (isModularRuntime()) return run(title, tasks) + return modularGradleRunner.run(title, tasks) + } + + /** + * Invokes Gradle tasks on {@link #gradleProjectDir} project. * Ignores the result of running Gradle. */ boolean forceRun(String title, String... tasks) { @@ -67,24 +84,40 @@ class GradleRunner { private boolean runInner(String... tasks) { def gradleScript = SystemInfo.isWindows ? 'gradlew.bat' : 'gradlew' List command = new ArrayList() - command.add("${projectDir.absolutePath}/$gradleScript".toString()) + command.add("${gradleProjectDir.absolutePath}/$gradleScript".toString()) command.add("-Djava.io.tmpdir=${System.getProperty('java.io.tmpdir')}".toString()) - command.addAll(tasks) command.add('--stacktrace') if (System.getProperty("intellij.build.use.gradle.daemon", "false").toBoolean()) { command.add('--daemon') - } else { + } + else { command.add('--no-daemon') } def additionalParams = System.getProperty('intellij.gradle.jdk.build.parameters') if (additionalParams != null && !additionalParams.isEmpty()) { command.addAll(additionalParams.split(" ")) } - def processBuilder = new ProcessBuilder(command).directory(projectDir) + command.addAll(tasks) + def processBuilder = new ProcessBuilder(command).directory(gradleProjectDir) processBuilder.environment().put("JAVA_HOME", javaHome) def process = processBuilder.start() process.consumeProcessOutputStream((OutputStream)System.out) process.consumeProcessErrorStream((OutputStream)System.err) return process.waitFor() == 0 } + + private boolean isModularRuntime() { + return JdkVersionDetector.instance + .detectJdkVersionInfo(javaHome) + .@version.feature >= 11 + } + + private GradleRunner createModularRunner() { + if (isModularRuntime()) return this + run('Downloading JBR 11', 'setupJdks', "-D$BuildOptions.JDK_VERSION_OPTION=11") + def modularRuntime = "$projectDir/build/jdk/11" + if (SystemInfo.isMac) modularRuntime += '/Contents/Home' + modularRuntime = FileUtil.toSystemIndependentName(new File(modularRuntime).canonicalPath) + return new GradleRunner(gradleProjectDir, projectDir, messages, modularRuntime) + } } diff --git a/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/BuildTasksImpl.groovy b/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/BuildTasksImpl.groovy index c0be0fe46548..3fabf661af3a 100644 --- a/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/BuildTasksImpl.groovy +++ b/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/BuildTasksImpl.groovy @@ -392,7 +392,7 @@ idea.fatal.error.notification=disabled "-Pintellij.build.output=${buildContext.paths.buildOutputRoot}/toolbox-lite-gen", ] - buildContext.gradle.run('Run Toolbox LiteGen', liteGenArgs) + buildContext.gradle.runWithModularRuntime('Run Toolbox LiteGen', liteGenArgs) } } } diff --git a/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/CompilationContextImpl.groovy b/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/CompilationContextImpl.groovy index a87385ec735c..9094552778db 100644 --- a/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/CompilationContextImpl.groovy +++ b/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/CompilationContextImpl.groovy @@ -65,7 +65,7 @@ class CompilationContextImpl implements CompilationContext { def dependenciesProjectDir = new File(communityHome, 'build/dependencies') logFreeDiskSpace(messages, projectHome, "before downloading dependencies") def gradleJdk = toCanonicalPath(JdkUtils.computeJdkHome(messages, "jdk8Home", null, "JDK_18_x64")) - GradleRunner gradle = new GradleRunner(dependenciesProjectDir, messages, gradleJdk) + GradleRunner gradle = new GradleRunner(dependenciesProjectDir, projectHome, messages, gradleJdk) if (!options.isInDevelopmentMode) { setupCompilationDependencies(gradle, options) }