From 2589b41969a09aa5ec81e9284421054f7bb66ff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Tue, 24 Dec 2024 10:25:59 +0100 Subject: [PATCH] Fix build failure Code originally contributed by @snicoll. --- .../ResourcesConfigModelSerializer.java | 12 +- ...licationWithResourcesFunctionalTest.groovy | 55 ++++---- .../GenerateResourcesConfigFileTest.groovy | 123 ++++++++++-------- ...licationWithResourcesFunctionalTest.groovy | 49 +++---- .../buildtools/maven/sbom/SBOMGenerator.java | 2 +- 5 files changed, 137 insertions(+), 104 deletions(-) diff --git a/common/utils/src/main/java/org/graalvm/buildtools/model/resources/ResourcesConfigModelSerializer.java b/common/utils/src/main/java/org/graalvm/buildtools/model/resources/ResourcesConfigModelSerializer.java index 41fc5c641..784ff0fd1 100644 --- a/common/utils/src/main/java/org/graalvm/buildtools/model/resources/ResourcesConfigModelSerializer.java +++ b/common/utils/src/main/java/org/graalvm/buildtools/model/resources/ResourcesConfigModelSerializer.java @@ -52,7 +52,7 @@ public class ResourcesConfigModelSerializer { public static void serialize(ResourcesConfigModel model, File outputFile) throws IOException { JSONObject json = toJson(model); - String pretty = json.toString(4); + String pretty = json.toString(2); File outputDir = outputFile.getParentFile(); if (outputDir.isDirectory() || outputDir.mkdirs()) { try (OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(outputFile), StandardCharsets.UTF_8)) { @@ -73,14 +73,20 @@ private static JSONObject toJson(ResourcesConfigModel model) { private static JSONObject toJson(ResourcesModel model) { JSONObject json = new JSONObject(); JSONArray includes = new JSONArray(); - model.getIncludes().forEach(includes::put); + model.getIncludes().forEach(patternValue -> includes.put(toJson(patternValue))); json.put("includes", includes); JSONArray excludes = new JSONArray(); - model.getExcludes().forEach(excludes::put); + model.getExcludes().forEach(patternValue -> excludes.put(toJson(patternValue))); json.put("excludes", excludes); return json; } + private static JSONObject toJson(PatternValue patternValue) { + JSONObject json = new JSONObject(); + json.put("pattern", patternValue.getPattern()); + return json; + } + private static JSONObject toJson(NamedValue namedValue) { JSONObject json = new JSONObject(); json.put("name", namedValue.getName()); diff --git a/native-gradle-plugin/src/functionalTest/groovy/org/graalvm/buildtools/gradle/JavaApplicationWithResourcesFunctionalTest.groovy b/native-gradle-plugin/src/functionalTest/groovy/org/graalvm/buildtools/gradle/JavaApplicationWithResourcesFunctionalTest.groovy index 6fa5b097f..aed1c67b8 100644 --- a/native-gradle-plugin/src/functionalTest/groovy/org/graalvm/buildtools/gradle/JavaApplicationWithResourcesFunctionalTest.groovy +++ b/native-gradle-plugin/src/functionalTest/groovy/org/graalvm/buildtools/gradle/JavaApplicationWithResourcesFunctionalTest.groovy @@ -78,13 +78,15 @@ class JavaApplicationWithResourcesFunctionalTest extends AbstractFunctionalTest and: matches(file("build/native/generated/generateResourcesConfigFile/resource-config.json").text, '''{ - "resources" : { - "includes" : [ { - "pattern" : "\\\\Qmessage.txt\\\\E" - } ], - "excludes" : [ ] + "resources": { + "includes": [ + { + "pattern": "\\\\Qmessage.txt\\\\E" + } + ], + "excludes": [] }, - "bundles" : [ ] + "bundles": [] }''') where: @@ -152,15 +154,18 @@ graalvmNative { and: matches(file("build/native/generated/generateTestResourcesConfigFile/resource-config.json").text, '''{ - "resources" : { - "includes" : [ { - "pattern" : "\\\\Qmessage.txt\\\\E" - }, { - "pattern" : "\\\\Qorg/graalvm/demo/expected.txt\\\\E" - } ], - "excludes" : [ ] + "resources": { + "includes": [ + { + "pattern": "\\\\Qmessage.txt\\\\E" + }, + { + "pattern": "\\\\Qorg/graalvm/demo/expected.txt\\\\E" + } + ], + "excludes": [] }, - "bundles" : [ ] + "bundles": [] }''') where: @@ -205,11 +210,11 @@ graalvmNative { resourcesFile.parentFile.mkdirs() resourcesFile << """ { - "resources" : { - "includes" : [ ], - "excludes" : [ ] + "resources": { + "includes": [], + "excludes": [] }, - "bundles" : [ ] + "bundles": [] } """ @@ -243,13 +248,15 @@ graalvmNative { and: matches(file("build/native/generated/generateResourcesConfigFile/resource-config.json").text, '''{ - "resources" : { - "includes" : [ { - "pattern" : "\\\\Qmessage.txt\\\\E" - } ], - "excludes" : [ ] + "resources": { + "includes": [ + { + "pattern": "\\\\Qmessage.txt\\\\E" + } + ], + "excludes": [] }, - "bundles" : [ ] + "bundles": [] }''') when: diff --git a/native-gradle-plugin/src/test/groovy/org/graalvm/buildtools/gradle/tasks/GenerateResourcesConfigFileTest.groovy b/native-gradle-plugin/src/test/groovy/org/graalvm/buildtools/gradle/tasks/GenerateResourcesConfigFileTest.groovy index 27b027c93..95025fbbf 100644 --- a/native-gradle-plugin/src/test/groovy/org/graalvm/buildtools/gradle/tasks/GenerateResourcesConfigFileTest.groovy +++ b/native-gradle-plugin/src/test/groovy/org/graalvm/buildtools/gradle/tasks/GenerateResourcesConfigFileTest.groovy @@ -52,11 +52,11 @@ class GenerateResourcesConfigFileTest extends AbstractPluginTest { with(project) { outputFile.exists() matches(outputFile.text, '''{ - "resources" : { - "includes" : [ ], - "excludes" : [ ] + "resources": { + "includes": [], + "excludes": [] }, - "bundles" : [ ] + "bundles": [] }''') } } @@ -73,15 +73,18 @@ class GenerateResourcesConfigFileTest extends AbstractPluginTest { with(project) { outputFile.exists() matches(outputFile.text, '''{ - "resources" : { - "includes" : [ ], - "excludes" : [ ] + "resources": { + "includes": [], + "excludes": [] }, - "bundles" : [ { - "name" : "my.bundle" - }, { - "name" : "other.bundle" - } ] + "bundles": [ + { + "name": "my.bundle" + }, + { + "name": "other.bundle" + } + ] }''') } } @@ -99,19 +102,25 @@ class GenerateResourcesConfigFileTest extends AbstractPluginTest { with(project) { outputFile.exists() matches(outputFile.text, '''{ - "resources" : { - "includes" : [ { - "pattern" : "pattern" - }, { - "pattern" : "[a-z]+" - } ], - "excludes" : [ { - "pattern" : "META-INF/.*" - }, { - "pattern" : ".*[.]class" - } ] + "resources": { + "includes": [ + { + "pattern": "pattern" + }, + { + "pattern": "[a-z]+" + } + ], + "excludes": [ + { + "pattern": "META-INF/.*" + }, + { + "pattern": ".*[.]class" + } + ] }, - "bundles" : [ ] + "bundles": [] }''') } } @@ -128,11 +137,11 @@ class GenerateResourcesConfigFileTest extends AbstractPluginTest { with(project) { outputFile.exists() matches(outputFile.text, '''{ - "resources" : { - "includes" : [ ], - "excludes" : [ ] + "resources": { + "includes": [], + "excludes": [] }, - "bundles" : [ ] + "bundles": [] }''') } } @@ -150,13 +159,15 @@ class GenerateResourcesConfigFileTest extends AbstractPluginTest { with(project) { outputFile.exists() matches(outputFile.text, '''{ - "resources" : { - "includes" : [ { - "pattern" : "\\\\Qorg/foo/some/resource.txt\\\\E" - } ], - "excludes" : [ ] + "resources": { + "includes": [ + { + "pattern": "\\\\Qorg/foo/some/resource.txt\\\\E" + } + ], + "excludes": [] }, - "bundles" : [ ] + "bundles": [] }''') } } @@ -175,13 +186,15 @@ class GenerateResourcesConfigFileTest extends AbstractPluginTest { with(project) { outputFile.exists() matches(outputFile.text, '''{ - "resources" : { - "includes" : [ { - "pattern" : "\\\\Qorg/foo/some/resource.txt\\\\E" - } ], - "excludes" : [ ] + "resources": { + "includes": [ + { + "pattern": "\\\\Qorg/foo/some/resource.txt\\\\E" + } + ], + "excludes": [] }, - "bundles" : [ ] + "bundles": [] }''') } } @@ -199,13 +212,15 @@ class GenerateResourcesConfigFileTest extends AbstractPluginTest { with(project) { outputFile.exists() matches(outputFile.text, '''{ - "resources" : { - "includes" : [ { - "pattern" : "\\\\Qorg/foo/some/resource.txt\\\\E" - } ], - "excludes" : [ ] + "resources": { + "includes": [ + { + "pattern": "\\\\Qorg/foo/some/resource.txt\\\\E" + } + ], + "excludes": [] }, - "bundles" : [ ] + "bundles": [] }''') } } @@ -225,11 +240,11 @@ class GenerateResourcesConfigFileTest extends AbstractPluginTest { with(project) { outputFile.exists() matches(outputFile.text, '''{ - "resources" : { - "includes" : [ ], - "excludes" : [ ] + "resources": { + "includes": [], + "excludes": [] }, - "bundles" : [ ] + "bundles": [] }''') } } @@ -247,11 +262,11 @@ class GenerateResourcesConfigFileTest extends AbstractPluginTest { with(project) { outputFile.exists() matches(outputFile.text, '''{ - "resources" : { - "includes" : [ ], - "excludes" : [ ] + "resources": { + "includes": [], + "excludes": [] }, - "bundles" : [ ] + "bundles": [] }''') } } diff --git a/native-maven-plugin/src/functionalTest/groovy/org/graalvm/buildtools/maven/JavaApplicationWithResourcesFunctionalTest.groovy b/native-maven-plugin/src/functionalTest/groovy/org/graalvm/buildtools/maven/JavaApplicationWithResourcesFunctionalTest.groovy index 7d38778f5..ead323735 100644 --- a/native-maven-plugin/src/functionalTest/groovy/org/graalvm/buildtools/maven/JavaApplicationWithResourcesFunctionalTest.groovy +++ b/native-maven-plugin/src/functionalTest/groovy/org/graalvm/buildtools/maven/JavaApplicationWithResourcesFunctionalTest.groovy @@ -32,11 +32,11 @@ class JavaApplicationWithResourcesFunctionalTest extends AbstractGraalVMMavenFun resourcesFile.parentFile.mkdirs() resourcesFile << """ { - "resources" : { - "includes" : [ ], - "excludes" : [ ] + "resources": { + "includes": [], + "excludes": [] }, - "bundles" : [ ] + "bundles": [] } """ @@ -49,21 +49,23 @@ class JavaApplicationWithResourcesFunctionalTest extends AbstractGraalVMMavenFun and: if (ignoreExistingResourcesConfig) { matches(file("target/native/generated/generateResourceConfig/resource-config.json").text, '''{ - "resources" : { - "includes" : [ { - "pattern" : "\\\\Qmessage.txt\\\\E" - } ], - "excludes" : [ ] + "resources": { + "includes": [ + { + "pattern" : "\\\\Qmessage.txt\\\\E" + } + ], + "excludes": [] }, - "bundles" : [ ] + "bundles": [] }''') } else { matches(file("target/native/generated/generateResourceConfig/resource-config.json").text, '''{ - "resources" : { - "includes" : [ ], - "excludes" : [ ] + "resources": { + "includes": [], + "excludes": [] }, - "bundles" : [ ] + "bundles": [] }''') } @@ -102,15 +104,18 @@ class JavaApplicationWithResourcesFunctionalTest extends AbstractGraalVMMavenFun and: matches(file("target/native/generated/generateTestResourceConfig/resource-config.json").text, '''{ - "resources" : { - "includes" : [ { - "pattern" : "\\\\Qmessage.txt\\\\E" - }, { - "pattern" : "\\\\Qorg/graalvm/demo/expected.txt\\\\E" - } ], - "excludes" : [ ] + "resources": { + "includes": [ + { + "pattern": "\\\\Qmessage.txt\\\\E" + }, + { + "pattern": "\\\\Qorg/graalvm/demo/expected.txt\\\\E" + } + ], + "excludes": [] }, - "bundles" : [ ] + "bundles": [] }''') where: diff --git a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/sbom/SBOMGenerator.java b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/sbom/SBOMGenerator.java index f28e60bc0..0a1ce00f6 100644 --- a/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/sbom/SBOMGenerator.java +++ b/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/sbom/SBOMGenerator.java @@ -252,7 +252,7 @@ private void augmentSBOM(Path baseSBOMPath, Set artifacts) thro } /* Save the augmented SBOM back to the file */ - Files.writeString(baseSBOMPath, sbomJson.toString(4)); + Files.writeString(baseSBOMPath, sbomJson.toString(2)); } /**