Skip to content

Commit

Permalink
Merge remote-tracking branch 'elastic/master' into ccr
Browse files Browse the repository at this point in the history
* elastic/master:
  Number of utilities for writing gradle integration tests (#32282)
  Determine the minimum gradle version based on the wrapper (#32226)
  Enable FIPS JVM in CI (#32330)
  Fix JarHell on X-Pack protocol
  • Loading branch information
jasontedor committed Jul 25, 2018
2 parents d2d7841 + 6aea829 commit 02c2268
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 19 deletions.
1 change: 1 addition & 0 deletions .ci/matrix-runtime-javas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@

ES_RUNTIME_JAVA:
- java8
- java8fips
- java10
- java11
14 changes: 7 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/

import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
import org.apache.tools.ant.taskdefs.condition.Os
import org.apache.tools.ant.filters.ReplaceTokens
import org.elasticsearch.gradle.BuildPlugin
import org.elasticsearch.gradle.LoggedExec
import org.elasticsearch.gradle.Version
import org.elasticsearch.gradle.VersionCollection
import org.elasticsearch.gradle.VersionProperties
import org.gradle.plugins.ide.eclipse.model.SourceFolder

import org.gradle.api.tasks.wrapper.Wrapper
import org.gradle.api.tasks.wrapper.Wrapper.DistributionType
import org.gradle.util.GradleVersion
import org.gradle.util.DistributionLocator
import org.apache.tools.ant.taskdefs.condition.Os
import org.apache.tools.ant.filters.ReplaceTokens

import java.nio.file.Files
import java.nio.file.Path
Expand Down Expand Up @@ -562,7 +558,7 @@ task run(type: Run) {
}

wrapper {
distributionType = DistributionType.ALL
distributionType = 'ALL'
doLast {
final DistributionLocator locator = new DistributionLocator()
final GradleVersion version = GradleVersion.version(wrapper.gradleVersion)
Expand All @@ -571,6 +567,10 @@ wrapper {
final String sha256Sum = new String(sha256Uri.toURL().bytes)
wrapper.getPropertiesFile() << "distributionSha256Sum=${sha256Sum}\n"
println "Added checksum to wrapper properties"
// Update build-tools to reflect the Gradle upgrade
// TODO: we can remove this once we have tests to make sure older versions work.
project(':build-tools').file('src/main/resources/minimumGradleVersion').text = gradleVersion
println "Updated minimum Gradle Version"
}
}

Expand Down
5 changes: 3 additions & 2 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ plugins {

group = 'org.elasticsearch.gradle'

if (GradleVersion.current() < GradleVersion.version('4.9')) {
throw new GradleException('Gradle 4.9+ is required to build elasticsearch')
String minimumGradleVersion = file('src/main/resources/minimumGradleVersion').text.trim()
if (GradleVersion.current() < GradleVersion.version(minimumGradleVersion)) {
throw new GradleException("Gradle ${minimumGradleVersion}+ is required to build elasticsearch")
}

if (JavaVersion.current() < JavaVersion.VERSION_1_8) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package org.elasticsearch.gradle

import com.carrotsearch.gradle.junit4.RandomizedTestingTask
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
import org.apache.commons.io.IOUtils
import org.apache.tools.ant.taskdefs.condition.Os
import org.eclipse.jgit.lib.Constants
import org.eclipse.jgit.lib.RepositoryBuilder
Expand Down Expand Up @@ -53,6 +54,7 @@ import org.gradle.internal.jvm.Jvm
import org.gradle.process.ExecResult
import org.gradle.util.GradleVersion

import java.nio.charset.StandardCharsets
import java.time.ZoneOffset
import java.time.ZonedDateTime
/**
Expand All @@ -67,8 +69,13 @@ class BuildPlugin implements Plugin<Project> {
+ 'elasticearch.standalone-rest-test, and elasticsearch.build '
+ 'are mutually exclusive')
}
if (GradleVersion.current() < GradleVersion.version('4.9')) {
throw new GradleException('Gradle 4.9+ is required to use elasticsearch.build plugin')
final String minimumGradleVersion
InputStream is = getClass().getResourceAsStream("/minimumGradleVersion")
try { minimumGradleVersion = IOUtils.toString(is, StandardCharsets.UTF_8.toString()) } finally { is.close() }
if (GradleVersion.current() < GradleVersion.version(minimumGradleVersion.trim())) {
throw new GradleException(
"Gradle ${minimumGradleVersion}+ is required to use elasticsearch.build plugin"
)
}
project.pluginManager.apply('java')
project.pluginManager.apply('carrotsearch.randomized-testing')
Expand Down Expand Up @@ -153,14 +160,6 @@ class BuildPlugin implements Plugin<Project> {
}
println " Random Testing Seed : ${project.testSeed}"

// enforce Gradle version
final GradleVersion currentGradleVersion = GradleVersion.current();

final GradleVersion minGradle = GradleVersion.version('4.3')
if (currentGradleVersion < minGradle) {
throw new GradleException("${minGradle} or above is required to build Elasticsearch")
}

// enforce Java version
if (compilerJavaVersionEnum < minimumCompilerVersion) {
final String message =
Expand Down
1 change: 1 addition & 0 deletions buildSrc/src/main/resources/minimumGradleVersion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.9
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package org.elasticsearch.gradle.test;

import org.gradle.testkit.runner.GradleRunner;

import java.io.File;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public abstract class GradleIntegrationTestCase extends GradleUnitTestCase {

Expand All @@ -13,4 +18,47 @@ protected File getProjectDir(String name) {
return new File(root, name);
}

protected GradleRunner getGradleRunner(String sampleProject) {
return GradleRunner.create()
.withProjectDir(getProjectDir(sampleProject))
.withPluginClasspath();
}

protected File getBuildDir(String name) {
return new File(getProjectDir(name), "build");
}

protected void assertOutputContains(String output, String... lines) {
for (String line : lines) {
assertOutputContains(output, line);
}
List<Integer> index = Stream.of(lines).map(line -> output.indexOf(line)).collect(Collectors.toList());
if (index.equals(index.stream().sorted().collect(Collectors.toList())) == false) {
fail("Expected the following lines to appear in this order:\n" +
Stream.of(lines).map(line -> " - `" + line + "`").collect(Collectors.joining("\n")) +
"\nBut they did not. Output is:\n\n```" + output + "\n```\n"
);
}
}

protected void assertOutputContains(String output, String line) {
assertTrue(
"Expected the following line in output:\n\n" + line + "\n\nOutput is:\n" + output,
output.contains(line)
);
}

protected void assertOutputDoesNotContain(String output, String line) {
assertFalse(
"Expected the following line not to be in output:\n\n" + line + "\n\nOutput is:\n" + output,
output.contains(line)
);
}

protected void assertOutputDoesNotContain(String output, String... lines) {
for (String line : lines) {
assertOutputDoesNotContain(line);
}
}

}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.

0 comments on commit 02c2268

Please sign in to comment.