From af632824ff486b5787fcb3a5347faa470c1b5a56 Mon Sep 17 00:00:00 2001 From: Camila Macedo Date: Mon, 20 May 2024 06:58:49 +0100 Subject: [PATCH] :warning: remove deprecated api NewBundle in favor of NewBundleWithOptions --- pkg/plugin/bundle.go | 38 +------------------------------------- pkg/plugin/bundle_test.go | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 41 deletions(-) diff --git a/pkg/plugin/bundle.go b/pkg/plugin/bundle.go index 47e4f879eaf..493458a9fc8 100644 --- a/pkg/plugin/bundle.go +++ b/pkg/plugin/bundle.go @@ -58,42 +58,6 @@ func WithDeprecationMessage(msg string) BundleOption { } -// NewBundle creates a new Bundle with the provided name and version, and that wraps the provided plugins. -// The list of supported project versions is computed from the provided plugins. -// -// Deprecated: Use the NewBundle informing the options from now one. Replace its use for as the -// following example. Example: -// -// mylanguagev1Bundle, _ := plugin.NewBundle(plugin.WithName(language.DefaultNameQualifier), -// plugin.WithVersion(plugin.Version{Number: 1}), -// plugin.WithPlugins(kustomizecommonv1.Plugin{}, mylanguagev1.Plugin{}), -func NewBundle(name string, version Version, deprecateWarning string, plugins ...Plugin) (Bundle, error) { - supportedProjectVersions := CommonSupportedProjectVersions(plugins...) - if len(supportedProjectVersions) == 0 { - return nil, fmt.Errorf("in order to bundle plugins, they must all support at least one common project version") - } - - // Plugins may be bundles themselves, so unbundle here - // NOTE(Adirio): unbundling here ensures that Bundle.Plugin always returns a flat list of Plugins instead of also - // including Bundles, and therefore we don't have to use a recursive algorithm when resolving. - allPlugins := make([]Plugin, 0, len(plugins)) - for _, plugin := range plugins { - if pluginBundle, isBundle := plugin.(Bundle); isBundle { - allPlugins = append(allPlugins, pluginBundle.Plugins()...) - } else { - allPlugins = append(allPlugins, plugin) - } - } - - return bundle{ - name: name, - version: version, - plugins: allPlugins, - supportedProjectVersions: supportedProjectVersions, - deprecateWarning: deprecateWarning, - }, nil -} - // NewBundleWithOptions creates a new Bundle with the provided BundleOptions. // The list of supported project versions is computed from the provided plugins in options. func NewBundleWithOptions(opts ...BundleOption) (Bundle, error) { @@ -149,7 +113,7 @@ func (b bundle) Plugins() []Plugin { return b.plugins } -// Plugins implements Bundle +// DeprecationWarning return the warning message func (b bundle) DeprecationWarning() string { return b.deprecateWarning } diff --git a/pkg/plugin/bundle_test.go b/pkg/plugin/bundle_test.go index ccb1a41d574..1c3306b4505 100644 --- a/pkg/plugin/bundle_test.go +++ b/pkg/plugin/bundle_test.go @@ -67,7 +67,10 @@ var _ = Describe("Bundle", func() { {p1, p2, p3}, {p1, p3, p4}, } { - b, err := NewBundle(name, version, "", plugins...) + + b, err := NewBundleWithOptions(WithName(name), + WithVersion(version), + WithPlugins(plugins...)) Expect(err).NotTo(HaveOccurred()) Expect(b.Name()).To(Equal(name)) Expect(b.Version().Compare(version)).To(Equal(0)) @@ -88,9 +91,13 @@ var _ = Describe("Bundle", func() { var a, b Bundle var err error plugins := []Plugin{p1, p2, p3} - a, err = NewBundle("a", version, "", p1, p2) + a, err = NewBundleWithOptions(WithName("a"), + WithVersion(version), + WithPlugins(p1, p2)) Expect(err).NotTo(HaveOccurred()) - b, err = NewBundle("b", version, "", a, p3) + b, err = NewBundleWithOptions(WithName("b"), + WithVersion(version), + WithPlugins(a, p3)) Expect(err).NotTo(HaveOccurred()) versions := b.SupportedProjectVersions() sort.Slice(versions, func(i int, j int) bool { @@ -113,7 +120,10 @@ var _ = Describe("Bundle", func() { {p1, p2, p3, p4}, } { - _, err := NewBundle(name, version, "", plugins...) + _, err := NewBundleWithOptions(WithName(name), + WithVersion(version), + WithPlugins(plugins...)) + Expect(err).To(HaveOccurred()) } })