Skip to content

Commit

Permalink
Merge branch 'master' into pr/28118
Browse files Browse the repository at this point in the history
* master: (94 commits)
  Completely remove Painless Type from AnalyzerCaster in favor of Java Class. (elastic#28329)
  Fix spelling error
  Reindex: Wait for deletion in test
  Reindex: log more on rare test failure
  Ensure we protect Collections obtained from scripts from self-referencing (elastic#28335)
  [Docs] Fix asciidoc style in composite agg docs
  Adds the ability to specify a format on composite date_histogram source (elastic#28310)
  Provide a better error message for the case when all shards failed (elastic#28333)
  [Test] Re-Add integer_range and date_range field types for query builder tests (elastic#28171)
  Added Put Mapping API to high-level Rest client (elastic#27869)
  Revert change that does not return all indices if a specific alias is requested via get alias api. (elastic#28294)
  Painless: Replace Painless Type with Java Class during Casts (elastic#27847)
  Notify affixMap settings when any under the registered prefix matches (elastic#28317)
  Trim down usages of `ShardOperationFailedException` interface (elastic#28312)
  Do not return all indices if a specific alias is requested via get aliases api.
  [Test] Lower bwc version for rank-eval rest tests
  CountedBitSet doesn't need to extend BitSet. (elastic#28239)
  Calculate sum in Kahan summation algorithm in aggregations (elastic#27807) (elastic#27848)
  Remove the `update_all_types` option. (elastic#28288)
  Add information when master node left to DiscoveryNodes' shortSummary() (elastic#28197)
  ...
  • Loading branch information
jasontedor committed Jan 24, 2018
2 parents e5b0201 + b945006 commit 630e98b
Show file tree
Hide file tree
Showing 537 changed files with 8,074 additions and 3,949 deletions.
12 changes: 10 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ Contributing to the Elasticsearch codebase

**Repository:** [https://github.com/elastic/elasticsearch](https://github.com/elastic/elasticsearch)

JDK 9 is required to build Elasticsearch. You must have a JDK 9 installation
with the environment variable `JAVA_HOME` referencing the path to Java home for
your JDK 9 installation. By default, tests use the same runtime as `JAVA_HOME`.
However, since Elasticsearch, supports JDK 8 the build supports compiling with
JDK 9 and testing on a JDK 8 runtime; to do this, set `RUNTIME_JAVA_HOME`
pointing to the Java home of a JDK 8 installation. Note that this mechanism can
be used to test against other JDKs as well, this is not only limited to JDK 8.

Elasticsearch uses the Gradle wrapper for its build. You can execute Gradle
using the wrapper via the `gradlew` script in the root of the repository.

Expand All @@ -118,8 +126,8 @@ Alternatively, `idea.no.launcher=true` can be set in the
[`idea.properties`](https://www.jetbrains.com/help/idea/file-idea-properties.html)
file which can be accessed under Help > Edit Custom Properties (this will require a
restart of IDEA). For IDEA 2017.3 and above, in addition to the JVM option, you will need to go to
`Run->Edit Configurations->...->Defaults->JUnit` and change the value for the `Shorten command line` setting from
`user-local default: none` to `classpath file`. You may also need to [remove `ant-javafx.jar` from your
`Run->Edit Configurations->...->Defaults->JUnit` and verify that the `Shorten command line` setting is set to
`user-local default: none`. You may also need to [remove `ant-javafx.jar` from your
classpath](https://github.com/elastic/elasticsearch/issues/14348) if that is
reported as a source of jar hell.

Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ subprojects {
"org.elasticsearch:rest-api-spec:${version}": ':rest-api-spec',
"org.elasticsearch:elasticsearch:${version}": ':server',
"org.elasticsearch:elasticsearch-cli:${version}": ':server:cli',
"org.elasticsearch:elasticsearch-core:${version}": ':libs:elasticsearch-core',
"org.elasticsearch:elasticsearch-nio:${version}": ':libs:elasticsearch-nio',
"org.elasticsearch.client:elasticsearch-rest-client:${version}": ':client:rest',
"org.elasticsearch.client:elasticsearch-rest-client-sniffer:${version}": ':client:sniffer',
Expand Down
126 changes: 69 additions & 57 deletions buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin
import org.gradle.api.publish.maven.tasks.GenerateMavenPom
import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.compile.GroovyCompile
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.api.tasks.javadoc.Javadoc
import org.gradle.internal.jvm.Jvm
Expand All @@ -56,7 +57,8 @@ import java.time.ZonedDateTime
*/
class BuildPlugin implements Plugin<Project> {

static final JavaVersion minimumJava = JavaVersion.VERSION_1_8
static final JavaVersion minimumRuntimeVersion = JavaVersion.VERSION_1_8
static final JavaVersion minimumCompilerVersion = JavaVersion.VERSION_1_9

@Override
void apply(Project project) {
Expand Down Expand Up @@ -93,20 +95,26 @@ class BuildPlugin implements Plugin<Project> {
/** Performs checks on the build environment and prints information about the build environment. */
static void globalBuildInfo(Project project) {
if (project.rootProject.ext.has('buildChecksDone') == false) {
String javaHome = findJavaHome()
String compilerJavaHome = findCompilerJavaHome()
String runtimeJavaHome = findRuntimeJavaHome(compilerJavaHome)
File gradleJavaHome = Jvm.current().javaHome
String javaVendor = System.getProperty('java.vendor')
String javaVersion = System.getProperty('java.version')
String gradleJavaVersionDetails = "${javaVendor} ${javaVersion}" +
" [${System.getProperty('java.vm.name')} ${System.getProperty('java.vm.version')}]"

String javaVersionDetails = gradleJavaVersionDetails
JavaVersion javaVersionEnum = JavaVersion.current()
if (new File(javaHome).canonicalPath != gradleJavaHome.canonicalPath) {
javaVersionDetails = findJavaVersionDetails(project, javaHome)
javaVersionEnum = JavaVersion.toVersion(findJavaSpecificationVersion(project, javaHome))
javaVendor = findJavaVendor(project, javaHome)
javaVersion = findJavaVersion(project, javaHome)
String compilerJavaVersionDetails = gradleJavaVersionDetails
JavaVersion compilerJavaVersionEnum = JavaVersion.current()
if (new File(compilerJavaHome).canonicalPath != gradleJavaHome.canonicalPath) {
compilerJavaVersionDetails = findJavaVersionDetails(project, compilerJavaHome)
compilerJavaVersionEnum = JavaVersion.toVersion(findJavaSpecificationVersion(project, compilerJavaHome))
}

String runtimeJavaVersionDetails = gradleJavaVersionDetails
JavaVersion runtimeJavaVersionEnum = JavaVersion.current()
if (new File(runtimeJavaHome).canonicalPath != gradleJavaHome.canonicalPath) {
runtimeJavaVersionDetails = findJavaVersionDetails(project, runtimeJavaHome)
runtimeJavaVersionEnum = JavaVersion.toVersion(findJavaSpecificationVersion(project, runtimeJavaHome))
}

// Build debugging info
Expand All @@ -115,11 +123,13 @@ class BuildPlugin implements Plugin<Project> {
println '======================================='
println " Gradle Version : ${project.gradle.gradleVersion}"
println " OS Info : ${System.getProperty('os.name')} ${System.getProperty('os.version')} (${System.getProperty('os.arch')})"
if (gradleJavaVersionDetails != javaVersionDetails) {
if (gradleJavaVersionDetails != compilerJavaVersionDetails || gradleJavaVersionDetails != runtimeJavaVersionDetails) {
println " JDK Version (gradle) : ${gradleJavaVersionDetails}"
println " JAVA_HOME (gradle) : ${gradleJavaHome}"
println " JDK Version (compile) : ${javaVersionDetails}"
println " JAVA_HOME (compile) : ${javaHome}"
println " JDK Version (compile) : ${compilerJavaVersionDetails}"
println " JAVA_HOME (compile) : ${compilerJavaHome}"
println " JDK Version (runtime) : ${runtimeJavaVersionDetails}"
println " JAVA_HOME (runtime) : ${runtimeJavaHome}"
} else {
println " JDK Version : ${gradleJavaVersionDetails}"
println " JAVA_HOME : ${gradleJavaHome}"
Expand All @@ -135,54 +145,49 @@ class BuildPlugin implements Plugin<Project> {
}

// enforce Java version
if (javaVersionEnum < minimumJava) {
throw new GradleException("Java ${minimumJava} or above is required to build Elasticsearch")
if (compilerJavaVersionEnum < minimumCompilerVersion) {
throw new GradleException("Java ${minimumCompilerVersion} or above is required to build Elasticsearch")
}

// this block of code detecting buggy JDK 8 compiler versions can be removed when minimum Java version is incremented
assert minimumJava == JavaVersion.VERSION_1_8 : "Remove JDK compiler bug detection only applicable to JDK 8"
if (javaVersionEnum == JavaVersion.VERSION_1_8) {
if (Objects.equals("Oracle Corporation", javaVendor)) {
def matcher = javaVersion =~ /1\.8\.0(?:_(\d+))?/
if (matcher.matches()) {
int update;
if (matcher.group(1) == null) {
update = 0
} else {
update = matcher.group(1).toInteger()
}
if (update < 40) {
throw new GradleException("JDK ${javaVendor} ${javaVersion} has compiler bug JDK-8052388, update your JDK to at least 8u40")
}
}
}
if (runtimeJavaVersionEnum < minimumRuntimeVersion) {
throw new GradleException("Java ${minimumRuntimeVersion} or above is required to run Elasticsearch")
}

project.rootProject.ext.javaHome = javaHome
project.rootProject.ext.javaVersion = javaVersionEnum
project.rootProject.ext.compilerJavaHome = compilerJavaHome
project.rootProject.ext.runtimeJavaHome = runtimeJavaHome
project.rootProject.ext.compilerJavaVersion = compilerJavaVersionEnum
project.rootProject.ext.runtimeJavaVersion = runtimeJavaVersionEnum
project.rootProject.ext.buildChecksDone = true
}
project.targetCompatibility = minimumJava
project.sourceCompatibility = minimumJava

project.targetCompatibility = minimumRuntimeVersion
project.sourceCompatibility = minimumRuntimeVersion

// set java home for each project, so they dont have to find it in the root project
project.ext.javaHome = project.rootProject.ext.javaHome
project.ext.javaVersion = project.rootProject.ext.javaVersion
project.ext.compilerJavaHome = project.rootProject.ext.compilerJavaHome
project.ext.runtimeJavaHome = project.rootProject.ext.runtimeJavaHome
project.ext.compilerJavaVersion = project.rootProject.ext.compilerJavaVersion
project.ext.runtimeJavaVersion = project.rootProject.ext.runtimeJavaVersion
}

/** Finds and enforces JAVA_HOME is set */
private static String findJavaHome() {
String javaHome = System.getenv('JAVA_HOME')
private static String findCompilerJavaHome() {
final String javaHome = System.getenv('JAVA_HOME')
if (javaHome == null) {
if (System.getProperty("idea.active") != null || System.getProperty("eclipse.launcher") != null) {
// intellij doesn't set JAVA_HOME, so we use the jdk gradle was run with
javaHome = Jvm.current().javaHome
// IntelliJ does not set JAVA_HOME, so we use the JDK that Gradle was run with
return Jvm.current().javaHome
} else {
throw new GradleException('JAVA_HOME must be set to build Elasticsearch')
throw new GradleException("JAVA_HOME must be set to build Elasticsearch")
}
}
return javaHome
}

private static String findRuntimeJavaHome(final String compilerJavaHome) {
assert compilerJavaHome != null
return System.getenv('RUNTIME_JAVA_HOME') ?: compilerJavaHome
}

/** Finds printable java version of the given JAVA_HOME */
private static String findJavaVersionDetails(Project project, String javaHome) {
String versionInfoScript = 'print(' +
Expand Down Expand Up @@ -412,19 +417,19 @@ class BuildPlugin implements Plugin<Project> {

/** Adds compiler settings to the project */
static void configureCompile(Project project) {
if (project.javaVersion < JavaVersion.VERSION_1_10) {
if (project.compilerJavaVersion < JavaVersion.VERSION_1_10) {
project.ext.compactProfile = 'compact3'
} else {
project.ext.compactProfile = 'full'
}
project.afterEvaluate {
project.tasks.withType(JavaCompile) {
File gradleJavaHome = Jvm.current().javaHome
final JavaVersion targetCompatibilityVersion = JavaVersion.toVersion(it.targetCompatibility)
// we fork because compiling lots of different classes in a shared jvm can eventually trigger GC overhead limitations
options.fork = true
options.forkOptions.executable = new File(project.javaHome, 'bin/javac')
options.forkOptions.javaHome = new File(project.compilerJavaHome)
options.forkOptions.memoryMaximumSize = "1g"
if (project.targetCompatibility >= JavaVersion.VERSION_1_8) {
if (targetCompatibilityVersion == JavaVersion.VERSION_1_8) {
// compile with compact 3 profile by default
// NOTE: this is just a compile time check: does not replace testing with a compact3 JRE
if (project.compactProfile != 'full') {
Expand All @@ -448,21 +453,25 @@ class BuildPlugin implements Plugin<Project> {
options.encoding = 'UTF-8'
options.incremental = true

if (project.javaVersion == JavaVersion.VERSION_1_9) {
// hack until gradle supports java 9's new "--release" arg
assert minimumJava == JavaVersion.VERSION_1_8
options.compilerArgs << '--release' << '8'
}
// TODO: use native Gradle support for --release when available (cf. https://github.com/gradle/gradle/issues/2510)
options.compilerArgs << '--release' << targetCompatibilityVersion.majorVersion
}
// also apply release flag to groovy, which is used in build-tools
project.tasks.withType(GroovyCompile) {
final JavaVersion targetCompatibilityVersion = JavaVersion.toVersion(it.targetCompatibility)
options.fork = true
options.forkOptions.javaHome = new File(project.compilerJavaHome)
options.compilerArgs << '--release' << targetCompatibilityVersion.majorVersion
}
}
}

static void configureJavadoc(Project project) {
project.tasks.withType(Javadoc) {
executable = new File(project.javaHome, 'bin/javadoc')
executable = new File(project.compilerJavaHome, 'bin/javadoc')
}
configureJavadocJar(project)
if (project.javaVersion == JavaVersion.VERSION_1_10) {
if (project.compilerJavaVersion == JavaVersion.VERSION_1_10) {
project.tasks.withType(Javadoc) { it.enabled = false }
project.tasks.getByName('javadocJar').each { it.enabled = false }
}
Expand Down Expand Up @@ -508,7 +517,7 @@ class BuildPlugin implements Plugin<Project> {
'X-Compile-Lucene-Version': VersionProperties.lucene,
'X-Compile-Elasticsearch-Snapshot': isSnapshot,
'Build-Date': ZonedDateTime.now(ZoneOffset.UTC),
'Build-Java-Version': project.javaVersion)
'Build-Java-Version': project.compilerJavaVersion)
if (jarTask.manifest.attributes.containsKey('Change') == false) {
logger.warn('Building without git revision id.')
jarTask.manifest.attributes('Change': 'Unknown')
Expand Down Expand Up @@ -545,7 +554,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 "${project.javaHome}/bin/java"
jvm "${project.runtimeJavaHome}/bin/java"
parallelism System.getProperty('tests.jvms', 'auto')
ifNoTests 'fail'
onNonEmptyWorkDirectory 'wipe'
Expand Down Expand Up @@ -650,7 +659,10 @@ class BuildPlugin implements Plugin<Project> {
Task precommit = PrecommitTasks.create(project, true)
project.check.dependsOn(precommit)
project.test.mustRunAfter(precommit)
project.dependencyLicenses.dependencies = project.configurations.runtime - project.configurations.provided
// only require dependency licenses for non-elasticsearch deps
project.dependencyLicenses.dependencies = project.configurations.runtime.fileCollection {
it.group.startsWith('org.elasticsearch') == false
} - project.configurations.provided
}

private static configureDependenciesInfo(Project project) {
Expand Down
Loading

0 comments on commit 630e98b

Please sign in to comment.