Load single parent plugin
This commit is contained in:
parent
4251b2ff7c
commit
cafa1d039d
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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{})
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user