Skip to content

Commit

Permalink
✨ Enable internal java provider (#701)
Browse files Browse the repository at this point in the history
Signed-off-by: Emily McMullan <[email protected]>
  • Loading branch information
eemcmullan authored Sep 26, 2024
1 parent aa4d8ca commit 3285583
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion external-providers/java-external-provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func main() {
log := logrusr.New(logrusLog)

// must use lspServerName for use of multiple grpc providers
client := java.NewJavaProvider(log, *lspServerName, *contextLines)
client := java.NewJavaProvider(log, *lspServerName, *contextLines, provider.Config{})

if logLevel != nil && *logLevel != 5 {
logrusLog.SetLevel(logrus.Level(*logLevel))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/konveyor/analyzer-lsp/tracing"
"github.com/nxadm/tail"
"github.com/swaggest/openapi-go/openapi3"
"go.lsp.dev/uri"
)

const (
Expand Down Expand Up @@ -64,6 +65,7 @@ var locationToCode = map[string]int{
}

type javaProvider struct {
config provider.Config
Log logr.Logger
contextLines int

Expand All @@ -80,6 +82,8 @@ type javaProvider struct {

var _ provider.BaseClient = &javaProvider{}

var _ provider.InternalProviderClient = &javaProvider{}

var _ provider.DependencyLocationResolver = &javaProvider{}

type javaCondition struct {
Expand All @@ -102,11 +106,12 @@ type element struct {
Value string `yaml:"value" json:"value"` // can be a (java) regex pattern
}

func NewJavaProvider(log logr.Logger, lspServerName string, contextLines int) *javaProvider {
func NewJavaProvider(log logr.Logger, lspServerName string, contextLines int, config provider.Config) *javaProvider {

_, mvnBinaryError := exec.LookPath("mvn")

return &javaProvider{
config: config,
hasMaven: mvnBinaryError == nil,
Log: log,
clients: []provider.ServiceClient{},
Expand Down Expand Up @@ -846,3 +851,33 @@ func contains(artifacts []javaArtifact, artifactToFind javaArtifact) bool {

return false
}

func (p *javaProvider) Evaluate(ctx context.Context, cap string, conditionInfo []byte) (provider.ProviderEvaluateResponse, error) {
return provider.FullResponseFromServiceClients(ctx, p.clients, cap, conditionInfo)
}

func (p *javaProvider) ProviderInit(ctx context.Context, additionalConfigs []provider.InitConfig) ([]provider.InitConfig, error) {
builtinConfs := []provider.InitConfig{}
if additionalConfigs != nil {
p.config.InitConfig = append(p.config.InitConfig, additionalConfigs...)
}
for _, c := range p.config.InitConfig {
client, builtinConf, err := p.Init(ctx, p.Log, c)
if err != nil {
return nil, err
}
p.clients = append(p.clients, client)
if builtinConf.Location != "" {
builtinConfs = append(builtinConfs, builtinConf)
}
}
return builtinConfs, nil
}

func (p *javaProvider) GetDependencies(ctx context.Context) (map[uri.URI][]*provider.Dep, error) {
return provider.FullDepsResponse(ctx, p.clients)
}

func (p *javaProvider) GetDependenciesDAG(ctx context.Context) (map[uri.URI][]provider.DepDAGItem, error) {
return provider.FullDepDAGResponse(ctx, p.clients)
}

0 comments on commit 3285583

Please sign in to comment.