Refactor the CR plugin to a Lifecycle one

This commit is contained in:
Sébastien Deleuze
2024-06-14 18:29:28 +02:00
parent b3612bd36c
commit e4ff6fc20c
110 changed files with 264 additions and 261 deletions

View File

@@ -12,13 +12,13 @@ repositories {
gradlePlugin {
plugins {
crSmokeTestPlugin {
id = "org.springframework.cr.smoke-test"
implementationClass = "org.springframework.cr.gradle.CrSmokeTestPlugin"
lifecycleSmokeTestPlugin {
id = "org.springframework.lifecycle.smoke-test"
implementationClass = "org.springframework.lifecycle.gradle.LifecycleSmokeTestPlugin"
}
crSmokeTestAggregatorPlugin {
id = "org.springframework.cr.smoke-test-aggregator"
implementationClass = "org.springframework.cr.gradle.CrSmokeTestAggregatorPlugin"
lifecycleSmokeTestAggregatorPlugin {
id = "org.springframework.lifecycle.smoke-test-aggregator"
implementationClass = "org.springframework.lifecycle.gradle.LifecycleSmokeTestAggregatorPlugin"
}
}
}

View File

@@ -13,4 +13,4 @@ pluginManagement {
}
}
rootProject.name="cr-smoke-test-plugin"
rootProject.name="lifecycle-smoke-test-plugin"

View File

@@ -14,15 +14,15 @@
* limitations under the License.
*/
package org.springframework.cr.gradle;
package org.springframework.lifecycle.gradle;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.tasks.TaskProvider;
import org.springframework.cr.gradle.tasks.UpdateConcoursePipeline;
import org.springframework.cr.gradle.tasks.UpdateStatusPage;
import org.springframework.lifecycle.gradle.tasks.UpdateConcoursePipeline;
import org.springframework.lifecycle.gradle.tasks.UpdateStatusPage;
/**
* Plugin for a project that aggregates the smoke tests to provide status and a CI
@@ -31,7 +31,7 @@ import org.springframework.cr.gradle.tasks.UpdateStatusPage;
* @author Andy Wilkinson
* @author Sebastien Deleuze
*/
public class CrSmokeTestAggregatorPlugin implements Plugin<Project> {
public class LifecycleSmokeTestAggregatorPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cr.gradle;
package org.springframework.lifecycle.gradle;
import java.util.HashMap;
import java.util.Locale;
@@ -37,22 +37,21 @@ import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.api.tasks.testing.Test;
import org.gradle.api.tasks.testing.logging.TestExceptionFormat;
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile;
import org.springframework.boot.gradle.plugin.SpringBootPlugin;
import org.springframework.boot.gradle.tasks.bundling.BootJar;
import org.springframework.cr.gradle.dsl.CrSmokeTestExtension;
import org.springframework.cr.gradle.tasks.AppTest;
import org.springframework.cr.gradle.tasks.DescribeSmokeTests;
import org.springframework.cr.gradle.tasks.RestoreJvmApplication;
import org.springframework.cr.gradle.tasks.StartAndCheckpointJvmApplication;
import org.springframework.cr.gradle.tasks.StartApplication;
import org.springframework.cr.gradle.tasks.StartJvmApplication;
import org.springframework.cr.gradle.tasks.StopApplication;
import org.springframework.lifecycle.gradle.dsl.LifecycleSmokeTestExtension;
import org.springframework.lifecycle.gradle.tasks.AppTest;
import org.springframework.lifecycle.gradle.tasks.DescribeSmokeTests;
import org.springframework.lifecycle.gradle.tasks.RestoreJvmApplication;
import org.springframework.lifecycle.gradle.tasks.StartAndCheckpointJvmApplication;
import org.springframework.lifecycle.gradle.tasks.StartApplication;
import org.springframework.lifecycle.gradle.tasks.StartJvmApplication;
import org.springframework.lifecycle.gradle.tasks.StopApplication;
/**
* {@link Plugin} for a checkpoint/restore smoke test project. Configures an {@code appTest} source set
* {@link Plugin} for a lifecycle smoke test project. Configures an {@code appTest} source set
* and tasks for running the contained tests against the application running on the JVM
* and as a native image.
*
@@ -60,7 +59,7 @@ import org.springframework.cr.gradle.tasks.StopApplication;
* @author Moritz Halbritter
* @author Sebastien Deleuze
*/
public class CrSmokeTestPlugin implements Plugin<Project> {
public class LifecycleSmokeTestPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
@@ -70,8 +69,8 @@ public class CrSmokeTestPlugin implements Plugin<Project> {
}
private void configureBootJavaProject(Project project) {
CrSmokeTestExtension extension = project.getExtensions()
.create("crSmokeTest", CrSmokeTestExtension.class, project);
LifecycleSmokeTestExtension extension = project.getExtensions()
.create("lifecycleSmokeTest", LifecycleSmokeTestExtension.class, project);
extension.getWebApplication().convention(false);
extension.getCheckpointEvent().convention("org.springframework.boot.context.event.ApplicationReadyEvent");
JavaPluginExtension javaExtension = project.getExtensions().getByType(JavaPluginExtension.class);
@@ -116,7 +115,7 @@ public class CrSmokeTestPlugin implements Plugin<Project> {
dependencies.project(Map.of("path", project.getPath(), "configuration", smokeTests.getName())));
}
private void configureAppTests(Project project, CrSmokeTestExtension extension, SourceSet appTest) {
private void configureAppTests(Project project, LifecycleSmokeTestExtension extension, SourceSet appTest) {
configureJvmAppTests(project, appTest, extension);
configureJvmCrAppTests(project, appTest, extension);
}
@@ -134,14 +133,14 @@ public class CrSmokeTestPlugin implements Plugin<Project> {
.setJvmTarget(javaExtension.getTargetCompatibility().toString()));
}
private void configureJvmAppTests(Project project, SourceSet sourceSet, CrSmokeTestExtension extension) {
private void configureJvmAppTests(Project project, SourceSet sourceSet, LifecycleSmokeTestExtension extension) {
Provider<RegularFile> archiveFile = project.getTasks()
.named(SpringBootPlugin.BOOT_JAR_TASK_NAME, BootJar.class)
.flatMap(BootJar::getArchiveFile);
configureTasks(project, sourceSet, ApplicationType.JVM, archiveFile, extension);
}
private void configureJvmCrAppTests(Project project, SourceSet sourceSet, CrSmokeTestExtension extension) {
private void configureJvmCrAppTests(Project project, SourceSet sourceSet, LifecycleSmokeTestExtension extension) {
Provider<RegularFile> archiveFile = project.getTasks()
.named(SpringBootPlugin.BOOT_JAR_TASK_NAME, BootJar.class)
.flatMap(BootJar::getArchiveFile);
@@ -149,7 +148,7 @@ public class CrSmokeTestPlugin implements Plugin<Project> {
}
private TaskProvider<AppTest> configureTasks(Project project, SourceSet appTest, ApplicationType type,
Provider<RegularFile> applicationBinary, CrSmokeTestExtension extension) {
Provider<RegularFile> applicationBinary, LifecycleSmokeTestExtension extension) {
String dir = switch (type) {
case JVM -> "jvmApp";
case JVM_CHECKPOINT_RESTORE -> "jvmCrApp";
@@ -214,7 +213,7 @@ public class CrSmokeTestPlugin implements Plugin<Project> {
private TaskProvider<? extends StartApplication> createRestoreApplicationTask(Project project,
Provider<RegularFile> applicationBinary, Provider<Directory> outputDirectory,
TaskProvider<? extends StartApplication> startTask, CrSmokeTestExtension extension) {
TaskProvider<? extends StartApplication> startTask, LifecycleSmokeTestExtension extension) {
TaskProvider<? extends StartApplication> restoreTask = project.getTasks().register("restoreApp", RestoreJvmApplication.class, (restore) -> {
restore.getApplicationBinary().set(applicationBinary);
restore.getOutputDirectory().set(outputDirectory);
@@ -253,7 +252,7 @@ public class CrSmokeTestPlugin implements Plugin<Project> {
private TaskProvider<? extends StartApplication> createStartApplicationTask(Project project, ApplicationType type,
Provider<RegularFile> applicationBinary, Provider<Directory> outputDirectory,
CrSmokeTestExtension extension) {
LifecycleSmokeTestExtension extension) {
String taskName = switch (type) {
case JVM -> "startApp";
case JVM_CHECKPOINT_RESTORE -> "startAndCheckpointApp";
@@ -285,10 +284,10 @@ public class CrSmokeTestPlugin implements Plugin<Project> {
task.getInputs()
.file(startTask.flatMap(StartApplication::getApplicationBinary))
.withPropertyName("applicationBinary");
task.systemProperty("org.springframework.cr.smoketest.standard-output",
task.systemProperty("org.springframework.lifecycle.smoketest.standard-output",
startTask.get().getOutputFile().get().getAsFile().getAbsolutePath());
if (checkpointTask != null && checkpointTask.isPresent()) {
task.systemProperty("org.springframework.cr.smoketest.standard-output-checkpoint",
task.systemProperty("org.springframework.lifecycle.smoketest.standard-output-checkpoint",
checkpointTask.get().getOutputFile().get().getAsFile().getAbsolutePath());
}
task.finalizedBy(stopTask);

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cr.gradle.dsl;
package org.springframework.lifecycle.gradle.dsl;
import javax.inject.Inject;
@@ -22,19 +22,19 @@ import org.gradle.api.Project;
import org.gradle.api.provider.Property;
/**
* DSL extension for configuring checkpoint/restore smoke tests.
* DSL extension for configuring lifecycle smoke tests.
*
* @author Andy Wilkinson
* @author Sebastien Deleuze
*/
public class CrSmokeTestExtension {
public class LifecycleSmokeTestExtension {
private final Property<Boolean> webApplication;
private final Property<String> checkpointEvent;
@Inject
public CrSmokeTestExtension(Project project) {
public LifecycleSmokeTestExtension(Project project) {
this.webApplication = project.getObjects().property(Boolean.class);
this.checkpointEvent = project.getObjects().property(String.class);
}

View File

@@ -17,4 +17,4 @@
/**
* DSL for smoke testing of applications using checkpoint/restore.
*/
package org.springframework.cr.gradle.dsl;
package org.springframework.lifecycle.gradle.dsl;

View File

@@ -17,4 +17,4 @@
/**
* Gradle plugin for smoke testing of applications using checkpoint/restore.
*/
package org.springframework.cr.gradle;
package org.springframework.lifecycle.gradle;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cr.gradle.tasks;
package org.springframework.lifecycle.gradle.tasks;
import java.io.File;
import java.io.FileInputStream;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cr.gradle.tasks;
package org.springframework.lifecycle.gradle.tasks;
import org.gradle.api.provider.MapProperty;
import org.gradle.api.tasks.Internal;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cr.gradle.tasks;
package org.springframework.lifecycle.gradle.tasks;
import java.io.File;
import java.io.IOException;

View File

@@ -1,4 +1,4 @@
package org.springframework.cr.gradle.tasks;
package org.springframework.lifecycle.gradle.tasks;
import java.io.File;
import java.util.ArrayList;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cr.gradle.tasks;
package org.springframework.lifecycle.gradle.tasks;
import java.util.Properties;

View File

@@ -1,4 +1,4 @@
package org.springframework.cr.gradle.tasks;
package org.springframework.lifecycle.gradle.tasks;
import java.io.File;
import java.io.IOException;
@@ -34,7 +34,7 @@ public abstract class StartAndCheckpointJvmApplication extends StartApplication
command.add("/bin/bash");
command.add("-c");
StringBuilder builder = new StringBuilder(executable.getAbsolutePath());
builder.append(" -Dorg.springframework.cr.smoketest.checkpoint=");
builder.append(" -Dorg.springframework.lifecycle.smoketest.checkpoint=");
builder.append(getCheckpointEvent().get());
builder.append(" -XX:CRaCCheckpointTo=");
builder.append(outputDirectory);

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cr.gradle.tasks;
package org.springframework.lifecycle.gradle.tasks;
import java.io.File;
import java.io.IOException;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cr.gradle.tasks;
package org.springframework.lifecycle.gradle.tasks;
import java.io.File;
import java.util.ArrayList;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cr.gradle.tasks;
package org.springframework.lifecycle.gradle.tasks;
import java.io.IOException;
import java.nio.file.Files;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cr.gradle.tasks;
package org.springframework.lifecycle.gradle.tasks;
import java.io.File;
import java.io.FileWriter;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cr.gradle.tasks;
package org.springframework.lifecycle.gradle.tasks;
import java.io.IOException;
import java.nio.file.Files;

View File

@@ -17,4 +17,4 @@
/**
* Tasks for smoke testing of applications using checkpoint/restore.
*/
package org.springframework.cr.gradle.tasks;
package org.springframework.lifecycle.gradle.tasks;