Skip to content

Commit

Permalink
close java-db client (#5273)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyLewen committed Oct 2, 2023
1 parent eb60e9f commit 18d1687
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
17 changes: 5 additions & 12 deletions pkg/fanal/analyzer/language/java/jar/jar.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"os"
"path/filepath"
"strings"
"sync"

"golang.org/x/xerrors"

Expand Down Expand Up @@ -35,7 +34,6 @@ var requiredExtensions = []string{

// javaLibraryAnalyzer analyzes jar/war/ear/par files
type javaLibraryAnalyzer struct {
once sync.Once
client *javadb.DB
slow bool
}
Expand All @@ -49,18 +47,13 @@ func newJavaLibraryAnalyzer(options analyzer.AnalyzerOptions) (analyzer.PostAnal
func (a *javaLibraryAnalyzer) PostAnalyze(ctx context.Context, input analyzer.PostAnalysisInput) (*analyzer.AnalysisResult, error) {
// TODO: think about the sonatype API and "--offline"
var err error
a.once.Do(func() {
log.Logger.Info("JAR files found")
a.client, err = javadb.NewClient()
if err != nil {
log.Logger.Errorf("Unable to initialize the Java DB: %s", err)
return
}
log.Logger.Info("Analyzing JAR files takes a while...")
})
log.Logger.Info("JAR files found")
a.client, err = javadb.NewClient()
if err != nil {
return nil, err
return nil, xerrors.Errorf("Unable to initialize the Java DB: %s", err)
}
defer func() { _ = a.client.Close() }()
log.Logger.Info("Analyzing JAR files takes a while...")

// Skip analyzing JAR files as the nil client means the Java DB was not downloaded successfully.
if a.client == nil {
Expand Down
7 changes: 7 additions & 0 deletions pkg/javadb/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,10 @@ func (d *DB) SearchByArtifactID(artifactID string) (string, error) {

return groupID, nil
}

func (d *DB) Close() error {
if d == nil {
return nil
}
return d.driver.Close()
}

0 comments on commit 18d1687

Please sign in to comment.