Skip to content

Commit

Permalink
make consume record
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Potucek authored and punkratz312 committed Jan 14, 2025
1 parent 9cc331d commit cb8d2c0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,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 @@ -236,7 +236,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
52 changes: 14 additions & 38 deletions core/builder/src/main/java/io/quarkus/builder/Consume.java
Original file line number Diff line number Diff line change
@@ -1,44 +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;
}

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);
}
public record Consume(BuildStepBuilder buildStepBuilder, ItemId itemId, Constraint constraint, ConsumeFlags flags) {

Constraint getConstraint() {
return constraint;
public Consume combine(final Constraint constraint, final ConsumeFlags flags) {
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));
}
}

0 comments on commit cb8d2c0

Please sign in to comment.