diff --git a/go.mod b/go.mod index 24acfbe..b328261 100644 --- a/go.mod +++ b/go.mod @@ -10,18 +10,19 @@ require ( github.com/mattn/go-shellwords v1.0.12 github.com/miekg/dns v1.1.47 github.com/onsi/gomega v1.18.1 - github.com/paketo-buildpacks/libpak v1.58.0 + github.com/paketo-buildpacks/libpak v1.59.0 github.com/pavel-v-chernykh/keystore-go/v4 v4.3.0 github.com/sclevine/spec v1.4.0 - golang.org/x/sys v0.0.0-20220207234003-57398862261d + golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 ) require ( github.com/BurntSushi/toml v1.0.0 // indirect github.com/creack/pty v1.1.17 // indirect + github.com/h2non/filetype v1.1.3 // indirect github.com/imdario/mergo v0.3.12 // indirect - github.com/mattn/go-colorable v0.1.2 // indirect - github.com/mattn/go-isatty v0.0.8 // indirect + github.com/mattn/go-colorable v0.1.12 // indirect + github.com/mattn/go-isatty v0.0.14 // indirect github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect github.com/pelletier/go-toml v1.9.4 // indirect github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect diff --git a/go.sum b/go.sum index f258904..64db50d 100644 --- a/go.sum +++ b/go.sum @@ -30,6 +30,8 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/h2non/filetype v1.1.3 h1:FKkx9QbD7HR/zjK1Ia5XiBsq9zdLi5Kf3zGyFTAFkGg= +github.com/h2non/filetype v1.1.3/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY= github.com/heroku/color v0.0.6 h1:UTFFMrmMLFcL3OweqP1lAdp8i1y/9oHqkeHjQ/b/Ny0= github.com/heroku/color v0.0.6/go.mod h1:ZBvOcx7cTF2QKOv4LbmoBtNl5uB17qWxGuzZrsi1wLU= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= @@ -38,10 +40,12 @@ github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= -github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE= +github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= +github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk= github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y= github.com/miekg/dns v1.1.47 h1:J9bWiXbqMbnZPcY8Qi2E3EWIBsIm6MZzzJB9VRg5gL8= @@ -61,8 +65,8 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE= github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs= -github.com/paketo-buildpacks/libpak v1.58.0 h1:tId115h3SZn8IY8DQxRF36PwhMob4G9TVkWWDTD9MKY= -github.com/paketo-buildpacks/libpak v1.58.0/go.mod h1:qxRaH+WrJYWEb4FZqYkMR9mdyNEsrNOq7bE7O4dXH1k= +github.com/paketo-buildpacks/libpak v1.59.0 h1:9Kt1G0IZZbnIrgsfxU9SuAqJB5EBnVwNJqMgw5qFMa0= +github.com/paketo-buildpacks/libpak v1.59.0/go.mod h1:hqdnjXrMRmt25/tw+FLC3UbT2uQXH1et2zZ8Br3ZXAo= github.com/pavel-v-chernykh/keystore-go/v4 v4.3.0 h1:TVckDDIKzWo9/cPdsvyikdmnnKIPeWgnGoekhQM5zBc= github.com/pavel-v-chernykh/keystore-go/v4 v4.3.0/go.mod h1:VxOBKEAW8/EJjil9qwfvVDSljDW0DCoZMD4ezsq9n8U= github.com/pelletier/go-toml v1.9.4 h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhECwM= @@ -76,8 +80,9 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo= github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -118,9 +123,10 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220207234003-57398862261d h1:Bm7BNOQt2Qv7ZqysjeLjgCBanX+88Z/OtdvsrEv1Djc= -golang.org/x/sys v0.0.0-20220207234003-57398862261d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 h1:OH54vjqzRWmbJ62fjuhxy7AxFFgoHN0/DPc/UrL8cAs= +golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= diff --git a/jdk.go b/jdk.go index 54e2139..d61cdc8 100644 --- a/jdk.go +++ b/jdk.go @@ -64,7 +64,7 @@ func (j JDK) Contribute(layer libcnb.Layer) (libcnb.Layer, error) { return j.LayerContributor.Contribute(layer, func(artifact *os.File) (libcnb.Layer, error) { j.Logger.Bodyf("Expanding to %s", layer.Path) - if err := crush.ExtractTarGz(artifact, layer.Path, 1); err != nil { + if err := crush.Extract(artifact, layer.Path, 1); err != nil { return libcnb.Layer{}, fmt.Errorf("unable to expand JDK\n%w", err) } diff --git a/jdk_test.go b/jdk_test.go index 8edbb18..c6c79fe 100644 --- a/jdk_test.go +++ b/jdk_test.go @@ -82,6 +82,33 @@ func testJDK(t *testing.T, context spec.G, it spec.S) { Expect(layer.BuildEnvironment["JDK_HOME.override"]).To(Equal(layer.Path)) }) + it("contributes JDK from a zip file", func() { + dep := libpak.BuildpackDependency{ + Version: "11.0.0", + URI: "https://localhost/stub-jdk-11.zip", + SHA256: "8138da5a0340f89b47ec4ab3fb5f12034ce793eb45af257820ec457316559a39", + } + dc := libpak.DependencyCache{CachePath: "testdata"} + + j, _, err := libjvm.NewJDK(dep, dc, cl) + Expect(err).NotTo(HaveOccurred()) + j.Logger = bard.NewLogger(ioutil.Discard) + + Expect(j.LayerContributor.ExpectedMetadata.(map[string]interface{})["cert-dir"]).To(HaveLen(4)) + + layer, err := ctx.Layers.Layer("test-layer") + Expect(err).NotTo(HaveOccurred()) + + layer, err = j.Contribute(layer) + Expect(err).NotTo(HaveOccurred()) + + Expect(layer.LayerTypes.Build).To(BeTrue()) + Expect(layer.LayerTypes.Cache).To(BeTrue()) + Expect(filepath.Join(layer.Path, "fixture-marker")).To(BeARegularFile()) + Expect(layer.BuildEnvironment["JAVA_HOME.override"]).To(Equal(layer.Path)) + Expect(layer.BuildEnvironment["JDK_HOME.override"]).To(Equal(layer.Path)) + }) + it("updates before Java 9 certificates", func() { dep := libpak.BuildpackDependency{ Version: "8.0.0", diff --git a/jre.go b/jre.go index ecf1c95..23960b0 100644 --- a/jre.go +++ b/jre.go @@ -73,7 +73,7 @@ func (j JRE) Contribute(layer libcnb.Layer) (libcnb.Layer, error) { return j.LayerContributor.Contribute(layer, func(artifact *os.File) (libcnb.Layer, error) { j.Logger.Bodyf("Expanding to %s", layer.Path) - if err := crush.ExtractTarGz(artifact, layer.Path, 1); err != nil { + if err := crush.Extract(artifact, layer.Path, 1); err != nil { return libcnb.Layer{}, fmt.Errorf("unable to expand JRE\n%w", err) } diff --git a/jre_test.go b/jre_test.go index fa80b54..af86db5 100644 --- a/jre_test.go +++ b/jre_test.go @@ -82,6 +82,29 @@ func testJRE(t *testing.T, context spec.G, it spec.S) { Expect(filepath.Join(layer.Path, "fixture-marker")).To(BeARegularFile()) }) + it("contributes JRE from a zip file", func() { + dep := libpak.BuildpackDependency{ + Version: "11.0.0", + URI: "https://localhost/stub-jre-11.zip", + SHA256: "e3b22e738f6e956ef576215b39d79d321157f1d3de3bddf9c4120ae0444bdba8", + } + dc := libpak.DependencyCache{CachePath: "testdata"} + + j, _, err := libjvm.NewJRE(ctx.Application.Path, dep, dc, libjvm.JREType, cl, NoContribution) + Expect(err).NotTo(HaveOccurred()) + j.Logger = bard.NewLogger(ioutil.Discard) + + Expect(j.LayerContributor.ExpectedMetadata.(map[string]interface{})["cert-dir"]).To(HaveLen(4)) + + layer, err := ctx.Layers.Layer("test-layer") + Expect(err).NotTo(HaveOccurred()) + + layer, err = j.Contribute(layer) + Expect(err).NotTo(HaveOccurred()) + + Expect(filepath.Join(layer.Path, "fixture-marker")).To(BeARegularFile()) + }) + it("updates JRE certificates", func() { dep := libpak.BuildpackDependency{ Version: "11.0.0", diff --git a/testdata/8138da5a0340f89b47ec4ab3fb5f12034ce793eb45af257820ec457316559a39.toml b/testdata/8138da5a0340f89b47ec4ab3fb5f12034ce793eb45af257820ec457316559a39.toml new file mode 100644 index 0000000..af1e648 --- /dev/null +++ b/testdata/8138da5a0340f89b47ec4ab3fb5f12034ce793eb45af257820ec457316559a39.toml @@ -0,0 +1,3 @@ +version = "11.0.0" +uri = "https://localhost/stub-jdk-11.zip" +sha256 = "8138da5a0340f89b47ec4ab3fb5f12034ce793eb45af257820ec457316559a39" \ No newline at end of file diff --git a/testdata/8138da5a0340f89b47ec4ab3fb5f12034ce793eb45af257820ec457316559a39/stub-jdk-11.zip b/testdata/8138da5a0340f89b47ec4ab3fb5f12034ce793eb45af257820ec457316559a39/stub-jdk-11.zip new file mode 100644 index 0000000..8a8be8f Binary files /dev/null and b/testdata/8138da5a0340f89b47ec4ab3fb5f12034ce793eb45af257820ec457316559a39/stub-jdk-11.zip differ diff --git a/testdata/e3b22e738f6e956ef576215b39d79d321157f1d3de3bddf9c4120ae0444bdba8.toml b/testdata/e3b22e738f6e956ef576215b39d79d321157f1d3de3bddf9c4120ae0444bdba8.toml new file mode 100644 index 0000000..7931d69 --- /dev/null +++ b/testdata/e3b22e738f6e956ef576215b39d79d321157f1d3de3bddf9c4120ae0444bdba8.toml @@ -0,0 +1,3 @@ +version = "11.0.0" +uri = "https://localhost/stub-jre-11.zip" +sha256 = "e3b22e738f6e956ef576215b39d79d321157f1d3de3bddf9c4120ae0444bdba8" \ No newline at end of file diff --git a/testdata/e3b22e738f6e956ef576215b39d79d321157f1d3de3bddf9c4120ae0444bdba8/stub-jre-11.zip b/testdata/e3b22e738f6e956ef576215b39d79d321157f1d3de3bddf9c4120ae0444bdba8/stub-jre-11.zip new file mode 100644 index 0000000..4f41d2e Binary files /dev/null and b/testdata/e3b22e738f6e956ef576215b39d79d321157f1d3de3bddf9c4120ae0444bdba8/stub-jre-11.zip differ