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

Drop unnecessary reflection as we use Quarkus 3.x and we are not compatible with older Quarkus versions anyway #940

Merged
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 @@ -6,6 +6,7 @@
import java.lang.annotation.Annotation;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Optional;
import java.util.ServiceLoader;

Expand All @@ -23,7 +24,6 @@
import io.quarkus.test.common.PathTestHelper;
import io.quarkus.test.services.QuarkusApplication;
import io.quarkus.test.services.quarkus.model.QuarkusProperties;
import io.quarkus.test.utils.ReflectionUtils;

public class ProdQuarkusApplicationManagedResourceBuilder extends ArtifactQuarkusApplicationManagedResourceBuilder {

Expand Down Expand Up @@ -145,22 +145,13 @@ private Path buildArtifact() {
.setIsolateDeployment(true)
.setProjectRoot(testLocation)
.setBaseName(getContext().getName())
.setTargetDirectory(appFolder);
.setTargetDirectory(appFolder)
.setLocalProjectDiscovery(true);

if (!getForcedDependencies().isEmpty()) {
// The method setForcedDependencies signature changed from `List<AppDependency>` to `List<Dependency>` where
// Dependency is an interface of AppDependency, so it should be fine. However, the compiler fails to cast it,
// so we need to use reflection to sort it out for the most recent version and older versions.
ReflectionUtils.invokeMethod(builder, "setForcedDependencies", getForcedDependencies());
builder.setForcedDependencies(new ArrayList<>(getForcedDependencies()));
}

// The method `setLocalProjectDiscovery` signature changed from `Boolean` to `boolean` and this might make
// to fail the tests at runtime when using different versions.
// In order to workaround this, we need to invoke this method at runtime to let JVM unbox the arguments properly.
// Note that this is happening because we want to support both 2.x and 1.13.x Quarkus versions.
// Another strategy could be to have our own version of Quarkus bootstrap.
ReflectionUtils.invokeMethod(builder, "setLocalProjectDiscovery", true);

AugmentResult result;
try (CuratedApplication curatedApplication = builder.build().bootstrap()) {
AugmentAction action = curatedApplication.createAugmentor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import io.quarkus.test.utils.FileUtils;
import io.quarkus.test.utils.MapUtils;
import io.quarkus.test.utils.PropertiesUtils;
import io.quarkus.test.utils.ReflectionUtils;

public abstract class QuarkusApplicationManagedResourceBuilder implements ManagedResourceBuilder {

Expand Down Expand Up @@ -155,14 +154,7 @@ public void initForcedDependencies(Dependency[] forcedDependencies) {
String groupId = StringUtils.defaultIfEmpty(resolveProperty(d.groupId()), QUARKUS_GROUP_ID_DEFAULT);
String version = StringUtils.defaultIfEmpty(resolveProperty(d.version()), Version.getVersion());
AppArtifact artifact = new AppArtifact(groupId, d.artifactId(), version);
// Quarkus introduces a breaking change in 2.3:
// https://github.com/quarkusio/quarkus/commit/0c85b27c4046c894c181ffea367fca503d1c682c
if (isQuarkusVersion2Dot3OrAbove()) {
return ReflectionUtils.createInstance(AppDependency.class,
artifact, DEPENDENCY_SCOPE_DEFAULT, new int[] { DEPENDENCY_DIRECT_FLAG });
}

return new AppDependency(artifact, DEPENDENCY_SCOPE_DEFAULT);
return new AppDependency(artifact, DEPENDENCY_SCOPE_DEFAULT, DEPENDENCY_DIRECT_FLAG);
}).collect(Collectors.toList());
}
}
Expand Down