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

Unrecognized property mp.messaging.* when Channel annotation is used along with Multi #451

Merged
merged 1 commit into from
Jul 11, 2024
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 @@ -21,7 +21,6 @@
import static org.eclipse.lsp4mp.jdt.core.utils.JDTTypeUtils.isBinary;
import static org.eclipse.lsp4mp.jdt.internal.reactivemessaging.MicroProfileReactiveMessagingConstants.CHANNEL_ANNOTATION;
import static org.eclipse.lsp4mp.jdt.internal.reactivemessaging.MicroProfileReactiveMessagingConstants.CONNECTOR_ANNOTATION;
import static org.eclipse.lsp4mp.jdt.internal.reactivemessaging.MicroProfileReactiveMessagingConstants.EMITTER_CLASS;
import static org.eclipse.lsp4mp.jdt.internal.reactivemessaging.MicroProfileReactiveMessagingConstants.CONNECTOR_ATTRIBUTES_ANNOTATION;
import static org.eclipse.lsp4mp.jdt.internal.reactivemessaging.MicroProfileReactiveMessagingConstants.CONNECTOR_ATTRIBUTE_ANNOTATION;
import static org.eclipse.lsp4mp.jdt.internal.reactivemessaging.MicroProfileReactiveMessagingConstants.INCOMING_ANNOTATION;
Expand All @@ -40,7 +39,6 @@
import org.eclipse.lsp4mp.commons.metadata.ValueHint;
import org.eclipse.lsp4mp.jdt.core.AbstractAnnotationTypeReferencePropertiesProvider;
import org.eclipse.lsp4mp.jdt.core.SearchContext;
import org.eclipse.lsp4mp.jdt.core.utils.JDTTypeUtils;

/**
* Properties provider to collect MicroProfile properties from the MicroProfile
Expand Down Expand Up @@ -104,13 +102,14 @@
*/
public class MicroProfileReactiveMessagingProvider extends AbstractAnnotationTypeReferencePropertiesProvider {

private static final String[] ANNOTATION_NAMES = { CONNECTOR_ANNOTATION, INCOMING_ANNOTATION, OUTGOING_ANNOTATION, CHANNEL_ANNOTATION };
private static final String[] ANNOTATION_NAMES = { CONNECTOR_ANNOTATION, INCOMING_ANNOTATION, OUTGOING_ANNOTATION,
CHANNEL_ANNOTATION };

private static enum Direction {
private enum Direction {
INCOMING, OUTGOING, INCOMING_AND_OUTGOING;
}

private static enum MessageType {
private enum MessageType {
INCOMING, OUTGOING, CONNECTOR;
}

Expand Down Expand Up @@ -145,11 +144,11 @@ protected void processAnnotation(IJavaElement javaElement, IAnnotation mprmAnnot
// public double process(int priceInUsd) {
processIncomingChannel(javaElement, mprmAnnotation, context);
break;
case CHANNEL_ANNOTATION:
case CHANNEL_ANNOTATION: // Used for both incoming and outgoing channels
// @Inject
// @Channel("prices")
// Emitter<double> pricesEmitter;
if (isAnnotatingEmitterObject(javaElement)) {
if (isChannelField(javaElement)) {
processOutgoingChannel(javaElement, mprmAnnotation, context);
}
break;
Expand All @@ -164,16 +163,8 @@ protected void processAnnotation(IJavaElement javaElement, IAnnotation mprmAnnot
}
}

private static boolean isAnnotatingEmitterObject(IJavaElement element) {
if (element.getElementType() != IJavaElement.FIELD) {
return false;
}
IField field = (IField) element;
String typeSignature = JDTTypeUtils.getResolvedTypeName(field);
if (typeSignature == null) {
return false;
}
return typeSignature.startsWith(EMITTER_CLASS);
private static boolean isChannelField(IJavaElement element) {
return element.getElementType() == IJavaElement.FIELD;
}

/**
Expand Down Expand Up @@ -238,8 +229,8 @@ private void processChannelConnector(IJavaElement javaElement, IAnnotation incom
boolean binary = isBinary(javaElement);
String description = null;
String type = "org.eclipse.microprofile.reactive.messaging.spi.Connector";
addMpMessagingItem(channelName, false, "connector", messageType, sourceType, sourceField, sourceMethod, binary, type,
description, null, context);
addMpMessagingItem(channelName, false, "connector", messageType, sourceType, sourceField, sourceMethod, binary,
type, description, null, context);
}

/**
Expand Down Expand Up @@ -310,34 +301,34 @@ private void processConnectorAttribute(String connectorName, IAnnotation connect
case INCOMING:
// Generate mp.messaging.incoming.${connector-name}.[attribute]
// ex : mp.messaging.incoming.${smallrye-kafka}.topic
addMpMessagingItem(connectorName, true, attributeName, MessageType.INCOMING, sourceType, null, null, binary, type,
description, defaultValue, context);
addMpMessagingItem(connectorName, true, attributeName, MessageType.INCOMING, sourceType, null, null, binary,
type, description, defaultValue, context);
break;
case OUTGOING:
// Generate mp.messaging.outgoing.${connector-name}.[attribute]
addMpMessagingItem(connectorName, true, attributeName, MessageType.OUTGOING, sourceType, null, null, binary, type,
description, defaultValue, context);
addMpMessagingItem(connectorName, true, attributeName, MessageType.OUTGOING, sourceType, null, null, binary,
type, description, defaultValue, context);
break;
case INCOMING_AND_OUTGOING:
// Generate mp.messaging.incoming.${connector-name}.[attribute]
addMpMessagingItem(connectorName, true, attributeName, MessageType.INCOMING, sourceType, null, null, binary, type,
description, defaultValue, context);
addMpMessagingItem(connectorName, true, attributeName, MessageType.INCOMING, sourceType, null, null, binary,
type, description, defaultValue, context);
// Generate mp.messaging.outgoing.${connector-name}.[attribute]
addMpMessagingItem(connectorName, true, attributeName, MessageType.OUTGOING, sourceType, null, null, binary, type,
description, defaultValue, context);
addMpMessagingItem(connectorName, true, attributeName, MessageType.OUTGOING, sourceType, null, null, binary,
type, description, defaultValue, context);
break;
}
// Generate mp.messaging.connector.[connector-name].[attribute]
addMpMessagingItem(connectorName, false, attributeName, MessageType.CONNECTOR, sourceType, null, null, binary, type,
description, defaultValue, context);
addMpMessagingItem(connectorName, false, attributeName, MessageType.CONNECTOR, sourceType, null, null, binary,
type, description, defaultValue, context);
}

private void addMpMessagingItem(String connectorOrChannelName, boolean dynamic, String attributeName,
MessageType messageType, String sourceType, String sourceField, String sourceMethod, boolean binary, String type,
String description, String defaultValue, SearchContext context) {
MessageType messageType, String sourceType, String sourceField, String sourceMethod, boolean binary,
String type, String description, String defaultValue, SearchContext context) {
String propertyName = getMPMessagingName(messageType, dynamic, connectorOrChannelName, attributeName);
super.addItemMetadata(context.getCollector(), propertyName, type, description, sourceType, sourceField, sourceMethod,
defaultValue, null, binary);
super.addItemMetadata(context.getCollector(), propertyName, type, description, sourceType, sourceField,
sourceMethod, defaultValue, null, binary);
}

/**
Expand Down Expand Up @@ -373,12 +364,10 @@ private String getType(String connectorAttributeType) {
if (StringUtils.isEmpty(connectorAttributeType)) {
return null;
}
switch (connectorAttributeType) {
case "string":
if (connectorAttributeType.equals("string")) {
return "java.lang.String";
default:
return connectorAttributeType;
}
return connectorAttributeType;
}

private static String getMPMessagingName(MessageType messageType, boolean dynamic, String connectorOrChannelName,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.acme.kafka;

public class Quote {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.acme.kafka;

import io.smallrye.mutiny.Multi;
import org.eclipse.microprofile.reactive.messaging.Channel;

public class QuoteResource {

@Channel("quotes")
Multi<Quote> quotes;

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ mp.messaging.outgoing.generated-price.value.serializer=org.apache.kafka.common.s

# Configure the Kafka source (we read from it)
mp.messaging.incoming.prices.connector=smallrye-kafka
mp.messaging.incoming.prices.value.deserializer=org.apache.kafka.common.serialization.IntegerDeserializer
mp.messaging.incoming.prices.value.deserializer=org.apache.kafka.common.serialization.IntegerDeserializer

mp.messaging.outgoing.quotes.connector=smallrye-kafka
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,14 @@ public void microprofileReactiveMessagingPropertiesTest() throws Exception {
// mp.messaging.incoming.${connector-name}
p(null, "mp.messaging.incoming.${smallrye-kafka}.bootstrap.servers", "java.lang.String",
"A comma-separated list of host:port to use for establishing the initial connection to the Kafka cluster.",
true, "io.smallrye.reactive.messaging.kafka.KafkaConnector", null, null, 0, "localhost:9092") //
true, "io.smallrye.reactive.messaging.kafka.KafkaConnector", null, null, 0, "localhost:9092"),

// mp.messaging.outgoing.quotes.connector
p(null, "mp.messaging.outgoing.quotes.connector",
"org.eclipse.microprofile.reactive.messaging.spi.Connector", null, false,
"org.acme.kafka.QuoteResource", "quotes", null, 0, null) //
);

assertPropertiesDuplicate(infoFromClasspath);

assertHints(infoFromClasspath, h("${mp.messaging.connector.binary}", null, true, null, //
Expand Down