Skip to content

Commit 1c29140

Browse files
authored
[7.x] Fix incremental build support copying REST api and tests (#52896)
A recent PR #52114 introduced two new tasks to copy the REST api and tests. A couple bugs were found in that initial PR that prevents the incremental build from working as expected. The pattern match of empty string is equivalent to match all and it was coded as match none. Fixed with explicit checks against empty patterns. The fileCollection.plus return value was ignored. Fixed by changing how the input's fileTree is constructed. If a project has an src/test/resources directory, and tests are being copied without a rest-api-spec/test directory could result no-op. Masked by the other bugs and fixed by minor changes to logic to determine if a project has tests.
1 parent eac38e9 commit 1c29140

File tree

2 files changed

+38
-23
lines changed

2 files changed

+38
-23
lines changed

buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/CopyRestApiTask.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,25 @@ public ListProperty<String> getIncludeXpack() {
8484
@SkipWhenEmpty
8585
@InputFiles
8686
public FileTree getInputDir() {
87-
xpackPatternSet.setIncludes(includeXpack.get().stream().map(prefix -> prefix + "*/**").collect(Collectors.toList()));
88-
ConfigurableFileCollection fileCollection = getProject().files(xpackConfig.getAsFileTree().matching(xpackPatternSet));
89-
if (BuildParams.isInternal()) {
90-
corePatternSet.setIncludes(includeCore.get().stream().map(prefix -> prefix + "*/**").collect(Collectors.toList()));
91-
fileCollection.plus(coreConfig.getAsFileTree().matching(corePatternSet));
92-
} else {
93-
fileCollection.plus(coreConfig);
87+
FileTree coreFileTree = null;
88+
FileTree xpackFileTree = null;
89+
if (includeXpack.get().isEmpty() == false) {
90+
xpackPatternSet.setIncludes(includeXpack.get().stream().map(prefix -> prefix + "*/**").collect(Collectors.toList()));
91+
xpackFileTree = xpackConfig.getAsFileTree().matching(xpackPatternSet);
9492
}
93+
boolean projectHasYamlRestTests = projectHasYamlRestTests();
94+
if (includeCore.get().isEmpty() == false || projectHasYamlRestTests) {
95+
if (BuildParams.isInternal()) {
96+
corePatternSet.setIncludes(includeCore.get().stream().map(prefix -> prefix + "*/**").collect(Collectors.toList()));
97+
coreFileTree = coreConfig.getAsFileTree().matching(corePatternSet); // directory on disk
98+
} else {
99+
coreFileTree = coreConfig.getAsFileTree(); // jar file
100+
}
101+
}
102+
ConfigurableFileCollection fileCollection = getProject().files(coreFileTree, xpackFileTree);
103+
95104
// if project has rest tests or the includes are explicitly configured execute the task, else NO-SOURCE due to the null input
96-
return projectHasYamlRestTests() || includeCore.get().isEmpty() == false || includeXpack.get().isEmpty() == false
105+
return projectHasYamlRestTests || includeCore.get().isEmpty() == false || includeXpack.get().isEmpty() == false
97106
? fileCollection.getAsFileTree()
98107
: null;
99108
}
@@ -148,15 +157,13 @@ private boolean projectHasYamlRestTests() {
148157
return false;
149158
}
150159
try {
151-
if (testSourceResourceDir != null) {
152-
return new File(testSourceResourceDir, "rest-api-spec/test").exists() == false
153-
|| Files.walk(testSourceResourceDir.toPath().resolve("rest-api-spec/test"))
154-
.anyMatch(p -> p.getFileName().toString().endsWith("yml"));
160+
if (testSourceResourceDir != null && new File(testSourceResourceDir, "rest-api-spec/test").exists()) {
161+
return Files.walk(testSourceResourceDir.toPath().resolve("rest-api-spec/test"))
162+
.anyMatch(p -> p.getFileName().toString().endsWith("yml"));
155163
}
156-
if (testOutputResourceDir != null) {
157-
return new File(testOutputResourceDir, "rest-api-spec/test").exists() == false
158-
|| Files.walk(testOutputResourceDir.toPath().resolve("rest-api-spec/test"))
159-
.anyMatch(p -> p.getFileName().toString().endsWith("yml"));
164+
if (testOutputResourceDir != null && new File(testOutputResourceDir, "rest-api-spec/test").exists()) {
165+
return Files.walk(testOutputResourceDir.toPath().resolve("rest-api-spec/test"))
166+
.anyMatch(p -> p.getFileName().toString().endsWith("yml"));
160167
}
161168
} catch (IOException e) {
162169
throw new IllegalStateException(String.format("Error determining if this project [%s] has rest tests.", getProject()), e);

buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/CopyRestTestsTask.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,22 @@ public ListProperty<String> getIncludeXpack() {
8181
@SkipWhenEmpty
8282
@InputFiles
8383
public FileTree getInputDir() {
84-
xpackPatternSet.setIncludes(includeXpack.get().stream().map(prefix -> prefix + "*/**").collect(Collectors.toList()));
85-
ConfigurableFileCollection fileCollection = getProject().files(xpackConfig.getAsFileTree().matching(xpackPatternSet));
86-
if (BuildParams.isInternal()) {
87-
corePatternSet.setIncludes(includeCore.get().stream().map(prefix -> prefix + "*/**").collect(Collectors.toList()));
88-
fileCollection.plus(coreConfig.getAsFileTree().matching(corePatternSet));
89-
} else {
90-
fileCollection.plus(coreConfig);
84+
FileTree coreFileTree = null;
85+
FileTree xpackFileTree = null;
86+
if (includeXpack.get().isEmpty() == false) {
87+
xpackPatternSet.setIncludes(includeXpack.get().stream().map(prefix -> prefix + "*/**").collect(Collectors.toList()));
88+
xpackFileTree = xpackConfig.getAsFileTree().matching(xpackPatternSet);
9189
}
90+
if (includeCore.get().isEmpty() == false) {
91+
if (BuildParams.isInternal()) {
92+
corePatternSet.setIncludes(includeCore.get().stream().map(prefix -> prefix + "*/**").collect(Collectors.toList()));
93+
coreFileTree = coreConfig.getAsFileTree().matching(corePatternSet); // directory on disk
94+
} else {
95+
coreFileTree = coreConfig.getAsFileTree(); // jar file
96+
}
97+
}
98+
ConfigurableFileCollection fileCollection = getProject().files(coreFileTree, xpackFileTree);
99+
92100
// copy tests only if explicitly requested
93101
return includeCore.get().isEmpty() == false || includeXpack.get().isEmpty() == false ? fileCollection.getAsFileTree() : null;
94102
}

0 commit comments

Comments
 (0)