Skip to content

Commit

Permalink
Fix conditional dependency resolution when runtime-deployment
Browse files Browse the repository at this point in the history
dependencies are not mirrored
  • Loading branch information
aloubyansky committed Nov 22, 2024
1 parent 9007580 commit b33f07e
Show file tree
Hide file tree
Showing 12 changed files with 496 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@
import java.util.HashMap;

import io.quarkus.bootstrap.model.ApplicationModel;
import io.quarkus.bootstrap.resolver.BootstrapAppModelResolver;
import io.quarkus.bootstrap.resolver.TsArtifact;
import io.quarkus.bootstrap.resolver.TsQuarkusExt;
import io.quarkus.bootstrap.resolver.maven.IncubatingApplicationModelResolver;
import io.quarkus.bootstrap.resolver.maven.workspace.LocalProject;
import io.quarkus.deployment.runnerjar.BootstrapFromOriginalJarTestBase;
import io.quarkus.maven.dependency.ResolvedDependency;

public class DependencyConditionMatchesConditionalDependencyTest extends BootstrapFromOriginalJarTestBase {

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

@Override
protected TsArtifact composeApplication() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.function.Supplier;

import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Model;
Expand Down Expand Up @@ -139,6 +138,10 @@ public TsArtifact addDependency(TsArtifact dep) {
return addDependency(new TsDependency(dep));
}

public TsArtifact addDependency(TsArtifact dep, boolean optional) {
return addDependency(new TsDependency(dep, optional));
}

public TsArtifact addDependency(TsArtifact dep, TsArtifact... excludes) {
return addDependency(new TsDependency(dep).exclude(excludes));
}
Expand All @@ -152,23 +155,23 @@ public TsArtifact addDependency(TsQuarkusExt dep, String scope) {
}

public TsArtifact addDependency(TsQuarkusExt dep, boolean optional) {
return addDependency(dep, () -> new TsDependency(dep.getRuntime(), optional));
return addDependency(dep, new TsDependency(dep.getRuntime(), optional));
}

public TsArtifact addDependency(TsQuarkusExt dep, String scope, boolean optional) {
return addDependency(dep, () -> new TsDependency(dep.getRuntime(), scope, optional));
return addDependency(dep, new TsDependency(dep.getRuntime(), scope, optional));
}

public TsArtifact addDependency(TsQuarkusExt dep, TsArtifact... excludes) {
return addDependency(dep, () -> new TsDependency(dep.getRuntime(), false).exclude(excludes));
return addDependency(dep, new TsDependency(dep.getRuntime(), false).exclude(excludes));
}

private TsArtifact addDependency(TsQuarkusExt dep, Supplier<TsDependency> dependencyFactory) {
private TsArtifact addDependency(TsQuarkusExt extDep, TsDependency dep) {
if (extDeps.isEmpty()) {
extDeps = new ArrayList<>(1);
}
extDeps.add(dep);
return addDependency(dependencyFactory.get());
extDeps.add(extDep);
return addDependency(dep);
}

public TsArtifact addDependency(TsDependency dep) {
Expand All @@ -179,6 +182,33 @@ public TsArtifact addDependency(TsDependency dep) {
return this;
}

/**
* Adds a dependency as the first in the list.
*
* @param dep dependency to add
* @return this artifact
*/
public TsArtifact addFirstDependency(TsDependency dep) {
if (deps.isEmpty()) {
deps = new ArrayList<>();
deps.add(dep);
} else {
deps.add(dep);
Collections.rotate(deps, 1);
}
return this;
}

/**
* Adds a dependency as the first in the list.
*
* @param dep dependency to add
* @return this artifact
*/
public TsArtifact addFirstDependency(TsArtifact dep) {
return addFirstDependency(new TsDependency(dep));
}

public TsArtifact addManagedDependency(TsArtifact a) {
return addManagedDependency(new TsDependency(a));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ public TsQuarkusExt setDependencyCondition(TsQuarkusExt... exts) {
return setDescriptorProp(BootstrapConstants.DEPENDENCY_CONDITION, buf.toString());
}

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

public TsQuarkusExt setDescriptorProp(String name, String value) {
rtDescr.set(name, value);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ConditionalDependenciesDevModelTestCase extends CollectDependencies
@Override
protected BootstrapAppModelResolver newAppModelResolver(LocalProject currentProject) throws Exception {
var resolver = super.newAppModelResolver(currentProject);
resolver.setIncubatingModelResolver(false);
//resolver.setIncubatingModelResolver(false);
return resolver;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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 ConditionalDependenciesDirectDependencyOnTransitiveDeploymentArtifactTestCase extends CollectDependenciesBase {

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

@Override
protected void setupDependencies() {

final TsQuarkusExt quarkusCore = new TsQuarkusExt("quarkus-core");
install(quarkusCore);

TsArtifact nettyNioClient = TsArtifact.jar("netty-nio-client");

final TsQuarkusExt nettyClientInternalExt = new TsQuarkusExt("netty-client-internal");
nettyClientInternalExt.addDependency(quarkusCore);
nettyClientInternalExt.getRuntime().addDependency(nettyNioClient, true);
nettyClientInternalExt.setDependencyCondition(nettyNioClient);
install(nettyClientInternalExt, false);
addCollectedDep(nettyClientInternalExt.getRuntime(),
DependencyFlags.RUNTIME_CP | DependencyFlags.DEPLOYMENT_CP | DependencyFlags.RUNTIME_EXTENSION_ARTIFACT);
addCollectedDeploymentDep(nettyClientInternalExt.getDeployment());

final TsQuarkusExt commonExt = new TsQuarkusExt("common");
commonExt.addDependency(quarkusCore);
commonExt.getRuntime().addDependency(nettyNioClient, true);
commonExt.getRuntime().addDependency(nettyClientInternalExt.getRuntime(), true);
commonExt.getDeployment().addDependency(nettyClientInternalExt.getDeployment(), true);
commonExt.setConditionalDeps(nettyClientInternalExt);
install(commonExt, false);
addCollectedDep(commonExt.getRuntime(),
DependencyFlags.RUNTIME_CP | DependencyFlags.DEPLOYMENT_CP | DependencyFlags.RUNTIME_EXTENSION_ARTIFACT);
addCollectedDeploymentDep(commonExt.getDeployment());

final TsQuarkusExt sqsExt = new TsQuarkusExt("sqs");
sqsExt.addDependency(quarkusCore);
sqsExt.getRuntime().addDependency(commonExt.getRuntime());
sqsExt.getRuntime().addDependency(nettyNioClient, true);
sqsExt.getDeployment().addFirstDependency(commonExt.getDeployment());
addCollectedDep(sqsExt.getRuntime(),
DependencyFlags.RUNTIME_CP | DependencyFlags.DEPLOYMENT_CP | DependencyFlags.RUNTIME_EXTENSION_ARTIFACT);
addCollectedDeploymentDep(sqsExt.getDeployment());

final TsQuarkusExt messagingSqsExt = new TsQuarkusExt("messaging-sqs");
messagingSqsExt.addDependency(quarkusCore);
messagingSqsExt.addDependency(sqsExt);
messagingSqsExt.getDeployment().addDependency(commonExt.getDeployment()); // this line breaks it

installAsDep(messagingSqsExt);
installAsDep(nettyNioClient);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ConditionalDependenciesProdModelTestCase extends CollectDependencie
@Override
protected BootstrapAppModelResolver newAppModelResolver(LocalProject currentProject) throws Exception {
var resolver = super.newAppModelResolver(currentProject);
resolver.setIncubatingModelResolver(false);
//resolver.setIncubatingModelResolver(false);
return resolver;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ConditionalDependenciesRuntimeOnlyProdModelTestCase extends Collect
@Override
protected BootstrapAppModelResolver newAppModelResolver(LocalProject currentProject) throws Exception {
var resolver = super.newAppModelResolver(currentProject);
resolver.setIncubatingModelResolver(false);
//resolver.setIncubatingModelResolver(false);
resolver.setRuntimeModelOnly(runtimeOnly);
return resolver;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class DevModeConditionalDependencyWithExtraConditionTestCase extends Coll
@Override
protected BootstrapAppModelResolver newAppModelResolver(LocalProject currentProject) throws Exception {
var resolver = super.newAppModelResolver(currentProject);
resolver.setIncubatingModelResolver(false);
//resolver.setIncubatingModelResolver(false);
return resolver;
}

Expand Down
Loading

0 comments on commit b33f07e

Please sign in to comment.