Skip to content

Commit

Permalink
Correct usage of bytes, add ref url
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Manuel Leflet Estrada <jleflete@redhat.com>
  • Loading branch information
jmle committed Feb 8, 2024
1 parent 5af5aac commit 791b0de
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 21 deletions.
4 changes: 4 additions & 0 deletions provider/internal/builtin/service_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
17 changes: 10 additions & 7 deletions provider/internal/java/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 4 additions & 0 deletions provider/internal/java/service_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 8 additions & 0 deletions provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 5 additions & 14 deletions provider_container_settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[
{
<<<<<<< Updated upstream
"name": "go",
"binaryPath": "/usr/bin/generic-external-provider",
"initConfig": [{
Expand Down Expand Up @@ -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",
Expand All @@ -67,10 +61,7 @@
{
"name": "builtin",
"initConfig": [
{"location": "examples/java/"},
{"location": "examples/python/"},
{"location": "examples/golang/"},
{"location": "examples/customers-tomcat-legacy/"}
{"location": "/java-app"}
]
}
]

0 comments on commit 791b0de

Please sign in to comment.