-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add @RegisterForProxy annotation
- Loading branch information
Showing
3 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
core/deployment/src/main/java/io/quarkus/deployment/steps/RegisterForProxyBuildStep.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.quarkus.deployment.steps; | ||
|
||
import java.util.ArrayList; | ||
|
||
import org.jboss.jandex.DotName; | ||
|
||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.builditem.CombinedIndexBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.NativeImageProxyDefinitionBuildItem; | ||
import io.quarkus.runtime.annotations.RegisterForProxy; | ||
|
||
public class RegisterForProxyBuildStep { | ||
|
||
@BuildStep | ||
public void build(CombinedIndexBuildItem combinedIndexBuildItem, | ||
BuildProducer<NativeImageProxyDefinitionBuildItem> proxy) { | ||
for (var annotationInstance : combinedIndexBuildItem.getIndex() | ||
.getAnnotations(DotName.createSimple(RegisterForProxy.class.getName()))) { | ||
var targetsValue = annotationInstance.value("targets"); | ||
var types = new ArrayList<String>(); | ||
if (targetsValue == null) { | ||
var classInfo = annotationInstance.target().asClass(); | ||
types.add(classInfo.name().toString()); | ||
classInfo.interfaceNames().forEach(dotName -> types.add(dotName.toString())); | ||
} else { | ||
for (var type : targetsValue.asClassArray()) { | ||
types.add(type.name().toString()); | ||
} | ||
} | ||
proxy.produce(new NativeImageProxyDefinitionBuildItem(types)); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
core/runtime/src/main/java/io/quarkus/runtime/annotations/RegisterForProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.quarkus.runtime.annotations; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Repeatable; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Annotation that can be used to force an interface (including its super interfaces) to be registered for dynamic proxy | ||
* generation in native image mode. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
@Repeatable(RegisterForProxy.List.class) | ||
public @interface RegisterForProxy { | ||
|
||
/** | ||
* Alternative interfaces that should actually be registered for dynamic proxy generation instead of the current interface. | ||
* This allows for interfaces in 3rd party libraries to be registered without modification or writing an | ||
* extension. If this is set then the interface it is placed on is not registered for dynamic proxy generation, so this | ||
* should generally just be placed on an empty interface that is not otherwise used. | ||
*/ | ||
Class<?>[] targets() default {}; | ||
|
||
/** | ||
* The repeatable holder for {@link RegisterForProxy}. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
@interface List { | ||
/** | ||
* The {@link RegisterForProxy} instances. | ||
* | ||
* @return the instances | ||
*/ | ||
RegisterForProxy[] value(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters