Browse through the existing implementation to find scope of refactoring so that the new plugin interface fits in better.
09/20/2023
Attendees
Nisha Kumar
Agenda
Plugin Interface Design
Notes
Most straightforward implementation is 1 method to return an SPDX document. This should work for SPDX2.x
In the current refactor we have a document handler which is called by the generator implementation
type GeneratorImplementation interface{GetDocumentFormatHandler(*options.Options)(DocumentFormatHandler,error)GetCodeParsers(*options.Options)([]plugin.Plugin,error)RunParser(*options.Options, plugin.Plugin)([]meta.Package,error)}
The GetDocumentFormatHandler handles different spdx specification versions
// GetDocumentFormatHandler gets a document handler according to the spdx schema versionfunc(di *defaultGeneratorImplementation)GetDocumentFormatHandler(opts *options.Options)(DocumentFormatHandler,error){switch opts.SchemaVersion {case"2.3":return&v23.Handler{},nilcase"2.2":return&v22.Handler{},nildefault:returnnil, errors.New("no document format handler defined")}}
// a mapping between each plugin var plugins :=make(map[string]DocumentFormatHandler)type DocumentHandler interface{GetDocumentFormatHandler(*options.Options)(DocumentFormatHandler,error)}type Plugin interface{GetDocument(opts *options.Options)}funcGetPluginHander(pluginName string) DocumentFormatHandler{return plugins[pluginName]}package main
import"plugin"import_"plugins/python"funcmain(){
dfh :=GetPluginHander("python")
dfh.CreateDocument()}