Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Don't use full konveyor.Dep for dependency Extras #566

Merged
merged 2 commits into from
Apr 5, 2024
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
7 changes: 6 additions & 1 deletion provider/internal/java/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,13 @@ func (p *javaServiceClient) parseMavenDepLines(lines []string, localRepoPath, po
if err != nil {
return nil, err
}
dm := map[string]interface{}{
"name": baseDep.Name,
"version": baseDep.Version,
"extras": baseDep.Extras,
}
transitiveDep.Indirect = true
transitiveDep.Extras[baseDepKey] = konveyor.Dep{Name: baseDep.Name, Version: baseDep.Version, Extras: baseDep.Extras} // Minimum needed set of attributes for GetLocation
transitiveDep.Extras[baseDepKey] = dm // Minimum needed set of attributes for GetLocation
item.AddedDeps = append(item.AddedDeps, provider.DepDAGItem{Dep: transitiveDep})
idx += 1
}
Expand Down
104 changes: 52 additions & 52 deletions provider/internal/java/dependency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ func Test_parseMavenDepLines(t *testing.T) {
groupIdKey: "org.hamcrest",
artifactIdKey: "hamcrest-core",
pomPathKey: "pom.xml",
baseDepKey: provider.Dep{
Name: "junit.junit",
Version: "4.11",
Extras: map[string]interface{}{
baseDepKey: map[string]interface{}{
"name": "junit.junit",
"version": "4.11",
"extras": map[string]interface{}{
groupIdKey: "junit",
artifactIdKey: "junit",
pomPathKey: "pom.xml",
Expand Down Expand Up @@ -132,10 +132,10 @@ func Test_parseMavenDepLines(t *testing.T) {
groupIdKey: "io.netty",
artifactIdKey: "netty-transport-native-epoll",
pomPathKey: "pom.xml",
baseDepKey: provider.Dep{
Name: "io.fabric8.kubernetes-client",
Version: "6.0.0",
Extras: map[string]interface{}{
baseDepKey: map[string]interface{}{
"name": "io.fabric8.kubernetes-client",
"version": "6.0.0",
"extras": map[string]interface{}{
groupIdKey: "io.fabric8",
artifactIdKey: "kubernetes-client",
pomPathKey: "pom.xml",
Expand All @@ -160,10 +160,10 @@ func Test_parseMavenDepLines(t *testing.T) {
groupIdKey: "io.fabric8",
artifactIdKey: "kubernetes-httpclient-okhttp",
pomPathKey: "pom.xml",
baseDepKey: provider.Dep{
Name: "io.fabric8.kubernetes-client",
Version: "6.0.0",
Extras: map[string]interface{}{
baseDepKey: map[string]interface{}{
"name": "io.fabric8.kubernetes-client",
"version": "6.0.0",
"extras": map[string]interface{}{
groupIdKey: "io.fabric8",
artifactIdKey: "kubernetes-client",
pomPathKey: "pom.xml",
Expand All @@ -188,10 +188,10 @@ func Test_parseMavenDepLines(t *testing.T) {
groupIdKey: "com.squareup.okhttp3",
artifactIdKey: "okhttp",
pomPathKey: "pom.xml",
baseDepKey: provider.Dep{
Name: "io.fabric8.kubernetes-client",
Version: "6.0.0",
Extras: map[string]interface{}{
baseDepKey: map[string]interface{}{
"name": "io.fabric8.kubernetes-client",
"version": "6.0.0",
"extras": map[string]interface{}{
groupIdKey: "io.fabric8",
artifactIdKey: "kubernetes-client",
pomPathKey: "pom.xml",
Expand All @@ -216,10 +216,10 @@ func Test_parseMavenDepLines(t *testing.T) {
groupIdKey: "com.squareup.okio",
artifactIdKey: "okio",
pomPathKey: "pom.xml",
baseDepKey: provider.Dep{
Name: "io.fabric8.kubernetes-client",
Version: "6.0.0",
Extras: map[string]interface{}{
baseDepKey: map[string]interface{}{
"name": "io.fabric8.kubernetes-client",
"version": "6.0.0",
"extras": map[string]interface{}{
groupIdKey: "io.fabric8",
artifactIdKey: "kubernetes-client",
pomPathKey: "pom.xml",
Expand All @@ -244,10 +244,10 @@ func Test_parseMavenDepLines(t *testing.T) {
groupIdKey: "com.squareup.okhttp3",
artifactIdKey: "logging-interceptor",
pomPathKey: "pom.xml",
baseDepKey: provider.Dep{
Name: "io.fabric8.kubernetes-client",
Version: "6.0.0",
Extras: map[string]interface{}{
baseDepKey: map[string]interface{}{
"name": "io.fabric8.kubernetes-client",
"version": "6.0.0",
"extras": map[string]interface{}{
groupIdKey: "io.fabric8",
artifactIdKey: "kubernetes-client",
pomPathKey: "pom.xml",
Expand All @@ -272,10 +272,10 @@ func Test_parseMavenDepLines(t *testing.T) {
groupIdKey: "io.fabric8",
artifactIdKey: "zjsonpatch",
pomPathKey: "pom.xml",
baseDepKey: provider.Dep{
Name: "io.fabric8.kubernetes-client",
Version: "6.0.0",
Extras: map[string]interface{}{
baseDepKey: map[string]interface{}{
"name": "io.fabric8.kubernetes-client",
"version": "6.0.0",
"extras": map[string]interface{}{
groupIdKey: "io.fabric8",
artifactIdKey: "kubernetes-client",
pomPathKey: "pom.xml",
Expand Down Expand Up @@ -341,10 +341,10 @@ func Test_parseMavenDepLines(t *testing.T) {
groupIdKey: "org.hamcrest",
artifactIdKey: "hamcrest-core",
pomPathKey: "pom.xml",
baseDepKey: provider.Dep{
Name: "junit.junit",
Version: "4.11",
Extras: map[string]interface{}{
baseDepKey: map[string]interface{}{
"name": "junit.junit",
"version": "4.11",
"extras": map[string]interface{}{
groupIdKey: "junit",
artifactIdKey: "junit",
pomPathKey: "pom.xml",
Expand Down Expand Up @@ -390,10 +390,10 @@ func Test_parseMavenDepLines(t *testing.T) {
groupIdKey: "io.fabric8",
artifactIdKey: "kubernetes-httpclient-okhttp",
pomPathKey: "pom.xml",
baseDepKey: provider.Dep{
Name: "io.fabric8.kubernetes-client",
Version: "6.0.0",
Extras: map[string]interface{}{
baseDepKey: map[string]interface{}{
"name": "io.fabric8.kubernetes-client",
"version": "6.0.0",
"extras": map[string]interface{}{
groupIdKey: "io.fabric8",
artifactIdKey: "kubernetes-client",
pomPathKey: "pom.xml",
Expand All @@ -418,10 +418,10 @@ func Test_parseMavenDepLines(t *testing.T) {
groupIdKey: "com.squareup.okhttp3",
artifactIdKey: "okhttp",
pomPathKey: "pom.xml",
baseDepKey: provider.Dep{
Name: "io.fabric8.kubernetes-client",
Version: "6.0.0",
Extras: map[string]interface{}{
baseDepKey: map[string]interface{}{
"name": "io.fabric8.kubernetes-client",
"version": "6.0.0",
"extras": map[string]interface{}{
groupIdKey: "io.fabric8",
artifactIdKey: "kubernetes-client",
pomPathKey: "pom.xml",
Expand All @@ -446,10 +446,10 @@ func Test_parseMavenDepLines(t *testing.T) {
groupIdKey: "com.squareup.okio",
artifactIdKey: "okio",
pomPathKey: "pom.xml",
baseDepKey: provider.Dep{
Name: "io.fabric8.kubernetes-client",
Version: "6.0.0",
Extras: map[string]interface{}{
baseDepKey: map[string]interface{}{
"name": "io.fabric8.kubernetes-client",
"version": "6.0.0",
"extras": map[string]interface{}{
groupIdKey: "io.fabric8",
artifactIdKey: "kubernetes-client",
pomPathKey: "pom.xml",
Expand All @@ -474,10 +474,10 @@ func Test_parseMavenDepLines(t *testing.T) {
groupIdKey: "com.squareup.okhttp3",
artifactIdKey: "logging-interceptor",
pomPathKey: "pom.xml",
baseDepKey: provider.Dep{
Name: "io.fabric8.kubernetes-client",
Version: "6.0.0",
Extras: map[string]interface{}{
baseDepKey: map[string]interface{}{
"name": "io.fabric8.kubernetes-client",
"version": "6.0.0",
"extras": map[string]interface{}{
groupIdKey: "io.fabric8",
artifactIdKey: "kubernetes-client",
pomPathKey: "pom.xml",
Expand All @@ -502,10 +502,10 @@ func Test_parseMavenDepLines(t *testing.T) {
groupIdKey: "io.fabric8",
artifactIdKey: "zjsonpatch",
pomPathKey: "pom.xml",
baseDepKey: provider.Dep{
Name: "io.fabric8.kubernetes-client",
Version: "6.0.0",
Extras: map[string]interface{}{
baseDepKey: map[string]interface{}{
"name": "io.fabric8.kubernetes-client",
"version": "6.0.0",
"extras": map[string]interface{}{
groupIdKey: "io.fabric8",
artifactIdKey: "kubernetes-client",
pomPathKey: "pom.xml",
Expand Down
13 changes: 12 additions & 1 deletion provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package provider

import (
"context"
"encoding/json"
"fmt"
"os"
"regexp"
Expand Down Expand Up @@ -742,8 +743,18 @@ func (dc DependencyCondition) Evaluate(ctx context.Context, log logr.Logger, con
// this is a best-effort step and we don't want to block if resolver misbehaves
timeoutContext, cancelFunc := context.WithTimeout(context.Background(), time.Second*3)
if baseDep, ok := matchedDep.dep.Extras["baseDep"]; ok {
// convert base dep back to konveyor.Dep
konvDep := konveyor.Dep{}
depBytes, err := json.Marshal(baseDep)
if err != nil {
log.V(7).Error(err, "failed to marshal dependency", "dep", matchedDep.dep.Name)
}
err = json.Unmarshal(depBytes, &konvDep)
if err != nil {
log.V(7).Error(err, "failed to unmarshal dependency", "dep", matchedDep.dep.Name)
}
// Use "parent" baseDep location lookup for indirect dependencies
location, err := depLocationResolver.GetLocation(timeoutContext, baseDep.(konveyor.Dep))
location, err := depLocationResolver.GetLocation(timeoutContext, konvDep)
if err == nil {
incident.LineNumber = &location.StartPosition.Line
incident.CodeLocation = &location
Expand Down
Loading