@@ -21,52 +21,60 @@ type Downloader interface {
2121 Download (url string , tmpDirPath string ) (string , error )
2222}
2323
24- func (actor Actor ) GetBuildpacks (labelSelector string ) ([]resources.Buildpack , Warnings , error ) {
25- queries := []ccv3.Query {ccv3. Query { Key : ccv3 . OrderBy , Values : [] string { ccv3 . PositionOrder }} }
24+ func (actor Actor ) GetBuildpacks (labelSelector string , lifecycle string ) ([]resources.Buildpack , Warnings , error ) {
25+ queries := []ccv3.Query {}
2626 if labelSelector != "" {
2727 queries = append (queries , ccv3.Query {Key : ccv3 .LabelSelectorFilter , Values : []string {labelSelector }})
2828 }
2929
30+ if lifecycle != "" {
31+ queries = append (queries , ccv3.Query {Key : ccv3 .LifecycleFilter , Values : []string {lifecycle }})
32+ }
33+
3034 buildpacks , warnings , err := actor .CloudControllerClient .GetBuildpacks (queries ... )
3135
3236 return buildpacks , Warnings (warnings ), err
3337}
3438
35- // GetBuildpackByNameAndStack returns a buildpack with the provided name and
36- // stack . If `buildpackStack` is not specified, and there are multiple
39+ // GetBuildpackByNameAndStackAndLifecycle returns a buildpack with the provided name, stack,
40+ // and lifecycle . If `buildpackStack` is not specified, and there are multiple
3741// buildpacks with the same name, it will return the one with no stack, if
38- // present.
39- func (actor Actor ) GetBuildpackByNameAndStack (buildpackName string , buildpackStack string ) (resources.Buildpack , Warnings , error ) {
42+ // present. If `buildpackLifecycle` is not specified and there are multiple buildpacks with
43+ // the same name, it will return the one with the default_app_lifecycle, if present.
44+ func (actor Actor ) GetBuildpackByNameAndStackAndLifecycle (buildpackName string , buildpackStack string , buildpackLifecycle string ) (resources.Buildpack , Warnings , error ) {
4045 var (
4146 buildpacks []resources.Buildpack
4247 warnings ccv3.Warnings
4348 err error
4449 )
4550
46- if buildpackStack == "" {
47- buildpacks , warnings , err = actor .CloudControllerClient .GetBuildpacks (ccv3.Query {
48- Key : ccv3 .NameFilter ,
49- Values : []string {buildpackName },
51+ queries := []ccv3.Query {{
52+ Key : ccv3 .NameFilter ,
53+ Values : []string {buildpackName },
54+ }}
55+
56+ if buildpackStack != "" {
57+ queries = append (queries , ccv3.Query {
58+ Key : ccv3 .StackFilter ,
59+ Values : []string {buildpackStack },
5060 })
51- } else {
52- buildpacks , warnings , err = actor .CloudControllerClient .GetBuildpacks (
53- ccv3.Query {
54- Key : ccv3 .NameFilter ,
55- Values : []string {buildpackName },
56- },
57- ccv3.Query {
58- Key : ccv3 .StackFilter ,
59- Values : []string {buildpackStack },
60- },
61- )
6261 }
6362
63+ if buildpackLifecycle != "" {
64+ queries = append (queries , ccv3.Query {
65+ Key : ccv3 .LifecycleFilter ,
66+ Values : []string {buildpackLifecycle },
67+ })
68+ }
69+
70+ buildpacks , warnings , err = actor .CloudControllerClient .GetBuildpacks (queries ... )
71+
6472 if err != nil {
6573 return resources.Buildpack {}, Warnings (warnings ), err
6674 }
6775
6876 if len (buildpacks ) == 0 {
69- return resources.Buildpack {}, Warnings (warnings ), actionerror.BuildpackNotFoundError {BuildpackName : buildpackName , StackName : buildpackStack }
77+ return resources.Buildpack {}, Warnings (warnings ), actionerror.BuildpackNotFoundError {BuildpackName : buildpackName , StackName : buildpackStack , Lifecycle : buildpackLifecycle }
7078 }
7179
7280 if len (buildpacks ) > 1 {
@@ -87,9 +95,9 @@ func (actor Actor) CreateBuildpack(buildpack resources.Buildpack) (resources.Bui
8795 return buildpack , Warnings (warnings ), err
8896}
8997
90- func (actor Actor ) UpdateBuildpackByNameAndStack (buildpackName string , buildpackStack string , buildpack resources.Buildpack ) (resources.Buildpack , Warnings , error ) {
98+ func (actor Actor ) UpdateBuildpackByNameAndStackAndLifecycle (buildpackName string , buildpackStack string , buildpackLifecycle string , buildpack resources.Buildpack ) (resources.Buildpack , Warnings , error ) {
9199 var warnings Warnings
92- foundBuildpack , getWarnings , err := actor .GetBuildpackByNameAndStack (buildpackName , buildpackStack )
100+ foundBuildpack , getWarnings , err := actor .GetBuildpackByNameAndStackAndLifecycle (buildpackName , buildpackStack , buildpackLifecycle )
93101 warnings = append (warnings , getWarnings ... )
94102
95103 if err != nil {
@@ -250,9 +258,9 @@ func Zipit(source, target, prefix string) error {
250258 return err
251259}
252260
253- func (actor Actor ) DeleteBuildpackByNameAndStack (buildpackName string , buildpackStack string ) (Warnings , error ) {
261+ func (actor Actor ) DeleteBuildpackByNameAndStackAndLifecycle (buildpackName string , buildpackStack string , buildpackLifecycle string ) (Warnings , error ) {
254262 var allWarnings Warnings
255- buildpack , getBuildpackWarnings , err := actor .GetBuildpackByNameAndStack (buildpackName , buildpackStack )
263+ buildpack , getBuildpackWarnings , err := actor .GetBuildpackByNameAndStackAndLifecycle (buildpackName , buildpackStack , buildpackLifecycle )
256264 allWarnings = append (allWarnings , getBuildpackWarnings ... )
257265 if err != nil {
258266 return allWarnings , err
0 commit comments