From 9a687e20fc1497501372f9ea49ca1f9ff2d8d40f Mon Sep 17 00:00:00 2001 From: Daniel Mikusa Date: Fri, 4 Oct 2024 10:07:17 -0400 Subject: [PATCH] Do not use effect.NewExecutor use CommandExecutor instead When running `syft`, do not use effect.NewExecutor which runs the command with a tty. This seems to cause an issue with syft (or possibly with our tty library pty), and in either case you end up with stray formatting characters even though we tell syft to be quiet. Using CommandExecutor is basically the same, but it doesn't run with a tty. Signed-off-by: Daniel Mikusa --- maven/build.go | 2 +- maven/maven_manager_test.go | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/maven/build.go b/maven/build.go index 76e1a55..c71b557 100644 --- a/maven/build.go +++ b/maven/build.go @@ -119,7 +119,7 @@ func (b Build) Build(context libcnb.BuildContext) (libcnb.BuildResult, error) { if _, found, err := pr.Resolve(PlanEntryJVMApplicationPackage); err != nil { return libcnb.BuildResult{}, fmt.Errorf("unable to resolve JVM Application Package plan entry\n%w", err) } else if found { - bomScanner := sbom.NewSyftCLISBOMScanner(context.Layers, effect.NewExecutor(), b.Logger) + bomScanner := sbom.NewSyftCLISBOMScanner(context.Layers, effect.CommandExecutor{}, b.Logger) // build a layer contributor to run Maven a, err := b.ApplicationFactory.NewApplication( diff --git a/maven/maven_manager_test.go b/maven/maven_manager_test.go index 492f395..25b6720 100644 --- a/maven/maven_manager_test.go +++ b/maven/maven_manager_test.go @@ -20,9 +20,9 @@ func testMavenManager(t *testing.T, context spec.G, it spec.S) { var ( Expect = NewWithT(t).Expect - ctx libcnb.BuildContext - mavenManager maven.MavenManager - mvnwFilepath string + ctx libcnb.BuildContext + mavenManager maven.MavenManager + mvnwFilepath string mvnwPropsPath string ) @@ -36,10 +36,12 @@ func testMavenManager(t *testing.T, context spec.G, it spec.S) { Expect(err).NotTo(HaveOccurred()) mvnwFilepath = filepath.Join(ctx.Application.Path, "mvnw") - mvnwPropsPath = filepath.Join(ctx.Application.Path, ".mvn/wrapper/") - + mvnwPropsPath = filepath.Join(ctx.Application.Path, ".mvn/wrapper/") + err = os.MkdirAll(mvnwPropsPath, 0755) Expect(err).NotTo(HaveOccurred()) + + t.Setenv("BP_ARCH", "amd64") }) it.After(func() { @@ -273,13 +275,13 @@ func testMavenManager(t *testing.T, context spec.G, it spec.S) { it("converts CRLF formatting in the maven-wrapper.properties file to LF (unix) if present", func() { propsFile := filepath.Join(mvnwPropsPath, "maven-wrapper.properties") Expect(os.WriteFile(propsFile, []byte("test\r\n"), 0755)).To(Succeed()) - + _, _, _, err := mavenManager.Install() - Expect(err).NotTo(HaveOccurred()) + Expect(err).NotTo(HaveOccurred()) - contents, err := os.ReadFile(propsFile) - Expect(err).NotTo(HaveOccurred()) - Expect(bytes.Compare(contents, []byte("test\n"))).To(Equal(0)) + contents, err := os.ReadFile(propsFile) + Expect(err).NotTo(HaveOccurred()) + Expect(bytes.Compare(contents, []byte("test\n"))).To(Equal(0)) }) })