Skip to content

Commit

Permalink
Fix build failure
Browse files Browse the repository at this point in the history
Code originally contributed by @snicoll.
  • Loading branch information
sdeleuze committed Dec 24, 2024
1 parent 2628d39 commit 2589b41
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -205,11 +210,11 @@ graalvmNative {
resourcesFile.parentFile.mkdirs()
resourcesFile << """
{
"resources" : {
"includes" : [ ],
"excludes" : [ ]
"resources": {
"includes": [],
"excludes": []
},
"bundles" : [ ]
"bundles": []
}
"""

Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ class GenerateResourcesConfigFileTest extends AbstractPluginTest {
with(project) {
outputFile.exists()
matches(outputFile.text, '''{
"resources" : {
"includes" : [ ],
"excludes" : [ ]
"resources": {
"includes": [],
"excludes": []
},
"bundles" : [ ]
"bundles": []
}''')
}
}
Expand All @@ -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"
}
]
}''')
}
}
Expand All @@ -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": []
}''')
}
}
Expand All @@ -128,11 +137,11 @@ class GenerateResourcesConfigFileTest extends AbstractPluginTest {
with(project) {
outputFile.exists()
matches(outputFile.text, '''{
"resources" : {
"includes" : [ ],
"excludes" : [ ]
"resources": {
"includes": [],
"excludes": []
},
"bundles" : [ ]
"bundles": []
}''')
}
}
Expand All @@ -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": []
}''')
}
}
Expand All @@ -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": []
}''')
}
}
Expand All @@ -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": []
}''')
}
}
Expand All @@ -225,11 +240,11 @@ class GenerateResourcesConfigFileTest extends AbstractPluginTest {
with(project) {
outputFile.exists()
matches(outputFile.text, '''{
"resources" : {
"includes" : [ ],
"excludes" : [ ]
"resources": {
"includes": [],
"excludes": []
},
"bundles" : [ ]
"bundles": []
}''')
}
}
Expand All @@ -247,11 +262,11 @@ class GenerateResourcesConfigFileTest extends AbstractPluginTest {
with(project) {
outputFile.exists()
matches(outputFile.text, '''{
"resources" : {
"includes" : [ ],
"excludes" : [ ]
"resources": {
"includes": [],
"excludes": []
},
"bundles" : [ ]
"bundles": []
}''')
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class JavaApplicationWithResourcesFunctionalTest extends AbstractGraalVMMavenFun
resourcesFile.parentFile.mkdirs()
resourcesFile << """
{
"resources" : {
"includes" : [ ],
"excludes" : [ ]
"resources": {
"includes": [],
"excludes": []
},
"bundles" : [ ]
"bundles": []
}
"""

Expand All @@ -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": []
}''')
}

Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private void augmentSBOM(Path baseSBOMPath, Set<ArtifactAdapter> artifacts) thro
}

/* Save the augmented SBOM back to the file */
Files.writeString(baseSBOMPath, sbomJson.toString(4));
Files.writeString(baseSBOMPath, sbomJson.toString(2));
}

/**
Expand Down

0 comments on commit 2589b41

Please sign in to comment.