diff --git a/examples/quarkus-cli/src/test/java/io/quarkus/qe/QuarkusCliClientIT.java b/examples/quarkus-cli/src/test/java/io/quarkus/qe/QuarkusCliClientIT.java index 5e0fcbde2..fff326cfc 100644 --- a/examples/quarkus-cli/src/test/java/io/quarkus/qe/QuarkusCliClientIT.java +++ b/examples/quarkus-cli/src/test/java/io/quarkus/qe/QuarkusCliClientIT.java @@ -25,6 +25,7 @@ import io.quarkus.test.bootstrap.config.QuarkusConfigCommand; import io.quarkus.test.scenarios.QuarkusScenario; import io.quarkus.test.scenarios.annotations.EnabledOnNative; +import io.quarkus.test.services.quarkus.CliDevModeVersionLessQuarkusApplicationManagedResource; import io.quarkus.test.services.quarkus.model.QuarkusProperties; @Tag("quarkus-cli") @@ -110,6 +111,22 @@ public void shouldCreateApplicationUsingArtifactId() { assertTrue(result.isSuccessful(), "The application didn't build on JVM. Output: " + result.getOutput()); } + @Test + public void shouldRunApplicationWithoutOverwritingVersion() { + QuarkusCliRestService app = cliClient.createApplication("versionFull:app", defaults() + .withStream("3.8") + .withPlatformBom(null) + .withManagedResourceCreator((serviceContext, + quarkusCliClient) -> managedResourceBuilder -> new CliDevModeVersionLessQuarkusApplicationManagedResource( + serviceContext, quarkusCliClient))); + + app.start(); + String response = app.given().get().getBody().asString(); + // check that app was indeed running with quarkus 3.8 (it was not overwritten) + // version is printed on welcome screen + assertTrue(response.contains("3.8"), "Quarkus is not running on 3.8"); + } + @Test public void shouldAddAndRemoveExtensions() { // Create application diff --git a/quarkus-test-cli/src/main/java/io/quarkus/test/bootstrap/QuarkusCliClient.java b/quarkus-test-cli/src/main/java/io/quarkus/test/bootstrap/QuarkusCliClient.java index 16021d1f2..70dea9130 100644 --- a/quarkus-test-cli/src/main/java/io/quarkus/test/bootstrap/QuarkusCliClient.java +++ b/quarkus-test-cli/src/main/java/io/quarkus/test/bootstrap/QuarkusCliClient.java @@ -90,7 +90,7 @@ public QuarkusCliRestService createApplication(String name, CreateApplicationReq QuarkusCliRestService service = new QuarkusCliRestService(this, serviceFolder); ServiceContext serviceContext = service.register(name, context); - service.init(s -> new CliDevModeLocalhostQuarkusApplicationManagedResource(serviceContext, this)); + service.init(request.managedResourceCreator.initBuilder(serviceContext, this)); // We need the service folder to be emptied before generating the project FileUtils.deletePath(serviceContext.getServiceFolder()); @@ -263,6 +263,9 @@ public static class CreateApplicationRequest { private String stream; private String[] extensions; private String[] extraArgs; + private ManagedResourceCreator managedResourceCreator = (serviceContext, + quarkusCliClient) -> managedResourceBuilder -> new CliDevModeLocalhostQuarkusApplicationManagedResource( + serviceContext, quarkusCliClient); public CreateApplicationRequest withPlatformBom(String platformBom) { this.platformBom = platformBom; @@ -288,6 +291,11 @@ public CreateApplicationRequest withExtraArgs(String... extraArgs) { return this; } + public CreateApplicationRequest withManagedResourceCreator(ManagedResourceCreator managedResourceCreator) { + this.managedResourceCreator = managedResourceCreator; + return this; + } + public static CreateApplicationRequest defaults() { if (isUpstream()) { // set platform due to https://github.com/quarkusio/quarkus/issues/40951#issuecomment-2147399201 @@ -298,6 +306,10 @@ public static CreateApplicationRequest defaults() { } } + public interface ManagedResourceCreator { + ManagedResourceBuilder initBuilder(ServiceContext serviceContext, QuarkusCliClient quarkusCliClient); + } + public static class UpdateApplicationRequest { private String stream; private String platformVersion; diff --git a/quarkus-test-cli/src/main/java/io/quarkus/test/services/quarkus/CliDevModeLocalhostQuarkusApplicationManagedResource.java b/quarkus-test-cli/src/main/java/io/quarkus/test/services/quarkus/CliDevModeLocalhostQuarkusApplicationManagedResource.java index 85bbd61b0..4474d5041 100644 --- a/quarkus-test-cli/src/main/java/io/quarkus/test/services/quarkus/CliDevModeLocalhostQuarkusApplicationManagedResource.java +++ b/quarkus-test-cli/src/main/java/io/quarkus/test/services/quarkus/CliDevModeLocalhostQuarkusApplicationManagedResource.java @@ -22,17 +22,17 @@ public class CliDevModeLocalhostQuarkusApplicationManagedResource extends QuarkusManagedResource { - private static final String QUARKUS_HTTP_PORT_PROPERTY = "quarkus.http.port"; - private static final String QUARKUS_PLATFORM_ARTIFACT_ID = "quarkus.platform.artifact-id"; - private static final String QUARKUS_PLATFORM_ARTIFACT_ID_VALUE = "quarkus-bom"; - private static final String QUARKUS_PLATFORM_VERSION = "quarkus.platform.version"; + protected static final String QUARKUS_HTTP_PORT_PROPERTY = "quarkus.http.port"; + protected static final String QUARKUS_PLATFORM_ARTIFACT_ID = "quarkus.platform.artifact-id"; + protected static final String QUARKUS_PLATFORM_ARTIFACT_ID_VALUE = "quarkus-bom"; + protected static final String QUARKUS_PLATFORM_VERSION = "quarkus.platform.version"; - private final ServiceContext serviceContext; - private final QuarkusCliClient client; + protected final ServiceContext serviceContext; + protected final QuarkusCliClient client; + protected int assignedHttpPort; private Process process; private LoggingHandler loggingHandler; - private int assignedHttpPort; public CliDevModeLocalhostQuarkusApplicationManagedResource(ServiceContext serviceContext, QuarkusCliClient client) { @@ -101,7 +101,7 @@ protected LoggingHandler getLoggingHandler() { return loggingHandler; } - private Map getPropertiesForCommand() { + protected Map getPropertiesForCommand() { Map runtimeProperties = new HashMap<>(serviceContext.getOwner().getProperties()); runtimeProperties.putIfAbsent(QUARKUS_HTTP_PORT_PROPERTY, "" + assignedHttpPort); runtimeProperties.putIfAbsent(QUARKUS_PLATFORM_VERSION, QuarkusProperties.getVersion()); diff --git a/quarkus-test-cli/src/main/java/io/quarkus/test/services/quarkus/CliDevModeVersionLessQuarkusApplicationManagedResource.java b/quarkus-test-cli/src/main/java/io/quarkus/test/services/quarkus/CliDevModeVersionLessQuarkusApplicationManagedResource.java new file mode 100644 index 000000000..723e2bcea --- /dev/null +++ b/quarkus-test-cli/src/main/java/io/quarkus/test/services/quarkus/CliDevModeVersionLessQuarkusApplicationManagedResource.java @@ -0,0 +1,21 @@ +package io.quarkus.test.services.quarkus; + +import java.util.HashMap; +import java.util.Map; + +import io.quarkus.test.bootstrap.QuarkusCliClient; +import io.quarkus.test.bootstrap.ServiceContext; + +public class CliDevModeVersionLessQuarkusApplicationManagedResource + extends CliDevModeLocalhostQuarkusApplicationManagedResource { + public CliDevModeVersionLessQuarkusApplicationManagedResource(ServiceContext serviceContext, QuarkusCliClient client) { + super(serviceContext, client); + } + + @Override + protected Map getPropertiesForCommand() { + Map runtimeProperties = new HashMap<>(serviceContext.getOwner().getProperties()); + runtimeProperties.putIfAbsent(QUARKUS_HTTP_PORT_PROPERTY, "" + assignedHttpPort); + return runtimeProperties; + } +}