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

JakartaEE: Fix more cases where jakarta namespace has to be supported #6473

Merged
merged 3 commits into from
Oct 1, 2023
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 @@ -62,11 +62,16 @@ public class CommonAnnotationHelper {
// see JSR250
private static final Set<String> RESOURCE_REF_TYPES = new HashSet<String>(Arrays.<String>asList(
"javax.sql.DataSource",
"jakarta.jms.ConnectionFactory",
"javax.jms.ConnectionFactory",
"jakarta.jms.QueueConnectionFactory",
"javax.jms.QueueConnectionFactory",
"jakarta.jms.TopicConnectionFactory",
"javax.jms.TopicConnectionFactory",
"jakarta.mail.Session",
"javax.mail.Session",
"java.net.URL",
"jakarta.resource.cci.ConnectionFactory",
"javax.resource.cci.ConnectionFactory",
"org.omg.CORBA_2_3.ORB"
// any other connection factory defined by a resource adapter
Expand All @@ -82,12 +87,19 @@ public class CommonAnnotationHelper {
"java.lang.Long",
"java.lang.Float"));
private static final Set<String> SERVICE_REF_TYPES = new HashSet<String>(Arrays.<String>asList(
"jakarta.xml.rpc.Service",
"jakarta.xml.ws.Service",
"jakarta.jws.WebService",
"javax.xml.rpc.Service",
"javax.xml.ws.Service",
"javax.jws.WebService"));
"javax.jws.WebService"
));
private static final Set<String> MESSAGE_DESTINATION_TYPES = new HashSet<String>(Arrays.<String>asList(
"jakarta.jms.Queue",
"jakarta.jms.Topic",
"javax.jms.Queue",
"javax.jms.Topic"));
"javax.jms.Topic"
));

private CommonAnnotationHelper() {
}
Expand All @@ -105,6 +117,11 @@ public Object handleArray(List<AnnotationValue> arrayMembers) {
}
}, null);
try {
helper.getAnnotationScanner().findAnnotations("jakarta.annotation.security.DeclareRoles", AnnotationScanner.TYPE_KINDS, new AnnotationHandler() { // NOI18N
public void handleAnnotation(TypeElement type, Element element, AnnotationMirror annotation) {
parser.parse(annotation);
}
});
helper.getAnnotationScanner().findAnnotations("javax.annotation.security.DeclareRoles", AnnotationScanner.TYPE_KINDS, new AnnotationHandler() { // NOI18N
public void handleAnnotation(TypeElement type, Element element, AnnotationMirror annotation) {
parser.parse(annotation);
Expand Down Expand Up @@ -280,7 +297,10 @@ public static String getServiceEndpoint(final AnnotationModelHelper helper, fina
}

Map<String, ? extends AnnotationMirror> ans = helper.getAnnotationsByType(typeElement.getAnnotationMirrors());
AnnotationMirror wsMirror = ans.get("javax.jws.WebService"); //NOI18N
AnnotationMirror wsMirror = ans.get("jakarta.jws.WebService"); //NOI18N
if (wsMirror == null) {
wsMirror = ans.get("javax.jws.WebService"); //NOI18N
}
if (wsMirror != null) {
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : wsMirror.getElementValues().entrySet()) {
ExecutableElement key = entry.getKey();
Expand All @@ -302,14 +322,18 @@ private static List<ResourceImpl> getResources(final AnnotationModelHelper helpe

// fields
for (VariableElement field : ElementFilter.fieldsIn(typeElement.getEnclosedElements())) {
if (helper.hasAnnotation(field.getAnnotationMirrors(), "javax.annotation.Resource")) { //NOI18N
if (helper.hasAnnotation(field.getAnnotationMirrors(), "jakarta.annotation.Resource") //NOI18N
|| helper.hasAnnotation(field.getAnnotationMirrors(), "javax.annotation.Resource") //NOI18N
) {
ResourceImpl resource = new ResourceImpl(field, typeElement, helper);
result.add(resource);
}
}
// methods
for (ExecutableElement method : ElementFilter.methodsIn(typeElement.getEnclosedElements())) {
if (helper.hasAnnotation(method.getAnnotationMirrors(), "javax.annotation.Resource")) { //NOI18N
if (helper.hasAnnotation(method.getAnnotationMirrors(), "jakarta.annotation.Resource") //NOI18N
|| helper.hasAnnotation(method.getAnnotationMirrors(), "javax.annotation.Resource") //NOI18N
) {
ResourceImpl resource = new ResourceImpl(method, typeElement, helper);
result.add(resource);
}
Expand All @@ -321,6 +345,14 @@ private static List<ResourceImpl> getResources(final AnnotationModelHelper helpe

final List<ResourceImpl> result = new ArrayList<ResourceImpl>();
try {
helper.getAnnotationScanner().findAnnotations(
"jakarta.annotation.Resource", // NOI18N
EnumSet.of(ElementKind.CLASS, ElementKind.METHOD, ElementKind.FIELD),new AnnotationHandler() {
public void handleAnnotation(TypeElement typeElement, Element element, AnnotationMirror annotation) {
ResourceImpl resource = new ResourceImpl(element, typeElement, helper);
result.add(resource);
}
});
helper.getAnnotationScanner().findAnnotations(
"javax.annotation.Resource", // NOI18N
EnumSet.of(ElementKind.CLASS, ElementKind.METHOD, ElementKind.FIELD),new AnnotationHandler() {
Expand All @@ -341,7 +373,9 @@ private static List<ServiceRef> getWebServiceRefs(final AnnotationModelHelper he

// fields
for (VariableElement field : ElementFilter.fieldsIn(typeElement.getEnclosedElements())) {
if (helper.hasAnnotation(field.getAnnotationMirrors(), "javax.xml.ws.WebServiceRef")) { //NOI18N
if (helper.hasAnnotation(field.getAnnotationMirrors(), "jakarta.xml.ws.WebServiceRef") //NOI18N
|| helper.hasAnnotation(field.getAnnotationMirrors(), "javax.xml.ws.WebServiceRef") //NOI18N
) { //NOI18N
addServiceReference(result, field, typeElement, helper);
}
}
Expand All @@ -352,6 +386,13 @@ private static List<ServiceRef> getWebServiceRefs(final AnnotationModelHelper he

final List<ServiceRef> result = new ArrayList<ServiceRef>();
try {
helper.getAnnotationScanner().findAnnotations(
"jakarta.xml.ws.WebServiceRef", // NOI18N
EnumSet.of(ElementKind.FIELD),new AnnotationHandler() {
public void handleAnnotation(TypeElement typeElement, Element element, AnnotationMirror annotation) {
addServiceReference(result, element, typeElement, helper);
}
});
helper.getAnnotationScanner().findAnnotations(
"javax.xml.ws.WebServiceRef", // NOI18N
EnumSet.of(ElementKind.FIELD),new AnnotationHandler() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
public class EjbRefHelper {

private static final String EJB_ANN = "javax.ejb.EJB"; // NOI18N
private static final String EJB_ANN_JAKARTA = "jakarta.ejb.EJB"; // NOI18N
private static final String EJBS_ANN = "javax.ejb.EJBs"; // NOI18N
private static final String EJBS_ANN_JAKARTA = "jakarta.ejb.EJBs"; // NOI18N

private EjbRefHelper() {
}
Expand All @@ -60,6 +62,22 @@ private EjbRefHelper() {
*/
public static void setEjbRefs(final AnnotationModelHelper helper, final List<EjbRef> resultEjbRefs, final List<EjbLocalRef> resultEjbLocalRefs) {
try {
helper.getAnnotationScanner().findAnnotations(
EJBS_ANN_JAKARTA,
EnumSet.of(ElementKind.CLASS),
new AnnotationHandler() {
public void handleAnnotation(TypeElement typeElement, Element element, AnnotationMirror annotation) {
parseEJBsAnnotation(helper, typeElement, resultEjbRefs, resultEjbLocalRefs);
}
});
helper.getAnnotationScanner().findAnnotations(
EJB_ANN_JAKARTA,
EnumSet.of(ElementKind.CLASS, ElementKind.METHOD, ElementKind.FIELD),
new AnnotationHandler() {
public void handleAnnotation(TypeElement typeElement, Element element, AnnotationMirror annotation) {
parseElement(helper, typeElement, element, resultEjbRefs, resultEjbLocalRefs, EJB_ANN_JAKARTA);
}
});
helper.getAnnotationScanner().findAnnotations(
EJBS_ANN,
EnumSet.of(ElementKind.CLASS),
Expand All @@ -73,7 +91,7 @@ public void handleAnnotation(TypeElement typeElement, Element element, Annotatio
EnumSet.of(ElementKind.CLASS, ElementKind.METHOD, ElementKind.FIELD),
new AnnotationHandler() {
public void handleAnnotation(TypeElement typeElement, Element element, AnnotationMirror annotation) {
parseElement(helper, typeElement, element, resultEjbRefs, resultEjbLocalRefs);
parseElement(helper, typeElement, element, resultEjbRefs, resultEjbLocalRefs, EJB_ANN);
}
});
} catch (InterruptedException ie) {
Expand All @@ -91,19 +109,25 @@ public static void setEjbRefsForClass(final AnnotationModelHelper helper, TypeEl
parseEJBsAnnotation(helper, typeElement, resultEjbRefs, resultEjbLocalRefs);

// @EJB at class
if (helper.hasAnnotation(typeElement.getAnnotationMirrors(), EJB_ANN)) {
parseElement(helper, typeElement, typeElement, resultEjbRefs, resultEjbLocalRefs);
if (helper.hasAnnotation(typeElement.getAnnotationMirrors(), EJB_ANN_JAKARTA)) {
parseElement(helper, typeElement, typeElement, resultEjbRefs, resultEjbLocalRefs, EJB_ANN_JAKARTA);
} else if (helper.hasAnnotation(typeElement.getAnnotationMirrors(), EJB_ANN)) {
parseElement(helper, typeElement, typeElement, resultEjbRefs, resultEjbLocalRefs, EJB_ANN);
}
// @EJB at field
for (VariableElement variableElement : ElementFilter.fieldsIn(typeElement.getEnclosedElements())) {
if (helper.hasAnnotation(variableElement.getAnnotationMirrors(), EJB_ANN)) {
parseElement(helper, typeElement, variableElement, resultEjbRefs, resultEjbLocalRefs);
if (helper.hasAnnotation(variableElement.getAnnotationMirrors(), EJB_ANN_JAKARTA)) {
parseElement(helper, typeElement, variableElement, resultEjbRefs, resultEjbLocalRefs, EJB_ANN_JAKARTA);
} else if (helper.hasAnnotation(variableElement.getAnnotationMirrors(), EJB_ANN)) {
parseElement(helper, typeElement, variableElement, resultEjbRefs, resultEjbLocalRefs, EJB_ANN);
}
}
// @EJB at method
for (ExecutableElement executableElement : ElementFilter.methodsIn(typeElement.getEnclosedElements())) {
if (helper.hasAnnotation(executableElement.getAnnotationMirrors(), EJB_ANN)) {
parseElement(helper, typeElement, executableElement, resultEjbRefs, resultEjbLocalRefs);
if (helper.hasAnnotation(executableElement.getAnnotationMirrors(), EJB_ANN_JAKARTA)) {
parseElement(helper, typeElement, executableElement, resultEjbRefs, resultEjbLocalRefs, EJB_ANN_JAKARTA);
} else if (helper.hasAnnotation(executableElement.getAnnotationMirrors(), EJB_ANN)) {
parseElement(helper, typeElement, executableElement, resultEjbRefs, resultEjbLocalRefs, EJB_ANN);
}
}

Expand All @@ -112,9 +136,14 @@ public static void setEjbRefsForClass(final AnnotationModelHelper helper, TypeEl
private static void parseEJBsAnnotation(final AnnotationModelHelper helper, TypeElement typeElement,
final List<EjbRef> resultEjbRefs, final List<EjbLocalRef> resultEjbLocalRefs) {
Map<String, ? extends AnnotationMirror> annByType = helper.getAnnotationsByType(typeElement.getAnnotationMirrors());
AnnotationMirror ejbsAnnotation = annByType.get(EJBS_ANN); // NOI18N
AnnotationMirror ejbsAnnotation = annByType.get(EJBS_ANN_JAKARTA);
String typeName = EJB_ANN_JAKARTA;
if(ejbsAnnotation == null) {
ejbsAnnotation = annByType.get(EJBS_ANN);
typeName = EJB_ANN;
}
AnnotationParser parser = AnnotationParser.create(helper);
parser.expectAnnotationArray("value", helper.resolveType(EJB_ANN), new ArrayValueHandler() { // NOI18N
parser.expectAnnotationArray("value", helper.resolveType(typeName), new ArrayValueHandler() { // NOI18N
public Object handleArray(List<AnnotationValue> arrayMembers) {
for (AnnotationValue arrayMember : arrayMembers) {
Object arrayMemberValue = arrayMember.getValue();
Expand All @@ -131,7 +160,7 @@ public Object handleArray(List<AnnotationValue> arrayMembers) {
/**
* Parses element
*/
private static void parseElement(AnnotationModelHelper helper, TypeElement ownerClass, Element element, List<EjbRef> resultEjbRefs, List<EjbLocalRef> resultEjbLocalRefs) {
private static void parseElement(AnnotationModelHelper helper, TypeElement ownerClass, Element element, List<EjbRef> resultEjbRefs, List<EjbLocalRef> resultEjbLocalRefs, String ejbAnnotation) {

String name = null;
String beanInterface = null;
Expand All @@ -151,7 +180,7 @@ private static void parseElement(AnnotationModelHelper helper, TypeElement owner
parser.expectString("beanName", null); // NOI18N
parser.expectString("mappedName", null); // NOI18N
parser.expectString("description", null); // NOI18N
ParseResult parseResult = parser.parse(annByType.get(EJB_ANN));
ParseResult parseResult = parser.parse(annByType.get(ejbAnnotation));

name = parseResult.get("name", String.class); // NOI18N
beanInterface = parseResult.get("beanInterface", String.class); // NOI18N
Expand Down Expand Up @@ -193,7 +222,7 @@ private static void parseElement(AnnotationModelHelper helper, TypeElement owner
}
}

ParseResult parseResult = parser.parse(annByType.get(EJB_ANN));
ParseResult parseResult = parser.parse(annByType.get(ejbAnnotation));
name = parseResult.get("name", String.class); // NOI18N
} else {
return;
Expand Down Expand Up @@ -243,7 +272,7 @@ private static void createReference(AnnotationModelHelper helper, TypeElement in
// this one just checks if there is @Remote annotation; if not, it is local
boolean isLocal = true;
Map<String, ? extends AnnotationMirror> memberAnnByType = helper.getAnnotationsByType(interfaceTypeElement.getAnnotationMirrors());
if (memberAnnByType.get("javax.ejb.Remote") != null) { // NOI18N
if (memberAnnByType.get("jakarta.ejb.Remote") != null || memberAnnByType.get("javax.ejb.Remote") != null) { // NOI18N
isLocal = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
public class ResourceImpl {

// package private because of unit tests
static final String DEFAULT_AUTHENTICATION_TYPE = AuthenticationType.CONTAINER.name();
static final String DEFAULT_AUTHENTICATION_TYPE = "javax.annotation.Resource.AuthenticationType.CONTAINER";
static final String DEFAULT_AUTHENTICATION_TYPE_JAKARTA = "jakarta.annotation.Resource.AuthenticationType.CONTAINER";
static final String DEFAULT_SHAREABLE = Boolean.TRUE.toString();
static final String DEFAULT_MAPPED_NAME = "";
static final String DEFAULT_DESCRIPTION = "";
Expand All @@ -70,8 +71,12 @@ public ResourceImpl(Element element, TypeElement typeElement, AnnotationModelHel
this.element = element;

Map<String, ? extends AnnotationMirror> annByType = annotationModelHelper.getAnnotationsByType(element.getAnnotationMirrors());

parseResult = parseAnnotation(annByType.get(javax.annotation.Resource.class.getName()));

AnnotationMirror annotationMirror = annByType.get("jakarta.annotation.Resource"); //NOI18N
if (annotationMirror == null) {
annotationMirror = annByType.get("javax.annotation.Resource"); //NOI18N
}
parseResult = parseAnnotation(annotationMirror);
}

private ParseResult parseAnnotation(AnnotationMirror resourceAnnotation) {
Expand Down Expand Up @@ -116,12 +121,20 @@ public Object getDefaultValue() {
return Object.class.getName();
}
});

// The authentication type to use for the resource, default AuthenticationType.CONTAINER
parser.expectEnumConstant(
"authenticationType", // NOI18N
annotationModelHelper.resolveType("javax.annotation.Resource.AuthenticationType"),
parser.defaultValue(DEFAULT_AUTHENTICATION_TYPE));

if(((TypeElement) resourceAnnotation.getAnnotationType().asElement()).getQualifiedName().toString().startsWith("jakarta.")) {
// The authentication type to use for the resource, default AuthenticationType.CONTAINER
parser.expectEnumConstant(
"authenticationType", // NOI18N
annotationModelHelper.resolveType("jakarta.annotation.Resource.AuthenticationType"),
parser.defaultValue(DEFAULT_AUTHENTICATION_TYPE_JAKARTA));
} else {
// The authentication type to use for the resource, default AuthenticationType.CONTAINER
parser.expectEnumConstant(
"authenticationType", // NOI18N
annotationModelHelper.resolveType("javax.annotation.Resource.AuthenticationType"),
parser.defaultValue(DEFAULT_AUTHENTICATION_TYPE));
}

// Indicates whether the resource can be shared, default true
parser.expectPrimitive("shareable", Boolean.class, parser.defaultValue(Boolean.parseBoolean(DEFAULT_SHAREABLE))); // NOI18N
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ public ServiceRefImpl(Element element, TypeElement typeElement, TypeElement pare
parser.expectString("wsdlLocation",null);
parser.expectClass("value",null);
parser.expectClass("type",null);
ParseResult parseResult = parser.parse(annByType.get("javax.xml.ws.WebServiceRef")); //NOI18N
AnnotationMirror annotationMirror = annByType.get("jakarta.xml.ws.WebServiceRef"); //NOI18N
if (annotationMirror == null) {
annotationMirror = annByType.get("javax.xml.ws.WebServiceRef"); //NOI18N
}
ParseResult parseResult = parser.parse(annotationMirror);
serviceRefName = parseResult.get("name", String.class); // NOI18N
wsdlFile = parseResult.get("wsdlLocation", String.class); // NOI18N
value = parseResult.get("value", String.class); // NOI18N
Expand Down
Loading
Loading