Skip to content

Commit

Permalink
CP #330 - generate static report if no deps (#331)
Browse files Browse the repository at this point in the history
generate static report if no deps output

Signed-off-by: Emily McMullan <emcmulla@redhat.com>
  • Loading branch information
eemcmullan committed Sep 16, 2024
1 parent 8e31a36 commit d6b06f3
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,15 @@ func (a *analyzeCommand) GenerateStaticReport(ctx context.Context) error {
if a.skipStaticReport {
return nil
}
// it's possible for dependency analysis to fail
// in this case we still want to generate a static report for successful source analysis
_, noDepFileErr := os.Stat(filepath.Join(a.output, "dependencies.yaml"))
if errors.Is(noDepFileErr, os.ErrNotExist) {
a.log.Info("unable to get dependency output in static report. generating static report from source analysis only")
} else if noDepFileErr != nil && !errors.Is(noDepFileErr, os.ErrNotExist) {
return noDepFileErr
}

volumes := map[string]string{
a.input: SourceMountPath,
a.output: OutputPath,
Expand Down Expand Up @@ -1591,23 +1600,26 @@ func (a *analyzeCommand) GenerateStaticReport(ctx context.Context) error {
outputAnalyses = append(outputAnalyses, strings.ReplaceAll(outputFiles[i], a.output, OutputPath)) // re-map paths to container mounts
outputDeps = append(outputDeps, fmt.Sprintf("%s.%s", DepsOutputMountPath, applicationName))
}
for i := range depFiles {
_, depErr := os.Stat(depFiles[i])
if a.mode != string(provider.FullAnalysisMode) || depErr != nil {
// Remove not existing dependency files from statis report generator list
outputDeps[i] = ""

if !errors.Is(noDepFileErr, os.ErrNotExist) {
for i := range depFiles {
_, depErr := os.Stat(depFiles[i])
if a.mode != string(provider.FullAnalysisMode) || depErr != nil {
// Remove not existing dependency files from statis report generator list
outputDeps[i] = ""
}
}
staticReportArgs = append(staticReportArgs,
fmt.Sprintf("--deps-output-list=%s", strings.Join(outputDeps, ",")))
}
staticReportArgs = append(staticReportArgs,
fmt.Sprintf("--deps-output-list=%s", strings.Join(outputDeps, ",")))
}

staticReportArgs = append(staticReportArgs,
fmt.Sprintf("--analysis-output-list=%s", strings.Join(outputAnalyses, ",")),
fmt.Sprintf("--application-name-list=%s", strings.Join(applicationNames, ",")))

// as of now, only java and go providers has dep capability
if !a.bulk {
if !a.bulk && !errors.Is(noDepFileErr, os.ErrNotExist) {
_, hasJava := a.providersMap[javaProvider]
_, hasGo := a.providersMap[goProvider]
if (hasJava || hasGo) && a.mode == string(provider.FullAnalysisMode) && len(a.providersMap) == 1 {
Expand Down

0 comments on commit d6b06f3

Please sign in to comment.