Improove the configuration time if the build (#41251)

This will help with reproduction lines and running tests form IDEs and
other operations that are quick and executed often enough for the
configuration time to matter.

Running Gradle with a FIPS JVM is not supproted, so if the runtime JVM
is the same one, no need to spend time checking for fips support.

Verification of the JAVA<version>_HOME env vars is now async and
parallel so it doesn't block configuration.
This commit is contained in:
Alpar Torok 2019-04-19 08:55:10 +03:00
parent c03394c236
commit 1f91759bc7
1 changed files with 41 additions and 20 deletions

View File

@ -61,6 +61,9 @@ import org.gradle.util.GradleVersion
import java.nio.charset.StandardCharsets
import java.time.ZoneOffset
import java.time.ZonedDateTime
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import java.util.concurrent.Future
import java.util.regex.Matcher
/**
@ -153,8 +156,12 @@ class BuildPlugin implements Plugin<Project> {
runtimeJavaVersionEnum = JavaVersion.toVersion(findJavaSpecificationVersion(project, runtimeJavaHome))
}
String inFipsJvmScript = 'print(java.security.Security.getProviders()[0].name.toLowerCase().contains("fips"));'
boolean inFipsJvm = Boolean.parseBoolean(runJavaAsScript(project, runtimeJavaHome, inFipsJvmScript))
boolean inFipsJvm = false
if (new File(runtimeJavaHome).canonicalPath != gradleJavaHome.canonicalPath) {
// We don't expect Gradle to be running in a FIPS JVM
String inFipsJvmScript = 'print(java.security.Security.getProviders()[0].name.toLowerCase().contains("fips"));'
inFipsJvm = Boolean.parseBoolean(runJavaAsScript(project, runtimeJavaHome, inFipsJvmScript))
}
// Build debugging info
println '======================================='
@ -190,24 +197,38 @@ class BuildPlugin implements Plugin<Project> {
throw new GradleException(message)
}
for (final Map.Entry<Integer, String> javaVersionEntry : javaVersions.entrySet()) {
final String javaHome = javaVersionEntry.getValue()
if (javaHome == null) {
continue
}
JavaVersion javaVersionEnum = JavaVersion.toVersion(findJavaSpecificationVersion(project, javaHome))
final JavaVersion expectedJavaVersionEnum
final int version = javaVersionEntry.getKey()
if (version < 9) {
expectedJavaVersionEnum = JavaVersion.toVersion("1." + version)
} else {
expectedJavaVersionEnum = JavaVersion.toVersion(Integer.toString(version))
}
if (javaVersionEnum != expectedJavaVersionEnum) {
final String message =
"the environment variable JAVA" + version + "_HOME must be set to a JDK installation directory for Java" +
" ${expectedJavaVersionEnum} but is [${javaHome}] corresponding to [${javaVersionEnum}]"
throw new GradleException(message)
ExecutorService exec = Executors.newFixedThreadPool(javaVersions.size())
Set<Future<Void>> results = new HashSet<>()
javaVersions.entrySet().stream()
.filter { it.getValue() != null }
.forEach { javaVersionEntry ->
results.add(exec.submit {
final String javaHome = javaVersionEntry.getValue()
final int version = javaVersionEntry.getKey()
if (project.file(javaHome).exists() == false) {
throw new GradleException("Invalid JAVA${version}_HOME=${javaHome} location does not exist")
}
JavaVersion javaVersionEnum = JavaVersion.toVersion(findJavaSpecificationVersion(project, javaHome))
final JavaVersion expectedJavaVersionEnum = version < 9 ?
JavaVersion.toVersion("1." + version) :
JavaVersion.toVersion(Integer.toString(version))
if (javaVersionEnum != expectedJavaVersionEnum) {
final String message =
"the environment variable JAVA" + version + "_HOME must be set to a JDK installation directory for Java" +
" ${expectedJavaVersionEnum} but is [${javaHome}] corresponding to [${javaVersionEnum}]"
throw new GradleException(message)
}
})
}
project.gradle.taskGraph.whenReady {
try {
results.forEach { it.get() }
} finally {
exec.shutdown();
}
}