Merge pull request #14717 from rjernst/force_java_home

Enforce JAVA_HOME is set
This commit is contained in:
Ryan Ernst 2015-11-12 10:45:33 -08:00
commit aae60e5b6e
4 changed files with 32 additions and 14 deletions

View File

@ -136,6 +136,9 @@ if (projectsPrefix.isEmpty()) {
vcs = 'Git'
}
}
tasks.cleanIdea {
delete '.idea'
}
}
// eclipse configuration
@ -154,19 +157,17 @@ allprojects {
}
}
}
task cleanEclipseSettings(type: Delete) {
delete '.settings'
}
task copyEclipseSettings(type: Copy) {
// TODO: "package this up" for external builds
from new File(project.rootDir, 'buildSrc/src/main/resources/eclipse.settings')
into '.settings'
}
// otherwise .settings is not nuked entirely
tasks.cleanEclipse.dependsOn(cleanEclipseSettings)
tasks.cleanEclipse {
delete '.settings'
}
// otherwise the eclipse merging is *super confusing*
tasks.eclipse.dependsOn(cleanEclipse)
tasks.eclipse.dependsOn(copyEclipseSettings)
tasks.eclipse.dependsOn(cleanEclipse, copyEclipseSettings)
}
// add buildSrc itself as a groovy project

View File

@ -28,6 +28,7 @@ import org.gradle.api.Task
import org.gradle.api.artifacts.dsl.RepositoryHandler
import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.internal.jvm.Jvm
import org.gradle.util.GradleVersion
/**
@ -60,12 +61,15 @@ class BuildPlugin implements Plugin<Project> {
static void globalBuildInfo(Project project) {
if (project.rootProject.ext.has('buildChecksDone') == false) {
String javaHome = System.getenv('JAVA_HOME')
// Build debugging info
println '======================================='
println 'Elasticsearch Build Hamster says Hello!'
println '======================================='
println " Gradle Version : ${project.gradle.gradleVersion}"
println " JDK Version : ${System.getProperty('java.runtime.version')} (${System.getProperty('java.vendor')})"
println " JAVA_HOME : ${javaHome == null ? 'not set' : javaHome}"
println " OS Info : ${System.getProperty('os.name')} ${System.getProperty('os.version')} (${System.getProperty('os.arch')})"
// enforce gradle version
@ -79,10 +83,22 @@ class BuildPlugin implements Plugin<Project> {
throw new GradleException("Java ${minimumJava} or above is required to build Elasticsearch")
}
// find java home so eg tests can use it to set java to run with
if (javaHome == null) {
if (System.getProperty("idea.active") != null) {
// intellij doesn't set JAVA_HOME, so we use the jdk gradle was run with
javaHome = Jvm.current().javaHome
} else {
throw new GradleException('JAVA_HOME must be set to build Elasticsearch')
}
}
project.rootProject.ext.javaHome = javaHome
project.rootProject.ext.buildChecksDone = true
}
project.targetCompatibility = minimumJava
project.sourceCompatibility = minimumJava
// set java home for each project, so they dont have to find it in the root project
project.ext.javaHome = project.rootProject.ext.javaHome
}
/** Makes dependencies non-transitive by default */
@ -146,7 +162,7 @@ class BuildPlugin implements Plugin<Project> {
/** Returns a closure of common configuration shared by unit and integration tests. */
static Closure commonTestConfig(Project project) {
return {
jvm System.getProperty("java.home") + File.separator + 'bin' + File.separator + 'java'
jvm "${project.javaHome}/bin/java"
parallelism System.getProperty('tests.jvms', 'auto')
// TODO: why are we not passing maxmemory to junit4?

View File

@ -213,7 +213,7 @@ class ClusterFormationTasks {
/** Adds a task to start an elasticsearch node with the given configuration */
static Task configureStartTask(String name, Project project, Task setup, File cwd, ClusterConfiguration config, String clusterName, File pidFile, File home) {
Map esEnv = [
'JAVA_HOME' : System.getProperty('java.home'),
'JAVA_HOME' : project.javaHome,
'ES_GC_OPTS': config.jvmArgs
]
List esProps = config.systemProperties.collect { key, value -> "-D${key}=${value}" }
@ -288,9 +288,9 @@ class ClusterFormationTasks {
ext.pid = "${ -> pidFile.getText('UTF-8').trim()}"
File jps
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
jps = getJpsExecutableByName("jps.exe")
jps = getJpsExecutableByName(project, "jps.exe")
} else {
jps = getJpsExecutableByName("jps")
jps = getJpsExecutableByName(project, "jps")
}
if (!jps.exists()) {
throw new GradleException("jps executable not found; ensure that you're running Gradle with the JDK rather than the JRE")
@ -313,8 +313,8 @@ class ClusterFormationTasks {
}
}
private static File getJpsExecutableByName(String jpsExecutableName) {
return Paths.get(Jvm.current().javaHome.toString(), "bin/" + jpsExecutableName).toFile()
private static File getJpsExecutableByName(Project project, String jpsExecutableName) {
return Paths.get(project.javaHome.toString(), "bin/" + jpsExecutableName).toFile()
}
/** Adds a task to kill an elasticsearch node with the given pidfile */

View File

@ -32,11 +32,12 @@ class StandaloneTestBasePlugin implements Plugin<Project> {
@Override
void apply(Project project) {
BuildPlugin.configureRepositories(project)
project.pluginManager.apply(JavaBasePlugin)
project.pluginManager.apply(RandomizedTestingPlugin)
BuildPlugin.globalBuildInfo(project)
BuildPlugin.configureRepositories(project)
// remove some unnecessary tasks for a qa test
project.tasks.removeAll { it.name in ['assemble', 'buildDependents'] }