Skip to content

Commit

Permalink
Merge pull request #843 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 b381ea9 + 553b910 commit 28c2f5a
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 108 deletions.
5 changes: 2 additions & 3 deletions helper/linker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package helper_test

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -40,12 +39,12 @@ func testLink(t *testing.T, context spec.G, it spec.S) {
it.Before(func() {
var err error

appDir, err = ioutil.TempDir("", "execd-helper-apps")
appDir, err = os.MkdirTemp("", "execd-helper-apps")
Expect(err).NotTo(HaveOccurred())
appDir, err = filepath.EvalSymlinks(appDir)
Expect(err).ToNot(HaveOccurred())

layerDir, err = ioutil.TempDir("", "execd-helper-layers")
layerDir, err = os.MkdirTemp("", "execd-helper-layers")
Expect(err).NotTo(HaveOccurred())
layerDir, err = filepath.EvalSymlinks(layerDir)
Expect(err).ToNot(HaveOccurred())
Expand Down
60 changes: 30 additions & 30 deletions internal/core/buildsrc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package core_test

import (
"io/ioutil"
"io"
"os"
"path/filepath"
"testing"
Expand All @@ -37,7 +37,7 @@ func testBuildSource(t *testing.T, when spec.G, it spec.S) {

it.Before(func() {
var err error
testPath, err = ioutil.TempDir("", "core")
testPath, err = os.MkdirTemp("", "core")
Expect(err).NotTo(HaveOccurred())
})

Expand All @@ -55,22 +55,22 @@ func testBuildSource(t *testing.T, when spec.G, it spec.S) {
Expect(os.WriteFile(filepath.Join(testPath, "META-INF", "MANIFEST.MF"),
[]byte("Main-Class: com.java.HelloWorld"),
0644)).To(Succeed())
appBuildSource := core.NewAppBuildSource(testPath, "liberty", bard.NewLogger(ioutil.Discard))
appBuildSource := core.NewAppBuildSource(testPath, "liberty", bard.NewLogger(io.Discard))
ok, err := appBuildSource.Detect()
Expect(err).ToNot(HaveOccurred())
Expect(ok).To(BeFalse())
})

it("detects successfully when Main-Class is not set", func() {
appBuildSrc := core.NewAppBuildSource(testPath, "liberty", bard.NewLogger(ioutil.Discard))
appBuildSrc := core.NewAppBuildSource(testPath, "liberty", bard.NewLogger(io.Discard))
ok, err := appBuildSrc.Detect()
Expect(err).ToNot(HaveOccurred())
Expect(ok).To(BeTrue())
})

it("validates successfully when a compiled web archive is supplied", func() {
Expect(os.Mkdir(filepath.Join(testPath, "WEB-INF"), 0755)).To(Succeed())
appBuildSrc := core.NewAppBuildSource(testPath, "liberty", bard.NewLogger(ioutil.Discard))
appBuildSrc := core.NewAppBuildSource(testPath, "liberty", bard.NewLogger(io.Discard))
ok, err := appBuildSrc.ValidateApp()
Expect(err).To(Succeed())
Expect(ok).To(BeTrue())
Expand All @@ -79,21 +79,21 @@ func testBuildSource(t *testing.T, when spec.G, it spec.S) {
it("validates successfully when a compiled enterprise archive is supplied", func() {
Expect(os.Mkdir(filepath.Join(testPath, "META-INF"), 0755)).To(Succeed())
Expect(os.WriteFile(filepath.Join(testPath, "META-INF", "application.xml"), []byte{}, 0644)).To(Succeed())
appBuildSrc := core.NewAppBuildSource(testPath, "liberty", bard.NewLogger(ioutil.Discard))
appBuildSrc := core.NewAppBuildSource(testPath, "liberty", bard.NewLogger(io.Discard))
ok, err := appBuildSrc.ValidateApp()
Expect(err).To(Succeed())
Expect(ok).To(BeTrue())
})

it("fails app validation when META-INF or application.xml not found", func() {
appBuildSrc := core.NewAppBuildSource(testPath, "liberty", bard.NewLogger(ioutil.Discard))
appBuildSrc := core.NewAppBuildSource(testPath, "liberty", bard.NewLogger(io.Discard))
ok, err := appBuildSrc.ValidateApp()
Expect(err).To(Succeed())
Expect(ok).To(BeFalse())
})

it("fails app validation when requested server is unknown", func() {
appBuildSrc := core.NewAppBuildSource(testPath, "foo", bard.NewLogger(ioutil.Discard))
appBuildSrc := core.NewAppBuildSource(testPath, "foo", bard.NewLogger(io.Discard))
ok, err := appBuildSrc.ValidateApp()
Expect(err).To(Succeed())
Expect(ok).To(BeFalse())
Expand All @@ -117,7 +117,7 @@ func testBuildSource(t *testing.T, when spec.G, it spec.S) {
defaultServerPath := filepath.Join(serversPath, "defaultServer")
Expect(os.Mkdir(defaultServerPath, 0755)).To(Succeed())
Expect(os.WriteFile(filepath.Join(defaultServerPath, "server.xml"), []byte{}, 0644)).To(Succeed())
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(ioutil.Discard))
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(io.Discard))
ok, err := serverBuildSource.Detect()
Expect(err).ToNot(HaveOccurred())
Expect(ok).To(BeTrue())
Expand All @@ -127,7 +127,7 @@ func testBuildSource(t *testing.T, when spec.G, it spec.S) {
testServerPath := filepath.Join(serversPath, "testServer")
Expect(os.Mkdir(testServerPath, 0755)).To(Succeed())
Expect(os.WriteFile(filepath.Join(testServerPath, "server.xml"), []byte{}, 0644)).To(Succeed())
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(ioutil.Discard))
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(io.Discard))
ok, err := serverBuildSource.Detect()
Expect(err).ToNot(HaveOccurred())
Expect(ok).To(BeTrue())
Expand All @@ -137,7 +137,7 @@ func testBuildSource(t *testing.T, when spec.G, it spec.S) {
testServerPath := filepath.Join(serversPath, "testServer")
Expect(os.Mkdir(testServerPath, 0755)).To(Succeed())
Expect(os.WriteFile(filepath.Join(testServerPath, "server.xml"), []byte{}, 0644)).To(Succeed())
serverBuildSource := core.NewServerBuildSource(testPath, "testServer", bard.NewLogger(ioutil.Discard))
serverBuildSource := core.NewServerBuildSource(testPath, "testServer", bard.NewLogger(io.Discard))
ok, err := serverBuildSource.Detect()
Expect(err).ToNot(HaveOccurred())
Expect(ok).To(BeTrue())
Expand All @@ -148,7 +148,7 @@ func testBuildSource(t *testing.T, when spec.G, it spec.S) {
Expect(os.Mkdir(testServerPath, 0755)).To(Succeed())
Expect(os.Mkdir(testServerPath+"-other", 0755)).To(Succeed())
Expect(os.WriteFile(filepath.Join(testServerPath, "server.xml"), []byte{}, 0644)).To(Succeed())
serverBuildSource := core.NewServerBuildSource(testPath, "testServer", bard.NewLogger(ioutil.Discard))
serverBuildSource := core.NewServerBuildSource(testPath, "testServer", bard.NewLogger(io.Discard))
ok, err := serverBuildSource.Detect()
Expect(err).ToNot(HaveOccurred())
Expect(ok).To(BeTrue())
Expand All @@ -159,21 +159,21 @@ func testBuildSource(t *testing.T, when spec.G, it spec.S) {
Expect(os.Mkdir(testServerPath, 0755)).To(Succeed())
Expect(os.Mkdir(testServerPath+"-other", 0755)).To(Succeed())
Expect(os.WriteFile(filepath.Join(testServerPath, "server.xml"), []byte{}, 0644)).To(Succeed())
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(ioutil.Discard))
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(io.Discard))
_, err := serverBuildSource.Detect()
Expect(err).To(HaveOccurred())
})

it("fails to detect if there are no servers", func() {
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(ioutil.Discard))
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(io.Discard))
_, err := serverBuildSource.Detect()
Expect(err).To(HaveOccurred())
})

it("validates enterprise archive is provided in apps", func() {
appPath := filepath.Join(serversPath, "testServer", "apps", "test.ear")
Expect(os.MkdirAll(appPath, 0755)).To(Succeed())
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(ioutil.Discard))
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(io.Discard))
ok, err := serverBuildSource.ValidateApp()
Expect(err).ToNot(HaveOccurred())
Expect(ok).To(BeTrue())
Expand All @@ -182,7 +182,7 @@ func testBuildSource(t *testing.T, when spec.G, it spec.S) {
it("validates enterprise archive is provided in dropins", func() {
appPath := filepath.Join(serversPath, "testServer", "dropins", "test.ear")
Expect(os.MkdirAll(appPath, 0755)).To(Succeed())
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(ioutil.Discard))
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(io.Discard))
ok, err := serverBuildSource.ValidateApp()
Expect(err).ToNot(HaveOccurred())
Expect(ok).To(BeTrue())
Expand All @@ -191,7 +191,7 @@ func testBuildSource(t *testing.T, when spec.G, it spec.S) {
it("validates web archive is provided in apps", func() {
appPath := filepath.Join(serversPath, "testServer", "apps", "test.war")
Expect(os.MkdirAll(appPath, 0755)).To(Succeed())
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(ioutil.Discard))
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(io.Discard))
ok, err := serverBuildSource.ValidateApp()
Expect(err).ToNot(HaveOccurred())
Expect(ok).To(BeTrue())
Expand All @@ -200,14 +200,14 @@ func testBuildSource(t *testing.T, when spec.G, it spec.S) {
it("validates web archive is provided in dropins", func() {
appPath := filepath.Join(serversPath, "testServer", "dropins", "test.war")
Expect(os.MkdirAll(appPath, 0755)).To(Succeed())
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(ioutil.Discard))
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(io.Discard))
ok, err := serverBuildSource.ValidateApp()
Expect(err).ToNot(HaveOccurred())
Expect(ok).To(BeTrue())
})

it("does not validate when an app is not provided", func() {
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(ioutil.Discard))
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(io.Discard))
_, err := serverBuildSource.ValidateApp()
Expect(err).To(HaveOccurred())
})
Expand All @@ -229,7 +229,7 @@ func testBuildSource(t *testing.T, when spec.G, it spec.S) {
defaultServerPath := filepath.Join(serversPath, "defaultServer")
Expect(os.Mkdir(defaultServerPath, 0755)).To(Succeed())
Expect(os.WriteFile(filepath.Join(defaultServerPath, "server.xml"), []byte{}, 0644)).To(Succeed())
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(ioutil.Discard))
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(io.Discard))
ok, err := serverBuildSource.Detect()
Expect(err).ToNot(HaveOccurred())
Expect(ok).To(BeTrue())
Expand All @@ -239,7 +239,7 @@ func testBuildSource(t *testing.T, when spec.G, it spec.S) {
testServerPath := filepath.Join(serversPath, "testServer")
Expect(os.Mkdir(testServerPath, 0755)).To(Succeed())
Expect(os.WriteFile(filepath.Join(testServerPath, "server.xml"), []byte{}, 0644)).To(Succeed())
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(ioutil.Discard))
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(io.Discard))
ok, err := serverBuildSource.Detect()
Expect(err).ToNot(HaveOccurred())
Expect(ok).To(BeTrue())
Expand All @@ -249,7 +249,7 @@ func testBuildSource(t *testing.T, when spec.G, it spec.S) {
testServerPath := filepath.Join(serversPath, "testServer")
Expect(os.Mkdir(testServerPath, 0755)).To(Succeed())
Expect(os.WriteFile(filepath.Join(testServerPath, "server.xml"), []byte{}, 0644)).To(Succeed())
serverBuildSource := core.NewServerBuildSource(testPath, "testServer", bard.NewLogger(ioutil.Discard))
serverBuildSource := core.NewServerBuildSource(testPath, "testServer", bard.NewLogger(io.Discard))
ok, err := serverBuildSource.Detect()
Expect(err).ToNot(HaveOccurred())
Expect(ok).To(BeTrue())
Expand All @@ -260,7 +260,7 @@ func testBuildSource(t *testing.T, when spec.G, it spec.S) {
Expect(os.Mkdir(testServerPath, 0755)).To(Succeed())
Expect(os.Mkdir(testServerPath+"-other", 0755)).To(Succeed())
Expect(os.WriteFile(filepath.Join(testServerPath, "server.xml"), []byte{}, 0644)).To(Succeed())
serverBuildSource := core.NewServerBuildSource(testPath, "testServer", bard.NewLogger(ioutil.Discard))
serverBuildSource := core.NewServerBuildSource(testPath, "testServer", bard.NewLogger(io.Discard))
ok, err := serverBuildSource.Detect()
Expect(err).ToNot(HaveOccurred())
Expect(ok).To(BeTrue())
Expand All @@ -271,21 +271,21 @@ func testBuildSource(t *testing.T, when spec.G, it spec.S) {
Expect(os.Mkdir(testServerPath, 0755)).To(Succeed())
Expect(os.Mkdir(testServerPath+"-other", 0755)).To(Succeed())
Expect(os.WriteFile(filepath.Join(testServerPath, "server.xml"), []byte{}, 0644)).To(Succeed())
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(ioutil.Discard))
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(io.Discard))
_, err := serverBuildSource.Detect()
Expect(err).To(HaveOccurred())
})

it("fails to detect if there are no servers", func() {
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(ioutil.Discard))
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(io.Discard))
_, err := serverBuildSource.Detect()
Expect(err).To(HaveOccurred())
})

it("validates enterprise archive is provided in dropins", func() {
appPath := filepath.Join(serversPath, "testServer", "dropins", "test.ear")
Expect(os.MkdirAll(appPath, 0755)).To(Succeed())
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(ioutil.Discard))
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(io.Discard))
ok, err := serverBuildSource.ValidateApp()
Expect(err).ToNot(HaveOccurred())
Expect(ok).To(BeTrue())
Expand All @@ -294,7 +294,7 @@ func testBuildSource(t *testing.T, when spec.G, it spec.S) {
it("validates web archive is provided in apps", func() {
appPath := filepath.Join(serversPath, "testServer", "apps", "test.war")
Expect(os.MkdirAll(appPath, 0755)).To(Succeed())
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(ioutil.Discard))
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(io.Discard))
ok, err := serverBuildSource.ValidateApp()
Expect(err).ToNot(HaveOccurred())
Expect(ok).To(BeTrue())
Expand All @@ -303,14 +303,14 @@ func testBuildSource(t *testing.T, when spec.G, it spec.S) {
it("validates web archive is provided in dropins", func() {
appPath := filepath.Join(serversPath, "testServer", "dropins", "test.war")
Expect(os.MkdirAll(appPath, 0755)).To(Succeed())
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(ioutil.Discard))
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(io.Discard))
ok, err := serverBuildSource.ValidateApp()
Expect(err).ToNot(HaveOccurred())
Expect(ok).To(BeTrue())
})

it("does not validate when an app is not provided", func() {
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(ioutil.Discard))
serverBuildSource := core.NewServerBuildSource(testPath, "", bard.NewLogger(io.Discard))
_, err := serverBuildSource.ValidateApp()
Expect(err).To(HaveOccurred())
})
Expand All @@ -320,7 +320,7 @@ func testBuildSource(t *testing.T, when spec.G, it spec.S) {
when("building an app source with server config", func() {
it("works", func() {
Expect(os.WriteFile(filepath.Join(testPath, "test.war"), []byte{}, 0644)).To(Succeed())
appBuildSource := core.NewAppBuildSource(testPath, "liberty", bard.NewLogger(ioutil.Discard))
appBuildSource := core.NewAppBuildSource(testPath, "liberty", bard.NewLogger(io.Discard))
ok, err := appBuildSource.Detect()
Expect(err).ToNot(HaveOccurred())
Expect(ok).To(BeTrue())
Expand Down
17 changes: 9 additions & 8 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ import (
"bytes"
"encoding/xml"
"fmt"
"github.com/antchfx/xmlquery"
"github.com/paketo-buildpacks/liberty/internal/util"
"github.com/paketo-buildpacks/libpak/bard"
"github.com/paketo-buildpacks/libpak/effect"
"github.com/paketo-buildpacks/libpak/sherpa"
"io/ioutil"
"io"
"os"
"path/filepath"
"regexp"
"sort"
"strings"

"github.com/antchfx/xmlquery"
"github.com/paketo-buildpacks/liberty/internal/util"
"github.com/paketo-buildpacks/libpak/bard"
"github.com/paketo-buildpacks/libpak/effect"
"github.com/paketo-buildpacks/libpak/sherpa"
)

func GetServerConfigPath(serverPath string) string {
Expand Down Expand Up @@ -189,7 +190,7 @@ func GetServerList(userPath string) ([]string, error) {
return []string{}, nil
}

serverDirs, err := ioutil.ReadDir(serversPath)
serverDirs, err := os.ReadDir(serversPath)
if err != nil {
return []string{}, err
}
Expand Down Expand Up @@ -409,7 +410,7 @@ func ReadServerConfig(configPath string) (Config, error) {
}
defer xmlFile.Close()

content, err := ioutil.ReadAll(xmlFile)
content, err := io.ReadAll(xmlFile)
if err != nil {
return Config{}, fmt.Errorf("unable to read config '%s'\n%w", configPath, err)
}
Expand Down
13 changes: 6 additions & 7 deletions internal/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package server_test

import (
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -42,7 +41,7 @@ func testServer(t *testing.T, when spec.G, it spec.S) {

it.Before(func() {
var err error
testPath, err = ioutil.TempDir("", "server")
testPath, err = os.MkdirTemp("", "server")
Expect(err).NotTo(HaveOccurred())

// EvalSymlinks on macOS resolves the temporary directory too so do that here or checking the symlinks will fail
Expand Down Expand Up @@ -170,11 +169,11 @@ func testServer(t *testing.T, when spec.G, it spec.S) {

it("loads iFixes", func() {
Expect(os.MkdirAll(iFixesPath, 0755)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(iFixesPath, "fix-1.jar"), []byte{}, 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(iFixesPath, "fix-2.jar"), []byte{}, 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(iFixesPath, ".DS_Store"), []byte{}, 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(iFixesPath, "foo.txt"), []byte{}, 0644)).To(Succeed())
Expect(ioutil.WriteFile(filepath.Join(iFixesPath, "fix-3.jar"), []byte{}, 0644)).To(Succeed())
Expect(os.WriteFile(filepath.Join(iFixesPath, "fix-1.jar"), []byte{}, 0644)).To(Succeed())
Expect(os.WriteFile(filepath.Join(iFixesPath, "fix-2.jar"), []byte{}, 0644)).To(Succeed())
Expect(os.WriteFile(filepath.Join(iFixesPath, ".DS_Store"), []byte{}, 0644)).To(Succeed())
Expect(os.WriteFile(filepath.Join(iFixesPath, "foo.txt"), []byte{}, 0644)).To(Succeed())
Expect(os.WriteFile(filepath.Join(iFixesPath, "fix-3.jar"), []byte{}, 0644)).To(Succeed())

fixes, err := server.LoadIFixesList(iFixesPath)

Expand Down
9 changes: 5 additions & 4 deletions internal/util/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ package util

import (
"fmt"
"github.com/paketo-buildpacks/libjvm"
"github.com/paketo-buildpacks/libpak/sherpa"
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/paketo-buildpacks/libjvm"
"github.com/paketo-buildpacks/libpak/sherpa"
)

// IsJvmApplicationPackage will return true if `META-INF/application.xml` or `WEB-INF/` exists, which happens when a
Expand Down Expand Up @@ -68,7 +69,7 @@ func GetApps(path string) ([]string, error) {
return []string{}, nil
}

files, err := ioutil.ReadDir(path)
files, err := os.ReadDir(path)
if err != nil {
return []string{}, err
}
Expand Down
Loading

0 comments on commit 28c2f5a

Please sign in to comment.