Skip to content

Commit

Permalink
RESTEasy Reactive Links
Browse files Browse the repository at this point in the history
  • Loading branch information
Gytis Trikleris committed Mar 15, 2021
1 parent 203bfca commit 665dd43
Show file tree
Hide file tree
Showing 35 changed files with 1,256 additions and 5 deletions.
10 changes: 10 additions & 0 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1942,6 +1942,16 @@
<artifactId>quarkus-resteasy-reactive-jackson-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-links</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-links-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-reactive-datasource</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public enum Feature {
RESTEASY_REACTIVE_JAXRS_CLIENT,
RESTEASY_REACTIVE_JSONB,
RESTEASY_REACTIVE_JACKSON,
RESTEASY_REACTIVE_LINKS,
REST_CLIENT,
REST_CLIENT_JACKSON,
REST_CLIENT_JAXB,
Expand Down
2 changes: 1 addition & 1 deletion devtools/bom-descriptor-json/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2496,4 +2496,4 @@
</profile>
</profiles>

</project>
</project>
13 changes: 13 additions & 0 deletions docs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1904,6 +1904,19 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-links-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-qute-deployment</artifactId>
Expand Down
1 change: 1 addition & 0 deletions extensions/resteasy-reactive/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<module>quarkus-resteasy-reactive-jsonb</module>
<module>quarkus-resteasy-reactive-qute</module>
<module>quarkus-resteasy-reactive-servlet</module>
<module>quarkus-resteasy-reactive-links</module>
</modules>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>quarkus-resteasy-reactive-links-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-resteasy-reactive-links-deployment</artifactId>
<name>Quarkus - RESTEasy Reactive - Links - Deployment</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-links</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
<parameters>true</parameters>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.quarkus.resteasy.reactive.links.deployment;

import static io.quarkus.gizmo.MethodDescriptor.ofMethod;

import io.quarkus.gizmo.ClassCreator;
import io.quarkus.gizmo.ClassOutput;
import io.quarkus.gizmo.MethodCreator;
import io.quarkus.gizmo.ResultHandle;
import io.quarkus.resteasy.reactive.links.runtime.GetterAccessor;

class GetterAccessorImplementor {

/**
* Implements a {@link GetterAccessor} that knows how to access a specific getter method of a specific type.
*/
void implement(ClassOutput classOutput, GetterMetadata getterMetadata) {
ClassCreator classCreator = ClassCreator.builder()
.classOutput(classOutput).className(getterMetadata.getGetterAccessorName())
.interfaces(GetterAccessor.class)
.build();
MethodCreator methodCreator = classCreator.getMethodCreator("get", Object.class, Object.class);
ResultHandle value = methodCreator.invokeVirtualMethod(
ofMethod(getterMetadata.getEntityType(), getterMetadata.getGetterName(), getterMetadata.getFieldType()),
methodCreator.getMethodParam(0));
methodCreator.returnValue(value);
methodCreator.close();
classCreator.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.quarkus.resteasy.reactive.links.deployment;

import static io.quarkus.gizmo.DescriptorUtils.objectToDescriptor;
import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
import static org.objectweb.asm.Opcodes.ALOAD;
import static org.objectweb.asm.Opcodes.GETFIELD;
import static org.objectweb.asm.Opcodes.IRETURN;

import java.util.function.BiFunction;

import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Type;

import io.quarkus.gizmo.Gizmo;

class GetterImplementor extends ClassVisitor {

private final GetterMetadata getterMetadata;

static BiFunction<String, ClassVisitor, ClassVisitor> getVisitorFunction(GetterMetadata getterMetadata) {
return (className, classVisitor) -> new GetterImplementor(classVisitor, getterMetadata);
}

GetterImplementor(ClassVisitor outputClassVisitor, GetterMetadata getterMetadata) {
super(Gizmo.ASM_API_VERSION, outputClassVisitor);
this.getterMetadata = getterMetadata;
}

@Override
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature,
String[] exceptions) {
return super.visitMethod(access, name, descriptor, signature, exceptions);
}

@Override
public void visitEnd() {
generateGetter();
super.visitEnd();
}

private void generateGetter() {
String owner = Type.getType(objectToDescriptor(getterMetadata.getEntityType())).getInternalName();
String fieldDescriptor = objectToDescriptor(getterMetadata.getFieldType());
String getterDescriptor = "()" + fieldDescriptor;

MethodVisitor mv = super.visitMethod(ACC_PUBLIC, getterMetadata.getGetterName(), getterDescriptor, null, null);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, owner, getterMetadata.getFieldName(), fieldDescriptor);
mv.visitInsn(Type.getType(fieldDescriptor).getOpcode(IRETURN));
mv.visitMaxs(0, 0);
mv.visitEnd();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package io.quarkus.resteasy.reactive.links.deployment;

import java.util.Objects;

import org.jboss.jandex.FieldInfo;

class GetterMetadata {

private static final String GETTER_PREFIX = "resteasy_links_get_";

private static final String ACCESSOR_SUFFIX = "$_resteasy_links";

private final String entityType;

private final String fieldType;

private final String fieldName;

GetterMetadata(FieldInfo fieldInfo) {
this.entityType = fieldInfo.declaringClass().toString();
this.fieldType = fieldInfo.type().name().toString();
this.fieldName = fieldInfo.name();
}

public String getEntityType() {
return entityType;
}

public String getFieldType() {
return fieldType;
}

public String getFieldName() {
return fieldName;
}

public String getGetterName() {
return GETTER_PREFIX + fieldName;
}

public String getGetterAccessorName() {
return entityType + ACCESSOR_SUFFIX + getGetterName();
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
GetterMetadata that = (GetterMetadata) o;
return entityType.equals(that.entityType)
&& fieldType.equals(that.fieldType)
&& fieldName.equals(that.fieldName);
}

@Override
public int hashCode() {
return Objects.hash(entityType, fieldType, fieldName);
}
}
Loading

0 comments on commit 665dd43

Please sign in to comment.