Skip to content

Commit

Permalink
Merge remote-tracking branch 'elastic/main' into fix-netty-leak
Browse files Browse the repository at this point in the history
  • Loading branch information
original-brownbear committed Jul 11, 2023
2 parents 1859bcf + a282aa3 commit a419261
Show file tree
Hide file tree
Showing 853 changed files with 13,355 additions and 5,012 deletions.
36 changes: 36 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,42 @@ node cannot continue to operate as a member of the cluster:

Errors like this should be very rare. When in doubt, prefer `WARN` to `ERROR`.

### Version numbers in the Elasticsearch codebase

Starting in 8.8.0, we have separated out the version number representations
of various aspects of Elasticsearch into their own classes, using their own
numbering scheme separate to release version. The main ones are
`TransportVersion` and `IndexVersion`, representing the version of the
inter-node binary protocol and index data + metadata respectively.

Separated version numbers are comprised of a simple incrementing number,
with no semantic versioning information. There is no direct mapping between
separated version numbers and the release version. The versions used by any
particular instance of Elasticsearch can be obtained by querying `/`
on the node.

#### Using separated version numbers

Whenever a change is made to a component versioned using a separated version
number, there are a few rules that need to be followed:

1. Each version number represents a specific modification to that component,
and should not be modified once it is defined. Each version is immutable
once merged into `main`.
2. To create a new component version, add a new constant to the respective class
using the preceding version number +1, modify the version id string to a new
unique string (normally a UUID), and set that constant as the new current
version.

The version ID string in the constant definition is not used in the executing
code; it is there to ensure that if two concurrent pull requests add the same
version constant, there will be a git conflict on those lines. This is to ensure
two PRs don't accidentally use the same version constant.

If your pull request has a conflict around your new version constant,
you need to update your PR from `main` and change your PR to use the next
available version number.

### Creating A Distribution

Run all build commands from within the root directory:
Expand Down
9 changes: 7 additions & 2 deletions benchmarks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ import org.elasticsearch.gradle.internal.info.BuildParams

apply plugin: 'elasticsearch.java'
apply plugin: 'application'
mainClassName = 'org.openjdk.jmh.Main'

application {
mainClass = 'org.openjdk.jmh.Main'
}

tasks.named("assemble").configure { enabled = false }
archivesBaseName = 'elasticsearch-benchmarks'
base {
archivesName = 'elasticsearch-benchmarks'
}

tasks.named("test").configure { enabled = false }

Expand Down
6 changes: 4 additions & 2 deletions build-conventions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ plugins {
group = "org.elasticsearch"

// This project contains Checkstyle rule implementations used by IDEs which use a Java 11 runtime
targetCompatibility = 11
sourceCompatibility = 11
java {
targetCompatibility = 11
sourceCompatibility = 11
}

gradlePlugin {
// We already configure publication and we don't need or want the one that comes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,11 @@
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.inject.Inject;
import java.io.Serializable;

import javax.inject.Inject;

/**
* Checks files for license headers..
*/
Expand Down Expand Up @@ -193,9 +189,8 @@ public void runRat() {
boolean unApprovedLicenses = stats.getNumUnApproved() > 0;
if (unknownLicenses || unApprovedLicenses) {
getLogger().error("The following files contain unapproved license headers:");
unapprovedFiles(repFile).stream().forEachOrdered(unapprovedFile -> getLogger().error(unapprovedFile));
throw new GradleException("Check failed. License header problems were found. Full details: " +
repFile.getAbsolutePath());
unapprovedFiles(repFile).forEach(getLogger()::error);
throw new GradleException("Check failed. License header problems were found. Full details: " + repFile.getAbsolutePath());
}
}

Expand Down
11 changes: 9 additions & 2 deletions build-tools-internal/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ gradlePlugin {
id = 'elasticsearch.standalone-test'
implementationClass = 'org.elasticsearch.gradle.internal.test.StandaloneTestPlugin'
}
stringTemplate {
id = 'elasticsearch.string-templates'
implementationClass = 'org.elasticsearch.gradle.internal.StringTemplatePlugin'
}
testFixtures {
id = 'elasticsearch.test.fixtures'
implementationClass = 'org.elasticsearch.gradle.internal.testfixtures.TestFixturesPlugin'
Expand Down Expand Up @@ -199,8 +203,10 @@ gradlePlugin {
*****************************************************************************/

def minCompilerJava = versions.get("minimumCompilerJava")
targetCompatibility = minCompilerJava
sourceCompatibility = minCompilerJava
java {
targetCompatibility = minCompilerJava
sourceCompatibility = minCompilerJava
}

if (JavaVersion.current() < JavaVersion.toVersion(minCompilerJava)) {
throw new GradleException("Java ${minCompilerJava} is required to build Elasticsearch but current Java is version ${JavaVersion.current()}.")
Expand Down Expand Up @@ -269,6 +275,7 @@ dependencies {
// needs to match the jackson minor version in use
api buildLibs.json.schema.validator
api buildLibs.jackson.dataformat.yaml
api buildLibs.antlrst4
api buildLibs.asm
api buildLibs.asm.tree
api buildLibs.httpclient
Expand Down
5 changes: 3 additions & 2 deletions build-tools-internal/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=5625a0ae20fe000d9225d000b36909c7a0e0e8dda61c19b12da769add847c975
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-all.zip
distributionSha256Sum=5022b0b25fe182b0e50867e77f484501dba44feeea88f5c1f13b6b4660463640
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.gradle.internal;

import org.elasticsearch.gradle.fixtures.AbstractGradleFuncTest;
import org.gradle.testkit.runner.TaskOutcome;

class StringTemplatePluginTest extends AbstractGradleFuncTest {

def "test substitution"() {
given:
internalBuild()
file('src/main/p/X-Box.java.st') << """
public class \$Type\$Box {
final \$type\$ value;
public \$Type\$Box(\$type\$ value) {
this.value = value;
}
}
""".stripIndent().stripTrailing()
file('src/main/generated-src/someFile.txt') << """
Just some random data
"""

buildFile << """
apply plugin: 'elasticsearch.build'
apply plugin: 'elasticsearch.string-templates'
tasks.named("stringTemplates").configure {
template {
it.properties = ["Type" : "Int", "type" : "int"]
it.inputFile = new File("${projectDir}/src/main/p/X-Box.java.st")
it.outputFile = "p/IntBox.java"
}
template {
it.properties = ["Type" : "Long", "type" : "long"]
it.inputFile = new File("${projectDir}/src/main/p/X-Box.java.st")
it.outputFile = "p/LongBox.java"
}
}
"""

when:
def result = gradleRunner("stringTemplates", '-g', gradleUserHome).build()

then:
result.task(":stringTemplates").outcome == TaskOutcome.SUCCESS
file("src/main/generated-src/someFile.txt").exists() == false
file("src/main/generated-src/p/IntBox.java").exists()
file("src/main/generated-src/p/LongBox.java").exists()

//assert output
normalized(file("src/main/generated-src/p/IntBox.java").text) == """
public class IntBox {
final int value;
public IntBox(int value) {
this.value = value;
}
}
""".stripIndent().stripTrailing()
normalized(file("src/main/generated-src/p/LongBox.java").text) == """
public class LongBox {
final long value;
public LongBox(long value) {
this.value = value;
}
}
""".stripIndent().stripTrailing()
}

def "test basic conditional"() {
given:
internalBuild()
file('src/main/Color.txt.st') << """
\$if(Red)\$1 Red\$endif\$
\$if(Blue)\$2 Blue\$endif\$
\$if(Green)\$3 Green\$endif\$
""".stripIndent().stripTrailing()

buildFile << """
apply plugin: 'elasticsearch.build'
apply plugin: 'elasticsearch.string-templates'
tasks.named("stringTemplates").configure {
template {
it.properties = ["Red" : "true", "Blue" : "", "Green" : "true"]
it.inputFile = new File("${projectDir}/src/main/Color.txt.st")
it.outputFile = "Color.txt"
}
}
"""

when:
def result = gradleRunner("stringTemplates", '-g', gradleUserHome).build()

then:
result.task(":stringTemplates").outcome == TaskOutcome.SUCCESS
file("src/main/generated-src/Color.txt").exists()
//assert output
normalized(file("src/main/generated-src/Color.txt").text) == """
1 Red
3 Green
""".stripIndent().stripTrailing()
}

def "test if then else"() {
given:
internalBuild()
file('src/main/Token.txt.st') << """
\$if(Foo)\$1 Foo
\$elseif(Bar)\$2 Bar
\$else\$3 Baz
\$endif\$
""".stripIndent().stripTrailing()

buildFile << """
apply plugin: 'elasticsearch.build'
apply plugin: 'elasticsearch.string-templates'
tasks.named("stringTemplates").configure {
template {
it.properties = [:] // no properties
it.inputFile = new File("${projectDir}/src/main/Token.txt.st")
it.outputFile = "Token.txt"
}
}
"""

when:
def result = gradleRunner("stringTemplates", '-g', gradleUserHome).build()

then:
result.task(":stringTemplates").outcome == TaskOutcome.SUCCESS
file("src/main/generated-src/Token.txt").exists()
//assert output
normalized(file("src/main/generated-src/Token.txt").text) == """
3 Baz
""".stripIndent().stripTrailing()
}

def "output file already present and up to date"() {
given:
internalBuild()
file('src/main/UpToDate.txt.st') << """
Hello World!
""".stripIndent().stripTrailing()
// the output file is already created and up to date (content wise)
file('src/main/generated-src/UpToDate.txt') << """
Hello World!
""".stripIndent().stripTrailing()

buildFile << """
apply plugin: 'elasticsearch.build'
apply plugin: 'elasticsearch.string-templates'
tasks.named("stringTemplates").configure {
template {
it.properties = [:] // no properties
it.inputFile = new File("${projectDir}/src/main/UpToDate.txt.st")
it.outputFile = "UpToDate.txt"
}
}
"""

when:
def result = gradleRunner("stringTemplates", '-g', gradleUserHome).build()

then:
result.task(":stringTemplates").outcome == TaskOutcome.SUCCESS
file("src/main/generated-src/UpToDate.txt").exists()
//assert output - expect the original output
normalized(file("src/main/generated-src/UpToDate.txt").text) == """
Hello World!
""".stripIndent().stripTrailing()
}

def "output file already present but not up to date"() {
given:
internalBuild()
file('src/main/Message.txt.st') << """
Hello World!
""".stripIndent().stripTrailing()
// the output file is already created, but not up to date (content wise)
file('src/main/generated-src/Message.txt') << """
Hello Chris xx
""".stripIndent().stripTrailing()

buildFile << """
apply plugin: 'elasticsearch.build'
apply plugin: 'elasticsearch.string-templates'
tasks.named("stringTemplates").configure {
template {
it.properties = [:] // no properties
it.inputFile = new File("${projectDir}/src/main/Message.txt.st")
it.outputFile = "Message.txt"
}
}
"""

when:
def result = gradleRunner("stringTemplates", '-g', gradleUserHome).build()

then:
result.task(":stringTemplates").outcome == TaskOutcome.SUCCESS
file("src/main/generated-src/Message.txt").exists()
//assert output - expect the updated message output
normalized(file("src/main/generated-src/Message.txt").text) == """
Hello World!
""".stripIndent().stripTrailing()
}

def "cleanup delete files"() {
given:
internalBuild()
file('src/main/generated-src/someFile.txt') << """
Just some random data
"""

buildFile << """
apply plugin: 'elasticsearch.build'
apply plugin: 'elasticsearch.string-templates'
tasks.named("stringTemplates").configure {
// no templates
}
"""

when:
def result = gradleRunner("stringTemplates", '-g', gradleUserHome).build()

then:
result.task(":stringTemplates").outcome == TaskOutcome.SUCCESS
file("src/main/generated-src/someFile.txt").exists() == false
file("src/main/generated-src").exists() == true
}
}
Loading

0 comments on commit a419261

Please sign in to comment.