Skip to content

Commit

Permalink
Use dedicated printer to pretty print embedded resources JSON.
Browse files Browse the repository at this point in the history
  • Loading branch information
petalex committed Dec 27, 2024
1 parent a9b0ed7 commit 3e291d3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,40 +64,31 @@ public static void printReport(JsonWriter writer) throws IOException {
}

private static void resourceReportElement(ResourceReportEntry p, JsonWriter w) throws IOException {
w.indent().newline();
w.appendObjectStart().newline();
w.appendObjectStart();
w.appendKeyValue("name", p.resourceName()).appendSeparator();
w.newline();
if (p.module() != null) {
w.appendKeyValue("module", p.module().getName()).appendSeparator();
w.newline();
}

if (p.isDirectory()) {
w.appendKeyValue("is_directory", true).appendSeparator();
w.newline();
}

if (p.isMissing()) {
w.appendKeyValue("is_missing", true).appendSeparator();
w.newline();
}

w.quote("entries").append(":");
w.quote("entries").appendFieldSeparator();
JsonPrinter.printCollection(w, p.entries(), Comparator.comparing(SourceSizePair::source), EmbeddedResourceExporter::sourceElement);
w.unindent().newline().appendObjectEnd();
w.appendObjectEnd();
}

private static void sourceElement(SourceSizePair p, JsonWriter w) throws IOException {
w.indent().newline();
w.appendObjectStart().newline();
w.appendObjectStart();
w.appendKeyValue("origin", p.source()).appendSeparator();
w.newline();
w.appendKeyValue("registration_origin", p.origin()).appendSeparator();
w.newline();
w.appendKeyValue("size", p.size());
w.newline().appendObjectEnd();
w.unindent();
w.appendObjectEnd();
}

private static List<ResourceReportEntry> getResourceReportEntryList(ConcurrentHashMap<Resources.ModuleResourceKey, List<SourceAndOrigin>> collection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
import jdk.graal.compiler.options.Option;
import jdk.graal.compiler.options.OptionType;
import jdk.graal.compiler.phases.util.Providers;
import jdk.graal.compiler.util.json.JsonPrettyWriter;
import jdk.graal.compiler.util.json.JsonWriter;
import jdk.vm.ci.meta.ResolvedJavaMethod;

Expand Down Expand Up @@ -638,7 +639,7 @@ public void afterAnalysis(AfterAnalysisAccess access) {
sealed = true;
if (Options.GenerateEmbeddedResourcesFile.getValue()) {
Path reportLocation = NativeImageGenerator.generatedFiles(HostedOptionValues.singleton()).resolve(Options.EMBEDDED_RESOURCES_FILE_NAME);
try (JsonWriter writer = new JsonWriter(reportLocation)) {
try (JsonWriter writer = new JsonPrettyWriter(reportLocation)) {
EmbeddedResourceExporter.printReport(writer);
} catch (IOException e) {
throw VMError.shouldNotReachHere("Json writer cannot write to: " + reportLocation, e);
Expand Down

0 comments on commit 3e291d3

Please sign in to comment.