From cafa1d039dc3ed3526873364fb5e31630fe449b4 Mon Sep 17 00:00:00 2001 From: sophia Date: Wed, 20 Oct 2021 15:22:33 -0500 Subject: [PATCH] Load single parent plugin --- internal/core/basis.go | 40 ++++++++++++++++----------------------- internal/plugin/plugin.go | 24 ++++++++++------------- 2 files changed, 26 insertions(+), 38 deletions(-) diff --git a/internal/core/basis.go b/internal/core/basis.go index 70f5c38ff..ab6380462 100644 --- a/internal/core/basis.go +++ b/internal/core/basis.go @@ -539,46 +539,38 @@ func (b *Basis) Run(ctx context.Context, task *vagrant_server.Task) (err error) } type HasParents interface { - Parents() ([]string, error) + Parent() (string, error) } func (b *Basis) loadParentPlugins(p *plugin.Plugin, typ component.Type) (err error) { plg, err := p.InstanceOf(typ) if err != nil { - panic(err) + return err } h, ok := plg.Component.(HasParents) if !ok { b.logger.Debug("Plugin of type ", typ, " does not have Parents") return nil } - parents, err := h.Parents() + parent, err := h.Parent() if err != nil { - panic(err) + return err } - if len(parents) == len(p.ParentPlugins) { + if parent == "" { return } - // TODO: avoid making duplicate entries - for _, parent := range parents { - // Avoid looping if a plugin name has erronously been added to the parent list - if parent == p.Name { - continue - } - b.logger.Debug("Loading parents: ", parent) - parentPlugin, err := b.plugins.Find(parent, typ) - if err != nil { - b.logger.Debug("Error finding parent plugin: ", parent) - continue - } - _, err = parentPlugin.InstanceOf(typ) - if err != nil { - b.logger.Debug("Error loading parent plugin: ", parent) - } - p.ParentPlugins = append(p.ParentPlugins, parentPlugin) - b.loadParentPlugins(parentPlugin, typ) + b.logger.Debug("Loading parent: ", parent) + parentPlugin, err := b.plugins.Find(parent, typ) + if err != nil { + b.logger.Debug("Error finding parent plugin: ", parent) } - p.SetParentPlugins(typ) + _, err = parentPlugin.InstanceOf(typ) + if err != nil { + b.logger.Debug("Error loading parent plugin: ", parent) + } + p.ParentPlugin = parentPlugin + b.loadParentPlugins(parentPlugin, typ) + p.SetParentPlugin(typ) return } diff --git a/internal/plugin/plugin.go b/internal/plugin/plugin.go index a82eb55c4..95f28df19 100644 --- a/internal/plugin/plugin.go +++ b/internal/plugin/plugin.go @@ -35,13 +35,13 @@ var ( ) type Plugin struct { - Builtin bool // Flags if this plugin is a builtin plugin - Client plugin.ClientProtocol // Client connection to plugin - Location string // Location of the plugin (generally path to binary) - Name string // Name of the plugin - Types []component.Type // Component types supported by this plugin - Cache cacher.Cache - ParentPlugins []*Plugin + Builtin bool // Flags if this plugin is a builtin plugin + Client plugin.ClientProtocol // Client connection to plugin + Location string // Location of the plugin (generally path to binary) + Name string // Name of the plugin + Types []component.Type // Component types supported by this plugin + Cache cacher.Cache + ParentPlugin *Plugin closers []func() error components map[component.Type]*Instance @@ -80,7 +80,7 @@ func (p *Plugin) Close() (err error) { return } -func (p *Plugin) SetParentPlugins(typ component.Type) { +func (p *Plugin) SetParentPlugin(typ component.Type) { i := p.components[typ] if i == nil { return @@ -96,11 +96,7 @@ func (p *Plugin) SetParentPlugins(typ component.Type) { "component", typ.String(), "name", p.Name) - parentComponents := []interface{}{} - for _, pp := range p.ParentPlugins { - parentComponents = append(parentComponents, pp.components[typ].Component) - } - pluginWithParent.SetParentPlugins(parentComponents) + pluginWithParent.SetParentPlugin(p.ParentPlugin.components[typ].Component) } } @@ -212,5 +208,5 @@ func (p *Plugin) types() []string { } type PluginWithParent interface { - SetParentPlugins([]interface{}) + SetParentPlugin(interface{}) }