From 421d41413022346356ebc48585a9147d8c003a72 Mon Sep 17 00:00:00 2001 From: Md Sahil Date: Wed, 16 Aug 2023 20:59:36 +0530 Subject: [PATCH] Passed contextLines to the providers Signed-off-by: Md Sahil --- cmd/analyzer/main.go | 1 + provider/internal/java/snipper.go | 9 +++------ provider/provider.go | 11 ++++++----- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/cmd/analyzer/main.go b/cmd/analyzer/main.go index 095fbad8..4bfe4b97 100644 --- a/cmd/analyzer/main.go +++ b/cmd/analyzer/main.go @@ -142,6 +142,7 @@ func main() { providers := map[string]provider.InternalProviderClient{} for _, config := range configs { + config.ContextLines = contextLines // IF analsyis mode is set from the CLI, then we will override this for each init config if analysisMode != "" { inits := []provider.InitConfig{} diff --git a/provider/internal/java/snipper.go b/provider/internal/java/snipper.go index 36bd47d1..385ad72c 100644 --- a/provider/internal/java/snipper.go +++ b/provider/internal/java/snipper.go @@ -14,9 +14,6 @@ import ( ) const ( - // TODO: make this configurable in the future - // We may or may not need to do this so holding off for now. - CONTEXT_LINES = 10 FILE_URI_PREFIX = "konveyor-jdt" ) @@ -91,13 +88,13 @@ func (p *javaProvider) scanFile(path string, loc engine.Location) (string, error scanner := bufio.NewScanner(readFile) lineNumber := 0 codeSnip := "" - paddingSize := len(strconv.Itoa(loc.EndPosition.Line + CONTEXT_LINES)) + paddingSize := len(strconv.Itoa(loc.EndPosition.Line + p.config.ContextLines)) for scanner.Scan() { - if (lineNumber - CONTEXT_LINES) == loc.EndPosition.Line { + if (lineNumber - p.config.ContextLines) == loc.EndPosition.Line { codeSnip = codeSnip + fmt.Sprintf("%*d %v", paddingSize, lineNumber+1, scanner.Text()) break } - if (lineNumber + CONTEXT_LINES) >= loc.StartPosition.Line { + if (lineNumber + p.config.ContextLines) >= loc.StartPosition.Line { codeSnip = codeSnip + fmt.Sprintf("%*d %v\n", paddingSize, lineNumber+1, scanner.Text()) } lineNumber += 1 diff --git a/provider/provider.go b/provider/provider.go index 8a7b43c2..f0c3cb93 100644 --- a/provider/provider.go +++ b/provider/provider.go @@ -68,11 +68,12 @@ type Capability struct { } type Config struct { - Name string `yaml:"name,omitempty" json:"name,omitempty"` - BinaryPath string `yaml:"binaryPath,omitempty" json:"binaryPath,omitempty"` - Address string `yaml:"address,omitempty" json:"address,omitempty"` - Proxy *Proxy `yaml:"proxyConfig,omitempty" json:"proxyConfig,omitempty"` - InitConfig []InitConfig `yaml:"initConfig,omitempty" json:"initConfig,omitempty"` + Name string `yaml:"name,omitempty" json:"name,omitempty"` + BinaryPath string `yaml:"binaryPath,omitempty" json:"binaryPath,omitempty"` + Address string `yaml:"address,omitempty" json:"address,omitempty"` + Proxy *Proxy `yaml:"proxyConfig,omitempty" json:"proxyConfig,omitempty"` + InitConfig []InitConfig `yaml:"initConfig,omitempty" json:"initConfig,omitempty"` + ContextLines int } type Proxy httpproxy.Config