Skip to content

Commit

Permalink
Merge pull request #142 from paketo-buildpacks/deprecations
Browse files Browse the repository at this point in the history
Add alternative for deprecated methods
  • Loading branch information
Daniel Mikusa authored Apr 28, 2022
2 parents 49b5c1d + aa35a52 commit d82231c
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,12 @@ type DependencyLayerContributor struct {
// NewDependencyLayer returns a new DependencyLayerContributor for the given BuildpackDependency and a BOMEntry describing the layer contents.
//
// Deprecated: this method uses `libcnb.BOMEntry` which has been deprecated upstream, a future version will drop
// support for `libcnb.BOMEntry` which will change this method signature
// support for `libcnb.BOMEntry` which will change this method signature. Use NewDependencyLayerContributor instead.
func NewDependencyLayer(dependency BuildpackDependency, cache DependencyCache, types libcnb.LayerTypes) (DependencyLayerContributor, libcnb.BOMEntry) {
c := DependencyLayerContributor{
Dependency: dependency,
ExpectedMetadata: dependency,
DependencyCache: cache,
ExpectedTypes: types,
}
dlc := NewDependencyLayerContributor(dependency, cache, types)

entry := dependency.AsBOMEntry()
entry.Metadata["layer"] = c.LayerName()
entry.Metadata["layer"] = dlc.LayerName()

if types.Launch {
entry.Launch = true
Expand All @@ -203,7 +198,17 @@ func NewDependencyLayer(dependency BuildpackDependency, cache DependencyCache, t
entry.Build = true
}

return c, entry
return dlc, entry
}

// NewDependencyLayerContributor returns a new DependencyLayerContributor for the given BuildpackDependency
func NewDependencyLayerContributor(dependency BuildpackDependency, cache DependencyCache, types libcnb.LayerTypes) DependencyLayerContributor {
return DependencyLayerContributor{
Dependency: dependency,
ExpectedMetadata: dependency,
DependencyCache: cache,
ExpectedTypes: types,
}
}

// DependencyLayerFunc is a callback function that is invoked when a dependency needs to be contributed.
Expand Down Expand Up @@ -267,25 +272,30 @@ type HelperLayerContributor struct {
// NewHelperLayer returns a new HelperLayerContributor and a BOMEntry describing the layer contents.
//
// Deprecated: this method uses `libcnb.BOMEntry` which has been deprecated upstream, a future version will drop
// support for `libcnb.BOMEntry` which will change this method signature
// support for `libcnb.BOMEntry` which will change this method signature. Use NewHelperLayerContributor instead.
func NewHelperLayer(buildpack libcnb.Buildpack, names ...string) (HelperLayerContributor, libcnb.BOMEntry) {
c := HelperLayerContributor{
Path: filepath.Join(buildpack.Path, "bin", "helper"),
Names: names,
BuildpackInfo: buildpack.Info,
}
hl := NewHelperLayerContributor(buildpack, names...)

return c, libcnb.BOMEntry{
return hl, libcnb.BOMEntry{
Name: "helper",
Metadata: map[string]interface{}{
"layer": c.Name(),
"layer": hl.Name(),
"names": names,
"version": buildpack.Info.Version,
},
Launch: true,
}
}

// NewHelperLayerContributor returns a new HelperLayerContributor
func NewHelperLayerContributor(buildpack libcnb.Buildpack, names ...string) HelperLayerContributor {
return HelperLayerContributor{
Path: filepath.Join(buildpack.Path, "bin", "helper"),
Names: names,
BuildpackInfo: buildpack.Info,
}
}

// Name returns the conventional name of the layer for this contributor
func (h HelperLayerContributor) Name() string {
return filepath.Base(h.Path)
Expand Down

0 comments on commit d82231c

Please sign in to comment.