Skip to content

Commit

Permalink
[issue-30] Dependencies need to be add to the deployment module when …
Browse files Browse the repository at this point in the history
…using Instance API
  • Loading branch information
gaol committed Nov 5, 2024
1 parent a23ab10 commit 15bf6e0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.DotName;
import org.jboss.jandex.FieldInfo;
import org.jboss.jandex.Type;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX;
import static org.jboss.jandex.Type.Kind.PARAMETERIZED_TYPE;

/**
*
Expand All @@ -33,23 +34,22 @@ public class VerticleDeploymentMarkerProcessor implements DeploymentUnitProcesso
public static final Phase PHASE = Phase.PARSE;
public static final int PRIORITY = 0x4000;

private static final String VERTX_ANNOTATION_NAME = "io.vertx.core.Vertx";
private static final String VERTX_MUTINY_ANNOTATION_NAME = "io.vertx.mutiny.core.Vertx";
private static final DotName DOT_NAME_INJECTION = DotName.createSimple("jakarta.inject.Inject");
private static final DotName DOT_NAME_VERTX_ANNOTATION = DotName.createSimple("io.vertx.core.Vertx");
private static final DotName DOT_NAME_VERTX_MUTINY_ANNOTATION = DotName.createSimple("io.vertx.mutiny.core.Vertx");
private static final DotName DOT_NAME_CDI_INSTANCE = DotName.createSimple("jakarta.enterprise.inject.Instance");

private static final List<DotName> dotNames = new ArrayList<>();
private static final Set<String> VERTX_CLASSES = new HashSet<>();
private static final Set<DotName> VERTX_CLASSES = new HashSet<>();
static {
dotNames.add(DotName.createSimple("jakarta.inject.Inject"));
dotNames.add(DotName.createSimple("jakarta.annotation.Resource"));
VERTX_CLASSES.add(VERTX_ANNOTATION_NAME);
VERTX_CLASSES.add(VERTX_MUTINY_ANNOTATION_NAME);
VERTX_CLASSES.add(DOT_NAME_VERTX_ANNOTATION);
VERTX_CLASSES.add(DOT_NAME_VERTX_MUTINY_ANNOTATION);
}

@Override
public void deploy(DeploymentPhaseContext context) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
final CompositeIndex index = deploymentUnit.getAttachment(COMPOSITE_ANNOTATION_INDEX);
if (dotNames.stream().anyMatch(dotName -> annotated(index, dotName))) {
if (annotated(index, DOT_NAME_INJECTION)) {
VertxDeploymentAttachment.attachVertxDeployments(deploymentUnit);
}
}
Expand All @@ -59,10 +59,17 @@ private boolean annotated(CompositeIndex index, DotName injectAnnotationName) {
for (AnnotationInstance annotation : resourceAnnotations) {
final AnnotationTarget annotationTarget = annotation.target();
if (annotationTarget instanceof FieldInfo) {
final String fieldType = annotationTarget.asField().type().name().toString();
Type type = annotationTarget.asField().type();
final DotName fieldType = type.name();
if (VERTX_CLASSES.contains(fieldType)) {
return true;
}
if (DOT_NAME_CDI_INSTANCE.equals(fieldType) && type.kind() == PARAMETERIZED_TYPE) {
List<Type> arguments = type.asParameterizedType().arguments();
if (arguments.size() == 1 && VERTX_CLASSES.contains(arguments.get(0).name())) {
return true;
}
}
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class VertxDependenciesProcessor implements DeploymentUnitProcessor {
private static final String MODULE_VERTX_CORE = "io.vertx.core";
private static final String MODULE_VERTX_MUTINY_CORE = "io.smallrye.reactive.mutiny.vertx-core";
private static final String MODULE_MUTINY = "io.smallrye.reactive.mutiny";
private static final String MODULE_SMALLRYE_COMMON_ANNOTATION = "io.smallrye.common.annotation";

@Override
public void deploy(DeploymentPhaseContext context) throws DeploymentUnitProcessingException {
Expand All @@ -51,7 +52,8 @@ public void deploy(DeploymentPhaseContext context) throws DeploymentUnitProcessi
new ModuleDependency(moduleLoader, MODULE_VERTX_EXTENSION, false, true, true, false),
new ModuleDependency(moduleLoader, MODULE_VERTX_CORE, false, true, true, false),
new ModuleDependency(moduleLoader, MODULE_VERTX_MUTINY_CORE, false, true, true, false),
new ModuleDependency(moduleLoader, MODULE_MUTINY, false, true, true, false)
new ModuleDependency(moduleLoader, MODULE_MUTINY, false, true, true, false),
new ModuleDependency(moduleLoader, MODULE_SMALLRYE_COMMON_ANNOTATION, true, false, false, false)
));
}

Expand Down

0 comments on commit 15bf6e0

Please sign in to comment.