Skip to content

Commit

Permalink
Add --bulk to containerless analysis (#371)
Browse files Browse the repository at this point in the history
* Add --bulk to containerless analysis

Adding --bulk option to analyze applications into the same static-report
(similar as the default containerized versions).

Fixes: https://issues.redhat.com/projects/MTA/issues/MTA-4205

Signed-off-by: Marek Aufart <[email protected]>

* Fix outputDeps and situation when missing for just some apps

Signed-off-by: Marek Aufart <[email protected]>

---------

Signed-off-by: Marek Aufart <[email protected]>
Signed-off-by: Cherry Picker <[email protected]>
  • Loading branch information
aufi authored and web-flow committed Nov 13, 2024
1 parent de5854f commit 6f5b127
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions cmd/analyze-bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"path/filepath"
"runtime"
"sort"
"strings"
"sync"

"github.com/bombsimon/logrusr/v3"
Expand Down Expand Up @@ -550,16 +551,40 @@ func (a *analyzeCommand) DependencyOutputContainerless(ctx context.Context, prov

func (a *analyzeCommand) buildStaticReportFile(ctx context.Context, staticReportPath string, depsErr bool) error {
// Prepare report args list with single input analysis
applicationName := []string{filepath.Base(a.input)}
outputAnalysis := []string{filepath.Join(a.output, "output.yaml")}
applicationNames := []string{filepath.Base(a.input)}
outputAnalyses := []string{filepath.Join(a.output, "output.yaml")}
outputDeps := []string{filepath.Join(a.output, "dependencies.yaml")}
outputJSPath := filepath.Join(staticReportPath, "output.js")

if a.bulk {
// Scan all available analysis output files to be reported
applicationNames = nil
outputAnalyses = nil
outputDeps = nil
outputFiles, err := filepath.Glob(filepath.Join(a.output, "output.yaml.*"))
if err != nil {
return err
}
for i := range outputFiles {
outputName := filepath.Base(outputFiles[i])
applicationName := strings.SplitN(outputName, "output.yaml.", 2)[1]
applicationNames = append(applicationNames, applicationName)
outputAnalyses = append(outputAnalyses, outputFiles[i])
deps := fmt.Sprintf("%s.%s", filepath.Join(a.output, "dependencies.yaml"), applicationName)
// If deps for given application are missing, empty the deps path allowing skip it in static-report
if _, err := os.Stat(deps); errors.Is(err, os.ErrNotExist) {
deps = ""
}
outputDeps = append(outputDeps, deps)
}

}

if depsErr {
outputDeps = []string{}
}
// create output.js file from analysis output.yaml
apps, err := validateFlags(outputAnalysis, applicationName, outputDeps, a.log)
apps, err := validateFlags(outputAnalyses, applicationNames, outputDeps, a.log)
if err != nil {
log.Fatalln("failed to validate flags", err)
}
Expand Down Expand Up @@ -612,8 +637,12 @@ func (a *analyzeCommand) GenerateStaticReportContainerless(ctx context.Context)
return noDepFileErr
}

staticReportAanlyzePath := filepath.Join(a.kantraDir, "static-report")
err = a.buildStaticReportFile(ctx, staticReportAanlyzePath, errors.Is(noDepFileErr, os.ErrNotExist))
if a.bulk {
a.moveResults()
}

staticReportAnalyzePath := filepath.Join(a.kantraDir, "static-report")
err = a.buildStaticReportFile(ctx, staticReportAnalyzePath, errors.Is(noDepFileErr, os.ErrNotExist))
if err != nil {
return err
}
Expand Down

0 comments on commit 6f5b127

Please sign in to comment.