Skip to content

Commit

Permalink
konveyor#392 Analyze all (yet known) formats of Maven dependency grap…
Browse files Browse the repository at this point in the history
…h elements

They may have more or less than fife elements when split up at the colon.

Signed-off-by: Gerd Aschemann <gerd@aschemann.net>
  • Loading branch information
ascheman committed Nov 20, 2023
1 parent fbb596e commit 4f0e59c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
6 changes: 4 additions & 2 deletions output/v1/konveyor/violations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
24 changes: 20 additions & 4 deletions provider/internal/java/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <groupId>:<artifactId>:<Packaging>: ... 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.
Expand Down
21 changes: 21 additions & 0 deletions provider/internal/java/dependency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e1ee2a9c5f63b1b71260caf127a1e50667d62854

0 comments on commit 4f0e59c

Please sign in to comment.