Skip to content

Commit e06598b

Browse files
committed
Merge remote-tracking branch 'es/master' into enrich
2 parents abdbd84 + 869cd6c commit e06598b

File tree

412 files changed

+6668
-4211
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

412 files changed

+6668
-4211
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/DependenciesInfoTask.groovy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import org.gradle.api.internal.ConventionTask
2727
import org.gradle.api.tasks.Input
2828
import org.gradle.api.tasks.InputDirectory
2929
import org.gradle.api.tasks.InputFiles
30+
import org.gradle.api.tasks.Optional
3031
import org.gradle.api.tasks.OutputFile
3132
import org.gradle.api.tasks.TaskAction
3233

@@ -53,8 +54,9 @@ class DependenciesInfoTask extends ConventionTask {
5354
Configuration compileOnlyConfiguration
5455

5556
/** Directory to read license files */
57+
@Optional
5658
@InputDirectory
57-
File licensesDir = new File(project.projectDir, 'licenses')
59+
File licensesDir = new File(project.projectDir, 'licenses').exists() ? new File(project.projectDir, 'licenses') : null
5860

5961
@OutputFile
6062
File outputFile = new File(project.buildDir, "reports/dependencies/dependencies.csv")
@@ -134,7 +136,7 @@ class DependenciesInfoTask extends ConventionTask {
134136
protected String getLicenseType(final String group, final String name) {
135137
File license
136138

137-
if (licensesDir.exists()) {
139+
if (licensesDir != null) {
138140
licensesDir.eachFileMatch({ it ==~ /.*-LICENSE.*/ }) { File file ->
139141
String prefix = file.name.split('-LICENSE.*')[0]
140142
if (group.contains(prefix) || name.contains(prefix)) {

buildSrc/src/main/java/org/elasticsearch/gradle/DistributionDownloadPlugin.java

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.elasticsearch.gradle.ElasticsearchDistribution.Flavor;
2323
import org.elasticsearch.gradle.ElasticsearchDistribution.Platform;
2424
import org.elasticsearch.gradle.ElasticsearchDistribution.Type;
25+
import org.elasticsearch.gradle.tool.ClasspathUtils;
2526
import org.gradle.api.GradleException;
2627
import org.gradle.api.NamedDomainObjectContainer;
2728
import org.gradle.api.Plugin;
@@ -56,7 +57,9 @@ public class DistributionDownloadPlugin implements Plugin<Project> {
5657

5758
private static final String CONTAINER_NAME = "elasticsearch_distributions";
5859
private static final String FAKE_IVY_GROUP = "elasticsearch-distribution";
60+
private static final String FAKE_SNAPSHOT_IVY_GROUP = "elasticsearch-distribution-snapshot";
5961
private static final String DOWNLOAD_REPO_NAME = "elasticsearch-downloads";
62+
private static final String SNAPSHOT_REPO_NAME = "elasticsearch-snapshots";
6063

6164
private BwcVersions bwcVersions;
6265
private NamedDomainObjectContainer<ElasticsearchDistribution> distributionsContainer;
@@ -72,9 +75,10 @@ public void apply(Project project) {
7275

7376
setupDownloadServiceRepo(project);
7477

75-
ExtraPropertiesExtension extraProperties = project.getExtensions().getExtraProperties();
76-
this.bwcVersions = (BwcVersions) extraProperties.get("bwcVersions");
77-
// TODO: setup snapshot dependency instead of pointing to bwc distribution projects for external projects
78+
if (ClasspathUtils.isElasticsearchProject(project)) {
79+
ExtraPropertiesExtension extraProperties = project.getExtensions().getExtraProperties();
80+
this.bwcVersions = (BwcVersions) extraProperties.get("bwcVersions");
81+
}
7882

7983
project.afterEvaluate(this::setupDistributions);
8084
}
@@ -148,13 +152,10 @@ private void setupRootDownload(Project rootProject, ElasticsearchDistribution di
148152
}
149153
}
150154

151-
private static void setupDownloadServiceRepo(Project project) {
152-
if (project.getRepositories().findByName(DOWNLOAD_REPO_NAME) != null) {
153-
return;
154-
}
155+
private static void addIvyRepo(Project project, String name, String url, String group) {
155156
project.getRepositories().ivy(ivyRepo -> {
156-
ivyRepo.setName(DOWNLOAD_REPO_NAME);
157-
ivyRepo.setUrl("https://artifacts.elastic.co");
157+
ivyRepo.setName(name);
158+
ivyRepo.setUrl(url);
158159
ivyRepo.metadataSources(IvyArtifactRepository.MetadataSources::artifact);
159160
// this header is not a credential but we hack the capability to send this header to avoid polluting our download stats
160161
ivyRepo.credentials(HttpHeaderCredentials.class, creds -> {
@@ -163,15 +164,25 @@ private static void setupDownloadServiceRepo(Project project) {
163164
});
164165
ivyRepo.getAuthentication().create("header", HttpHeaderAuthentication.class);
165166
ivyRepo.patternLayout(layout -> layout.artifact("/downloads/elasticsearch/[module]-[revision](-[classifier]).[ext]"));
166-
ivyRepo.content(content -> content.includeGroup(FAKE_IVY_GROUP));
167+
ivyRepo.content(content -> content.includeGroup(group));
167168
});
168169
project.getRepositories().all(repo -> {
169-
if (repo.getName().equals(DOWNLOAD_REPO_NAME) == false) {
170+
if (repo.getName().equals(name) == false) {
170171
// all other repos should ignore the special group name
171-
repo.content(content -> content.excludeGroup(FAKE_IVY_GROUP));
172+
repo.content(content -> content.excludeGroup(group));
172173
}
173174
});
174-
// TODO: need maven repo just for integ-test-zip, but only in external cases
175+
}
176+
177+
private static void setupDownloadServiceRepo(Project project) {
178+
if (project.getRepositories().findByName(DOWNLOAD_REPO_NAME) != null) {
179+
return;
180+
}
181+
addIvyRepo(project, DOWNLOAD_REPO_NAME, "https://artifacts.elastic.co", FAKE_IVY_GROUP);
182+
if (ClasspathUtils.isElasticsearchProject(project) == false) {
183+
// external, so add snapshot repo as well
184+
addIvyRepo(project, SNAPSHOT_REPO_NAME, "https://snapshots.elastic.co", FAKE_SNAPSHOT_IVY_GROUP);
185+
}
175186
}
176187

177188
/**
@@ -187,25 +198,30 @@ private static void setupDownloadServiceRepo(Project project) {
187198
*/
188199
private Object dependencyNotation(Project project, ElasticsearchDistribution distribution) {
189200

190-
if (Version.fromString(VersionProperties.getElasticsearch()).equals(distribution.getVersion())) {
191-
return projectDependency(project, distributionProjectPath(distribution), "default");
192-
// TODO: snapshot dep when not in ES repo
193-
}
194-
BwcVersions.UnreleasedVersionInfo unreleasedInfo = bwcVersions.unreleasedInfo(distribution.getVersion());
195-
if (unreleasedInfo != null) {
196-
assert distribution.getBundledJdk();
197-
return projectDependency(project, unreleasedInfo.gradleProjectPath, distributionProjectName(distribution));
201+
if (ClasspathUtils.isElasticsearchProject(project)) {
202+
// non-external project, so depend on local build
203+
204+
if (VersionProperties.getElasticsearch().equals(distribution.getVersion())) {
205+
return projectDependency(project, distributionProjectPath(distribution), "default");
206+
}
207+
BwcVersions.UnreleasedVersionInfo unreleasedInfo = bwcVersions.unreleasedInfo(Version.fromString(distribution.getVersion()));
208+
if (unreleasedInfo != null) {
209+
assert distribution.getBundledJdk();
210+
return projectDependency(project, unreleasedInfo.gradleProjectPath, distributionProjectName(distribution));
211+
}
198212
}
199213

200214
if (distribution.getType() == Type.INTEG_TEST_ZIP) {
201215
return "org.elasticsearch.distribution.integ-test-zip:elasticsearch:" + distribution.getVersion();
202216
}
203217

218+
219+
Version distroVersion = Version.fromString(distribution.getVersion());
204220
String extension = distribution.getType().toString();
205221
String classifier = ":x86_64";
206222
if (distribution.getType() == Type.ARCHIVE) {
207223
extension = distribution.getPlatform() == Platform.WINDOWS ? "zip" : "tar.gz";
208-
if (distribution.getVersion().onOrAfter("7.0.0")) {
224+
if (distroVersion.onOrAfter("7.0.0")) {
209225
classifier = ":" + distribution.getPlatform() + "-x86_64";
210226
} else {
211227
classifier = "";
@@ -214,10 +230,12 @@ private Object dependencyNotation(Project project, ElasticsearchDistribution dis
214230
classifier = ":amd64";
215231
}
216232
String flavor = "";
217-
if (distribution.getFlavor() == Flavor.OSS && distribution.getVersion().onOrAfter("6.3.0")) {
233+
if (distribution.getFlavor() == Flavor.OSS && distroVersion.onOrAfter("6.3.0")) {
218234
flavor = "-oss";
219235
}
220-
return FAKE_IVY_GROUP + ":elasticsearch" + flavor + ":" + distribution.getVersion() + classifier + "@" + extension;
236+
237+
String group = distribution.getVersion().endsWith("-SNAPSHOT") ? FAKE_SNAPSHOT_IVY_GROUP : FAKE_IVY_GROUP;
238+
return group + ":elasticsearch" + flavor + ":" + distribution.getVersion() + classifier + "@" + extension;
221239
}
222240

223241
private static Dependency projectDependency(Project project, String projectPath, String projectConfig) {

buildSrc/src/main/java/org/elasticsearch/gradle/ElasticsearchDistribution.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public String toString() {
114114
final Configuration configuration;
115115
private final Extracted extracted;
116116

117-
private final Property<Version> version;
117+
private final Property<String> version;
118118
private final Property<Type> type;
119119
private final Property<Platform> platform;
120120
private final Property<Flavor> flavor;
@@ -124,8 +124,7 @@ public String toString() {
124124
Configuration extractedConfiguration) {
125125
this.name = name;
126126
this.configuration = fileConfiguration;
127-
this.version = objectFactory.property(Version.class);
128-
this.version.convention(Version.fromString(VersionProperties.getElasticsearch()));
127+
this.version = objectFactory.property(String.class).convention(VersionProperties.getElasticsearch());
129128
this.type = objectFactory.property(Type.class);
130129
this.type.convention(Type.ARCHIVE);
131130
this.platform = objectFactory.property(Platform.class);
@@ -138,12 +137,13 @@ public String getName() {
138137
return name;
139138
}
140139

141-
public Version getVersion() {
140+
public String getVersion() {
142141
return version.get();
143142
}
144143

145144
public void setVersion(String version) {
146-
this.version.set(Version.fromString(version));
145+
Version.fromString(version); // ensure the version parses, but don't store as Version since that removes -SNAPSHOT
146+
this.version.set(version);
147147
}
148148

149149
public Platform getPlatform() {

buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
import java.util.Locale;
2929
import java.util.Map;
3030
import java.util.Random;
31+
import java.util.regex.Matcher;
32+
import java.util.regex.Pattern;
3133
import java.util.stream.Collectors;
34+
import java.util.stream.Stream;
3235

3336
public class GlobalBuildInfoPlugin implements Plugin<Project> {
3437
private static final String GLOBAL_INFO_EXTENSION_NAME = "globalInfo";
@@ -261,7 +264,23 @@ public static String gitRevision(File rootDir) {
261264
}
262265
final String ref = readFirstLine(head);
263266
if (ref.startsWith("ref:")) {
264-
revision = readFirstLine(gitDir.resolve(ref.substring("ref:".length()).trim()));
267+
String refName = ref.substring("ref:".length()).trim();
268+
Path refFile = gitDir.resolve(refName);
269+
if (Files.exists(refFile)) {
270+
revision = readFirstLine(refFile);
271+
} else if (Files.exists(dotGit.resolve("packed-refs"))) {
272+
// Check packed references for commit ID
273+
Pattern p = Pattern.compile("^([a-f0-9]{40}) " + refName + "$");
274+
try (Stream<String> lines = Files.lines(dotGit.resolve("packed-refs"))) {
275+
revision = lines.map(p::matcher)
276+
.filter(Matcher::matches)
277+
.map(m -> m.group(1))
278+
.findFirst()
279+
.orElseThrow(() -> new IOException("Packed reference not found for refName " + refName));
280+
}
281+
} else {
282+
throw new GradleException("Can't find revision for refName " + refName);
283+
}
265284
} else {
266285
// we are in detached HEAD state
267286
revision = ref;
@@ -274,8 +293,12 @@ public static String gitRevision(File rootDir) {
274293
}
275294

276295
private static String readFirstLine(final Path path) throws IOException {
277-
return Files.lines(path, StandardCharsets.UTF_8)
278-
.findFirst()
279-
.orElseThrow(() -> new IOException("file [" + path + "] is empty"));
296+
String firstLine;
297+
try (Stream<String> lines = Files.lines(path, StandardCharsets.UTF_8)) {
298+
firstLine = lines
299+
.findFirst()
300+
.orElseThrow(() -> new IOException("file [" + path + "] is empty"));
301+
}
302+
return firstLine;
280303
}
281304
}

buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public String getName() {
180180

181181
@Internal
182182
public Version getVersion() {
183-
return distributions.get(currentDistro).getVersion();
183+
return Version.fromString(distributions.get(currentDistro).getVersion());
184184
}
185185

186186
@Internal
@@ -660,7 +660,8 @@ private Map<String, String> getESEnvironment() {
660660
})
661661
.collect(Collectors.joining(" "));
662662
}
663-
defaultEnv.put("ES_JAVA_OPTS", "-Xms512m -Xmx512m -ea -esa " +
663+
String heapSize = System.getProperty("tests.heap.size", "512m");
664+
defaultEnv.put("ES_JAVA_OPTS", "-Xms" + heapSize + " -Xmx" + heapSize + " -ea -esa " +
664665
systemPropertiesString + " " +
665666
jvmArgsString + " " +
666667
// Support passing in additional JVM arguments

buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/RunTask.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010
import java.io.IOException;
1111
import java.nio.file.Files;
1212
import java.util.HashSet;
13+
import java.util.Map;
1314
import java.util.Set;
15+
import java.util.stream.Collectors;
1416

1517
public class RunTask extends DefaultTestClustersTask {
1618

1719
private static final Logger logger = Logging.getLogger(RunTask.class);
20+
public static final String CUSTOM_SETTINGS_PREFIX = "tests.es.";
1821

1922
private Boolean debug = false;
2023

@@ -36,12 +39,19 @@ public void beforeStart() {
3639
int debugPort = 8000;
3740
int httpPort = 9200;
3841
int transportPort = 9300;
42+
Map<String, String> additionalSettings = System.getProperties().entrySet().stream()
43+
.filter(entry -> entry.getKey().toString().startsWith(CUSTOM_SETTINGS_PREFIX))
44+
.collect(Collectors.toMap(
45+
entry -> entry.getKey().toString().substring(CUSTOM_SETTINGS_PREFIX.length()),
46+
entry -> entry.getValue().toString()
47+
));
3948
for (ElasticsearchCluster cluster : getClusters()) {
4049
cluster.getFirstNode().setHttpPort(String.valueOf(httpPort));
4150
httpPort++;
4251
cluster.getFirstNode().setTransportPort(String.valueOf(transportPort));
4352
transportPort++;
4453
for (ElasticsearchNode node : cluster.getNodes()) {
54+
additionalSettings.forEach(node::setting);
4555
if (debug) {
4656
logger.lifecycle(
4757
"Running elasticsearch in debug mode, {} suspending until connected on debugPort {}",

buildSrc/src/test/java/org/elasticsearch/gradle/DistributionDownloadPluginIT.java

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
3939

4040
public class DistributionDownloadPluginIT extends GradleIntegrationTestCase {
41+
4142
// TODO: check reuse of root task across projects MOVE TO UNIT TEST
4243
// TODO: future: check integ-test-zip to maven, snapshots to snapshot service for external project
4344

@@ -48,32 +49,61 @@ public void testCurrent() throws Exception {
4849
"tests.local_distro.project", projectName);
4950
}
5051

52+
public void testCurrentExternal() throws Exception {
53+
checkService(VersionProperties.getElasticsearch(), "archive", "linux", null, null,
54+
"/downloads/elasticsearch/elasticsearch-" + VersionProperties.getElasticsearch() + "-linux-x86_64.tar.gz",
55+
"tests.internal", "false");
56+
}
57+
5158
public void testBwc() throws Exception {
52-
assertExtractedDistro("1.1.0", "archive", "linux", null, null,
59+
assertExtractedDistro("8.1.0", "archive", "linux", null, null,
5360
"tests.local_distro.config", "linux-tar",
5461
"tests.local_distro.project", ":distribution:bwc:minor",
55-
"tests.current_version", "2.0.0");
62+
"tests.current_version", "8.0.0");
63+
}
64+
65+
public void testBwcExternal() throws Exception {
66+
checkService("8.1.0-SNAPSHOT", "archive", "linux", null, null,
67+
"/downloads/elasticsearch/elasticsearch-8.1.0-SNAPSHOT-linux-x86_64.tar.gz",
68+
"tests.internal", "false",
69+
"tests.current_version", "9.0.0");
5670
}
5771

5872
public void testReleased() throws Exception {
59-
doTestReleased("7.0.0", "/downloads/elasticsearch/elasticsearch-7.0.0-windows-x86_64.zip");
60-
doTestReleased("6.5.0", "/downloads/elasticsearch/elasticsearch-6.5.0.zip");
73+
checkService("7.0.0", "archive", "windows", null, null,
74+
"/downloads/elasticsearch/elasticsearch-7.0.0-windows-x86_64.zip");
75+
checkService("6.5.0", "archive", "windows", null, null,
76+
"/downloads/elasticsearch/elasticsearch-6.5.0.zip");
77+
}
78+
79+
public void testReleasedExternal() throws Exception {
80+
checkService("7.0.0", "archive", "windows", null, null,
81+
"/downloads/elasticsearch/elasticsearch-7.0.0-windows-x86_64.zip",
82+
"tests.internal", "false");
83+
checkService("6.5.0", "archive", "windows", null, null,
84+
"/downloads/elasticsearch/elasticsearch-6.5.0.zip",
85+
"tests.internal", "false");
6186
}
6287

63-
private void doTestReleased(String version, String urlPath) throws IOException {
88+
private void checkService(String version, String type, String platform, String flavor, Boolean bundledJdk,
89+
String urlPath, String... sysProps) throws IOException {
90+
String suffix = urlPath.endsWith("zip") ? "zip" : "tar.gz";
91+
String sourceFile = "src/testKit/distribution-download/distribution/files/fake_elasticsearch." + suffix;
6492
WireMockServer wireMock = new WireMockServer(0);
6593
try {
6694
final byte[] filebytes;
67-
try (InputStream stream =
68-
Files.newInputStream(Paths.get("src/testKit/distribution-download/distribution/files/fake_elasticsearch.zip"))) {
95+
try (InputStream stream = Files.newInputStream(Paths.get(sourceFile))) {
6996
filebytes = stream.readAllBytes();
7097
}
7198
wireMock.stubFor(head(urlEqualTo(urlPath)).willReturn(aResponse().withStatus(200)));
7299
wireMock.stubFor(get(urlEqualTo(urlPath)).willReturn(aResponse().withStatus(200).withBody(filebytes)));
73100
wireMock.start();
74101

75-
assertExtractedDistro(version, "archive", "windows", null, null,
76-
"tests.download_service", wireMock.baseUrl());
102+
List<String> allSysProps = new ArrayList<>();
103+
allSysProps.addAll(Arrays.asList(sysProps));
104+
allSysProps.add("tests.download_service");
105+
allSysProps.add(wireMock.baseUrl());
106+
assertExtractedDistro(version, type, platform, flavor, bundledJdk, allSysProps.toArray(new String[0]));
77107
} catch (Exception e) {
78108
// for debugging
79109
System.err.println("missed requests: " + wireMock.findUnmatchedRequests().getRequests());

0 commit comments

Comments
 (0)