From 791b0de967ebc521c8b8a4bb230dd0d3533dfa87 Mon Sep 17 00:00:00 2001 From: Juan Manuel Leflet Estrada Date: Thu, 8 Feb 2024 12:34:05 +0100 Subject: [PATCH] Correct usage of bytes, add ref url Signed-off-by: Juan Manuel Leflet Estrada --- provider/internal/builtin/service_client.go | 4 ++++ provider/internal/java/dependency.go | 17 ++++++++++------- provider/internal/java/service_client.go | 4 ++++ provider/provider_test.go | 8 ++++++++ provider_container_settings.json | 19 +++++-------------- 5 files changed, 31 insertions(+), 21 deletions(-) diff --git a/provider/internal/builtin/service_client.go b/provider/internal/builtin/service_client.go index 0e568f26..dbb06fce 100644 --- a/provider/internal/builtin/service_client.go +++ b/provider/internal/builtin/service_client.go @@ -80,12 +80,15 @@ func (p *builtinServiceClient) Evaluate(ctx context.Context, cap string, conditi } return response, nil case "filecontent": + p.log.V(5).Info("[JARL] Evaluating filecontent with location", "location", p.config.Location) + c := cond.Filecontent if c.Pattern == "" { return response, fmt.Errorf("could not parse provided regex pattern as string: %v", conditionInfo) } var outputBytes []byte grep := exec.Command("grep", "-o", "-n", "-R", "-P", c.Pattern, p.config.Location) + p.log.V(5).Info("[JARL] Running grep", "grepCommand", grep) outputBytes, err := grep.Output() if err != nil { if exitError, ok := err.(*exec.ExitError); ok && exitError.ExitCode() == 1 { @@ -100,6 +103,7 @@ func (p *builtinServiceClient) Evaluate(ctx context.Context, cap string, conditi matches = append(matches, strings.Split(outputString, "\n")...) } + p.log.V(5).Info("[JARL] Got matches", "matches", matches) for _, match := range matches { //TODO(fabianvf): This will not work if there is a `:` in the filename, do we care? pieces := strings.SplitN(match, ":", 3) diff --git a/provider/internal/java/dependency.go b/provider/internal/java/dependency.go index d63092ab..47324100 100644 --- a/provider/internal/java/dependency.go +++ b/provider/internal/java/dependency.go @@ -427,24 +427,27 @@ func (p *javaServiceClient) parseDepString(dep, localRepoPath, pomPath string) ( // resolveDepFilepath tries to extract a valid filepath for the dependency with either JAR or POM packaging func resolveDepFilepath(dep *provider.Dep, p *javaServiceClient, group string, artifact string, localRepoPath string) string { groupPath := strings.Replace(group, ".", "/", -1) + // Try jar packaging fp := getFilepathForPackaging(dep, localRepoPath, groupPath, artifact, "jar") b, err := os.ReadFile(fp) if err != nil { - // Try pom packaging + // Try pom packaging (see https://www.baeldung.com/maven-packaging-types#4-pom) fp := getFilepathForPackaging(dep, localRepoPath, groupPath, artifact, "pom") b, err = os.ReadFile(fp) - if err != nil { - // Log the error and continue with the next dependency. - p.log.V(5).Error(err, "error reading SHA hash file for dependency", "dep", dep.Name) - // Set some default or empty resolved identifier for the dependency. - dep.ResolvedIdentifier = "" - } + } + + if err != nil { + // Log the error and continue with the next dependency. + p.log.V(5).Error(err, "error reading SHA hash file for dependency", "dep", dep.Name) + // Set some default or empty resolved identifier for the dependency. + dep.ResolvedIdentifier = "" } else { // sometimes sha file contains name of the jar followed by the actual sha sha, _, _ := strings.Cut(string(b), " ") dep.ResolvedIdentifier = sha } + return fp } diff --git a/provider/internal/java/service_client.go b/provider/internal/java/service_client.go index d9d3e6ce..fc55cc53 100644 --- a/provider/internal/java/service_client.go +++ b/provider/internal/java/service_client.go @@ -123,6 +123,10 @@ func (p *javaServiceClient) GetAllSymbols(ctx context.Context, query, location s p.log.Error(err, "unable to ask for tackle rule entry") } + //for _, ref := range refs { + // p.log.Info(fmt.Sprintf("%v", ref.Location.Value)) + //} + // return refs } diff --git a/provider/provider_test.go b/provider/provider_test.go index 2a2045e1..bcc0950b 100644 --- a/provider/provider_test.go +++ b/provider/provider_test.go @@ -115,6 +115,14 @@ func Test_dependencyConditionEvaluation(t *testing.T) { dependencies: []*Dep{{Name: "DE", Version: "10.0.0"}}, shouldErr: true, }, + { + title: "Valid weird version should match", + name: "java.jws.jsr188-api", + lowerbound: "0.0.0", + dependencies: []*Dep{{Name: "java.jws.jsr188-api", Version: "1.0-MR1"}}, + shouldErr: false, + shouldMatch: true, + }, } for _, tt := range tests { diff --git a/provider_container_settings.json b/provider_container_settings.json index f1a9d662..b4b1435c 100644 --- a/provider_container_settings.json +++ b/provider_container_settings.json @@ -1,5 +1,6 @@ [ { +<<<<<<< Updated upstream "name": "go", "binaryPath": "/usr/bin/generic-external-provider", "initConfig": [{ @@ -41,20 +42,13 @@ }] }, { +======= +>>>>>>> Stashed changes "name": "java", "binaryPath": "/jdtls/bin/jdtls", "initConfig": [ { - "location": "examples/java", - "providerSpecificConfig": { - "bundles": "/jdtls/java-analyzer-bundle/java-analyzer-bundle.core/target/java-analyzer-bundle.core-1.0.0-SNAPSHOT.jar", - "depOpenSourceLabelsFile": "/usr/local/etc/maven.default.index", - "lspServerPath": "/jdtls/bin/jdtls" - }, - "analysisMode": "source-only" - }, - { - "location": "examples/customers-tomcat-legacy", + "location": "/java-app", "providerSpecificConfig": { "lspServerPath": "/jdtls/bin/jdtls", "depOpenSourceLabelsFile": "/usr/local/etc/maven.default.index", @@ -67,10 +61,7 @@ { "name": "builtin", "initConfig": [ - {"location": "examples/java/"}, - {"location": "examples/python/"}, - {"location": "examples/golang/"}, - {"location": "examples/customers-tomcat-legacy/"} + {"location": "/java-app"} ] } ]