From f5dfc7469726fc5c21dd26b7de370761790b6fc7 Mon Sep 17 00:00:00 2001 From: Nick Cross Date: Fri, 31 May 2024 13:42:44 +0100 Subject: [PATCH 1/2] Fix yaml output generation --- .../redhat/hacbs/recipes/RecipeManager.java | 14 +++++-- .../build/BuildRecipeInfoManagerTest.java | 39 ++++++++++++++++++- .../src/test/resources/build.yaml | 27 +++++++++++++ 3 files changed, 76 insertions(+), 4 deletions(-) diff --git a/java-components/build-recipes-database/src/main/java/com/redhat/hacbs/recipes/RecipeManager.java b/java-components/build-recipes-database/src/main/java/com/redhat/hacbs/recipes/RecipeManager.java index 621a52280..9587ea0ef 100644 --- a/java-components/build-recipes-database/src/main/java/com/redhat/hacbs/recipes/RecipeManager.java +++ b/java-components/build-recipes-database/src/main/java/com/redhat/hacbs/recipes/RecipeManager.java @@ -1,5 +1,6 @@ package com.redhat.hacbs.recipes; +import static com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature.INDENT_ARRAYS_WITH_INDICATOR; import static com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature.MINIMIZE_QUOTES; import static com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature.SPLIT_LINES; @@ -11,15 +12,22 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.json.JsonMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; public interface RecipeManager { - ObjectMapper MAPPER = new ObjectMapper( - new YAMLFactory().disable(SPLIT_LINES).enable(MINIMIZE_QUOTES)) + ObjectMapper MAPPER = JsonMapper.builder(new YAMLFactory() + .disable(SPLIT_LINES) + .disable(MINIMIZE_QUOTES) + .enable(INDENT_ARRAYS_WITH_INDICATOR)) .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) - .setSerializationInclusion(JsonInclude.Include.NON_DEFAULT); + .configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true) + .configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true) + .build().setSerializationInclusion(JsonInclude.Include.NON_DEFAULT); default T parse(Path file) throws IOException { try (var in = Files.newInputStream(file)) { diff --git a/java-components/build-recipes-database/src/test/java/com/redhat/hacbs/recipes/build/BuildRecipeInfoManagerTest.java b/java-components/build-recipes-database/src/test/java/com/redhat/hacbs/recipes/build/BuildRecipeInfoManagerTest.java index 85b2b5c70..e6d249d84 100644 --- a/java-components/build-recipes-database/src/test/java/com/redhat/hacbs/recipes/build/BuildRecipeInfoManagerTest.java +++ b/java-components/build-recipes-database/src/test/java/com/redhat/hacbs/recipes/build/BuildRecipeInfoManagerTest.java @@ -2,22 +2,59 @@ import static org.junit.jupiter.api.Assertions.*; +import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.nio.file.Files; import java.nio.file.Path; import java.util.Objects; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; class BuildRecipeInfoManagerTest { @Test - void parse() + void parse(@TempDir Path tempDir) throws IOException, URISyntaxException { BuildRecipeInfoManager buildRecipeInfoManager = new BuildRecipeInfoManager(); var result = buildRecipeInfoManager.parse(Path.of( Objects.requireNonNull( BuildRecipeInfoManagerTest.class.getClassLoader().getResource("build.yaml")).toURI())); assertNotNull(result); + + assertEquals(1, result.additionalArgs.size()); + assertEquals("-DskipDocs", result.additionalArgs.get(0)); + + File written = new File(tempDir.toFile(), "result.yaml"); + BuildRecipeInfoManager.MAPPER.writeValue(written, result); + String generated = Files.readString(written.toPath()); + + assertEquals("---\n" + + "additionalArgs:\n" + + " - \"-DskipDocs\"\n" + + "additionalBuilds:\n" + + " pureJava:\n" + + " additionalArgs:\n" + + " - \"-Dlz4-pure-java=true\"\n" + + " preBuildScript: \"./autogen.sh\\n/bin/sh -c \\\"$(rpm --eval %configure); $(rpm --eval %__make) $(rpm --eval %_smp_mflags)\\\"\\n\"\n" + + + "additionalDownloads:\n" + + " - binaryPath: \"only_for_tar/bin\"\n" + + " fileName: \"yq\"\n" + + " sha256: \"30459aa144a26125a1b22c62760f9b3872123233a5658934f7bd9fe714d7864d\"\n" + + " type: \"executable\"\n" + + " uri: \"https://github.com/mikefarah/yq/releases/download/v4.30.4/yq_linux_amd64\"\n" + + " - packageName: \"glibc-devel\"\n" + + " type: \"rpm\"\n" + + "additionalMemory: 4096\n" + + "allowedDifferences:\n" + + " - \"\\\\Q-:jbossws-common-4.0.0.Final.jar:class:org/jboss/ws/common/CalendarTest\\\\E\"\n" + + "alternativeArgs:\n" + + " - \"'set Global / baseVersionSuffix:=\\\"\\\"'\"\n" + + " - \"enableOptimizer\"\n" + + "enforceVersion: true\n" + + "repositories:\n" + + " - \"caucho\"\n", generated); } } diff --git a/java-components/build-recipes-database/src/test/resources/build.yaml b/java-components/build-recipes-database/src/test/resources/build.yaml index e69de29bb..804714d30 100644 --- a/java-components/build-recipes-database/src/test/resources/build.yaml +++ b/java-components/build-recipes-database/src/test/resources/build.yaml @@ -0,0 +1,27 @@ +--- +repositories: + - caucho +additionalArgs: + - "-DskipDocs" +additionalDownloads: + - uri: https://github.com/mikefarah/yq/releases/download/v4.30.4/yq_linux_amd64 + sha256: 30459aa144a26125a1b22c62760f9b3872123233a5658934f7bd9fe714d7864d + type: executable + fileName: yq + binaryPath: only_for_tar/bin + - type: rpm + packageName: glibc-devel +additionalMemory: 4096 +additionalBuilds: + pureJava: + preBuildScript: | + ./autogen.sh + /bin/sh -c "$(rpm --eval %configure); $(rpm --eval %__make) $(rpm --eval %_smp_mflags)" + additionalArgs: + - "-Dlz4-pure-java=true" +allowedDifferences: + - \Q-:jbossws-common-4.0.0.Final.jar:class:org/jboss/ws/common/CalendarTest\E +alternativeArgs: + - "'set Global / baseVersionSuffix:=\"\"'" + - "enableOptimizer" +enforceVersion: true From df7d6f18c95b7cde5b1280c09eef9686f175d74d Mon Sep 17 00:00:00 2001 From: Nick Cross Date: Fri, 31 May 2024 13:43:07 +0100 Subject: [PATCH 2/2] Minor logging enhancement --- pkg/reconciler/dependencybuild/buildrecipeyaml.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/reconciler/dependencybuild/buildrecipeyaml.go b/pkg/reconciler/dependencybuild/buildrecipeyaml.go index 5618e41e3..9c7798326 100644 --- a/pkg/reconciler/dependencybuild/buildrecipeyaml.go +++ b/pkg/reconciler/dependencybuild/buildrecipeyaml.go @@ -706,7 +706,7 @@ func additionalPackages(recipe *v1alpha1.BuildRecipe) string { } func gitScript(db *v1alpha1.DependencyBuild, recipe *v1alpha1.BuildRecipe) string { - gitArgs := "echo \"Cloning $(params." + PipelineParamScmUrl + ")\" && " + gitArgs := "echo \"Cloning $(params." + PipelineParamScmUrl + ") and resetting to $(params." + PipelineParamScmHash + ")\" && " if db.Spec.ScmInfo.Private { gitArgs = gitArgs + "echo \"$GIT_TOKEN\" > $HOME/.git-credentials && chmod 400 $HOME/.git-credentials && " gitArgs = gitArgs + "echo '[credential]\n helper=store\n' > $HOME/.gitconfig && "