mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-05 20:40:16 -08:00
feat(jar): add file path (fanal#345)
This commit is contained in:
@@ -24,16 +24,18 @@ func Analyze(fileType, filePath string, content []byte, parse Parser) (*analyzer
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return ToAnalysisResult(fileType, filePath, parsedLibs), nil
|
||||
// The file path of each library should be empty in case of lock files since they all will the same path.
|
||||
return ToAnalysisResult(fileType, filePath, "", parsedLibs), nil
|
||||
}
|
||||
|
||||
func ToAnalysisResult(fileType, filePath string, libs []godeptypes.Library) *analyzer.AnalysisResult {
|
||||
func ToAnalysisResult(fileType, filePath, libFilePath string, libs []godeptypes.Library) *analyzer.AnalysisResult {
|
||||
var pkgs []types.Package
|
||||
for _, lib := range libs {
|
||||
pkgs = append(pkgs, types.Package{
|
||||
Name: lib.Name,
|
||||
Version: lib.Version,
|
||||
License: lib.License,
|
||||
Name: lib.Name,
|
||||
Version: lib.Version,
|
||||
FilePath: libFilePath,
|
||||
License: lib.License,
|
||||
})
|
||||
}
|
||||
apps := []types.Application{{
|
||||
|
||||
@@ -33,7 +33,7 @@ func (a javaLibraryAnalyzer) Analyze(_ context.Context, target analyzer.Analysis
|
||||
return nil, xerrors.Errorf("jar/war/ear parse error: %w", err)
|
||||
}
|
||||
|
||||
return language.ToAnalysisResult(types.Jar, target.FilePath, libs), nil
|
||||
return language.ToAnalysisResult(types.Jar, target.FilePath, target.FilePath, libs), nil
|
||||
}
|
||||
|
||||
func (a javaLibraryAnalyzer) Required(filePath string, _ os.FileInfo) bool {
|
||||
|
||||
@@ -28,14 +28,14 @@ func Test_javaLibraryAnalyzer_Analyze(t *testing.T) {
|
||||
Type: types.Jar,
|
||||
FilePath: "testdata/test.war",
|
||||
Libraries: []types.Package{
|
||||
{Name: "org.glassfish:javax.el", Version: "3.0.0"},
|
||||
{Name: "com.fasterxml.jackson.core:jackson-databind", Version: "2.9.10.6"},
|
||||
{Name: "com.fasterxml.jackson.core:jackson-annotations", Version: "2.9.10"},
|
||||
{Name: "com.fasterxml.jackson.core:jackson-core", Version: "2.9.10"},
|
||||
{Name: "org.slf4j:slf4j-api", Version: "1.7.30"},
|
||||
{Name: "com.cronutils:cron-utils", Version: "9.1.2"},
|
||||
{Name: "org.apache.commons:commons-lang3", Version: "3.11"},
|
||||
{Name: "com.example:web-app", Version: "1.0-SNAPSHOT"},
|
||||
{Name: "org.glassfish:javax.el", FilePath: "testdata/test.war", Version: "3.0.0"},
|
||||
{Name: "com.fasterxml.jackson.core:jackson-databind", FilePath: "testdata/test.war", Version: "2.9.10.6"},
|
||||
{Name: "com.fasterxml.jackson.core:jackson-annotations", FilePath: "testdata/test.war", Version: "2.9.10"},
|
||||
{Name: "com.fasterxml.jackson.core:jackson-core", FilePath: "testdata/test.war", Version: "2.9.10"},
|
||||
{Name: "org.slf4j:slf4j-api", FilePath: "testdata/test.war", Version: "1.7.30"},
|
||||
{Name: "com.cronutils:cron-utils", FilePath: "testdata/test.war", Version: "9.1.2"},
|
||||
{Name: "org.apache.commons:commons-lang3", FilePath: "testdata/test.war", Version: "3.11"},
|
||||
{Name: "com.example:web-app", FilePath: "testdata/test.war", Version: "1.0-SNAPSHOT"},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user