Skip to content

Commit

Permalink
Support quarkus-cli 999-SNAPSHOT
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo gonzalez granados committed May 25, 2022
1 parent 85426f4 commit 5454a4f
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
@DisabledIfSystemProperty(named = "profile.id", matches = "native", disabledReason = "Only for JVM verification")
public class QuarkusCliCreateJvmApplicationIT {

static final String RESTEASY_EXTENSION = "quarkus-resteasy";
static final String RESTEASY_REACTIVE_EXTENSION = "quarkus-resteasy-reactive";
static final String SMALLRYE_HEALTH_EXTENSION = "quarkus-smallrye-health";
static final String SPRING_WEB_EXTENSION = "quarkus-spring-web";
static final String RESTEASY_JACKSON_EXTENSION = "quarkus-resteasy-jackson";
static final String RESTEASY_REACTIVE_JACKSON_EXTENSION = "quarkus-resteasy-reactive-jackson";
static final String ROOT_FOLDER = "";
static final String DOCKER_FOLDER = "/src/main/docker";
static final String JDK_11 = "11";
Expand Down Expand Up @@ -78,7 +78,6 @@ public void shouldCreateApplicationOnJvm() {

@Tag("QUARKUS-1472")
@Test
@Disabled("https://github.com/quarkusio/quarkus/issues/24613")
public void createAppShouldAutoDetectJavaVersion() {
QuarkusCliRestService app = cliClient.createApplication("app", defaultWithFixedStream());
assertExpectedJavaVersion(getFileFromApplication(app, ROOT_FOLDER, "pom.xml"), getSystemJavaVersion());
Expand Down Expand Up @@ -152,23 +151,24 @@ public void shouldCreateApplicationOnJvmFromMultipleBoms() {
final String kogitoExtension = "kogito-quarkus-rules";
final String prettytimeExtension = "quarkus-prettytime";
QuarkusCliRestService app = cliClient.createApplication("app", defaultWithFixedStream().withExtensions(kogitoExtension,
prettytimeExtension, RESTEASY_EXTENSION, RESTEASY_JACKSON_EXTENSION));
prettytimeExtension, RESTEASY_REACTIVE_EXTENSION, RESTEASY_REACTIVE_JACKSON_EXTENSION));

// Should build on Jvm
Result result = app.buildOnJvm();
assertTrue(result.isSuccessful(), "The application didn't build on JVM. Output: " + result.getOutput());
assertInstalledExtensions(app, kogitoExtension, prettytimeExtension, RESTEASY_EXTENSION, RESTEASY_JACKSON_EXTENSION);
assertInstalledExtensions(app, kogitoExtension, prettytimeExtension, RESTEASY_REACTIVE_EXTENSION,
RESTEASY_REACTIVE_JACKSON_EXTENSION);
}

@Tag("QUARKUS-1071")
@Test
public void shouldCreateApplicationWithCodeStarter() {
// Create application with Resteasy Jackson + Spring Web (we need both for the app to run)
QuarkusCliRestService app = cliClient.createApplication("app",
defaultWithFixedStream().withExtensions(RESTEASY_JACKSON_EXTENSION, SPRING_WEB_EXTENSION));
defaultWithFixedStream().withExtensions(RESTEASY_REACTIVE_JACKSON_EXTENSION, SPRING_WEB_EXTENSION));

// Verify By default, it installs only "quarkus-resteasy-jackson" and "quarkus-spring-web"
assertInstalledExtensions(app, RESTEASY_JACKSON_EXTENSION, SPRING_WEB_EXTENSION);
// Verify By default, it installs only "quarkus-resteasy-reactive-jackson" and "quarkus-spring-web"
assertInstalledExtensions(app, RESTEASY_REACTIVE_JACKSON_EXTENSION, SPRING_WEB_EXTENSION);

// Start using DEV mode
app.start();
Expand All @@ -183,14 +183,14 @@ public void shouldAddAndRemoveExtensions() {
QuarkusCliRestService app = cliClient.createApplication("app", defaults().withPlatformBom(gav));

// By default, it installs only "quarkus-resteasy"
assertInstalledExtensions(app, RESTEASY_EXTENSION);
assertInstalledExtensions(app, RESTEASY_REACTIVE_EXTENSION);

// Let's install Quarkus SmallRye Health
Result result = app.installExtension(SMALLRYE_HEALTH_EXTENSION);
assertTrue(result.isSuccessful(), SMALLRYE_HEALTH_EXTENSION + " was not installed. Output: " + result.getOutput());

// Verify both extensions now
assertInstalledExtensions(app, RESTEASY_EXTENSION, SMALLRYE_HEALTH_EXTENSION);
assertInstalledExtensions(app, RESTEASY_REACTIVE_EXTENSION, SMALLRYE_HEALTH_EXTENSION);

// The health endpoint should be now available
app.start();
Expand All @@ -210,7 +210,7 @@ public void shouldAddAndRemoveExtensions() {
@Test
public void shouldCreateJacocoReportsFromApplicationOnJvm() {
QuarkusCliRestService app = cliClient.createApplication("app-with-jacoco",
defaultWithFixedStream().withExtensions("jacoco"));
defaultWithFixedStream().withExtensions("resteasy", "jacoco"));

Result result = app.buildOnJvm();
assertTrue(result.isSuccessful(), "The application didn't build on JVM. Output: " + result.getOutput());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.ts.quarkus.cli;

import static io.quarkus.ts.quarkus.cli.QuarkusCliUtils.getCurrentStreamVersion;
import static io.quarkus.ts.quarkus.cli.QuarkusCliUtils.isUpstream;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.ArrayList;
Expand Down Expand Up @@ -44,31 +45,39 @@ public class QuarkusCliExtensionsIT {

@Test
public void shouldListExtensionsUsingDefaults() {
whenGetListExtensions("--stream", getCurrentStreamVersion());
whenGetListExtensions(getDefaultAppArgs().toArray(new String[0]));
assertListDefaultOptionOutput();
}

@Test
public void shouldListExtensionsUsingName() {
whenGetListExtensions("--stream", getCurrentStreamVersion(), "--name");
List<String> args = getDefaultAppArgs();
args.add("--name");
whenGetListExtensions(args.toArray(new String[0]));
assertListNameOptionOutput();
}

@Test
public void shouldListExtensionsUsingOrigins() {
whenGetListExtensions("--stream", getCurrentStreamVersion(), "--origins");
List<String> args = getDefaultAppArgs();
args.add("--origins");
whenGetListExtensions(args.toArray(new String[0]));
assertListOriginsOptionOutput();
}

@Test
public void shouldListExtensionsUsingConcise() {
whenGetListExtensions("--stream", getCurrentStreamVersion(), "--concise");
List<String> args = getDefaultAppArgs();
args.add("--concise");
whenGetListExtensions(args.toArray(new String[0]));
assertListConciseOptionOutput();
}

@Test
public void shouldListExtensionsUsingFull() {
whenGetListExtensions("--stream", getCurrentStreamVersion(), "--full");
List<String> args = getDefaultAppArgs();
args.add("--full");
whenGetListExtensions(args.toArray(new String[0]));
assertListFullOptionOutput();
}

Expand Down Expand Up @@ -103,7 +112,9 @@ public void shouldListExtensionsUsingStream() {

@Test
public void shouldListExtensionsUsingInstallable() {
whenGetListExtensions("--stream", getCurrentStreamVersion(), "--installable");
List<String> args = getDefaultAppArgs();
args.add("--installable");
whenGetListExtensions(args.toArray(new String[0]));
assertListDefaultOptionOutput();
}

Expand Down Expand Up @@ -158,4 +169,14 @@ private void assertListFullOptionOutput() {
private void assertResultIsSuccessful() {
assertTrue(result.isSuccessful(), "Extensions list command didn't work. Output: " + result.getOutput());
}
}

private List<String> getDefaultAppArgs() {
String version = getCurrentStreamVersion();
List<String> args = new ArrayList<>();
if (!isUpstream(version)) {
args.addAll(Arrays.asList("--stream", version));
}

return args;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package io.quarkus.ts.quarkus.cli;

import static io.quarkus.ts.quarkus.cli.QuarkusCliUtils.getCurrentStreamVersion;
import static io.quarkus.ts.quarkus.cli.QuarkusCliUtils.isUpstream;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.inject.Inject;

Expand Down Expand Up @@ -131,8 +135,9 @@ private void whenBuildOnJvmAppAt(String folder) {
}

private void whenCreateAppAt(String folder) {
result = cliClient.run("create", "app", "--stream", getCurrentStreamVersion(), "--output-directory=" + folder,
ARTIFACT_ID);
List<String> args = getDefaultAppArgs("create", "app");
args.addAll(List.of("--output-directory=" + folder, ARTIFACT_ID));
result = cliClient.run(args.toArray(new String[args.size()]));
}

private void thenResultIsSuccessful() {
Expand All @@ -148,4 +153,15 @@ private void deleteFolder(String folder) {
FileUtils.deletePath(TARGET.resolve(folder));
}

private List<String> getDefaultAppArgs(String... defaultArgs) {
String version = getCurrentStreamVersion();
List<String> args = new ArrayList<>();
args.addAll(List.of(defaultArgs));
if (!isUpstream(version)) {
args.addAll(Arrays.asList("--stream", version));
}

return args;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,47 @@

import java.util.regex.Pattern;

import org.jboss.logging.Logger;

import io.quarkus.builder.Version;
import io.quarkus.test.bootstrap.QuarkusCliClient;

public class QuarkusCliUtils {

public static final String QUARKUS_UPSTREAM_VERSION = "999-SNAPSHOT";
private static final Logger LOG = Logger.getLogger(QuarkusCliUtils.class);

public static QuarkusCliClient.CreateApplicationRequest defaultWithFixedStream() {
return defaults().withStream(getCurrentStreamVersion());
String version = getCurrentStreamVersion();
if (isUpstream(version)) {
LOG.warn("fixed streams are not supported on upstream");
return defaults();
}

return defaults().withStream(version);
}

public static QuarkusCliClient.CreateExtensionRequest defaultNewExtensionArgsWithFixedStream() {
return QuarkusCliClient.CreateExtensionRequest.defaults().withStream(getCurrentStreamVersion());
String version = getCurrentStreamVersion();
if (isUpstream(version)) {
LOG.warn("fixed streams are not supported on upstream");
return QuarkusCliClient.CreateExtensionRequest.defaults();
}

return QuarkusCliClient.CreateExtensionRequest.defaults().withStream(version);
}

public static boolean isUpstream(String version) {
return version.equalsIgnoreCase(QUARKUS_UPSTREAM_VERSION);
}

public static String getCurrentStreamVersion() {
String[] version = Version.getVersion().split(Pattern.quote("."));
String rawVersion = Version.getVersion();
if (QUARKUS_UPSTREAM_VERSION.equalsIgnoreCase(rawVersion)) {
return QUARKUS_UPSTREAM_VERSION;
}

String[] version = rawVersion.split(Pattern.quote("."));
return String.format("%s.%s", version[0], version[1]);
}
}

0 comments on commit 5454a4f

Please sign in to comment.