Skip to content

Commit

Permalink
Merge pull request #105 from paketo-buildpacks/lifecycle_0_13_3
Browse files Browse the repository at this point in the history
Generate label-based BOM for all API versions
  • Loading branch information
Daniel Mikusa authored Feb 8, 2022
2 parents 219a106 + e8150ff commit b462971
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
13 changes: 5 additions & 8 deletions application.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ type Application struct {
Logger bard.Logger
BOM *libcnb.BOM
SBOMScanner sbom.SBOMScanner
BuildpackAPI string
}

func (a Application) Contribute(layer libcnb.Layer) (libcnb.Layer, error) {
Expand Down Expand Up @@ -123,14 +122,12 @@ func (a Application) Contribute(layer libcnb.Layer) (libcnb.Layer, error) {
return libcnb.Layer{}, fmt.Errorf("unable to create Build SBoM \n%w", err)
}

if a.BuildpackAPI == "0.6" || a.BuildpackAPI == "0.5" || a.BuildpackAPI == "0.4" || a.BuildpackAPI == "0.3" || a.BuildpackAPI == "0.2" || a.BuildpackAPI == "0.1" {
entry, err := a.Cache.AsBOMEntry()
if err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to generate build dependencies\n%w", err)
}
entry.Metadata["layer"] = a.Cache.Name()
a.BOM.Entries = append(a.BOM.Entries, entry)
entry, err := a.Cache.AsBOMEntry()
if err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to generate build dependencies\n%w", err)
}
entry.Metadata["layer"] = a.Cache.Name()
a.BOM.Entries = append(a.BOM.Entries, entry)

// Purge Workspace
a.Logger.Header("Removing source code")
Expand Down
28 changes: 22 additions & 6 deletions application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/buildpacks/libcnb"
. "github.com/onsi/gomega"
"github.com/paketo-buildpacks/libjvm"
"github.com/paketo-buildpacks/libpak"
"github.com/paketo-buildpacks/libpak/bard"
"github.com/paketo-buildpacks/libpak/effect"
Expand Down Expand Up @@ -85,10 +86,9 @@ func testApplication(t *testing.T, context spec.G, it spec.S) {
map[string]interface{}{},
libcnb.LayerTypes{Cache: true},
),
Logger: bard.Logger{},
BOM: bom,
SBOMScanner: sbomScanner,
BuildpackAPI: ctx.Buildpack.API,
Logger: bard.Logger{},
BOM: bom,
SBOMScanner: sbomScanner,
}
})

Expand Down Expand Up @@ -133,7 +133,24 @@ func testApplication(t *testing.T, context spec.G, it spec.S) {
Expect(filepath.Join(ctx.Application.Path, "fixture-marker")).To(BeARegularFile())

sbomScanner.AssertCalled(t, "ScanBuild", ctx.Application.Path, libcnb.CycloneDXJSON, libcnb.SyftJSON)
Expect(bom.Entries).To(HaveLen(0))
Expect(bom.Entries).To(HaveLen(1))
Expect(bom.Entries).To(Equal([]libcnb.BOMEntry{
libcnb.BOMEntry{
Name: "build-dependencies",
Metadata: map[string]interface{}{
"layer": "cache",
"dependencies": []libjvm.MavenJAR{
{
Name: "test-file",
Version: "1.1.1",
SHA256: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
},
},
},
Launch: false,
Build: true,
},
}))
})

context("contributes layer with ", func() {
Expand Down Expand Up @@ -285,7 +302,6 @@ func testApplication(t *testing.T, context spec.G, it spec.S) {
Expect(filepath.Join(ctx.Application.Path, "native-sources", "stub-executable.jar")).To(BeAnExistingFile())
Expect(filepath.Join(ctx.Application.Path, "code-sources", "source-stub-application.jar")).To(BeAnExistingFile())
Expect(filepath.Join(ctx.Application.Path, "code-sources", "source-stub-executable.jar")).To(BeAnExistingFile())

})
})
})
Expand Down
2 changes: 0 additions & 2 deletions factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func (f *ApplicationFactory) NewApplication(
bom *libcnb.BOM,
applicationPath string,
bomScanner sbom.SBOMScanner,
buildpackAPI string,
) (Application, error) {

app := Application{
Expand All @@ -49,7 +48,6 @@ func (f *ApplicationFactory) NewApplication(
Executor: f.Executor,
BOM: bom,
SBOMScanner: bomScanner,
BuildpackAPI: buildpackAPI,
}

expected, err := f.expectedMetadata(additionalMetadata, app)
Expand Down
2 changes: 0 additions & 2 deletions factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func testFactory(t *testing.T, context spec.G, it spec.S) {
},
}
bomScanner := sbom.NewSyftCLISBOMScanner(libcnb.Layers{}, executor, bard.Logger{})
buildpackAPI := "0.7"

application, err = applicationFactory.NewApplication(
map[string]interface{}{"addl-key": "addl-value"},
Expand All @@ -97,7 +96,6 @@ func testFactory(t *testing.T, context spec.G, it spec.S) {
nil,
appDir,
bomScanner,
buildpackAPI,
)
Expect(err).NotTo(HaveOccurred())
})
Expand Down

0 comments on commit b462971

Please sign in to comment.