Skip to content

Commit

Permalink
Merge branch 'main' into transform_node_info_api
Browse files Browse the repository at this point in the history
  • Loading branch information
przemekwitek committed May 28, 2024
2 parents 6640ffc + f2c2fc0 commit 96e2613
Show file tree
Hide file tree
Showing 191 changed files with 7,219 additions and 1,297 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public void apply(Project project) {
project.getRootProject().getPluginManager().apply(DockerSupportPlugin.class);

TaskContainer tasks = project.getTasks();
TestFixtureExtension extension = project.getExtensions().create("testFixtures", TestFixtureExtension.class, project);
Provider<DockerComposeThrottle> dockerComposeThrottle = project.getGradle()
.getSharedServices()
.registerIfAbsent(DOCKER_COMPOSE_THROTTLE, DockerComposeThrottle.class, spec -> spec.getMaxParallelUsages().set(1));
Expand All @@ -84,73 +83,63 @@ public void apply(Project project) {
File testFixturesDir = project.file("testfixtures_shared");
ext.set("testFixturesDir", testFixturesDir);

if (project.file(DOCKER_COMPOSE_YML).exists()) {
project.getPluginManager().apply(BasePlugin.class);
project.getPluginManager().apply(DockerComposePlugin.class);
TaskProvider<TestFixtureTask> preProcessFixture = project.getTasks().register("preProcessFixture", TestFixtureTask.class, t -> {
t.getFixturesDir().set(testFixturesDir);
t.doFirst(task -> {
try {
Files.createDirectories(testFixturesDir.toPath());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
});
TaskProvider<Task> buildFixture = project.getTasks()
.register("buildFixture", t -> t.dependsOn(preProcessFixture, tasks.named("composeUp")));

TaskProvider<TestFixtureTask> postProcessFixture = project.getTasks()
.register("postProcessFixture", TestFixtureTask.class, task -> {
task.getFixturesDir().set(testFixturesDir);
task.dependsOn(buildFixture);
configureServiceInfoForTask(
task,
project,
false,
(name, port) -> task.getExtensions().getByType(ExtraPropertiesExtension.class).set(name, port)
);
});

maybeSkipTask(dockerSupport, preProcessFixture);
maybeSkipTask(dockerSupport, postProcessFixture);
maybeSkipTask(dockerSupport, buildFixture);

ComposeExtension composeExtension = project.getExtensions().getByType(ComposeExtension.class);
composeExtension.setProjectName(project.getName());
composeExtension.getUseComposeFiles().addAll(Collections.singletonList(DOCKER_COMPOSE_YML));
composeExtension.getRemoveContainers().set(true);
composeExtension.getCaptureContainersOutput()
.set(EnumSet.of(LogLevel.INFO, LogLevel.DEBUG).contains(project.getGradle().getStartParameter().getLogLevel()));
composeExtension.getUseDockerComposeV2().set(false);
composeExtension.getExecutable().set(this.providerFactory.provider(() -> {
String composePath = dockerSupport.get().getDockerAvailability().dockerComposePath();
LOGGER.debug("Docker Compose path: {}", composePath);
return composePath != null ? composePath : "/usr/bin/docker-compose";
}));

tasks.named("composeUp").configure(t -> {
// Avoid running docker-compose tasks in parallel in CI due to some issues on certain Linux distributions
if (BuildParams.isCi()) {
t.usesService(dockerComposeThrottle);
if (project.file(DOCKER_COMPOSE_YML).exists() == false) {
// if only one fixture is used, that's this one, but without a compose file that's not a valid configuration
throw new IllegalStateException("No " + DOCKER_COMPOSE_YML + " found for " + project.getPath() + ".");
}
project.getPluginManager().apply(BasePlugin.class);
project.getPluginManager().apply(DockerComposePlugin.class);
TaskProvider<TestFixtureTask> preProcessFixture = project.getTasks().register("preProcessFixture", TestFixtureTask.class, t -> {
t.getFixturesDir().set(testFixturesDir);
t.doFirst(task -> {
try {
Files.createDirectories(testFixturesDir.toPath());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
t.mustRunAfter(preProcessFixture);
});
tasks.named("composePull").configure(t -> t.mustRunAfter(preProcessFixture));
tasks.named("composeDown").configure(t -> t.doLast(t2 -> getFileSystemOperations().delete(d -> d.delete(testFixturesDir))));
} else {
project.afterEvaluate(spec -> {
if (extension.fixtures.isEmpty()) {
// if only one fixture is used, that's this one, but without a compose file that's not a valid configuration
throw new IllegalStateException(
"No " + DOCKER_COMPOSE_YML + " found for " + project.getPath() + " nor does it use other fixtures."
);
}
});
TaskProvider<Task> buildFixture = project.getTasks()
.register("buildFixture", t -> t.dependsOn(preProcessFixture, tasks.named("composeUp")));

TaskProvider<TestFixtureTask> postProcessFixture = project.getTasks()
.register("postProcessFixture", TestFixtureTask.class, task -> {
task.getFixturesDir().set(testFixturesDir);
task.dependsOn(buildFixture);
configureServiceInfoForTask(
task,
project,
false,
(name, port) -> task.getExtensions().getByType(ExtraPropertiesExtension.class).set(name, port)
);
});
}

extension.fixtures.matching(fixtureProject -> fixtureProject.equals(project) == false)
.all(fixtureProject -> project.evaluationDependsOn(fixtureProject.getPath()));
maybeSkipTask(dockerSupport, preProcessFixture);
maybeSkipTask(dockerSupport, postProcessFixture);
maybeSkipTask(dockerSupport, buildFixture);

ComposeExtension composeExtension = project.getExtensions().getByType(ComposeExtension.class);
composeExtension.setProjectName(project.getName());
composeExtension.getUseComposeFiles().addAll(Collections.singletonList(DOCKER_COMPOSE_YML));
composeExtension.getRemoveContainers().set(true);
composeExtension.getCaptureContainersOutput()
.set(EnumSet.of(LogLevel.INFO, LogLevel.DEBUG).contains(project.getGradle().getStartParameter().getLogLevel()));
composeExtension.getUseDockerComposeV2().set(false);
composeExtension.getExecutable().set(this.providerFactory.provider(() -> {
String composePath = dockerSupport.get().getDockerAvailability().dockerComposePath();
LOGGER.debug("Docker Compose path: {}", composePath);
return composePath != null ? composePath : "/usr/bin/docker-compose";
}));

tasks.named("composeUp").configure(t -> {
// Avoid running docker-compose tasks in parallel in CI due to some issues on certain Linux distributions
if (BuildParams.isCi()) {
t.usesService(dockerComposeThrottle);
}
t.mustRunAfter(preProcessFixture);
});
tasks.named("composePull").configure(t -> t.mustRunAfter(preProcessFixture));
tasks.named("composeDown").configure(t -> t.doLast(t2 -> getFileSystemOperations().delete(d -> d.delete(testFixturesDir))));

// Skip docker compose tasks if it is unavailable
maybeSkipTasks(tasks, dockerSupport, Test.class);
Expand All @@ -161,17 +150,18 @@ public void apply(Project project) {
maybeSkipTasks(tasks, dockerSupport, ComposePull.class);
maybeSkipTasks(tasks, dockerSupport, ComposeDown.class);

tasks.withType(Test.class).configureEach(task -> extension.fixtures.all(fixtureProject -> {
task.dependsOn(fixtureProject.getTasks().named("postProcessFixture"));
task.finalizedBy(fixtureProject.getTasks().named("composeDown"));
tasks.withType(Test.class).configureEach(testTask -> {
testTask.dependsOn(postProcessFixture);
testTask.finalizedBy(tasks.named("composeDown"));
configureServiceInfoForTask(
task,
fixtureProject,
testTask,
project,
true,
(name, host) -> task.getExtensions().getByType(SystemPropertyCommandLineArgumentProvider.class).systemProperty(name, host)
(name, host) -> testTask.getExtensions()
.getByType(SystemPropertyCommandLineArgumentProvider.class)
.systemProperty(name, host)
);
}));

});
}

private void maybeSkipTasks(TaskContainer tasks, Provider<DockerSupportService> dockerSupport, Class<? extends DefaultTask> taskClass) {
Expand Down Expand Up @@ -203,28 +193,20 @@ private void configureServiceInfoForTask(
task.doFirst(new Action<Task>() {
@Override
public void execute(Task theTask) {
TestFixtureExtension extension = theTask.getProject().getExtensions().getByType(TestFixtureExtension.class);

fixtureProject.getExtensions()
.getByType(ComposeExtension.class)
.getServicesInfos()
.entrySet()
.stream()
.filter(entry -> enableFilter == false || extension.isServiceRequired(entry.getKey(), fixtureProject.getPath()))
.forEach(entry -> {
String service = entry.getKey();
ServiceInfo infos = entry.getValue();
infos.getTcpPorts().forEach((container, host) -> {
String name = "test.fixtures." + service + ".tcp." + container;
theTask.getLogger().info("port mapping property: {}={}", name, host);
consumer.accept(name, host);
});
infos.getUdpPorts().forEach((container, host) -> {
String name = "test.fixtures." + service + ".udp." + container;
theTask.getLogger().info("port mapping property: {}={}", name, host);
consumer.accept(name, host);
});
fixtureProject.getExtensions().getByType(ComposeExtension.class).getServicesInfos().entrySet().stream().forEach(entry -> {
String service = entry.getKey();
ServiceInfo infos = entry.getValue();
infos.getTcpPorts().forEach((container, host) -> {
String name = "test.fixtures." + service + ".tcp." + container;
theTask.getLogger().info("port mapping property: {}={}", name, host);
consumer.accept(name, host);
});
infos.getUdpPorts().forEach((container, host) -> {
String name = "test.fixtures." + service + ".udp." + container;
theTask.getLogger().info("port mapping property: {}={}", name, host);
consumer.accept(name, host);
});
});
}
});
}
Expand Down
2 changes: 0 additions & 2 deletions distribution/docker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ if (useDra == false) {
}
}

testFixtures.useFixture()

configurations {
aarch64DockerSource {
attributes {
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog/108911.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 108911
summary: Store source for fields in objects with `dynamic` override
area: Mapping
type: enhancement
issues: []
5 changes: 5 additions & 0 deletions docs/changelog/109044.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 109044
summary: Enable fallback synthetic source for `token_count`
area: Mapping
type: feature
issues: []
Loading

0 comments on commit 96e2613

Please sign in to comment.