From aa35a52b2736a86a8ead6c5dcea326454c8a2008 Mon Sep 17 00:00:00 2001 From: Daniel Mikusa Date: Wed, 27 Apr 2022 20:13:52 -0400 Subject: [PATCH] Add alternative for deprecated methods Adds new alternatives for the following deprecated methods: - `NewDependencyLayer` -> `NewDependencyLayerContributor` - `NewHelperLayer` -> `NewHelperLayerContributor` This removes the `libcnb.BOMEntry` which was deprecated upstream. Signed-off-by: Daniel Mikusa --- layer.go | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/layer.go b/layer.go index 1591fd8..797ba5c 100644 --- a/layer.go +++ b/layer.go @@ -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 @@ -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. @@ -267,18 +272,14 @@ 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, }, @@ -286,6 +287,15 @@ func NewHelperLayer(buildpack libcnb.Buildpack, names ...string) (HelperLayerCon } } +// 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)