Skip to content

Commit

Permalink
Merge pull request #285 from paketo-buildpacks/fix-chars
Browse files Browse the repository at this point in the history
Do not use effect.NewExecutor use CommandExecutor instead
  • Loading branch information
dmikusa authored Oct 4, 2024
2 parents 5652b0b + 476f0da commit 5e28579
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 36 deletions.
2 changes: 1 addition & 1 deletion executable/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (b Build) Build(context libcnb.BuildContext) (libcnb.BuildResult, error) {
}

if b.SBOMScanner == nil {
b.SBOMScanner = sbom.NewSyftCLISBOMScanner(context.Layers, effect.NewExecutor(), b.Logger)
b.SBOMScanner = sbom.NewSyftCLISBOMScanner(context.Layers, effect.CommandExecutor{}, b.Logger)
}
if err := b.SBOMScanner.ScanLaunch(context.Application.Path, libcnb.SyftJSON, libcnb.CycloneDXJSON); err != nil {
return libcnb.BuildResult{}, fmt.Errorf("unable to create Build SBoM \n%w", err)
Expand Down
28 changes: 11 additions & 17 deletions executable/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package executable_test
import (
"fmt"
"io/fs"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -41,13 +40,8 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
)

it.Before(func() {
var err error

ctx.Application.Path, err = ioutil.TempDir("", "build-application")
Expect(err).NotTo(HaveOccurred())

ctx.Layers.Path, err = ioutil.TempDir("", "build-layers")
Expect(err).NotTo(HaveOccurred())
ctx.Application.Path = t.TempDir()
ctx.Layers.Path = t.TempDir()

Expect(os.MkdirAll(filepath.Join(ctx.Application.Path, "META-INF"), 0755)).To(Succeed())
sbomScanner = mocks.SBOMScanner{}
Expand All @@ -62,7 +56,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {

context("manifest with Main-Class and Class-Path", func() {
it.Before(func() {
Expect(ioutil.WriteFile(
Expect(os.WriteFile(
filepath.Join(ctx.Application.Path, "META-INF", "MANIFEST.MF"),
[]byte("Main-Class: test-main-class"),
0644,
Expand All @@ -71,7 +65,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {

it("contributes process types and classpath", func() {
Expect(os.MkdirAll(filepath.Join(ctx.Application.Path, "META-INF"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(
Expect(os.WriteFile(
filepath.Join(ctx.Application.Path, "META-INF", "MANIFEST.MF"),
[]byte("Main-Class: test-main-class\nClass-Path: test-class-path"),
0644,
Expand Down Expand Up @@ -108,7 +102,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {

context("manifest with Main-Class and without Class-Path", func() {
it.Before(func() {
Expect(ioutil.WriteFile(
Expect(os.WriteFile(
filepath.Join(ctx.Application.Path, "META-INF", "MANIFEST.MF"),
[]byte("Main-Class: test-main-class"),
0644,
Expand All @@ -117,7 +111,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {

it("contributes process types and classpath", func() {
Expect(os.MkdirAll(filepath.Join(ctx.Application.Path, "META-INF"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(
Expect(os.WriteFile(
filepath.Join(ctx.Application.Path, "META-INF", "MANIFEST.MF"),
[]byte("Main-Class: test-main-class"),
0644,
Expand Down Expand Up @@ -155,7 +149,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {

it("contributes Executable JAR without Class-Path", func() {
Expect(os.MkdirAll(filepath.Join(ctx.Application.Path, "META-INF"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(
Expect(os.WriteFile(
filepath.Join(ctx.Application.Path, "META-INF", "MANIFEST.MF"),
[]byte(`Main-Class: test-main-class`),
0644,
Expand Down Expand Up @@ -200,7 +194,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {

it("contributes reloadable process type", func() {
Expect(os.MkdirAll(filepath.Join(ctx.Application.Path, "META-INF"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(
Expect(os.WriteFile(
filepath.Join(ctx.Application.Path, "META-INF", "MANIFEST.MF"),
[]byte(`Main-Class: test-main-class`),
0644,
Expand Down Expand Up @@ -242,7 +236,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {

it("marks all workspace files as group read-writable", func() {
Expect(os.MkdirAll(filepath.Join(ctx.Application.Path, "META-INF"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(
Expect(os.WriteFile(
filepath.Join(ctx.Application.Path, "META-INF", "MANIFEST.MF"),
[]byte(`Main-Class: test-main-class`),
0644,
Expand Down Expand Up @@ -278,7 +272,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
context("native image", func() {
it("contributes classpath for build", func() {
Expect(os.MkdirAll(filepath.Join(ctx.Application.Path, "META-INF"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(
Expect(os.WriteFile(
filepath.Join(ctx.Application.Path, "META-INF", "MANIFEST.MF"),
[]byte("Main-Class: test-main-class\nClass-Path: test-class-path"),
0644,
Expand All @@ -304,7 +298,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
context("Manifest does not have Main-Class", func() {
it("return unmet jvm-application plan entry", func() {
Expect(os.MkdirAll(filepath.Join(ctx.Application.Path, "META-INF"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(
Expect(os.WriteFile(
filepath.Join(ctx.Application.Path, "META-INF", "MANIFEST.MF"),
[]byte(`Class-Path: test-class-path`),
0644,
Expand Down
6 changes: 1 addition & 5 deletions executable/classpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package executable_test

import (
"io/ioutil"
"os"
"testing"

Expand All @@ -37,10 +36,7 @@ func testClassPath(t *testing.T, context spec.G, it spec.S) {
)

it.Before(func() {
var err error

ctx.Layers.Path, err = ioutil.TempDir("", "class-path-layers")
Expect(err).NotTo(HaveOccurred())
ctx.Layers.Path = t.TempDir()
contributor = executable.ClassPath{
ClassPath: []string{"test-value-1", "test-value-2"},
}
Expand Down
9 changes: 3 additions & 6 deletions executable/detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package executable_test

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -39,9 +38,7 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
)

it.Before(func() {
var err error
path, err = ioutil.TempDir("", "executable-jar")
Expect(err).NotTo(HaveOccurred())
path = t.TempDir()

ctx.Application.Path = path
})
Expand Down Expand Up @@ -74,7 +71,7 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
context("empty META-INF/MANIFEST.MF not found", func() {
it.Before(func() {
Expect(os.MkdirAll(filepath.Join(path, "META-INF"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(
Expect(os.WriteFile(
filepath.Join(path, "META-INF", "MANIFEST.MF"),
[]byte(""),
0644,
Expand Down Expand Up @@ -104,7 +101,7 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
context("META-INF/MANIFEST.MF with Main-Class", func() {
it.Before(func() {
Expect(os.MkdirAll(filepath.Join(path, "META-INF"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(
Expect(os.WriteFile(
filepath.Join(path, "META-INF", "MANIFEST.MF"),
[]byte("Main-Class: test-main-class"),
0644,
Expand Down
10 changes: 3 additions & 7 deletions executable/executable_jar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package executable_test
import (
"archive/zip"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -36,10 +35,7 @@ func testManifest(t *testing.T, context spec.G, it spec.S) {
)

it.Before(func() {
var err error

appPath, err = ioutil.TempDir("", "manifest")
Expect(err).NotTo(HaveOccurred())
appPath = t.TempDir()
})

it.After(func() {
Expand All @@ -49,7 +45,7 @@ func testManifest(t *testing.T, context spec.G, it spec.S) {
context("exploded JAR", func() {
it("fail if not executable", func() {
Expect(os.MkdirAll(filepath.Join(appPath, "META-INF"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(
Expect(os.WriteFile(
filepath.Join(appPath, "META-INF", "MANIFEST.MF"),
[]byte(`foo: bar`),
0644,
Expand All @@ -74,7 +70,7 @@ func testManifest(t *testing.T, context spec.G, it spec.S) {

it("loads executable JAR properties", func() {
Expect(os.MkdirAll(filepath.Join(appPath, "META-INF"), 0755)).To(Succeed())
Expect(ioutil.WriteFile(
Expect(os.WriteFile(
filepath.Join(appPath, "META-INF", "MANIFEST.MF"),
[]byte(`Main-Class: Foo`),
0644,
Expand Down

0 comments on commit 5e28579

Please sign in to comment.