forked from konveyor/kantra
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🌱 Extract getConfigVolumes to an interface (konveyor#372)
extract providers to an interface Signed-off-by: Alejandro Brugarolas <[email protected]> Co-authored-by: Alejandro Brugarolas <[email protected]>
- Loading branch information
Showing
8 changed files
with
231 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
GetConfigVolume(a *analyzeCommand, tmpDir string) (provider.Config, error) | ||
} |
Oops, something went wrong.