forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move native Proxy configuration from Feature to json
Follow up to quarkusio#29886
- Loading branch information
Showing
2 changed files
with
42 additions
and
50 deletions.
There are no files selected for viewing
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
42 changes: 42 additions & 0 deletions
42
core/deployment/src/main/java/io/quarkus/deployment/steps/NativeImageProxyConfigStep.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,42 @@ | ||
package io.quarkus.deployment.steps; | ||
|
||
import java.io.IOException; | ||
import java.io.StringWriter; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
|
||
import io.quarkus.builder.Json; | ||
import io.quarkus.builder.Json.JsonArrayBuilder; | ||
import io.quarkus.builder.Json.JsonObjectBuilder; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.builditem.GeneratedResourceBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.NativeImageProxyDefinitionBuildItem; | ||
import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild; | ||
|
||
public class NativeImageProxyConfigStep { | ||
|
||
@BuildStep(onlyIf = NativeOrNativeSourcesBuild.class) | ||
void generateProxyConfig(BuildProducer<GeneratedResourceBuildItem> proxyConfig, | ||
List<NativeImageProxyDefinitionBuildItem> proxies) { | ||
JsonArrayBuilder root = Json.array(); | ||
|
||
for (NativeImageProxyDefinitionBuildItem proxy : proxies) { | ||
JsonArrayBuilder interfaces = Json.array(); | ||
for (String cl : proxy.getClasses()) { | ||
interfaces.add(cl); | ||
} | ||
JsonObjectBuilder proxyJson = Json.object(); | ||
proxyJson.put("interfaces", interfaces); | ||
root.add(proxyJson); | ||
} | ||
|
||
try (StringWriter writer = new StringWriter()) { | ||
root.appendTo(writer); | ||
proxyConfig.produce(new GeneratedResourceBuildItem("META-INF/native-image/proxy-config.json", | ||
writer.toString().getBytes(StandardCharsets.UTF_8))); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |