[MM-53156] Remove Multi-Product architecture (#25669)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
d3b799eaa5
Коммит
de3e5aab25
@@ -40,13 +40,6 @@ var excludedPluginHooks = []string{
|
||||
"ServeMetrics",
|
||||
}
|
||||
|
||||
var excludedProductHooks = []string{
|
||||
"Implemented",
|
||||
"OnActivate",
|
||||
"OnDeactivate",
|
||||
"ServeHTTP",
|
||||
}
|
||||
|
||||
type IHookEntry struct {
|
||||
FuncName string
|
||||
Args *ast.FieldList
|
||||
@@ -385,62 +378,6 @@ func (s *apiRPCServer) {{.Name}}(args *{{.Name | obscure}}Args, returns *{{.Name
|
||||
{{end}}
|
||||
`
|
||||
|
||||
var productHooksTemplate = `// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
// Code generated by "make pluginapi"
|
||||
// DO NOT EDIT
|
||||
|
||||
package plugin
|
||||
|
||||
{{range .HooksMethods}}
|
||||
type {{.Name}}IFace interface {
|
||||
{{.Name}}{{funcStyle .Params}} {{funcStyle .Return}}
|
||||
}
|
||||
|
||||
{{end}}
|
||||
|
||||
type HooksAdapter struct {
|
||||
implemented map[int]struct{}
|
||||
productHooks any
|
||||
}
|
||||
|
||||
func NewAdapter(productHooks any) (*HooksAdapter, error) {
|
||||
a := &HooksAdapter{
|
||||
implemented: make(map[int]struct{}),
|
||||
productHooks: productHooks,
|
||||
}
|
||||
var tt reflect.Type
|
||||
ft := reflect.TypeOf(productHooks)
|
||||
{{range .HooksMethods}}
|
||||
// Assessing the type of the productHooks if it individually implements {{.Name}} interface.
|
||||
tt = reflect.TypeOf((*{{.Name}}IFace)(nil)).Elem()
|
||||
|
||||
if ft.Implements(tt) {
|
||||
a.implemented[{{.Name}}ID] = struct{}{}
|
||||
} else if _, ok := ft.MethodByName("{{.Name}}"); ok{
|
||||
return nil, errors.New("hook has {{.Name}} method but does not implement plugin.{{.Name}} interface")
|
||||
}
|
||||
|
||||
{{end}}
|
||||
|
||||
return a, nil
|
||||
}
|
||||
|
||||
{{range .HooksMethods}}
|
||||
func (a *HooksAdapter) {{.Name}}{{funcStyle .Params}} {{funcStyle .Return}} {
|
||||
if _, ok := a.implemented[{{.Name}}ID]; !ok {
|
||||
panic("product hooks must implement {{.Name}}")
|
||||
}
|
||||
|
||||
{{if .Return}}return a.productHooks.({{.Name}}IFace).{{.Name}}({{valuesOnly .Params}}){{else}}a.productHooks.({{.Name}}IFace).{{.Name}}({{valuesOnly .Params}}){{end}}
|
||||
|
||||
}
|
||||
|
||||
{{end}}
|
||||
|
||||
`
|
||||
|
||||
var apiTimerLayerTemplate = `// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
@@ -586,39 +523,6 @@ func generateHooksGlue(info *PluginInterfaceInfo) {
|
||||
}
|
||||
}
|
||||
|
||||
func generateProductHooksInterfaces(info *PluginInterfaceInfo) {
|
||||
templateFunctions := map[string]any{
|
||||
"funcStyle": func(fields *ast.FieldList) string { return FieldListToFuncList(fields, info.FileSet) },
|
||||
"valuesOnly": func(fields *ast.FieldList) string { return FieldListToNames(fields, false) },
|
||||
}
|
||||
|
||||
templateParams := HooksTemplateParams{}
|
||||
for _, hook := range info.Hooks {
|
||||
templateParams.HooksMethods = append(templateParams.HooksMethods, MethodParams{
|
||||
Name: hook.FuncName,
|
||||
Params: hook.Args,
|
||||
Return: hook.Results,
|
||||
})
|
||||
}
|
||||
|
||||
productHooksTemplate, err := template.New("hooks").Funcs(templateFunctions).Parse(productHooksTemplate)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
templateResult := &bytes.Buffer{}
|
||||
productHooksTemplate.Execute(templateResult, &templateParams)
|
||||
|
||||
formatted, err := imports.Process("", templateResult.Bytes(), nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := os.WriteFile(filepath.Join(getPluginPackageDir(), "product_hooks_generated.go"), formatted, 0664); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func generatePluginTimerLayer(info *PluginInterfaceInfo) {
|
||||
templateFunctions := map[string]any{
|
||||
"funcStyle": func(fields *ast.FieldList) string { return FieldListToFuncList(fields, info.FileSet) },
|
||||
@@ -723,8 +627,6 @@ func main() {
|
||||
if err != nil {
|
||||
fmt.Println("Unable to get plugin info: " + err.Error())
|
||||
}
|
||||
log.Println("Generating product hooks interfaces")
|
||||
generateProductHooksInterfaces(removeExcluded(forRPC, excludedProductHooks))
|
||||
|
||||
log.Println("Generating plugin hooks glue")
|
||||
generateHooksGlue(removeExcluded(forRPC, excludedPluginHooks))
|
||||
|
||||
Ссылка в новой задаче
Block a user