Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ func getMavenLocalRepoPath(mvnSettingsFile string) string {
func (p *javaServiceClient) GetDependenciesFallback(ctx context.Context, location string) (map[uri.URI][]*provider.Dep, error) {
deps := []*provider.Dep{}

m2Repo := getMavenLocalRepoPath(p.mvnSettingsFile)

path, err := filepath.Abs(p.findPom())
if err != nil {
return nil, err
Expand Down Expand Up @@ -279,8 +277,8 @@ func (p *javaServiceClient) GetDependenciesFallback(ctx context.Context, locatio
} else {
dep.Version = *d.Version
}
if m2Repo != "" && d.ArtifactID != nil && d.GroupID != nil {
dep.FileURIPrefix = fmt.Sprintf("file://%s", filepath.Join(m2Repo,
if p.mvnLocalRepo != "" && d.ArtifactID != nil && d.GroupID != nil {
dep.FileURIPrefix = fmt.Sprintf("file://%s", filepath.Join(p.mvnLocalRepo,
strings.Replace(*d.GroupID, ".", "/", -1), *d.ArtifactID, dep.Version))
}
}
Expand Down Expand Up @@ -335,8 +333,6 @@ func (p *javaServiceClient) GetDependenciesDAG(ctx context.Context) (map[uri.URI
}

func (p *javaServiceClient) getDependenciesForMaven(_ context.Context) (map[uri.URI][]provider.DepDAGItem, error) {
localRepoPath := getMavenLocalRepoPath(p.mvnSettingsFile)

path := p.findPom()
file := uri.File(path)

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

var pomDeps []provider.DepDAGItem
for _, tree := range submoduleTrees {
submoduleDeps, err := p.parseMavenDepLines(tree, localRepoPath, path)
submoduleDeps, err := p.parseMavenDepLines(tree, p.mvnLocalRepo, path)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -600,7 +596,7 @@ func (p *javaServiceClient) discoverDepsFromJars(path string, ll map[uri.URI][]k
w := walker{
deps: ll,
depToLabels: p.depToLabels,
m2RepoPath: getMavenLocalRepoPath(p.mvnSettingsFile),
m2RepoPath: p.mvnLocalRepo,
seen: map[string]bool{},
initialPath: path,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,15 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
}
}()

m2Repo := getMavenLocalRepoPath(mavenSettingsFile)

mavenIndexPath := ""
if val, ok := config.ProviderSpecificConfig[providerSpecificConfigOpenSourceDepListKey]; ok {
if strVal, ok := val.(string); ok {
mavenIndexPath = strVal
}
}

svcClient := javaServiceClient{
rpc: rpc,
cancelFunc: cancelFunc,
Expand All @@ -503,6 +512,8 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
isLocationBinary: isBinary,
mvnInsecure: mavenInsecure,
mvnSettingsFile: mavenSettingsFile,
mvnLocalRepo: m2Repo,
mvnIndexPath: mavenIndexPath,
globalSettings: globalSettingsFile,
depsLocationCache: make(map[string]int),
includedPaths: provider.GetIncludedPathsFromConfig(config, false),
Expand All @@ -514,7 +525,7 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
// we need to do this for jdtls to correctly recognize source attachment for dep
switch svcClient.GetBuildTool() {
case maven:
err := resolveSourcesJarsForMaven(ctx, log, fernflower, config.Location, mavenSettingsFile, mavenInsecure)
err := resolveSourcesJarsForMaven(ctx, log, fernflower, config.Location, mavenSettingsFile, m2Repo, mavenInsecure)
if err != nil {
// TODO (pgaikwad): should we ignore this failure?
log.Error(err, "failed to resolve maven sources jar for location", "location", config.Location)
Expand Down Expand Up @@ -790,11 +801,16 @@ func (j *javaProvider) GetLocation(ctx context.Context, dep konveyor.Dep, file s

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

if mavenLocalRepo == "" {
log.V(5).Info("unable to discover dependency sources as maven local repo path is unknown")
return nil
}

decompileJobs := []decompileJob{}

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

m2Repo := getMavenLocalRepoPath(mavenSettings)
if m2Repo == "" {
return nil
}
for _, artifact := range artifacts {
log.WithValues("artifact", artifact).Info("sources for artifact not found, decompiling...")

Expand All @@ -837,9 +849,9 @@ func resolveSourcesJarsForMaven(ctx context.Context, log logr.Logger, fernflower
decompileJobs = append(decompileJobs, decompileJob{
artifact: artifact,
inputPath: filepath.Join(
m2Repo, groupDirs, artifactDirs, artifact.Version, jarName),
mavenLocalRepo, groupDirs, artifactDirs, artifact.Version, jarName),
outputPath: filepath.Join(
m2Repo, groupDirs, artifactDirs, artifact.Version, "decompiled", jarName),
mavenLocalRepo, groupDirs, artifactDirs, artifact.Version, "decompiled", jarName),
})
}
err = decompile(ctx, log, alwaysDecompileFilter(true), 10, decompileJobs, fernflower, "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type javaServiceClient struct {
isLocationBinary bool
mvnInsecure bool
mvnSettingsFile string
mvnLocalRepo string
mvnIndexPath string
globalSettings string
depsMutex sync.RWMutex
depsFileHash *string
Expand Down Expand Up @@ -122,6 +124,11 @@ func (p *javaServiceClient) GetAllSymbols(ctx context.Context, c javaCondition,
"location": fmt.Sprintf("%v", locationToCode[strings.ToLower(c.Referenced.Location)]),
"analysisMode": string(p.config.AnalysisMode),
"includeOpenSourceLibraries": true,
"mavenLocalRepo": p.mvnLocalRepo,
}

if p.mvnIndexPath != "" {
argumentsMap["mavenIndexPath"] = p.mvnIndexPath
}

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