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

Make io.quarkus.builder.Consume a record #45633

Merged
merged 1 commit into from
Jan 26, 2025
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 @@ -178,7 +178,7 @@ private Map<BuildStepBuilder, Set<Produce>> wireDependencies(Set<BuildStepBuilde
for (Map.Entry<ItemId, Consume> entry : stepBuilder.getConsumes().entrySet()) {
final Consume consume = entry.getValue();
final ItemId id = entry.getKey();
if (!consume.getFlags().contains(ConsumeFlag.OPTIONAL) && !id.isMulti()) {
if (!consume.flags().contains(ConsumeFlag.OPTIONAL) && !id.isMulti()) {
if (!initialIds.contains(id) && !allProduces.containsKey(id)) {
throw new ChainBuildException("No producers for required item " + id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ Map<ItemId, Produce> getProduces() {

Set<ItemId> getRealConsumes() {
final HashMap<ItemId, Consume> map = new HashMap<>(consumes);
map.entrySet().removeIf(e -> e.getValue().getConstraint() == Constraint.ORDER_ONLY);
map.entrySet().removeIf(e -> e.getValue().constraint() == Constraint.ORDER_ONLY);
return map.keySet();
}

Expand Down
48 changes: 13 additions & 35 deletions core/builder/src/main/java/io/quarkus/builder/Consume.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,20 @@
package io.quarkus.builder;

final class Consume {
private final BuildStepBuilder buildStepBuilder;
private final ItemId itemId;
private final Constraint constraint;
private final ConsumeFlags flags;
import static io.quarkus.builder.Constraint.ORDER_ONLY;
import static io.quarkus.builder.Constraint.REAL;
import static io.quarkus.builder.ConsumeFlag.OPTIONAL;

Consume(final BuildStepBuilder buildStepBuilder, final ItemId itemId, final Constraint constraint,
final ConsumeFlags flags) {
this.buildStepBuilder = buildStepBuilder;
this.itemId = itemId;
this.constraint = constraint;
this.flags = flags;
}

BuildStepBuilder getBuildStepBuilder() {
return buildStepBuilder;
}

ItemId getItemId() {
return itemId;
}

ConsumeFlags getFlags() {
return flags;
}
record Consume(BuildStepBuilder buildStepBuilder, ItemId itemId, Constraint constraint, ConsumeFlags flags) {

Consume combine(final Constraint constraint, final ConsumeFlags flags) {
final Constraint outputConstraint = constraint == Constraint.REAL || this.constraint == Constraint.REAL
? Constraint.REAL
: Constraint.ORDER_ONLY;
final ConsumeFlags outputFlags = !flags.contains(ConsumeFlag.OPTIONAL) || !this.flags.contains(ConsumeFlag.OPTIONAL)
? flags.with(this.flags).without(ConsumeFlag.OPTIONAL)
: flags.with(this.flags);
return new Consume(buildStepBuilder, itemId, outputConstraint, outputFlags);
}

Constraint getConstraint() {
return constraint;
return new Consume(
buildStepBuilder,
itemId,
constraint == REAL || this.constraint == REAL
? REAL
: ORDER_ONLY,
!flags.contains(OPTIONAL) || !this.flags.contains(OPTIONAL)
? flags.with(this.flags).without(OPTIONAL)
: flags.with(this.flags));
}
}
Loading