Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport/https devui+choose jar #647

Merged
merged 2 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,35 @@
@DisabledOnNative(reason = "This scenario is using uber-jar, so it's incompatible with Native")
@QuarkusScenario
public class TodoDemoIT {
@GitRepositoryQuarkusApplication(repo = "https://github.com/quarkusio/todo-demo-app.git", mavenArgs = "-Dquarkus.package.type=uber-jar -DskipTests=true -Dquarkus.platform.group-id=${QUARKUS_PLATFORM_GROUP-ID} -Dquarkus.platform.version=${QUARKUS_VERSION}")
private static final String REPO = "https://github.com/quarkusio/todo-demo-app.git";
private static final String DEFAULT_ARGS = "-DskipTests=true -Dquarkus.platform.group-id=${QUARKUS_PLATFORM_GROUP-ID} -Dquarkus.platform.version=${QUARKUS_VERSION} ";
private static final String UBER = "-Dquarkus.package.type=uber-jar ";

@GitRepositoryQuarkusApplication(repo = REPO, mavenArgs = DEFAULT_ARGS + UBER)
static final RestService app = new RestService();

@GitRepositoryQuarkusApplication(repo = REPO, artifact = "todo-backend-1.0-SNAPSHOT-runner.jar", mavenArgs = DEFAULT_ARGS
+ UBER)
static final RestService explicit = new RestService();

private static final String NO_SUFFIX = "-Dquarkus.package.add-runner-suffix=false";

@GitRepositoryQuarkusApplication(repo = REPO, artifact = "todo-backend-1.0-SNAPSHOT.jar", mavenArgs = DEFAULT_ARGS + UBER
+ NO_SUFFIX)
static final RestService unsuffixed = new RestService();

@Test
public void verify() {
app.given()
.get()
.then()
.statusCode(HttpStatus.SC_OK);
app.given().get().then().statusCode(HttpStatus.SC_OK);
}

@Test
public void verifyExplicitArtifact() {
explicit.given().get().then().statusCode(HttpStatus.SC_OK);
}

@Test
public void verifyNoSuffix() {
unsuffixed.given().get().then().statusCode(HttpStatus.SC_OK);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.quarkus.qe;

import org.apache.http.HttpStatus;
import org.junit.jupiter.api.Test;

import io.quarkus.test.bootstrap.DevModeQuarkusService;
import io.quarkus.test.scenarios.QuarkusScenario;
import io.quarkus.test.scenarios.annotations.DisabledOnNative;
import io.quarkus.test.services.DevModeQuarkusApplication;

@QuarkusScenario
@DisabledOnNative
public class DevModeGreetingResourceIT {
@DevModeQuarkusApplication(ssl = true)
static DevModeQuarkusService app = new DevModeQuarkusService();

@Test
public void shouldOpenDevUi() {
app.given().get("/q/dev").then().statusCode(HttpStatus.SC_OK);
}

@Test
public void shouldOpenHttpsDevUi() {
app.relaxedHttps().get("/q/dev").then().statusCode(HttpStatus.SC_OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public RequestSpecification https() {
.port(host.getPort());
}

public RequestSpecification relaxedHttps() {
return this.https().relaxedHTTPSValidation();
}

public WebClient mutiny() {
return mutiny(new WebClientOptions());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@
* Enable GRPC configuration. This property will map the gPRC service to a random port.
*/
boolean grpc() default false;

/**
* Enable SSL configuration. This property needs `quarkus.http.ssl.certificate.key-store-file` and
* `quarkus.http.ssl.certificate.key-store-password` to be set.
*/
boolean ssl() default false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ String mavenArgs() default "-DskipTests=true -DskipITs=true "

boolean devMode() default false;

String artifact() default "";

/**
* @return the properties file to use to configure the Quarkus application.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public void init(Annotation annotation) {
initAppClasses(metadata.classes());
setPropertiesFile(metadata.properties());
setGrpcEnabled(metadata.grpc());
setSslEnabled(metadata.ssl());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public void init(Annotation annotation) {
contextDir = metadata.contextDir();
mavenArgs = metadata.mavenArgs();
devMode = metadata.devMode();
setArtifactSuffix(metadata.artifact());
initAppClasses(new Class[0]);
setPropertiesFile(metadata.properties());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,21 @@ public class ProdQuarkusApplicationManagedResourceBuilder extends ArtifactQuarku

private Path artifact;
private QuarkusManagedResource managedResource;
private String artifactSuffix;

@Override
protected Path getArtifact() {
return artifact;
}

protected void setArtifactSuffix(String suffix) {
if (suffix == null || suffix.isEmpty() || suffix.isBlank()) {
this.artifactSuffix = null;
} else {
this.artifactSuffix = suffix;
}
}

@Override
public void init(Annotation annotation) {
QuarkusApplication metadata = (QuarkusApplication) annotation;
Expand All @@ -70,7 +79,7 @@ public void build() {
managedResource.onPreBuild();
copyResourcesToAppFolder();
if (managedResource.needsBuildArtifact()) {
tryToReuseOrBuildArtifact();
this.artifact = tryToReuseOrBuildArtifact();
}

managedResource.onPostBuild();
Expand All @@ -90,27 +99,34 @@ protected Path getTargetFolderForLocalArtifacts() {
return Paths.get(TARGET);
}

private void tryToReuseOrBuildArtifact() {
private Path tryToReuseOrBuildArtifact() {
Optional<String> artifactLocation = Optional.empty();
final Path targetFolder = getTargetFolderForLocalArtifacts();
if (artifactSuffix != null) {
return findTargetFile(targetFolder, artifactSuffix)
.map(Path::of)
.orElseThrow(() -> new IllegalStateException(String.format("Folder %s doesn't contain '%s'",
targetFolder,
artifactSuffix)));
}
if (!containsBuildProperties() && !requiresCustomBuild()) {
if (QuarkusProperties.isNativePackageType(getContext())) {
String nativeRunnerExpectedLocation = NATIVE_RUNNER;
if (OS.WINDOWS.isCurrentOs()) {
nativeRunnerExpectedLocation += EXE;
}

artifactLocation = findTargetFile(getTargetFolderForLocalArtifacts(), nativeRunnerExpectedLocation);

artifactLocation = findTargetFile(targetFolder, nativeRunnerExpectedLocation);
} else {
artifactLocation = findTargetFile(getTargetFolderForLocalArtifacts(), JVM_RUNNER)
.or(() -> findTargetFile(getTargetFolderForLocalArtifacts().resolve(QUARKUS_APP), QUARKUS_RUN));
artifactLocation = findTargetFile(targetFolder, JVM_RUNNER)
.or(() -> findTargetFile(targetFolder.resolve(QUARKUS_APP), QUARKUS_RUN));
}
}

if (artifactLocation.isEmpty()) {
this.artifact = buildArtifact();
return buildArtifact();
} else {
this.artifact = Path.of(artifactLocation.get());
return Path.of(artifactLocation.get());
}
}

Expand Down