Skip to content

Commit

Permalink
Allow running CLI in dev mode, without overwriting quarkus version (#…
Browse files Browse the repository at this point in the history
…1232)

* Allow running CLI in dev mode, without overwriting quarkus version
  • Loading branch information
mocenas authored Jul 31, 2024
1 parent b286c9f commit be7a968
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -101,7 +101,7 @@ protected LoggingHandler getLoggingHandler() {
return loggingHandler;
}

private Map<String, String> getPropertiesForCommand() {
protected Map<String, String> getPropertiesForCommand() {
Map<String, String> runtimeProperties = new HashMap<>(serviceContext.getOwner().getProperties());
runtimeProperties.putIfAbsent(QUARKUS_HTTP_PORT_PROPERTY, "" + assignedHttpPort);
runtimeProperties.putIfAbsent(QUARKUS_PLATFORM_VERSION, QuarkusProperties.getVersion());
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, String> getPropertiesForCommand() {
Map<String, String> runtimeProperties = new HashMap<>(serviceContext.getOwner().getProperties());
runtimeProperties.putIfAbsent(QUARKUS_HTTP_PORT_PROPERTY, "" + assignedHttpPort);
return runtimeProperties;
}
}

0 comments on commit be7a968

Please sign in to comment.