diff --git a/api/internal/plugins/loader/loader.go b/api/internal/plugins/loader/loader.go index ca186e454ec..fac3e87852d 100644 --- a/api/internal/plugins/loader/loader.go +++ b/api/internal/plugins/loader/loader.go @@ -178,12 +178,12 @@ func (l *Loader) loadPlugin(res *resource.Resource) (resmap.Configurable, error) func (l *Loader) loadExecOrGoPlugin(resId resid.ResId) (resmap.Configurable, error) { // First try to load the plugin as an executable. - pluginPath := l.absolutePluginPath(resId) - if runtime.GOOS == "windows" { - pluginPath = fmt.Sprintf("%s.exe", pluginPath) + path, err := lookForExecutable(l.absolutePluginPath(resId)) + if err != nil { + return execplugin.NewExecPlugin(path), nil } - p := execplugin.NewExecPlugin(pluginPath) - err := p.ErrIfNotExecutable() + p := execplugin.NewExecPlugin(path) + err = p.ErrIfNotExecutable() if err == nil { return p, nil } @@ -249,3 +249,21 @@ func copyPlugin(c resmap.Configurable) resmap.Configurable { newNamed := newIndirect.Interface() return newNamed.(resmap.Configurable) } + +func lookForExecutable(partialPath string) (fullPath string, err error) { + if runtime.GOOS != "windows" { + return partialPath, nil + } + + possibleWindowsSuffixes := []string{"exe", "bat", "ps1"} + + for _, possibleWindowsSuffix := range possibleWindowsSuffixes { + fullPath := fmt.Sprintf("%s.%s", partialPath, possibleWindowsSuffix) + _, err := os.Stat(fullPath) + if err == nil { + return fullPath, nil + } + } + + return "", fmt.Errorf("no possible excutable found, partial path: %v tried suffixes: %v", partialPath, possibleWindowsSuffixes) +}