in plugins/lifecycle/src/main/java/co/elastic/gradle/lifecycle/MultiArchLifecyclePlugin.java [65:178]
private void createMultiPlatformBuildLifecycle(TaskContainer tasks) {
final Map<String, Map<String, String>> taskMap = Map.of(
"check", Map.of(
"ForPlatform", "Run all platform specific verifications for the current platform only.",
"PlatformIndependent", "Run all platform independent verifications " +
"(that don't depend on platform dependent tasks)",
"CombinePlatform", "Run all verifications for all platforms that can be ran in a platform independent way. " +
"Assumes that platform specific artefacts for this version are already published.",
"", "Run verification for the current platform and that are platform independent." +
" Useful for local testing."
),
"assemble", Map.of(
"ForPlatform", "Intended to create build artefacts, without running any tests for the current platform",
"PlatformIndependent", "Create platform independent build artefacts",
"CombinePlatform", "Create multi platform build artefacts, without running any tests. " +
"This includes the production artifacts and generating documentation for all supported platforms." +
"Assumes that the platform specific artefacts were already published for this version.",
"", "Create platform specific artefacts for the current platform and emulate multi platform artefacts based on them." +
" Useful for local testing."
),
"build", Map.of(
"ForPlatform", "Create artefacts and run all platform specific verifications for the current platform only.",
"PlatformIndependent", "Create artefacts and run all platform independent verifications " +
"(that don't depend on platform dependent tasks)",
"CombinePlatform", "Create artefacts and run all verifications for all platforms that can be ran in a platform independent way. " +
"Assumes that platform specific artefacts for this version are already published.",
"", "Create artefacts and run verification for the current platform and that are platform independent." +
" Useful for local testing."
),
"publish", Map.of(
"ForPlatform", "Create, verify and publish all platform specific artefacts for the current platform only.",
"PlatformIndependent", "Create, verify and publish platform independent artefacts " +
"(that don't depend on platform dependent tasks)",
"CombinePlatform", "Create, verify and publish artefacts multi platform artefacts. " +
"Assumes that platform specific artefacts for this version are already published.",
"", "Create, verify and run verification for the current platform and that are platform independent." +
" Useful for local testing."
)
);
final Map<String, String> groupLookup = Map.of(
"check", "verification",
"assemble", "build"
);
taskMap.forEach((kind, descriptions) -> {
descriptions.forEach((name, description) -> {
final Action<Task> taskConfig = task -> {
if (!kind.equals("publish")) {
task.setGroup(groupLookup.getOrDefault(kind, kind));
} else {
task.setGroup("publishing");
}
task.setDescription(description);
};
if (name.isEmpty()) {
tasks.named(kind, taskConfig);
} else {
tasks.register(kind + name, taskConfig);
}
});
tasks.named(kind, task -> task.dependsOn(
tasks.named(kind + "ForPlatform"),
tasks.named(kind + "PlatformIndependent"),
tasks.named(kind + "CombinePlatform")
));
});
// The specialized "build" tasks have the specialized "check" and "assemble" tasks as dependencies, just like the base
tasks.named("buildForPlatform", task -> task.dependsOn("assembleForPlatform", "checkForPlatform"));
tasks.named("buildPlatformIndependent", task -> task.dependsOn("assemblePlatformIndependent", "checkPlatformIndependent"));
tasks.named("buildCombinePlatform", task -> task.dependsOn("assembleCombinePlatform", "checkCombinePlatform"));
// The specialized "publish" tasks have the specialized "build" tasks as dependencies, just like the base
tasks.named("publishForPlatform", task -> task.dependsOn("buildForPlatform"));
tasks.named("publishPlatformIndependent", task -> task.dependsOn("buildPlatformIndependent"));
tasks.named("publishCombinePlatform", task -> task.dependsOn("buildCombinePlatform"));
tasks.register("checkConsistency", task -> task.doFirst(it -> {
it.getLogger().info("Checking that tasks aren't added to the base lifecycle tasks only");
taskMap.keySet().forEach(kind -> {
final Set<String> allLifecycleTasks = taskMap.entrySet().stream()
.flatMap(entry ->
Stream.concat(
Stream.of(entry.getKey()),
entry.getValue().keySet().stream()
.map(s -> entry.getKey() + s)
)
)
.collect(Collectors.toSet());
allLifecycleTasks.add("preCommit");
final Set<String> taskToCheck = new HashSet<>(getDependencySet(tasks.getByName(kind), allLifecycleTasks));
final Set<String> specializedTasks = new HashSet<>();
specializedTasks.addAll(getDependencySet(tasks.getByName(kind + "ForPlatform"), allLifecycleTasks));
specializedTasks.addAll(getDependencySet(tasks.getByName(kind + "PlatformIndependent"), allLifecycleTasks));
specializedTasks.addAll(getDependencySet(tasks.getByName(kind + "CombinePlatform"), allLifecycleTasks));
taskToCheck.removeAll(specializedTasks);
if (!taskToCheck.isEmpty()) {
throw new GradleException("Dependencies '" + taskToCheck + "' for " + kind +
" isn't added to any platform specialized lifecycle tasks. " +
"Please add it to " + kind + "ForPlatform, " + kind + "PlatformIndependent " +
"or " + kind + "ALl"
);
}
});
}));
tasks.named("checkPlatformIndependent", task -> task.dependsOn("checkConsistency"));
}