Skip to content

Commit

Permalink
⚠️ remove deprecated api NewBundle in favor of NewBundleWithOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
camilamacedo86 committed May 20, 2024
1 parent 943b854 commit 580ce8d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 41 deletions.
38 changes: 1 addition & 37 deletions pkg/plugin/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
18 changes: 14 additions & 4 deletions pkg/plugin/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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 {
Expand All @@ -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())
}
})
Expand Down

0 comments on commit 580ce8d

Please sign in to comment.