-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🌱 Extract getConfigVolumes to an interface #372
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/konveyor/analyzer-lsp/provider" | ||
) | ||
|
||
type BuiltinProvider struct { | ||
config provider.Config | ||
} | ||
|
||
func (p *BuiltinProvider) GetConfigVolume(a *analyzeCommand, tmpDir string) (provider.Config, error) { | ||
p.config = provider.Config{ | ||
Name: "builtin", | ||
InitConfig: []provider.InitConfig{ | ||
{ | ||
Location: SourceMountPath, | ||
AnalysisMode: provider.AnalysisMode(a.mode), | ||
}, | ||
}, | ||
} | ||
return p.config, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/konveyor/analyzer-lsp/provider" | ||
) | ||
|
||
type DotNetProvider struct { | ||
config provider.Config | ||
} | ||
|
||
func (p *DotNetProvider) GetConfigVolume(a *analyzeCommand, tmpDir string) (provider.Config, error) { | ||
p.config = provider.Config{ | ||
Name: dotnetProvider, | ||
Address: fmt.Sprintf("0.0.0.0:%v", a.providersMap[dotnetProvider].port), | ||
InitConfig: []provider.InitConfig{ | ||
{ | ||
Location: SourceMountPath, | ||
AnalysisMode: provider.SourceOnlyAnalysisMode, | ||
ProviderSpecificConfig: map[string]interface{}{ | ||
provider.LspServerPathConfigKey: "/opt/app-root/.dotnet/tools/csharp-ls", | ||
}, | ||
}, | ||
}, | ||
} | ||
return p.config, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/konveyor/analyzer-lsp/provider" | ||
) | ||
|
||
type GoProvider struct { | ||
config provider.Config | ||
} | ||
|
||
func (p *GoProvider) GetConfigVolume(a *analyzeCommand, tmpDir string) (provider.Config, error) { | ||
p.config = provider.Config{ | ||
Name: goProvider, | ||
Address: fmt.Sprintf("0.0.0.0:%v", a.providersMap[goProvider].port), | ||
InitConfig: []provider.InitConfig{ | ||
{ | ||
AnalysisMode: provider.FullAnalysisMode, | ||
ProviderSpecificConfig: map[string]interface{}{ | ||
"lspServerName": "generic", | ||
"workspaceFolders": []string{fmt.Sprintf("file://%s", SourceMountPath)}, | ||
"dependencyProviderPath": "/usr/local/bin/golang-dependency-provider", | ||
provider.LspServerPathConfigKey: "/root/go/bin/gopls", | ||
}, | ||
}, | ||
}, | ||
} | ||
return p.config, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/konveyor/analyzer-lsp/provider" | ||
"path" | ||
"path/filepath" | ||
) | ||
|
||
type JavaProvider struct { | ||
config provider.Config | ||
} | ||
|
||
func (p *JavaProvider) GetConfigVolume(a *analyzeCommand, tmpDir string) (provider.Config, error) { | ||
|
||
var mountPath = SourceMountPath | ||
// when input is a file, it means it's probably a binary | ||
// only java provider can work with binaries, all others | ||
// continue pointing to the directory instead of file | ||
if a.isFileInput { | ||
mountPath = path.Join(SourceMountPath, filepath.Base(a.input)) | ||
} | ||
|
||
p.config = provider.Config{ | ||
Name: javaProvider, | ||
Address: fmt.Sprintf("0.0.0.0:%v", a.providersMap[javaProvider].port), | ||
InitConfig: []provider.InitConfig{ | ||
{ | ||
Location: mountPath, | ||
AnalysisMode: provider.AnalysisMode(a.mode), | ||
ProviderSpecificConfig: map[string]interface{}{ | ||
"lspServerName": javaProvider, | ||
"bundles": JavaBundlesLocation, | ||
"depOpenSourceLabelsFile": "/usr/local/etc/maven.default.index", | ||
provider.LspServerPathConfigKey: "/jdtls/bin/jdtls", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
if a.mavenSettingsFile != "" { | ||
err := copyFileContents(a.mavenSettingsFile, filepath.Join(tmpDir, "settings.xml")) | ||
if err != nil { | ||
a.log.V(1).Error(err, "failed copying maven settings file", "path", a.mavenSettingsFile) | ||
return provider.Config{}, err | ||
} | ||
p.config.InitConfig[0].ProviderSpecificConfig["mavenSettingsFile"] = fmt.Sprintf("%s/%s", ConfigMountPath, "settings.xml") | ||
} | ||
if Settings.JvmMaxMem != "" { | ||
p.config.InitConfig[0].ProviderSpecificConfig["jvmMaxMem"] = Settings.JvmMaxMem | ||
} | ||
|
||
return p.config, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/konveyor/analyzer-lsp/provider" | ||
) | ||
|
||
type NodeJsProvider struct { | ||
config provider.Config | ||
} | ||
|
||
func (p *NodeJsProvider) GetConfigVolume(a *analyzeCommand, tmpDir string) (provider.Config, error) { | ||
p.config = provider.Config{ | ||
Name: nodeJSProvider, | ||
Address: fmt.Sprintf("0.0.0.0:%v", a.providersMap[nodeJSProvider].port), | ||
InitConfig: []provider.InitConfig{ | ||
{ | ||
AnalysisMode: provider.SourceOnlyAnalysisMode, | ||
ProviderSpecificConfig: map[string]interface{}{ | ||
"lspServerName": "nodejs", | ||
"workspaceFolders": []string{fmt.Sprintf("file://%s", SourceMountPath)}, | ||
provider.LspServerPathConfigKey: "/usr/local/bin/typescript-language-server", | ||
}, | ||
}, | ||
}, | ||
} | ||
_, dependencyFolders := a.getDepsFolders() | ||
if len(dependencyFolders) != 0 { | ||
p.config.InitConfig[0].ProviderSpecificConfig["dependencyFolders"] = dependencyFolders | ||
} | ||
return p.config, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package cmd | ||
|
||
import "github.com/konveyor/analyzer-lsp/provider" | ||
|
||
type Provider interface { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this can be extended to include other methods. In particular, |
||
GetConfigVolume(a *analyzeCommand, tmpDir string) (provider.Config, error) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could probably remove the return err here - I don't notice it being used. We can always add it back later if needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The java provider can throw an error when copying the maven settings file to the temp dir |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about moving the provider files into a folder such as
providers
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My initial idea was to place the provider structs in a
providers
folder. However, the analyzeCommand does not export any parameters, and I didn't want to change that in this PR since I don't have enough context on the code.Should I change the
AnalyzeCommand
to export the necessary properties?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There could be a
pkg/providers
dir, and export necessary params from the analyze cmd. I think it would be good if it could further be refactored so that theproviders
were agnostic to the analyze command. This would require a bit more work though, as some of the analyze cmd fields would need to be copied into a map, or similar, to pass to the providers (mostly the Java provider). But, I do think this is a good start to that, so am happy to merge and address these things later.