Skip to content

Commit

Permalink
Add support for resource bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Nov 20, 2019
1 parent a94abc6 commit b7ce582
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageProxyDefinitionBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveHierarchyBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeReinitializedClassBuildItem;
import io.quarkus.runtime.annotations.RegisterForReflection;
import io.quarkus.runtime.annotations.RegisterProxy;
import io.quarkus.runtime.annotations.RegisterResourceBundle;
import io.quarkus.runtime.annotations.RuntimeInitialized;
import io.quarkus.runtime.annotations.RuntimeReinitialized;

Expand All @@ -45,6 +47,9 @@ public class NativeAnnotationBuildStep {
@Inject
BuildProducer<NativeImageProxyDefinitionBuildItem> proxyDefinition;

@Inject
BuildProducer<NativeImageResourceBuildItem> resourceBundle;

@BuildStep
public void build() throws Exception {
//reflection
Expand Down Expand Up @@ -106,6 +111,14 @@ public void build() throws Exception {
registerProxy(j);
}
}

//resource bundle

for (AnnotationInstance i : combinedIndexBuildItem.getIndex()
.getAnnotations(DotName.createSimple(RegisterResourceBundle.class.getName()))) {
String[] bundles = i.value().asStringArray();
resourceBundle.produce(new NativeImageResourceBuildItem(Arrays.asList(bundles)));
}
}

private void registerProxy(AnnotationInstance i) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.quarkus.runtime.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Annotation that can be used to register a resource bundle for native mode
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface RegisterResourceBundle {

/**
* The bundles to register
*/
String[] value();
}
12 changes: 9 additions & 3 deletions docs/src/main/asciidoc/writing-native-applications-tips.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ GraalVM imposes a number of constraints and making your application a native exe
This guide covers some of the annotations that Quarkus supports to help generate native images. In some cases these
annotations are applied directly to a relevant class, but in others the class that they are placed on does not actually
matter (e.g. if you are referencing a class in a 3rd party jar). In this case we recommend creating an empty `NativeConfig`
class somewhere in your application and placing all annotation that control native image generation on it, so they are all
class somewhere in your application and placing all annotations that control native image generation on it, so they are all
in the same place.

=== Including resources
Expand Down Expand Up @@ -197,11 +197,11 @@ that you actually want to register in the `targets` member of the annotation:
[source,java]
----
@RegisterForReflection(targets={ThirdPartyClass.class, OtherClass.class})
public class EmptyClass {
public class NativeConfig {
}
----

In this example only the `ThirdPartyClass` and `ThirdPartyClass` other class are registered, `EmptyClass` is ignored.
In this example only the `ThirdPartyClass` and `ThirdPartyClass` other class are registered, `NativeConfig` is ignored.

There may also be cases where you want to include all dependencies of a class as well. Generally this is useful
for serialization, where a serialization library may need to set all fields on a class. This can be done by
Expand Down Expand Up @@ -333,6 +333,12 @@ proxies for. Note that order is important, so the order of the annotation values
are passed into the proxy create method. This is a repeatable annotation so multiple proxies can be declared on the same
class.

=== Resource Bundles

By default native images do not include resource bundles. You can select the bundles to include with the
`@io.quarkus.runtime.annotations.RegisterResourceBundle` annotation.


[[native-in-extension]]
== Supporting native in a Quarkus extension

Expand Down

0 comments on commit b7ce582

Please sign in to comment.