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

Move reflection and serialization configuration from Feature to json #29886

Merged
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
26 changes: 13 additions & 13 deletions core/builder/src/main/java/io/quarkus/builder/Json.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* A simple JSON string generator.
*/
final class Json {
public final class Json {

private static final String OBJECT_START = "{";
private static final String OBJECT_END = "}";
Expand Down Expand Up @@ -47,7 +47,7 @@ private Json() {
/**
* @return the new JSON array builder, empty builders are not ignored
*/
static JsonArrayBuilder array() {
public static JsonArrayBuilder array() {
return new JsonArrayBuilder(false);
}

Expand All @@ -65,7 +65,7 @@ static JsonArrayBuilder array(boolean ignoreEmptyBuilders) {
*
* @return the new JSON object builder, empty builders are not ignored
*/
static JsonObjectBuilder object() {
public static JsonObjectBuilder object() {
return new JsonObjectBuilder(false);
}

Expand Down Expand Up @@ -142,7 +142,7 @@ protected boolean isValuesEmpty(Collection<Object> values) {
/**
* JSON array builder.
*/
static class JsonArrayBuilder extends JsonBuilder<JsonArrayBuilder> {
public static class JsonArrayBuilder extends JsonBuilder<JsonArrayBuilder> {

private final List<Object> values;

Expand All @@ -156,12 +156,12 @@ JsonArrayBuilder add(JsonArrayBuilder value) {
return this;
}

JsonArrayBuilder add(JsonObjectBuilder value) {
public JsonArrayBuilder add(JsonObjectBuilder value) {
addInternal(value);
return this;
}

JsonArrayBuilder add(String value) {
public JsonArrayBuilder add(String value) {
addInternal(value);
return this;
}
Expand Down Expand Up @@ -205,7 +205,7 @@ String build() throws IOException {
}

@Override
void appendTo(Appendable appendable) throws IOException {
public void appendTo(Appendable appendable) throws IOException {
appendable.append(ARRAY_START);
int idx = 0;
for (ListIterator<Object> iterator = values.listIterator(); iterator.hasNext();) {
Expand All @@ -231,7 +231,7 @@ protected JsonArrayBuilder self() {
/**
* JSON object builder.
*/
static class JsonObjectBuilder extends JsonBuilder<JsonObjectBuilder> {
public static class JsonObjectBuilder extends JsonBuilder<JsonObjectBuilder> {

private final Map<String, Object> properties;

Expand All @@ -240,22 +240,22 @@ private JsonObjectBuilder(boolean ignoreEmptyBuilders) {
this.properties = new HashMap<String, Object>();
}

JsonObjectBuilder put(String name, String value) {
public JsonObjectBuilder put(String name, String value) {
putInternal(name, value);
return this;
}

JsonObjectBuilder put(String name, JsonObjectBuilder value) {
public JsonObjectBuilder put(String name, JsonObjectBuilder value) {
putInternal(name, value);
return this;
}

JsonObjectBuilder put(String name, JsonArrayBuilder value) {
public JsonObjectBuilder put(String name, JsonArrayBuilder value) {
putInternal(name, value);
return this;
}

JsonObjectBuilder put(String name, boolean value) {
public JsonObjectBuilder put(String name, boolean value) {
putInternal(name, value);
return this;
}
Expand Down Expand Up @@ -295,7 +295,7 @@ String build() throws IOException {
}

@Override
void appendTo(Appendable appendable) throws IOException {
public void appendTo(Appendable appendable) throws IOException {
appendable.append(OBJECT_START);
int idx = 0;
for (Iterator<Entry<String, Object>> iterator = properties.entrySet().iterator(); iterator.hasNext();) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public final class ReflectiveClassBuildItem extends MultiBuildItem {
private final boolean methods;
private final boolean fields;
private final boolean constructors;
private final boolean finalFieldsWritable;
private final boolean weak;
private final boolean serialization;

Expand All @@ -29,13 +28,8 @@ public ReflectiveClassBuildItem(boolean constructors, boolean methods, boolean f
this(constructors, methods, fields, false, false, className);
}

private ReflectiveClassBuildItem(boolean constructors, boolean methods, boolean fields, boolean finalFieldsWritable,
boolean weak, Class<?>... className) {
this(constructors, methods, fields, finalFieldsWritable, weak, false, className);
}

private ReflectiveClassBuildItem(boolean constructors, boolean methods, boolean fields, boolean finalFieldsWritable,
boolean weak, boolean serialization, Class<?>... className) {
private ReflectiveClassBuildItem(boolean constructors, boolean methods, boolean fields, boolean weak, boolean serialization,
Class<?>... className) {
List<String> names = new ArrayList<>();
for (Class<?> i : className) {
if (i == null) {
Expand All @@ -47,16 +41,10 @@ private ReflectiveClassBuildItem(boolean constructors, boolean methods, boolean
this.methods = methods;
this.fields = fields;
this.constructors = constructors;
this.finalFieldsWritable = finalFieldsWritable;
this.weak = weak;
this.serialization = serialization;
if (weak) {
if (serialization) {
throw new RuntimeException("Weak reflection not supported with serialization");
}
if (finalFieldsWritable) {
throw new RuntimeException("Weak reflection not supported with finalFieldsWritable");
}
if (weak && serialization) {
throw new RuntimeException("Weak reflection not supported with serialization");
}
}

Expand All @@ -70,7 +58,7 @@ public ReflectiveClassBuildItem(boolean constructors, boolean methods, boolean f

public ReflectiveClassBuildItem(boolean constructors, boolean methods, boolean fields, boolean serialization,
String... className) {
this(constructors, methods, fields, false, false, serialization, className);
this(constructors, methods, fields, false, serialization, className);
}

public static ReflectiveClassBuildItem weakClass(String... className) {
Expand All @@ -79,20 +67,15 @@ public static ReflectiveClassBuildItem weakClass(String... className) {

public static ReflectiveClassBuildItem weakClass(boolean constructors, boolean methods, boolean fields,
String... className) {
return new ReflectiveClassBuildItem(constructors, methods, fields, false, true, className);
return new ReflectiveClassBuildItem(constructors, methods, fields, true, false, className);
}

public static ReflectiveClassBuildItem serializationClass(String... className) {
return new ReflectiveClassBuildItem(false, false, false, false, false, true, className);
return new ReflectiveClassBuildItem(false, false, false, false, true, className);
}

private ReflectiveClassBuildItem(boolean constructors, boolean methods, boolean fields, boolean finalFieldsWritable,
boolean weak, String... className) {
this(constructors, methods, fields, finalFieldsWritable, weak, false, className);
}

private ReflectiveClassBuildItem(boolean constructors, boolean methods, boolean fields, boolean finalFieldsWritable,
boolean weak, boolean serialization, String... className) {
private ReflectiveClassBuildItem(boolean constructors, boolean methods, boolean fields, boolean weak, boolean serialization,
String... className) {
for (String i : className) {
if (i == null) {
throw new NullPointerException();
Expand All @@ -102,7 +85,6 @@ private ReflectiveClassBuildItem(boolean constructors, boolean methods, boolean
this.methods = methods;
this.fields = fields;
this.constructors = constructors;
this.finalFieldsWritable = finalFieldsWritable;
this.weak = weak;
this.serialization = serialization;
}
Expand All @@ -123,8 +105,13 @@ public boolean isConstructors() {
return constructors;
}

/**
* @deprecated As of GraalVM 21.2 finalFieldsWritable is no longer needed when registering fields for reflection. This will
* be removed in a future verion of Quarkus.
*/
@Deprecated
zakkak marked this conversation as resolved.
Show resolved Hide resolved
public boolean areFinalFieldsWritable() {
return finalFieldsWritable;
return false;
}

public boolean isWeak() {
Expand Down Expand Up @@ -159,7 +146,6 @@ public static class Builder {
private boolean constructors = true;
private boolean methods;
private boolean fields;
private boolean finalFieldsWritable;
private boolean weak;
private boolean serialization;

Expand All @@ -186,8 +172,12 @@ public Builder fields(boolean fields) {
return this;
}

/**
* @deprecated As of GraalVM 21.2 finalFieldsWritable is no longer needed when registering fields for reflection. This
* will be removed in a future verion of Quarkus.
*/
@Deprecated
public Builder finalFieldsWritable(boolean finalFieldsWritable) {
this.finalFieldsWritable = finalFieldsWritable;
return this;
}

Expand All @@ -202,8 +192,7 @@ public Builder serialization(boolean serialize) {
}

public ReflectiveClassBuildItem build() {
return new ReflectiveClassBuildItem(constructors, methods, fields, finalFieldsWritable, weak, serialization,
className);
return new ReflectiveClassBuildItem(constructors, methods, fields, weak, serialization, className);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.quarkus.deployment.builditem.nativeimage;

import io.quarkus.builder.item.MultiBuildItem;

/**
* Used to define a condition to register a class for reflection in native mode only when a specific type is reachable
*/
public final class ReflectiveClassConditionBuildItem extends MultiBuildItem {

private final String className;
private final String typeReachable;
zakkak marked this conversation as resolved.
Show resolved Hide resolved

public ReflectiveClassConditionBuildItem(Class<?> className, String typeReachable) {
this(className.getName(), typeReachable);
}

public ReflectiveClassConditionBuildItem(String className, String typeReachable) {
this.className = className;
this.typeReachable = typeReachable;
}

public String getClassName() {
return className;
}

public String getTypeReachable() {
return typeReachable;
}
}
Loading