Skip to content

Commit

Permalink
Use lazy api for Gradle tasks
Browse files Browse the repository at this point in the history
Signed-off-by: Konstantin Gribov <[email protected]>
  • Loading branch information
grossws committed Apr 24, 2022
1 parent 0a758b8 commit b4b915c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.nio.file.Path;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import javax.inject.Inject;
Expand Down Expand Up @@ -151,24 +150,9 @@ private void registerTasks(Project project, QuarkusPluginExtension quarkusExt) {

configureBuildNativeTask(project);

final Consumer<Test> configureTestTask = t -> {
// Quarkus test configuration action which should be executed before any Quarkus test
// Use anonymous classes in order to leverage task avoidance.
t.doFirst(new Action<Task>() {
@Override
public void execute(Task test) {
quarkusExt.beforeTest(t);
}
});
// also make each task use the JUnit platform since it's the only supported test environment
t.useJUnitPlatform();
// quarkusBuild is expected to run after the project has passed the tests
quarkusBuild.configure(task -> task.shouldRunAfter(t));
};

project.getPlugins().withType(
BasePlugin.class,
basePlugin -> tasks.getByName(BasePlugin.ASSEMBLE_TASK_NAME).dependsOn(quarkusBuild));
basePlugin -> tasks.named(BasePlugin.ASSEMBLE_TASK_NAME, task -> task.dependsOn(quarkusBuild)));
project.getPlugins().withType(
JavaPlugin.class,
javaPlugin -> {
Expand Down Expand Up @@ -287,8 +271,20 @@ public void execute(Task test) {
testNative.setClasspath(nativeTestSourceSet.getRuntimeClasspath());
});

tasks.withType(Test.class).forEach(configureTestTask);
tasks.withType(Test.class).whenTaskAdded(configureTestTask::accept);
tasks.withType(Test.class).configureEach(t -> {
// Quarkus test configuration action which should be executed before any Quarkus test
// Use anonymous classes in order to leverage task avoidance.
t.doFirst(new Action<Task>() {
@Override
public void execute(Task task) {
quarkusExt.beforeTest(t);
}
});
// also make each task use the JUnit platform since it's the only supported test environment
t.useJUnitPlatform();
});
// quarkusBuild is expected to run after the project has passed the tests
quarkusBuild.configure(task -> task.shouldRunAfter(tasks.withType(Test.class)));

SourceSet generatedSourceSet = sourceSets.create(QuarkusGenerateCode.QUARKUS_GENERATED_SOURCES);
SourceSet generatedTestSourceSet = sourceSets.create(QuarkusGenerateCode.QUARKUS_TEST_GENERATED_SOURCES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private void registerTasks(Project project, QuarkusExtensionConfiguration quarku
javaPlugin -> {
tasks.named(JavaPlugin.PROCESS_RESOURCES_TASK_NAME, task -> task.finalizedBy(extensionDescriptorTask));
tasks.named(JavaPlugin.COMPILE_JAVA_TASK_NAME, task -> task.dependsOn(extensionDescriptorTask));
tasks.withType(Test.class, test -> test.useJUnitPlatform());
tasks.withType(Test.class).configureEach(Test::useJUnitPlatform);
addAnnotationProcessorDependency(project);
});

Expand All @@ -87,7 +87,7 @@ private void registerTasks(Project project, QuarkusExtensionConfiguration quarku
task.setDeploymentModuleClasspath(deploymentModuleClasspath);
});

deploymentProject.getTasks().withType(Test.class, test -> {
deploymentProject.getTasks().withType(Test.class).configureEach(test -> {
test.useJUnitPlatform();
test.doFirst(task -> {
final Map<String, Object> props = test.getSystemProperties();
Expand Down

0 comments on commit b4b915c

Please sign in to comment.