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

[1.5.z] Backport quarkus CLI PRs #1325

Merged
merged 4 commits into from
Sep 17, 2024
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 @@ -28,7 +28,9 @@
import org.codehaus.plexus.util.xml.XmlStreamReader;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;

import io.quarkus.test.bootstrap.QuarkusCliClient;
import io.quarkus.test.bootstrap.QuarkusCliRestService;
import io.quarkus.test.services.quarkus.model.QuarkusProperties;
import io.smallrye.common.os.OS;

public abstract class QuarkusCLIUtils {
Expand All @@ -45,6 +47,16 @@ public abstract class QuarkusCLIUtils {
*/
private static final int GAV_FIELDS_LENGTH = 3;

public static IQuarkusCLIAppManager createAppManager(QuarkusCliClient cliClient,
DefaultArtifactVersion oldVersionStream,
DefaultArtifactVersion newVersionStream) {
if (QuarkusProperties.isRHBQ()) {
return new RHBQPlatformAppManager(cliClient, oldVersionStream, newVersionStream,
new DefaultArtifactVersion(QuarkusProperties.getVersion()));
}
return new DefaultQuarkusCLIAppManager(cliClient, oldVersionStream, newVersionStream);
}

/**
* Create app, put properties into application.properties file,
* then update the app and verify that properties are the expected ones.
Expand Down Expand Up @@ -259,6 +271,33 @@ public static Properties getProperties(QuarkusCliRestService app) throws XmlPull
return getPom(app).getProperties();
}

/**
* Change given properties in app's pom.
* Other properties are unchanged.
*/
public static void changePropertiesInPom(QuarkusCliRestService app, Properties properties)
throws XmlPullParserException, IOException {
Model pom = getPom(app);
Properties pomProperties = pom.getProperties();
pomProperties.putAll(properties);
pom.setProperties(pomProperties);
savePom(app, pom);
}

/**
* If tests are not on RHBQ it will set properties in app's pom to work with community quarkus BOM.
* Expects that app is using RHBQ by default.
*/
public static void setCommunityBomIfNotRunningRHBQ(QuarkusCliRestService app, String communityQuarkusVersion)
throws XmlPullParserException, IOException {
if (!QuarkusProperties.getVersion().contains("redhat")) {
Properties communityBomProperties = new Properties();
communityBomProperties.put("quarkus.platform.group-id", "io.quarkus.platform");
communityBomProperties.put("quarkus.platform.version", communityQuarkusVersion);
changePropertiesInPom(app, communityBomProperties);
}
}

/**
* Get main pom of the application (the one in root dir).
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package io.quarkus.test.util;

import static io.quarkus.test.bootstrap.QuarkusCliClient.UpdateApplicationRequest.defaultUpdate;
import static io.quarkus.test.util.QuarkusCLIUtils.getQuarkusAppVersion;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;

import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;

import io.quarkus.test.bootstrap.QuarkusCliClient;
import io.quarkus.test.bootstrap.QuarkusCliRestService;
import io.quarkus.test.logging.Log;

/**
* AppManager designed to update app to specific quarkus-bom version, instead of to stream as DefaultQuarkusCLIAppManager.
*/
public class RHBQPlatformAppManager extends DefaultQuarkusCLIAppManager {
protected final DefaultArtifactVersion newPlatformVersion;

public RHBQPlatformAppManager(QuarkusCliClient cliClient, DefaultArtifactVersion oldStreamVersion,
DefaultArtifactVersion newStreamVersion, DefaultArtifactVersion newPlatformVersion) {
super(cliClient, oldStreamVersion, newStreamVersion);
this.newPlatformVersion = newPlatformVersion;
}

@Override
public void updateApp(QuarkusCliRestService app) {
Log.info("Updating app to version: " + newPlatformVersion);
app.update(defaultUpdate()
.withPlatformVersion(newPlatformVersion.toString()));
}

@Override
public QuarkusCliRestService createApplication() {
return assertIsUsingRHBQ(super.createApplication());
}

@Override
public QuarkusCliRestService createApplicationWithExtensions(String... extensions) {
return assertIsUsingRHBQ(super.createApplicationWithExtensions(extensions));
}

@Override
public QuarkusCliRestService createApplicationWithExtraArgs(String... extraArgs) {
return assertIsUsingRHBQ(super.createApplicationWithExtraArgs(extraArgs));
}

private QuarkusCliRestService assertIsUsingRHBQ(QuarkusCliRestService app) {
try {
// check that created application uses version with "redhat" suffix.
assertTrue(getQuarkusAppVersion(app).toString().contains("redhat"),
"Created Quarkus application does not use \"redhat\" version, while should be RHBQ");
} catch (IOException | XmlPullParserException e) {
throw new RuntimeException(e);
}
return app;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ private QuarkusProperties() {

}

public static boolean isRHBQ() {
return QuarkusProperties.getVersion().contains("redhat");
}

public static String getVersion() {
return defaultVersionIfEmpty(PLATFORM_VERSION.get());
}
Expand Down