|
1 | 1 | package io.quarkus.arc.deployment;
|
2 | 2 |
|
| 3 | +import java.util.HashSet; |
3 | 4 | import java.util.Objects;
|
| 5 | +import java.util.Set; |
4 | 6 |
|
5 | 7 | import io.quarkus.builder.item.MultiBuildItem;
|
6 | 8 |
|
7 | 9 | /**
|
8 | 10 | * Marks a bean archive with given coordinates (groupId, artifactId and optionally classifier)
|
9 |
| - * as known compatible with Quarkus. This is only useful for bean archives whose {@code beans.xml} |
10 |
| - * defines a bean discovery mode of {@code all}; bean archives with discovery mode of {@code none} |
11 |
| - * or {@code annotated} are always compatible. If a bean archive is known to be compatible with |
12 |
| - * Quarkus, no warning about {@code all} discovery is logged during application build. |
| 11 | + * as known compatible with Quarkus. If a bean archive is known to be compatible with |
| 12 | + * Quarkus, any error logging or exception throwing related to that compatibility is skipped. |
| 13 | + * <p> |
| 14 | + * This is useful in the following cases: |
| 15 | + * <li>Bean archives whose {@code beans.xml} defines a bean discovery mode of {@code all}; bean archives with discovery mode of |
| 16 | + * {@code none} or {@code annotated} are always compatible.</li> |
| 17 | + * <li>Bean archives that contain the unsupported {@link jakarta.enterprise.inject.Specializes} annotation.</li> |
13 | 18 | */
|
14 | 19 | public final class KnownCompatibleBeanArchiveBuildItem extends MultiBuildItem {
|
| 20 | + final Set<Reason> reasons; |
15 | 21 | final String groupId;
|
16 | 22 | final String artifactId;
|
17 | 23 | final String classifier;
|
18 | 24 |
|
| 25 | + /** |
| 26 | + * Deprecated, use {@link KnownCompatibleBeanArchiveBuildItem#builder(String, String)} method instead. |
| 27 | + * For compatibility reasons, this method automatically registers the artifact with {@link Reason#BEANS_XML_ALL}. |
| 28 | + */ |
| 29 | + @Deprecated |
19 | 30 | public KnownCompatibleBeanArchiveBuildItem(String groupId, String artifactId) {
|
20 | 31 | this(groupId, artifactId, "");
|
21 | 32 | }
|
22 | 33 |
|
| 34 | + /** |
| 35 | + * Deprecated, use {@link KnownCompatibleBeanArchiveBuildItem#builder(String, String)} method instead. |
| 36 | + * For compatibility reasons, this method automatically registers the artifact with {@link Reason#BEANS_XML_ALL}. |
| 37 | + */ |
| 38 | + @Deprecated |
23 | 39 | public KnownCompatibleBeanArchiveBuildItem(String groupId, String artifactId, String classifier) {
|
24 |
| - this.groupId = Objects.requireNonNull(groupId, "groupId must be set"); |
25 |
| - this.artifactId = Objects.requireNonNull(artifactId, "artifactId must be set"); |
26 |
| - this.classifier = Objects.requireNonNull(classifier, "classifier must be set"); |
| 40 | + this(groupId, artifactId, classifier, Set.of(Reason.BEANS_XML_ALL)); |
| 41 | + } |
| 42 | + |
| 43 | + private KnownCompatibleBeanArchiveBuildItem(String groupId, String artifactId, String classifier, Set<Reason> reasons) { |
| 44 | + Objects.requireNonNull(groupId, "groupId must be set"); |
| 45 | + Objects.requireNonNull(artifactId, "artifactId must be set"); |
| 46 | + Objects.requireNonNull(classifier, "classifier must be set"); |
| 47 | + if (reasons.isEmpty()) { |
| 48 | + throw new IllegalStateException( |
| 49 | + "KnownCompatibleBeanArchiveBuildItem.Builder needs to declare at least one compatibility reason. Artifact with following coordinates had no reason associated: " |
| 50 | + + groupId + ":" + artifactId); |
| 51 | + } |
| 52 | + this.groupId = groupId; |
| 53 | + this.artifactId = artifactId; |
| 54 | + this.classifier = classifier; |
| 55 | + this.reasons = reasons; |
| 56 | + } |
| 57 | + |
| 58 | + public static Builder builder(String groupId, String artifactId) { |
| 59 | + return new Builder(groupId, artifactId); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * An enum listing known reasons for which an archive might be marked as compatible despite using some unsupported |
| 64 | + * feature such as {@code beans.xml} discovery mode {@code all} or using {@link jakarta.enterprise.inject.Specializes} |
| 65 | + * annotation on its classes. |
| 66 | + */ |
| 67 | + public enum Reason { |
| 68 | + BEANS_XML_ALL, |
| 69 | + SPECIALIZES_ANNOTATION; |
| 70 | + } |
| 71 | + |
| 72 | + public static class Builder { |
| 73 | + |
| 74 | + private final String groupId; |
| 75 | + private final String artifactId; |
| 76 | + private final Set<Reason> reasons; |
| 77 | + private String classifier; |
| 78 | + |
| 79 | + private Builder(String groupId, String artifactId) { |
| 80 | + this.groupId = groupId; |
| 81 | + this.artifactId = artifactId; |
| 82 | + this.classifier = ""; |
| 83 | + this.reasons = new HashSet<>(); |
| 84 | + } |
| 85 | + |
| 86 | + public Builder setClassifier(String classifier) { |
| 87 | + this.classifier = classifier; |
| 88 | + return this; |
| 89 | + } |
| 90 | + |
| 91 | + public Builder addReason(Reason reason) { |
| 92 | + this.reasons.add(reason); |
| 93 | + return this; |
| 94 | + } |
| 95 | + |
| 96 | + public KnownCompatibleBeanArchiveBuildItem build() { |
| 97 | + return new KnownCompatibleBeanArchiveBuildItem(groupId, artifactId, classifier, reasons); |
| 98 | + } |
27 | 99 | }
|
28 | 100 | }
|
0 commit comments