Skip to content

Commit 9597586

Browse files
committed
Support entitlements in internal cluster tests
1 parent dc46b79 commit 9597586

File tree

3 files changed

+28
-20
lines changed

3 files changed

+28
-20
lines changed

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchTestBasePlugin.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.io.File;
3535
import java.util.List;
3636
import java.util.Map;
37+
import java.util.Set;
3738
import java.util.stream.Stream;
3839

3940
import javax.inject.Inject;
@@ -50,6 +51,8 @@ public abstract class ElasticsearchTestBasePlugin implements Plugin<Project> {
5051

5152
public static final String DUMP_OUTPUT_ON_FAILURE_PROP_NAME = "dumpOutputOnFailure";
5253

54+
public static final Set<String> TEST_TASKS_WITH_ENTITLEMENTS = Set.of("test", "internalClusterTest");
55+
5356
@Inject
5457
protected abstract ProviderFactory getProviderFactory();
5558

@@ -178,10 +181,17 @@ public void execute(Task t) {
178181
SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
179182
SourceSet mainSourceSet = sourceSets.findByName(SourceSet.MAIN_SOURCE_SET_NAME);
180183
SourceSet testSourceSet = sourceSets.findByName(SourceSet.TEST_SOURCE_SET_NAME);
181-
if ("test".equals(test.getName()) && mainSourceSet != null && testSourceSet != null) {
184+
SourceSet internalClusterTestSourceSet = sourceSets.findByName("internalClusterTest");
185+
186+
if (TEST_TASKS_WITH_ENTITLEMENTS.contains(test.getName()) && mainSourceSet != null && testSourceSet != null) {
182187
FileCollection mainRuntime = mainSourceSet.getRuntimeClasspath();
183188
FileCollection testRuntime = testSourceSet.getRuntimeClasspath();
184-
FileCollection testOnlyFiles = testRuntime.minus(mainRuntime);
189+
FileCollection internalClusterTestRuntime = "internalClusterTest".equals(test.getName())
190+
&& internalClusterTestSourceSet == null
191+
? project.files() // empty file collection
192+
: internalClusterTestSourceSet.getRuntimeClasspath();
193+
FileCollection testOnlyFiles = testRuntime.plus(internalClusterTestRuntime).minus(mainRuntime);
194+
185195
test.doFirst(task -> test.environment("es.entitlement.testOnlyPath", testOnlyFiles.getAsPath()));
186196
}
187197

@@ -241,16 +251,18 @@ public void execute(Task t) {
241251
* Computes and sets the {@code --patch-module=java.base} and {@code --add-opens=java.base} JVM command line options.
242252
*/
243253
private void configureJavaBaseModuleOptions(Project project) {
244-
project.getTasks().withType(Test.class).matching(task -> task.getName().equals("test")).configureEach(test -> {
245-
FileCollection patchedImmutableCollections = patchedImmutableCollections(project);
254+
project.getTasks().withType(Test.class).configureEach(test -> {
255+
// patch immutable collections only for "test" task
256+
FileCollection patchedImmutableCollections = test.getName().equals("test") ? patchedImmutableCollections(project) : null;
246257
if (patchedImmutableCollections != null) {
247258
test.getInputs().files(patchedImmutableCollections);
248259
test.systemProperty("tests.hackImmutableCollections", "true");
249260
}
250261

251-
FileCollection entitlementBridge = entitlementBridge(project);
262+
FileCollection entitlementBridge = TEST_TASKS_WITH_ENTITLEMENTS.contains(test.getName()) ? entitlementBridge(project) : null;
252263
if (entitlementBridge != null) {
253264
test.getInputs().files(entitlementBridge);
265+
test.systemProperty("es.entitlement.enableForTests", "true");
254266
}
255267

256268
test.getJvmArgumentProviders().add(() -> {
@@ -312,7 +324,9 @@ private static void configureEntitlements(Project project) {
312324
}
313325
FileCollection bridgeFiles = bridgeConfig;
314326

315-
project.getTasks().withType(Test.class).configureEach(test -> {
327+
project.getTasks().withType(Test.class)
328+
.matching(test -> TEST_TASKS_WITH_ENTITLEMENTS.contains(test.getName()))
329+
.configureEach(test -> {
316330
// See also SystemJvmOptions.maybeAttachEntitlementAgent.
317331

318332
// Agent

build-tools/src/main/java/org/elasticsearch/gradle/test/TestBuildInfoPlugin.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,5 @@ public void apply(Project project) {
5656
project.getTasks().withType(ProcessResources.class).named("processResources").configure(task -> {
5757
task.into("META-INF", copy -> copy.from(testBuildInfoTask));
5858
});
59-
60-
if (project.getRootProject().getName().equals("elasticsearch")) {
61-
project.getTasks().withType(Test.class).matching(test -> List.of("test").contains(test.getName())).configureEach(test -> {
62-
test.systemProperty("es.entitlement.enableForTests", "true");
63-
});
64-
}
6559
}
6660
}

libs/build.gradle

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ configure(childProjects.values()) {
4646
apply plugin: 'elasticsearch.build'
4747
}
4848

49-
// This is for any code potentially included in the server at runtime.
50-
// Omit oddball libraries that aren't in server.
51-
def nonServerLibs = ['plugin-scanner']
52-
if (false == nonServerLibs.contains(project.name)) {
53-
project.getTasks().withType(Test.class).matching(test -> ['test'].contains(test.name)).configureEach(test -> {
54-
test.systemProperty('es.entitlement.enableForTests', 'true')
55-
})
56-
}
49+
// // This is for any code potentially included in the server at runtime.
50+
// // Omit oddball libraries that aren't in server.
51+
// def nonServerLibs = ['plugin-scanner']
52+
// if (false == nonServerLibs.contains(project.name)) {
53+
// project.getTasks().withType(Test.class).matching(test -> ['test', 'internalClusterTest'].contains(test.name)).configureEach(test -> {
54+
// test.systemProperty('es.entitlement.enableForTests', 'true')
55+
// })
56+
// }
5757

5858
}

0 commit comments

Comments
 (0)