Skip to content

Commit

Permalink
Do not use unnecessary file
Browse files Browse the repository at this point in the history
  • Loading branch information
jmle committed Oct 30, 2023
1 parent ca653b6 commit 1f101e0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 31 deletions.
18 changes: 1 addition & 17 deletions provider/internal/java/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,6 @@ func (p *javaServiceClient) GetDependenciesDAG(ctx context.Context) (map[uri.URI
path := p.findPom()
file := uri.File(path)

//Create temp file to use
f, err := os.CreateTemp("", "*")
if err != nil {
return nil, err
}
defer os.Remove(f.Name())

moddir := filepath.Dir(path)

pom, err := gopom.Parse(path)
Expand Down Expand Up @@ -212,16 +205,7 @@ func (p *javaServiceClient) GetDependenciesDAG(ctx context.Context) (map[uri.URI
return nil, err
}

if _, err = f.Write(mvnOutput); err != nil {
return nil, err
}

b, err := os.ReadFile(f.Name())
if err != nil {
return nil, err
}

lines := strings.Split(string(b), "\n")
lines := strings.Split(string(mvnOutput), "\n")
submoduleTrees := extractSubmoduleTrees(lines)

var pomDeps []provider.DepDAGItem
Expand Down
18 changes: 4 additions & 14 deletions provider/internal/java/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package java

import (
"bufio"
"bytes"
"context"
"fmt"
"io"
Expand Down Expand Up @@ -321,11 +322,6 @@ func (p *javaProvider) GetDependenciesDAG(ctx context.Context) (map[uri.URI][]pr
// deps that don't have sources attached and decompiles them
func resolveSourcesJars(ctx context.Context, log logr.Logger, location, mavenSettings string) error {
decompileJobs := []decompileJob{}
mvnOutput, err := os.CreateTemp("", "mvn-sources-")
if err != nil {
return err
}
defer mvnOutput.Close()

log.V(5).Info("resolving dependency sources")

Expand All @@ -348,19 +344,13 @@ func resolveSourcesJars(ctx context.Context, log logr.Logger, location, mavenSet
}
cmd := exec.CommandContext(ctx, "mvn", args...)
cmd.Dir = location
output, err := cmd.CombinedOutput()
mvnOutput, err := cmd.CombinedOutput()
if err != nil {
return err
}

if _, err = mvnOutput.Write(output); err != nil {
return err
}
if _, err = mvnOutput.Seek(0, 0); err != nil {
return err
}

artifacts, err := parseUnresolvedSources(mvnOutput)
reader := bytes.NewReader(mvnOutput)
artifacts, err := parseUnresolvedSources(reader)
if err != nil {
return err
}
Expand Down

0 comments on commit 1f101e0

Please sign in to comment.