diff --git a/output/v1/konveyor/violations.go b/output/v1/konveyor/violations.go index 5c8bb22e..961e0a65 100644 --- a/output/v1/konveyor/violations.go +++ b/output/v1/konveyor/violations.go @@ -219,8 +219,10 @@ func (l *Link) cmpLess(other *Link) bool { } type Dep struct { - Name string `json:"name,omitempty" yaml:"name,omitempty"` - Version string `json:"version,omitempty" yaml:"version,omitempty"` + Name string `json:"name,omitempty" yaml:"name,omitempty"` + Version string `json:"version,omitempty" yaml:"version,omitempty"` + Classifier string `json:"classifier,omitempty" yaml:"classifier,omitempty"` + // TODO The so-called "type" is the "scope" in Maven speak Type string `json:"type,omitempty" yaml:"type,omitempty"` Indirect bool `json:"indirect,omitempty" yaml:"indirect,omitempty"` ResolvedIdentifier string `json:"resolvedIdentifier,omitempty" yaml:"resolvedIdentifier,omitempty"` diff --git a/provider/internal/java/dependency.go b/provider/internal/java/dependency.go index 1c31f21a..99954f84 100644 --- a/provider/internal/java/dependency.go +++ b/provider/internal/java/dependency.go @@ -228,6 +228,7 @@ func (p *javaServiceClient) GetDependenciesDAG(ctx context.Context) (map[uri.URI moddir := filepath.Dir(path) args := []string{ + "-B", "dependency:tree", "-Djava.net.useSystemProxies=true", } @@ -368,7 +369,6 @@ func (w *walker) walkDirForJar(path string, info fs.DirEntry, err error) error { } // parseDepString parses a java dependency string -// assumes format :::: func (p *javaServiceClient) parseDepString(dep, localRepoPath, pomPath string) (provider.Dep, error) { d := provider.Dep{} // remove all the pretty print characters. @@ -382,14 +382,30 @@ func (p *javaServiceClient) parseDepString(dep, localRepoPath, pomPath string) ( // Split string on ":" must have 5 parts. // For now we ignore Type as it appears most everything is a jar parts := strings.Split(dep, ":") - if len(parts) != 5 { + if len(parts) >= 3 { + // Its always ::: ... then + if len(parts) == 6 { + d.Classifier = parts[3] + d.Version = parts[4] + d.Type = parts[5] + } else if len(parts) == 5 { + d.Version = parts[3] + d.Type = parts[4] + } else { + p.log.Info("Cannot derive version from dependency string", "dependency", dep) + d.Version = "Unknown" + } + } else { return d, fmt.Errorf("unable to split dependency string %s", dep) } d.Name = fmt.Sprintf("%s.%s", parts[0], parts[1]) - d.Version = parts[3] - d.Type = parts[4] - fp := filepath.Join(localRepoPath, strings.Replace(parts[0], ".", "/", -1), parts[1], d.Version, fmt.Sprintf("%v-%v.jar.sha1", parts[1], d.Version)) + var fp string + if d.Classifier == "" { + fp = filepath.Join(localRepoPath, strings.Replace(parts[0], ".", "/", -1), parts[1], d.Version, fmt.Sprintf("%v-%v.jar.sha1", parts[1], d.Version)) + } else { + fp = filepath.Join(localRepoPath, strings.Replace(parts[0], ".", "/", -1), parts[1], d.Version, fmt.Sprintf("%v-%v-%v.jar.sha1", parts[1], d.Version, d.Classifier)) + } b, err := os.ReadFile(fp) if err != nil { // Log the error and continue with the next dependency. diff --git a/provider/internal/java/dependency_test.go b/provider/internal/java/dependency_test.go index adf02ee3..7846da8b 100644 --- a/provider/internal/java/dependency_test.go +++ b/provider/internal/java/dependency_test.go @@ -41,6 +41,7 @@ func Test_parseMavenDepLines(t *testing.T) { +- junit:junit:jar:4.11:test | \- org.hamcrest:hamcrest-core:jar:1.3:test +- io.fabric8:kubernetes-client:jar:6.0.0:compile +| +- io.netty:netty-transport-native-epoll:jar:linux-aarch_64:4.1.76.Final:runtime | +- io.fabric8:kubernetes-httpclient-okhttp:jar:6.0.0:runtime | | +- com.squareup.okhttp3:okhttp:jar:3.12.12:runtime | | | \- com.squareup.okio:okio:jar:1.15.0:runtime @@ -106,6 +107,26 @@ func Test_parseMavenDepLines(t *testing.T) { FileURIPrefix: "file://testdata/io/fabric8/kubernetes-client/6.0.0", }, AddedDeps: []provider.DepDAGItem{ + { + Dep: provider.Dep{ + Name: "io.netty.netty-transport-native-epoll", + Version: "4.1.76.Final", + Type: "runtime", + Classifier: "linux-aarch_64", + Indirect: true, + ResolvedIdentifier: "e1ee2a9c5f63b1b71260caf127a1e50667d62854", + Labels: []string{ + labels.AsString(provider.DepSourceLabel, "internal"), + labels.AsString(provider.DepLanguageLabel, "java"), + }, + Extras: map[string]interface{}{ + groupIdKey: "io.netty", + artifactIdKey: "netty-transport-native-epoll", + pomPathKey: "pom.xml", + }, + FileURIPrefix: "file://testdata/io/netty/netty-transport-native-epoll/4.1.76.Final", + }, + }, { Dep: provider.Dep{ Name: "io.fabric8.kubernetes-httpclient-okhttp", diff --git a/provider/internal/java/testdata/io/netty/netty-transport-native-epoll/4.1.76.Final/netty-transport-native-epoll-4.1.76.Final-linux-aarch_64.jar.sha1 b/provider/internal/java/testdata/io/netty/netty-transport-native-epoll/4.1.76.Final/netty-transport-native-epoll-4.1.76.Final-linux-aarch_64.jar.sha1 new file mode 100644 index 00000000..a435fcc0 --- /dev/null +++ b/provider/internal/java/testdata/io/netty/netty-transport-native-epoll/4.1.76.Final/netty-transport-native-epoll-4.1.76.Final-linux-aarch_64.jar.sha1 @@ -0,0 +1 @@ +e1ee2a9c5f63b1b71260caf127a1e50667d62854 \ No newline at end of file