File tree Expand file tree Collapse file tree 2 files changed +12
-12
lines changed
fanal/analyzer/language/java/jar Expand file tree Collapse file tree 2 files changed +12
-12
lines changed Original file line number Diff line number Diff line change 6
6
"os"
7
7
"path/filepath"
8
8
"strings"
9
- "sync"
10
9
11
10
"golang.org/x/xerrors"
12
11
@@ -35,7 +34,6 @@ var requiredExtensions = []string{
35
34
36
35
// javaLibraryAnalyzer analyzes jar/war/ear/par files
37
36
type javaLibraryAnalyzer struct {
38
- once sync.Once
39
37
client * javadb.DB
40
38
slow bool
41
39
}
@@ -49,18 +47,13 @@ func newJavaLibraryAnalyzer(options analyzer.AnalyzerOptions) (analyzer.PostAnal
49
47
func (a * javaLibraryAnalyzer ) PostAnalyze (ctx context.Context , input analyzer.PostAnalysisInput ) (* analyzer.AnalysisResult , error ) {
50
48
// TODO: think about the sonatype API and "--offline"
51
49
var err error
52
- a .once .Do (func () {
53
- log .Logger .Info ("JAR files found" )
54
- a .client , err = javadb .NewClient ()
55
- if err != nil {
56
- log .Logger .Errorf ("Unable to initialize the Java DB: %s" , err )
57
- return
58
- }
59
- log .Logger .Info ("Analyzing JAR files takes a while..." )
60
- })
50
+ log .Logger .Info ("JAR files found" )
51
+ a .client , err = javadb .NewClient ()
61
52
if err != nil {
62
- return nil , err
53
+ return nil , xerrors . Errorf ( "Unable to initialize the Java DB: %s" , err )
63
54
}
55
+ defer func () { _ = a .client .Close () }()
56
+ log .Logger .Info ("Analyzing JAR files takes a while..." )
64
57
65
58
// Skip analyzing JAR files as the nil client means the Java DB was not downloaded successfully.
66
59
if a .client == nil {
Original file line number Diff line number Diff line change @@ -170,3 +170,10 @@ func (d *DB) SearchByArtifactID(artifactID string) (string, error) {
170
170
171
171
return groupID , nil
172
172
}
173
+
174
+ func (d * DB ) Close () error {
175
+ if d == nil {
176
+ return nil
177
+ }
178
+ return d .driver .Close ()
179
+ }
You can’t perform that action at this time.
0 commit comments