Skip to content

Commit 88b7b92

Browse files
🐛 MTA-5179 pass in maven local repo path to bundle (#825) (#828)
Bundle PR: 132 Needs konveyor/java-analyzer-bundle#131 Signed-off-by: Pranav Gaikwad <[email protected]> Signed-off-by: Cherry Picker <[email protected]> Signed-off-by: Pranav Gaikwad <[email protected]> Signed-off-by: Cherry Picker <[email protected]> Co-authored-by: Pranav Gaikwad <[email protected]>
1 parent 4bd6de1 commit 88b7b92

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

external-providers/java-external-provider/pkg/java_external_provider/dependency.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,6 @@ func getMavenLocalRepoPath(mvnSettingsFile string) string {
211211
func (p *javaServiceClient) GetDependenciesFallback(ctx context.Context, location string) (map[uri.URI][]*provider.Dep, error) {
212212
deps := []*provider.Dep{}
213213

214-
m2Repo := getMavenLocalRepoPath(p.mvnSettingsFile)
215-
216214
path, err := filepath.Abs(p.findPom())
217215
if err != nil {
218216
return nil, err
@@ -279,8 +277,8 @@ func (p *javaServiceClient) GetDependenciesFallback(ctx context.Context, locatio
279277
} else {
280278
dep.Version = *d.Version
281279
}
282-
if m2Repo != "" && d.ArtifactID != nil && d.GroupID != nil {
283-
dep.FileURIPrefix = fmt.Sprintf("file://%s", filepath.Join(m2Repo,
280+
if p.mvnLocalRepo != "" && d.ArtifactID != nil && d.GroupID != nil {
281+
dep.FileURIPrefix = fmt.Sprintf("file://%s", filepath.Join(p.mvnLocalRepo,
284282
strings.Replace(*d.GroupID, ".", "/", -1), *d.ArtifactID, dep.Version))
285283
}
286284
}
@@ -335,8 +333,6 @@ func (p *javaServiceClient) GetDependenciesDAG(ctx context.Context) (map[uri.URI
335333
}
336334

337335
func (p *javaServiceClient) getDependenciesForMaven(_ context.Context) (map[uri.URI][]provider.DepDAGItem, error) {
338-
localRepoPath := getMavenLocalRepoPath(p.mvnSettingsFile)
339-
340336
path := p.findPom()
341337
file := uri.File(path)
342338

@@ -369,7 +365,7 @@ func (p *javaServiceClient) getDependenciesForMaven(_ context.Context) (map[uri.
369365

370366
var pomDeps []provider.DepDAGItem
371367
for _, tree := range submoduleTrees {
372-
submoduleDeps, err := p.parseMavenDepLines(tree, localRepoPath, path)
368+
submoduleDeps, err := p.parseMavenDepLines(tree, p.mvnLocalRepo, path)
373369
if err != nil {
374370
return nil, err
375371
}
@@ -600,7 +596,7 @@ func (p *javaServiceClient) discoverDepsFromJars(path string, ll map[uri.URI][]k
600596
w := walker{
601597
deps: ll,
602598
depToLabels: p.depToLabels,
603-
m2RepoPath: getMavenLocalRepoPath(p.mvnSettingsFile),
599+
m2RepoPath: p.mvnLocalRepo,
604600
seen: map[string]bool{},
605601
initialPath: path,
606602
}

external-providers/java-external-provider/pkg/java_external_provider/provider.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,15 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
491491
}
492492
}()
493493

494+
m2Repo := getMavenLocalRepoPath(mavenSettingsFile)
495+
496+
mavenIndexPath := ""
497+
if val, ok := config.ProviderSpecificConfig[providerSpecificConfigOpenSourceDepListKey]; ok {
498+
if strVal, ok := val.(string); ok {
499+
mavenIndexPath = strVal
500+
}
501+
}
502+
494503
svcClient := javaServiceClient{
495504
rpc: rpc,
496505
cancelFunc: cancelFunc,
@@ -503,6 +512,8 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
503512
isLocationBinary: isBinary,
504513
mvnInsecure: mavenInsecure,
505514
mvnSettingsFile: mavenSettingsFile,
515+
mvnLocalRepo: m2Repo,
516+
mvnIndexPath: mavenIndexPath,
506517
globalSettings: globalSettingsFile,
507518
depsLocationCache: make(map[string]int),
508519
includedPaths: provider.GetIncludedPathsFromConfig(config, false),
@@ -514,7 +525,7 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
514525
// we need to do this for jdtls to correctly recognize source attachment for dep
515526
switch svcClient.GetBuildTool() {
516527
case maven:
517-
err := resolveSourcesJarsForMaven(ctx, log, fernflower, config.Location, mavenSettingsFile, mavenInsecure)
528+
err := resolveSourcesJarsForMaven(ctx, log, fernflower, config.Location, mavenSettingsFile, m2Repo, mavenInsecure)
518529
if err != nil {
519530
// TODO (pgaikwad): should we ignore this failure?
520531
log.Error(err, "failed to resolve maven sources jar for location", "location", config.Location)
@@ -790,11 +801,16 @@ func (j *javaProvider) GetLocation(ctx context.Context, dep konveyor.Dep, file s
790801

791802
// resolveSourcesJarsForMaven for a given source code location, runs maven to find
792803
// deps that don't have sources attached and decompiles them
793-
func resolveSourcesJarsForMaven(ctx context.Context, log logr.Logger, fernflower, location, mavenSettings string, mvnInsecure bool) error {
804+
func resolveSourcesJarsForMaven(ctx context.Context, log logr.Logger, fernflower, location, mavenSettings, mavenLocalRepo string, mvnInsecure bool) error {
794805
// TODO (pgaikwad): when we move to external provider, inherit context from parent
795806
ctx, span := tracing.StartNewSpan(ctx, "resolve-sources")
796807
defer span.End()
797808

809+
if mavenLocalRepo == "" {
810+
log.V(5).Info("unable to discover dependency sources as maven local repo path is unknown")
811+
return nil
812+
}
813+
798814
decompileJobs := []decompileJob{}
799815

800816
log.Info("resolving dependency sources")
@@ -824,10 +840,6 @@ func resolveSourcesJarsForMaven(ctx context.Context, log logr.Logger, fernflower
824840
return err
825841
}
826842

827-
m2Repo := getMavenLocalRepoPath(mavenSettings)
828-
if m2Repo == "" {
829-
return nil
830-
}
831843
for _, artifact := range artifacts {
832844
log.WithValues("artifact", artifact).Info("sources for artifact not found, decompiling...")
833845

@@ -837,9 +849,9 @@ func resolveSourcesJarsForMaven(ctx context.Context, log logr.Logger, fernflower
837849
decompileJobs = append(decompileJobs, decompileJob{
838850
artifact: artifact,
839851
inputPath: filepath.Join(
840-
m2Repo, groupDirs, artifactDirs, artifact.Version, jarName),
852+
mavenLocalRepo, groupDirs, artifactDirs, artifact.Version, jarName),
841853
outputPath: filepath.Join(
842-
m2Repo, groupDirs, artifactDirs, artifact.Version, "decompiled", jarName),
854+
mavenLocalRepo, groupDirs, artifactDirs, artifact.Version, "decompiled", jarName),
843855
})
844856
}
845857
err = decompile(ctx, log, alwaysDecompileFilter(true), 10, decompileJobs, fernflower, "")

external-providers/java-external-provider/pkg/java_external_provider/service_client.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ type javaServiceClient struct {
3434
isLocationBinary bool
3535
mvnInsecure bool
3636
mvnSettingsFile string
37+
mvnLocalRepo string
38+
mvnIndexPath string
3739
globalSettings string
3840
depsMutex sync.RWMutex
3941
depsFileHash *string
@@ -122,6 +124,11 @@ func (p *javaServiceClient) GetAllSymbols(ctx context.Context, c javaCondition,
122124
"location": fmt.Sprintf("%v", locationToCode[strings.ToLower(c.Referenced.Location)]),
123125
"analysisMode": string(p.config.AnalysisMode),
124126
"includeOpenSourceLibraries": true,
127+
"mavenLocalRepo": p.mvnLocalRepo,
128+
}
129+
130+
if p.mvnIndexPath != "" {
131+
argumentsMap["mavenIndexPath"] = p.mvnIndexPath
125132
}
126133

127134
depLabelSelector, err := labels.NewLabelSelector[*openSourceLabels](condCTX.DepLabelSelector, nil)

0 commit comments

Comments
 (0)