Add support for configuring additional dependencies in @QuarkusProdModeTest

This commit is contained in:
Georgios Andrianakis
2020-02-18 13:48:06 +02:00
parent 13c054a80c
commit e98b2da33a
3 changed files with 38 additions and 2 deletions

View File

@@ -80,6 +80,8 @@ public class BootstrapAppModelFactory {
private LocalProject appClassesWorkspace;
private List<AppDependency> forcedDependencies = Collections.emptyList();
private BootstrapAppModelFactory() {
}
@@ -143,6 +145,11 @@ public class BootstrapAppModelFactory {
return this;
}
public BootstrapAppModelFactory setForcedDependencies(List<AppDependency> forcedDependencies) {
this.forcedDependencies = forcedDependencies;
return this;
}
public AppModelResolver getAppModelResolver() {
if (bootstrapAppModelResolver != null) {
@@ -273,7 +280,7 @@ public class BootstrapAppModelFactory {
}
AppModelResolver appModelResolver = getAppModelResolver();
CurationResult curationResult = new CurationResult(appModelResolver
.resolveManagedModel(appArtifact, Collections.emptyList(), managingProject));
.resolveManagedModel(appArtifact, forcedDependencies, managingProject));
if (cachedCpPath != null) {
Files.createDirectories(cachedCpPath.getParent());
try (DataOutputStream out = new DataOutputStream(Files.newOutputStream(cachedCpPath))) {

View File

@@ -3,6 +3,7 @@ package io.quarkus.bootstrap.app;
import io.quarkus.bootstrap.BootstrapAppModelFactory;
import io.quarkus.bootstrap.BootstrapException;
import io.quarkus.bootstrap.model.AppArtifact;
import io.quarkus.bootstrap.model.AppDependency;
import io.quarkus.bootstrap.resolver.AppModelResolver;
import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
import io.quarkus.bootstrap.resolver.update.DependenciesOrigin;
@@ -72,6 +73,7 @@ public class QuarkusBootstrap implements Serializable {
private final boolean isolateDeployment;
private final MavenArtifactResolver mavenArtifactResolver;
private final AppArtifact managingProject;
private final List<AppDependency> forcedDependencies;
private QuarkusBootstrap(Builder builder) {
this.applicationRoot = builder.applicationRoot;
@@ -95,6 +97,7 @@ public class QuarkusBootstrap implements Serializable {
this.additionalDeploymentArchives = builder.additionalDeploymentArchives;
this.mavenArtifactResolver = builder.mavenArtifactResolver;
this.managingProject = builder.managingProject;
this.forcedDependencies = new ArrayList<>(builder.forcedDependencies);
}
public CuratedApplication bootstrap() throws BootstrapException {
@@ -119,6 +122,7 @@ public class QuarkusBootstrap implements Serializable {
.setLocalProjectsDiscovery(localProjectDiscovery)
.setAppArtifact(appArtifact)
.setManagingProject(managingProject)
.setForcedDependencies(forcedDependencies)
.setAppClasses(getProjectRoot() != null ? getProjectRoot()
: getApplicationRoot());
if (mode == Mode.TEST || test) {
@@ -213,6 +217,7 @@ public class QuarkusBootstrap implements Serializable {
boolean isolateDeployment;
MavenArtifactResolver mavenArtifactResolver;
AppArtifact managingProject;
List<AppDependency> forcedDependencies = new ArrayList<>();
public Builder(Path applicationRoot) {
this.applicationRoot = applicationRoot;
@@ -329,6 +334,15 @@ public class QuarkusBootstrap implements Serializable {
return this;
}
/**
* If set, each of these dependencies will either be added to the application dependencies if the GA doesn't match any
* application dependencies, or override the existing version if the GA does match
*/
public Builder setForcedDependencies(List<AppDependency> forcedDependencies) {
this.forcedDependencies = forcedDependencies;
return this;
}
public QuarkusBootstrap build() {
return new QuarkusBootstrap(this);
}

View File

@@ -15,6 +15,7 @@ import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
@@ -42,6 +43,8 @@ import io.quarkus.bootstrap.app.AugmentAction;
import io.quarkus.bootstrap.app.AugmentResult;
import io.quarkus.bootstrap.app.CuratedApplication;
import io.quarkus.bootstrap.app.QuarkusBootstrap;
import io.quarkus.bootstrap.model.AppArtifact;
import io.quarkus.bootstrap.model.AppDependency;
import io.quarkus.test.common.PathTestHelper;
import io.quarkus.test.common.RestAssuredURLManager;
import io.quarkus.utilities.JavaBinFinder;
@@ -84,6 +87,7 @@ public class QuarkusProdModeTest
private Optional<Field> prodModeTestResultsField = Optional.empty();
private Path logfilePath;
private Optional<Field> logfileField = Optional.empty();
private List<AppArtifact> forcedDependencies = Collections.emptyList();
public Supplier<JavaArchive> getArchiveProducer() {
return archiveProducer;
@@ -148,6 +152,15 @@ public class QuarkusProdModeTest
return this;
}
/**
* Provides a convenient way to either add additional dependencies to the application (if it doesn't already contain a
* dependency), or override a version (if the dependency already exists)
*/
public QuarkusProdModeTest setForcedDependencies(List<AppArtifact> forcedDependencies) {
this.forcedDependencies = forcedDependencies;
return this;
}
private void exportArchive(Path deploymentDir, Class<?> testClass) {
try {
JavaArchive archive = getArchiveProducerOrDefault();
@@ -229,7 +242,9 @@ public class QuarkusProdModeTest
.setLocalProjectDiscovery(true)
.addExcludedPath(testLocation)
.setProjectRoot(testLocation)
.setTargetDirectory(buildDir);
.setTargetDirectory(buildDir)
.setForcedDependencies(forcedDependencies.stream().map(d -> new AppDependency(d, "compile"))
.collect(Collectors.toList()));
if (applicationName != null) {
builder.setBaseName(applicationName);
}