Skip to content

Commit

Permalink
Support for dev-mode-only conditional dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Loubyansky committed Nov 15, 2024
1 parent 45fa5d3 commit e5d0ae0
Show file tree
Hide file tree
Showing 16 changed files with 492 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,17 @@ protected QuarkusBootstrap.Builder initBootstrapBuilder() throws Exception {
final QuarkusBootstrap.Builder bootstrap = QuarkusBootstrap.builder()
.setApplicationRoot(applicationRoot)
.setProjectRoot(applicationRoot)
.setAppModelResolver(resolver)
.setTest(isBootstrapForTestMode());
.setAppModelResolver(resolver);

switch (getBootstrapMode()) {
case PROD:
break;
case TEST:
bootstrap.setTest(true);
break;
default:
throw new IllegalArgumentException("Not supported bootstrap mode " + getBootstrapMode());
}

if (createWorkspace() || !wsModules.isEmpty()) {
System.setProperty("basedir", ws.toAbsolutePath().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@ protected QuarkusBootstrap.Builder initBootstrapBuilder()
.setApplicationRoot(applicationRoot)
.setProjectRoot(applicationRoot)
.setTargetDirectory(appModel.getAppArtifact().getWorkspaceModule().getBuildDir().toPath())
.setAppModelResolver(resolver)
.setTest(isBootstrapForTestMode());
.setAppModelResolver(resolver);
switch (getBootstrapMode()) {
case PROD:
break;
case TEST:
bootstrap.setTest(true);
break;
default:
throw new IllegalArgumentException("Not supported bootstrap mode " + getBootstrapMode());
}
return bootstrap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.HashSet;
import java.util.Set;

import io.quarkus.bootstrap.app.QuarkusBootstrap;
import io.quarkus.bootstrap.model.ApplicationModel;
import io.quarkus.bootstrap.resolver.TsArtifact;
import io.quarkus.bootstrap.resolver.TsDependency;
Expand All @@ -17,8 +18,8 @@
public class ProvidedExtensionDepsInTestModeTest extends BootstrapFromOriginalJarTestBase {

@Override
protected boolean isBootstrapForTestMode() {
return true;
protected QuarkusBootstrap.Mode getBootstrapMode() {
return QuarkusBootstrap.Mode.TEST;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.eclipse.aether.util.artifact.JavaScopes;

import io.quarkus.bootstrap.app.QuarkusBootstrap;
import io.quarkus.bootstrap.model.ApplicationModel;
import io.quarkus.bootstrap.resolver.TsArtifact;
import io.quarkus.bootstrap.resolver.TsDependency;
Expand All @@ -19,8 +20,8 @@
public class ProvidedExtensionDepsTestModeTest extends BootstrapFromOriginalJarTestBase {

@Override
protected boolean isBootstrapForTestMode() {
return true;
protected QuarkusBootstrap.Mode getBootstrapMode() {
return QuarkusBootstrap.Mode.TEST;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public interface BootstrapConstants {
String SERIALIZED_TEST_APP_MODEL = "quarkus-internal-test.serialized-app-model.path";
String DESCRIPTOR_FILE_NAME = "quarkus-extension.properties";
String CONDITIONAL_DEPENDENCIES = "conditional-dependencies";
String CONDITIONAL_DEV_DEPENDENCIES = "conditional-dev-dependencies";
String DEPENDENCY_CONDITION = "dependency-condition";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;

import io.quarkus.bootstrap.app.QuarkusBootstrap;
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenException;
import io.quarkus.bootstrap.resolver.maven.IncubatingApplicationModelResolver;
import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
Expand Down Expand Up @@ -143,15 +144,24 @@ protected boolean cleanWorkDir() {
return true;
}

protected boolean isBootstrapForTestMode() {
return false;
protected QuarkusBootstrap.Mode getBootstrapMode() {
return QuarkusBootstrap.Mode.PROD;
}

protected BootstrapAppModelResolver newAppModelResolver(LocalProject currentProject) throws Exception {
final BootstrapAppModelResolver appModelResolver = new BootstrapAppModelResolver(newArtifactResolver(currentProject));
appModelResolver.setIncubatingModelResolver(IncubatingApplicationModelResolver.isIncubatingEnabled(null));
if (isBootstrapForTestMode()) {
appModelResolver.setTest(true);
switch (getBootstrapMode()) {
case PROD:
break;
case TEST:
appModelResolver.setTest(true);
break;
case DEV:
appModelResolver.setDevMode(true);
break;
default:
throw new IllegalArgumentException("Not supported bootstrap mode " + getBootstrapMode());
}
return appModelResolver;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ public TsQuarkusExt setConditionalDeps(TsQuarkusExt... exts) {
return setDescriptorProp(BootstrapConstants.CONDITIONAL_DEPENDENCIES, buf.toString());
}

public TsQuarkusExt setConditionalDevDeps(TsQuarkusExt... exts) {
final StringBuilder buf = new StringBuilder();
int i = 0;
buf.append(exts[i++].getRuntime().toString());
while (i < exts.length) {
buf.append(' ').append(exts[i++].getRuntime().toString());
}
return setDescriptorProp(BootstrapConstants.CONDITIONAL_DEV_DEPENDENCIES, buf.toString());
}

public TsQuarkusExt setDependencyCondition(TsQuarkusExt... exts) {
final StringBuilder buf = new StringBuilder();
int i = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package io.quarkus.bootstrap.resolver.test;

import io.quarkus.bootstrap.app.QuarkusBootstrap;
import io.quarkus.bootstrap.resolver.BootstrapAppModelResolver;
import io.quarkus.bootstrap.resolver.CollectDependenciesBase;
import io.quarkus.bootstrap.resolver.TsArtifact;
import io.quarkus.bootstrap.resolver.TsQuarkusExt;
import io.quarkus.bootstrap.resolver.maven.workspace.LocalProject;
import io.quarkus.maven.dependency.DependencyFlags;

public class ConditionalDependenciesDevModelTestCase extends CollectDependenciesBase {

@Override
protected BootstrapAppModelResolver newAppModelResolver(LocalProject currentProject) throws Exception {
var resolver = super.newAppModelResolver(currentProject);
resolver.setIncubatingModelResolver(false);
return resolver;
}

@Override
protected QuarkusBootstrap.Mode getBootstrapMode() {
return QuarkusBootstrap.Mode.DEV;
}

@Override
protected void setupDependencies() {

final TsQuarkusExt extA = new TsQuarkusExt("ext-a");
install(extA, false);
addCollectedDeploymentDep(extA.getDeployment());

installAsDep(extA.getRuntime(),
DependencyFlags.DIRECT
| DependencyFlags.RUNTIME_EXTENSION_ARTIFACT
| DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT);

final TsQuarkusExt extB = new TsQuarkusExt("ext-b");
install(extB, false);
addCollectedDep(extB.getRuntime(), DependencyFlags.RUNTIME_EXTENSION_ARTIFACT);
addCollectedDeploymentDep(extB.getDeployment());

final TsQuarkusExt extC = new TsQuarkusExt("ext-c");
extC.setDependencyCondition(extB);
install(extC, false);
addCollectedDep(extC.getRuntime(), DependencyFlags.RUNTIME_EXTENSION_ARTIFACT);
addCollectedDeploymentDep(extC.getDeployment());

final TsQuarkusExt extD = new TsQuarkusExt("ext-d");
install(extD, false);
installAsDep(extD.getRuntime(),
DependencyFlags.DIRECT
| DependencyFlags.RUNTIME_EXTENSION_ARTIFACT
| DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT);
addCollectedDeploymentDep(extD.getDeployment());

final TsArtifact libE = TsArtifact.jar("lib-e");
install(libE, true);
final TsArtifact libEBuildTIme = TsArtifact.jar("lib-e-build-time");
install(libEBuildTIme);
addCollectedDeploymentDep(libEBuildTIme);

final TsQuarkusExt extE = new TsQuarkusExt("ext-e");
extE.setDependencyCondition(extD);
extE.getRuntime().addDependency(libE);
extE.getDeployment().addDependency(libEBuildTIme);
install(extE, false);
addCollectedDep(extE.getRuntime(), DependencyFlags.RUNTIME_EXTENSION_ARTIFACT);
addCollectedDeploymentDep(extE.getDeployment());

final TsQuarkusExt extF = new TsQuarkusExt("ext-f");
extF.setConditionalDeps(extC, extE);
install(extF, false);
installAsDep(extF.getRuntime(),
DependencyFlags.DIRECT
| DependencyFlags.RUNTIME_EXTENSION_ARTIFACT
| DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT);
addCollectedDeploymentDep(extF.getDeployment());

final TsQuarkusExt extG = new TsQuarkusExt("ext-g");
extG.setConditionalDevDeps(extB);
install(extG, false);
installAsDep(extG.getRuntime(),
DependencyFlags.DIRECT
| DependencyFlags.RUNTIME_EXTENSION_ARTIFACT
| DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT);
addCollectedDeploymentDep(extG.getDeployment());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package io.quarkus.bootstrap.resolver.test;

import io.quarkus.bootstrap.resolver.BootstrapAppModelResolver;
import io.quarkus.bootstrap.resolver.CollectDependenciesBase;
import io.quarkus.bootstrap.resolver.TsArtifact;
import io.quarkus.bootstrap.resolver.TsQuarkusExt;
import io.quarkus.bootstrap.resolver.maven.workspace.LocalProject;
import io.quarkus.maven.dependency.DependencyFlags;

public class ConditionalDependenciesProdModelTestCase extends CollectDependenciesBase {

@Override
protected BootstrapAppModelResolver newAppModelResolver(LocalProject currentProject) throws Exception {
var resolver = super.newAppModelResolver(currentProject);
resolver.setIncubatingModelResolver(false);
return resolver;
}

@Override
protected void setupDependencies() {

final TsQuarkusExt extA = new TsQuarkusExt("ext-a");
install(extA, false);
addCollectedDeploymentDep(extA.getDeployment());

installAsDep(extA.getRuntime(),
DependencyFlags.DIRECT
| DependencyFlags.RUNTIME_EXTENSION_ARTIFACT
| DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT);

final TsQuarkusExt extB = new TsQuarkusExt("ext-b");
install(extB, false);

final TsQuarkusExt extC = new TsQuarkusExt("ext-c");
extC.setDependencyCondition(extB);
install(extC, false);

final TsQuarkusExt extD = new TsQuarkusExt("ext-d");
install(extD, false);
installAsDep(extD.getRuntime(),
DependencyFlags.DIRECT
| DependencyFlags.RUNTIME_EXTENSION_ARTIFACT
| DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT);
addCollectedDeploymentDep(extD.getDeployment());

final TsArtifact libE = TsArtifact.jar("lib-e");
install(libE, true);
final TsArtifact libEBuildTIme = TsArtifact.jar("lib-e-build-time");
install(libEBuildTIme);
addCollectedDeploymentDep(libEBuildTIme);

final TsQuarkusExt extE = new TsQuarkusExt("ext-e");
extE.setDependencyCondition(extD);
extE.getRuntime().addDependency(libE);
extE.getDeployment().addDependency(libEBuildTIme);
install(extE, false);
addCollectedDep(extE.getRuntime(), DependencyFlags.RUNTIME_EXTENSION_ARTIFACT);
addCollectedDeploymentDep(extE.getDeployment());

final TsQuarkusExt extF = new TsQuarkusExt("ext-f");
extF.setConditionalDeps(extC, extE);
install(extF, false);
installAsDep(extF.getRuntime(),
DependencyFlags.DIRECT
| DependencyFlags.RUNTIME_EXTENSION_ARTIFACT
| DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT);
addCollectedDeploymentDep(extF.getDeployment());

final TsQuarkusExt extG = new TsQuarkusExt("ext-g");
extG.setConditionalDevDeps(extB);
install(extG, false);
installAsDep(extG.getRuntime(),
DependencyFlags.DIRECT
| DependencyFlags.RUNTIME_EXTENSION_ARTIFACT
| DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT);
addCollectedDeploymentDep(extG.getDeployment());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import io.quarkus.bootstrap.resolver.maven.workspace.LocalProject;
import io.quarkus.maven.dependency.DependencyFlags;

public class RuntimeOnlyApplicationModelTestCase extends CollectDependenciesBase {
public class ConditionalDependenciesRuntimeOnlyProdModelTestCase extends CollectDependenciesBase {

private static final boolean runtimeOnly = true;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package io.quarkus.bootstrap.resolver.test;

import io.quarkus.bootstrap.app.QuarkusBootstrap;
import io.quarkus.bootstrap.resolver.BootstrapAppModelResolver;
import io.quarkus.bootstrap.resolver.CollectDependenciesBase;
import io.quarkus.bootstrap.resolver.TsQuarkusExt;
import io.quarkus.bootstrap.resolver.maven.workspace.LocalProject;
import io.quarkus.maven.dependency.DependencyFlags;

public class DevModeConditionalDependencyWithExtraConditionTestCase extends CollectDependenciesBase {

@Override
protected BootstrapAppModelResolver newAppModelResolver(LocalProject currentProject) throws Exception {
var resolver = super.newAppModelResolver(currentProject);
resolver.setIncubatingModelResolver(false);
return resolver;
}

@Override
protected QuarkusBootstrap.Mode getBootstrapMode() {
return QuarkusBootstrap.Mode.DEV;
}

@Override
protected void setupDependencies() {

final TsQuarkusExt extA = new TsQuarkusExt("ext-a");
install(extA, false);
addCollectedDeploymentDep(extA.getDeployment());

installAsDep(extA.getRuntime(),
DependencyFlags.DIRECT
| DependencyFlags.RUNTIME_EXTENSION_ARTIFACT
| DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT);

final TsQuarkusExt extB = new TsQuarkusExt("ext-b");
install(extB, false);
addCollectedDep(extB.getRuntime(), DependencyFlags.RUNTIME_EXTENSION_ARTIFACT);
addCollectedDeploymentDep(extB.getDeployment());

final TsQuarkusExt extC = new TsQuarkusExt("ext-c");
extC.setDependencyCondition(extA);
install(extC, false);
addCollectedDep(extC.getRuntime(), DependencyFlags.RUNTIME_EXTENSION_ARTIFACT);
addCollectedDeploymentDep(extC.getDeployment());

final TsQuarkusExt extD = new TsQuarkusExt("ext-d");
install(extD, false);

final TsQuarkusExt extE = new TsQuarkusExt("ext-e");
extE.setDependencyCondition(extD);
install(extE, false);

final TsQuarkusExt extG = new TsQuarkusExt("ext-g");
extG.setConditionalDevDeps(extB, extC, extE);
install(extG, false);
installAsDep(extG.getRuntime(),
DependencyFlags.DIRECT
| DependencyFlags.RUNTIME_EXTENSION_ARTIFACT
| DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT);
addCollectedDeploymentDep(extG.getDeployment());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ private ApplicationModel buildAppModel(ResolvedDependencyBuilder appArtifact,
.setCollectCompileOnly(filteredProvidedDeps)
.setDependencyLogging(depLogConfig)
.setRuntimeModelOnly(runtimeModelOnly)
.setDevMode(devmode)
.resolve(collectRtDepsRequest);
} else {
ApplicationDependencyTreeResolver.newInstance()
Expand All @@ -387,6 +388,7 @@ private ApplicationModel buildAppModel(ResolvedDependencyBuilder appArtifact,
.setCollectCompileOnly(filteredProvidedDeps)
.setBuildTreeConsumer(depLogConfig == null ? null : depLogConfig.getMessageConsumer())
.setRuntimeModelOnly(runtimeModelOnly)
.setDevMode(devmode)
.resolve(collectRtDepsRequest);
}
if (logTime) {
Expand Down
Loading

0 comments on commit e5d0ae0

Please sign in to comment.