Skip to content

Commit c287239

Browse files
authored
feat(jar): add file path (fanal#345)
1 parent 0a17306 commit c287239

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

analyzer/language/analyze.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@ func Analyze(fileType, filePath string, content []byte, parse Parser) (*analyzer
2424
return nil, nil
2525
}
2626

27-
return ToAnalysisResult(fileType, filePath, parsedLibs), nil
27+
// The file path of each library should be empty in case of lock files since they all will the same path.
28+
return ToAnalysisResult(fileType, filePath, "", parsedLibs), nil
2829
}
2930

30-
func ToAnalysisResult(fileType, filePath string, libs []godeptypes.Library) *analyzer.AnalysisResult {
31+
func ToAnalysisResult(fileType, filePath, libFilePath string, libs []godeptypes.Library) *analyzer.AnalysisResult {
3132
var pkgs []types.Package
3233
for _, lib := range libs {
3334
pkgs = append(pkgs, types.Package{
34-
Name: lib.Name,
35-
Version: lib.Version,
36-
License: lib.License,
35+
Name: lib.Name,
36+
Version: lib.Version,
37+
FilePath: libFilePath,
38+
License: lib.License,
3739
})
3840
}
3941
apps := []types.Application{{

analyzer/language/java/jar/jar.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (a javaLibraryAnalyzer) Analyze(_ context.Context, target analyzer.Analysis
3333
return nil, xerrors.Errorf("jar/war/ear parse error: %w", err)
3434
}
3535

36-
return language.ToAnalysisResult(types.Jar, target.FilePath, libs), nil
36+
return language.ToAnalysisResult(types.Jar, target.FilePath, target.FilePath, libs), nil
3737
}
3838

3939
func (a javaLibraryAnalyzer) Required(filePath string, _ os.FileInfo) bool {

analyzer/language/java/jar/jar_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ func Test_javaLibraryAnalyzer_Analyze(t *testing.T) {
2828
Type: types.Jar,
2929
FilePath: "testdata/test.war",
3030
Libraries: []types.Package{
31-
{Name: "org.glassfish:javax.el", Version: "3.0.0"},
32-
{Name: "com.fasterxml.jackson.core:jackson-databind", Version: "2.9.10.6"},
33-
{Name: "com.fasterxml.jackson.core:jackson-annotations", Version: "2.9.10"},
34-
{Name: "com.fasterxml.jackson.core:jackson-core", Version: "2.9.10"},
35-
{Name: "org.slf4j:slf4j-api", Version: "1.7.30"},
36-
{Name: "com.cronutils:cron-utils", Version: "9.1.2"},
37-
{Name: "org.apache.commons:commons-lang3", Version: "3.11"},
38-
{Name: "com.example:web-app", Version: "1.0-SNAPSHOT"},
31+
{Name: "org.glassfish:javax.el", FilePath: "testdata/test.war", Version: "3.0.0"},
32+
{Name: "com.fasterxml.jackson.core:jackson-databind", FilePath: "testdata/test.war", Version: "2.9.10.6"},
33+
{Name: "com.fasterxml.jackson.core:jackson-annotations", FilePath: "testdata/test.war", Version: "2.9.10"},
34+
{Name: "com.fasterxml.jackson.core:jackson-core", FilePath: "testdata/test.war", Version: "2.9.10"},
35+
{Name: "org.slf4j:slf4j-api", FilePath: "testdata/test.war", Version: "1.7.30"},
36+
{Name: "com.cronutils:cron-utils", FilePath: "testdata/test.war", Version: "9.1.2"},
37+
{Name: "org.apache.commons:commons-lang3", FilePath: "testdata/test.war", Version: "3.11"},
38+
{Name: "com.example:web-app", FilePath: "testdata/test.war", Version: "1.0-SNAPSHOT"},
3939
},
4040
},
4141
},

0 commit comments

Comments
 (0)