Skip to content

Commit

Permalink
trim dep prefixes outside of internal provider
Browse files Browse the repository at this point in the history
Signed-off-by: Emily McMullan <emcmulla@redhat.com>
  • Loading branch information
eemcmullan committed Mar 27, 2024
1 parent 1f18a90 commit b2beb66
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
48 changes: 45 additions & 3 deletions cmd/analyzer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -443,10 +444,17 @@ func DependencyOutput(ctx context.Context, providers map[string]provider.Interna
continue
}
for u, ds := range deps {
var outputDepDag []konveyor.DepDAGItem
// trim m2 repo prefix for java deps
if name == "java" {
outputDepDag = trimDagItemPrefixes(ds)
} else {
outputDepDag = ds
}
depsTree = append(depsTree, konveyor.DepsTreeItem{
FileURI: string(u),
Provider: name,
Dependencies: ds,
Dependencies: outputDepDag,
})
}
} else {
Expand All @@ -456,11 +464,17 @@ func DependencyOutput(ctx context.Context, providers map[string]provider.Interna
continue
}
for u, ds := range deps {
newDeps := ds
var outputDeps []*konveyor.Dep
// trim m2 repo prefix for java deps
if name == "java" {
outputDeps = trimFlatDepPrefixes(ds)
} else {
outputDeps = ds
}
depsFlat = append(depsFlat, konveyor.DepsFlatItem{
Provider: name,
FileURI: string(u),
Dependencies: newDeps,
Dependencies: outputDeps,
})
}
}
Expand Down Expand Up @@ -503,3 +517,31 @@ func DependencyOutput(ctx context.Context, providers map[string]provider.Interna
}

}

func trimFlatDepPrefixes(deps []*konveyor.Dep) []*konveyor.Dep {
for _, dep := range deps {
dep.FileURIPrefix = fmt.Sprintf("file:///%s", filepath.Join(strings.Replace(
dep.Extras["groupId"].(string), ".", "/", -1), dep.Extras["artifactId"].(string), dep.Version))
}
return deps
}

func trimDagItemPrefixes(depItem []konveyor.DepDAGItem) []konveyor.DepDAGItem {
newDagItem := make([]konveyor.DepDAGItem, len(depItem))
for i, item := range depItem {
d := item.Dep
newDagItem[i] = item
d.FileURIPrefix = fmt.Sprintf("file:///%s", filepath.Join(strings.Replace(
d.Extras["groupId"].(string), ".", "/", -1), d.Extras["artifactId"].(string), d.Version))

newDagItem[i].Dep.FileURIPrefix = d.FileURIPrefix

for j, de := range item.AddedDeps {
de.Dep.FileURIPrefix = fmt.Sprintf("file:///%s", filepath.Join(strings.Replace(
de.Dep.Extras["groupId"].(string), ".", "/", -1), de.Dep.Extras["artifactId"].(string), de.Dep.Version))

newDagItem[i].AddedDeps[j].Dep.FileURIPrefix = de.Dep.FileURIPrefix
}
}
return newDagItem
}
2 changes: 1 addition & 1 deletion provider/internal/java/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func (p *javaServiceClient) parseDepString(dep, localRepoPath, pomPath string) (
fp := resolveDepFilepath(&d, p, group, artifact, localRepoPath)

d.Labels = addDepLabels(p.depToLabels, d.Name)
d.FileURIPrefix = fmt.Sprintf("file://%v", filepath.Dir(strings.TrimPrefix(fp, localRepoPath)))
d.FileURIPrefix = fmt.Sprintf("file://%v", filepath.Dir(fp))

d.Extras = map[string]interface{}{
groupIdKey: group,
Expand Down

0 comments on commit b2beb66

Please sign in to comment.